/* YT Scrubber — a small token set plus component classes. Extend this rather than inventing a
   per-page styling system; it is deliberately not a framework. */

:root {
    --accent: #134a8e;
    --accent-contrast: #ffffff;

    --bg: #f4f6f7;
    --surface: #ffffff;
    --surface-2: #eef1f3;
    --border: #d9e0e3;

    --text: #16202a;
    --text-muted: #5c6b76;
    --danger: #b3261e;
    --danger-bg: #fdecea;
    --warn: #7a5300;
    --warn-bg: #fdf3d8;

    --radius: 10px;
    --gap: 1rem;
    --topbar-height: 3.25rem;
    --shadow: 0 1px 2px rgb(16 32 42 / 8%), 0 2px 8px rgb(16 32 42 / 6%);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #10161b;
        --surface: #182027;
        --surface-2: #212b33;
        --border: #2d3944;

        --text: #e7edf1;
        --text-muted: #9aabb7;
        --danger: #f2b8b5;
        --danger-bg: #3a1c1a;
        --warn: #ecd08a;
        --warn-bg: #33290f;
        --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 2px 8px rgb(0 0 0 / 30%);
    }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }

a { color: var(--accent); }

.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }
.empty { padding: 2rem 0; text-align: center; }

/* ----------------------------------------------------------------- layout */

.app-shell { min-height: 100dvh; }

.app-main {
    max-width: 52rem;
    margin: 0 auto;
    /* Clears the fixed topbar, and the iOS home indicator at the bottom. */
    padding: calc(var(--topbar-height) + var(--gap)) var(--gap)
             calc(var(--gap) + env(safe-area-inset-bottom));
}

.blank-layout { min-height: 100dvh; display: grid; place-items: center; padding: var(--gap); }

.page > * + * { margin-top: var(--gap); }

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--gap);
    flex-wrap: wrap;
}

.page-header h1 { margin: 0; }

/* ----------------------------------------------------------------- topbar */

.topbar {
    position: fixed;
    inset: 0 0 auto;
    z-index: 10;
    height: calc(var(--topbar-height) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) var(--gap) 0;
    display: flex;
    align-items: center;
    gap: var(--gap);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 650;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
}

.brand-mark { color: var(--accent); }

.topnav { display: flex; gap: 0.25rem; margin-right: auto; }

.topnav-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.7rem;
    border-radius: var(--radius);
    color: var(--text-muted);
    text-decoration: none;
    white-space: nowrap;
}

.topnav-item:hover { background: var(--surface-2); color: var(--text); }
.topnav-item.active { background: var(--surface-2); color: var(--accent); font-weight: 600; }

.account { display: flex; align-items: center; gap: 0.5rem; }

.account-name {
    max-width: 12ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Keep the nav labels as long as possible; drop the account name first, then the labels. */
@media (max-width: 30rem) { .account-name { display: none; } }
@media (max-width: 22rem) { .topnav-label { display: none; } .brand-text { display: none; } }

/* ----------------------------------------------------------------- buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 0.9rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-weight: 550;
    text-decoration: none;
    cursor: pointer;
    /* Below this, iOS Safari zooms the page on tap. */
    min-height: 2.5rem;
}

.btn:hover:not(:disabled) { filter: brightness(0.97); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn.primary { background: var(--accent); color: var(--accent-contrast); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.small { padding: 0.3rem 0.6rem; min-height: 2rem; font-size: 0.875rem; }

/* ----------------------------------------------------------------- cards */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: var(--gap);
}

.card-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; }

.card-list .card { display: flex; align-items: flex-start; gap: var(--gap); }

.card-main { flex: 1; min-width: 0; }
.card-title { margin: 0 0 0.25rem; }
.card-body { margin: 0 0 0.25rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.card-actions { display: flex; gap: 0.35rem; flex-shrink: 0; }

/* ----------------------------------------------------------------- forms */

.form { display: grid; gap: var(--gap); }

.field { display: grid; gap: 0.3rem; }
.field > span { font-weight: 550; font-size: 0.9rem; }

.input {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    /* 16px minimum, or iOS Safari zooms on focus. */
    font: inherit;
}

.input:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

textarea.input { resize: vertical; }

/* The config editor. Monospace because it is JSON, and tab-size because pasted config is indented. */
textarea.input.code {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.45;
    tab-size: 2;
    white-space: pre;
    overflow-wrap: normal;
    overflow-x: auto;
}

.field-row { display: flex; gap: var(--gap); flex-wrap: wrap; }
.field-row > .field { flex: 1 1 12rem; }

.check { display: flex; align-items: center; gap: 0.5rem; font-weight: 550; font-size: 0.9rem; }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }

.form-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.validation-message { color: var(--danger); font-size: 0.85rem; }
.invalid { border-color: var(--danger); }

.alert {
    padding: 0.7rem var(--gap);
    border-radius: var(--radius);
    border: 1px solid transparent;
}

.alert.error { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.alert.warn { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }

/* Long plugin errors — an upstream stack or a JSON parse message — must not stretch the layout. */
.alert { overflow-wrap: anywhere; }

/* ----------------------------------------------------------------- status */

.centered-status {
    display: grid;
    place-items: center;
    gap: 0.75rem;
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-muted);
}

.spinner {
    width: 2rem;
    height: 2rem;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    .spinner { animation-duration: 3s; }
    *, *::before, *::after { transition-duration: 0.01ms !important; }
}

/* ----------------------------------------------------------------- hits */

/* A hit is a video, so it gets a thumbnail. 16:9 fixed so a slow image load does not reflow the
   list — nothing is more annoying than tapping a row that moves as the pictures arrive. */
.hit-thumb {
    flex: 0 0 auto;
    width: 8.5rem;
    aspect-ratio: 16 / 9;
    border-radius: calc(var(--radius) - 2px);
    background: var(--surface-2);
    object-fit: cover;
    display: block;
}

@media (max-width: 34rem) {
    .card-list .card { flex-wrap: wrap; }
    .hit-thumb { width: 100%; }
    .card-actions { width: 100%; }
}

.hit-label {
    font-weight: 650;
    margin: 0 0 0.15rem;
    font-size: 1rem;
}

.hit-title {
    margin: 0 0 0.3rem;
    overflow-wrap: anywhere;
}

.hit-meta {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.hit-meta > * + *::before { content: "·"; margin-right: 0.5rem; }

/* Why the plugin matched. Collapsed by default because it is diagnostic, not the point — but one
   tap away, because a scrubber matching the wrong thing is the failure you need to explain. */
.hit-reason { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.35rem; }
.hit-reason summary { cursor: pointer; }

/* The unseen marker. A left border rather than a background: it survives dark mode without
   fighting the card surface, and it does not reduce the contrast of the text on top of it. */
.card.unseen { border-left: 3px solid var(--accent); }

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.4rem;
    padding: 0 0.35rem;
    height: 1.4rem;
    border-radius: 0.7rem;
    background: var(--accent);
    color: var(--accent-contrast);
    font-size: 0.75rem;
    font-weight: 650;
}

.badge.quiet { background: var(--surface-2); color: var(--text-muted); }

.filters { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}

.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }

/* ----------------------------------------------------------------- scrubbers */

.scrubber-state { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.dot {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: var(--text-muted);
    flex: 0 0 auto;
}

.dot.on { background: #1e8e3e; }
.dot.off { background: var(--text-muted); }
.dot.bad { background: var(--danger); }

.stat-row { display: flex; gap: var(--gap); flex-wrap: wrap; color: var(--text-muted); font-size: 0.85rem; }

/* --------------------------------------------- boot + error UI (framework) */

/* Shown by index.html before the WebAssembly runtime starts; the framework drives the variables. */
.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 20vh auto 1rem;
}

.loading-progress circle {
    fill: none;
    stroke: var(--surface-2);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--accent);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    text-align: center;
    color: var(--text-muted);
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}

#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    z-index: 1000;
    padding: 0.7rem var(--gap);
    background: #ffe9a8;
    color: #16202a;
    box-shadow: 0 -1px 4px rgb(0 0 0 / 20%);
}

#blazor-error-ui .dismiss { float: right; cursor: pointer; }
