/* Design tokens. Dark by default; light when the OS asks for it. */
:root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1f2630;
    --border: #2d3540;
    --text: #e6edf3;
    --muted: #8b949e;
    --accent: #4fb3ff;
    --accent-strong: #1f8fe0;
    --mark: rgba(79, 179, 255, .25);
    --danger: #f2545b;
    --ok: #3fb950;
    --radius: 10px;
    --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
    color-scheme: dark;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f6f8fa;
        --surface: #ffffff;
        --surface-2: #eef1f4;
        --border: #d0d7de;
        --text: #1f2328;
        --muted: #59636e;
        --accent: #0969da;
        --accent-strong: #0550ae;
        --mark: rgba(9, 105, 218, .15);
        color-scheme: light;
    }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 2px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); }

/* Controls */
.input {
    background: var(--surface); color: var(--text); border: 1px solid var(--border);
    border-radius: var(--radius); padding: .55rem .8rem; font: inherit; min-width: 0;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.input-lg { font-size: 1.05rem; padding: .8rem 1rem; flex: 1; }
.btn {
    background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
    border-radius: var(--radius); padding: .5rem .9rem; font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn-lg { padding: .8rem 1.4rem; }
.btn-danger:hover, .btn-danger.armed { border-color: var(--danger); color: var(--danger); }
.btn-link { background: none; border: none; color: var(--accent); padding: .25rem 0; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.seg { background: var(--surface); color: var(--muted); border: 0; padding: .45rem .9rem; font: inherit; cursor: pointer; }
.seg.active { background: var(--accent-strong); color: #fff; }
.field { display: inline-flex; align-items: center; gap: .4rem; color: var(--muted); }
.badge {
    display: inline-block; font-size: .78rem; padding: .05rem .5rem; border-radius: 999px;
    background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}
.badge-info { color: var(--accent); border-color: var(--accent); }
.badge-ok { color: var(--ok); border-color: var(--ok); }
.badge-error { color: var(--danger); border-color: var(--danger); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }

/* Search */
.brand { font-weight: 700; color: var(--text); letter-spacing: .01em; }
.hero {
    min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 1rem; padding: 1rem; text-align: center;
}
.hero-title { font-size: 2.4rem; margin: 0; }
.hero .search-bar { width: min(720px, 100%); }
.search-bar { display: flex; flex-direction: column; gap: .6rem; }
.search-input { display: flex; gap: .5rem; }
.search-options { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }
.topbar {
    position: sticky; top: 0; z-index: 5; display: flex; gap: 1.5rem; align-items: center;
    padding: .8rem max(1rem, calc((100vw - 980px) / 2)); background: var(--bg); border-bottom: 1px solid var(--border);
}
.topbar .search-bar { flex: 1; }
.results { max-width: 980px; margin: 0 auto; padding: 1rem; display: flex; flex-direction: column; gap: 1rem; }
.summary { margin: 0; }
.loading { opacity: .5; }

.video-card { display: grid; grid-template-columns: 220px 1fr; gap: 1rem; padding: 1rem; }
.thumb { position: relative; align-self: start; }
.thumb img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; display: block; background: var(--surface-2); }
.duration {
    position: absolute; right: 6px; bottom: 6px; background: rgba(0, 0, 0, .8); color: #fff;
    font-size: .75rem; padding: 0 .35rem; border-radius: 4px;
}
.video-title { font-weight: 600; font-size: 1.05rem; color: var(--text); }
.meta { display: flex; flex-wrap: wrap; gap: .3rem 1rem; color: var(--muted); font-size: .85rem; margin: .25rem 0 .6rem; }
.matches { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.matches li { display: flex; gap: .7rem; align-items: baseline; }
.timestamp {
    font-variant-numeric: tabular-nums; font-size: .8rem; padding: .05rem .45rem; border-radius: 6px;
    background: var(--surface-2); color: var(--accent); flex-shrink: 0; cursor: pointer;
}
.snippet { color: var(--muted); }
.snippet mark { color: var(--text); }
.pagination { display: flex; justify-content: center; align-items: center; gap: 1rem; padding: 1rem 0; }

/* Video page */
.video-page { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.video-page.is-short { grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); }
.video-main { position: sticky; top: 5.5rem; display: flex; flex-direction: column; gap: .6rem; }
.video-main h1 { margin: .4rem 0 0; font-size: 1.3rem; }
.player { aspect-ratio: 16 / 9; width: 100%; background: #000; border-radius: var(--radius); overflow: hidden; }
.player.short { aspect-ratio: 9 / 16; width: auto; max-height: 72vh; margin: 0 auto; }
.player iframe, .player > div { width: 100%; height: 100%; border: 0; display: block; }
.player.unplayable { position: relative; display: grid; place-items: center; }
.player.unplayable img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .35; }
.unplayable-text { position: relative; display: flex; flex-direction: column; align-items: center; gap: .5rem;
    text-align: center; padding: 1rem; color: #fff; max-width: 28rem; }
.tracking-note { margin: 0; }
.timeline { position: relative; height: 14px; border-radius: 999px; background: var(--surface-2); cursor: pointer; }
.timeline .tick { position: absolute; top: 2px; width: 3px; height: 10px; margin-left: -1px; border-radius: 2px; background: #d29922; }
.timeline .playhead { position: absolute; top: -3px; width: 4px; height: 20px; margin-left: -2px; border-radius: 2px;
    background: var(--accent); box-shadow: 0 0 0 2px var(--bg); }
.tags { display: flex; flex-wrap: wrap; gap: .35rem; }

.transcript { padding: 1rem; display: flex; flex-direction: column; gap: .6rem; position: relative; }
.transcript-tools { display: flex; gap: .4rem; align-items: center; }
.transcript-tools .input { flex: 1; }
.match-count { white-space: nowrap; font-variant-numeric: tabular-nums; }
.transcript-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.transcript-head h2 { margin: 0; }
.transcript-scroll { position: relative; max-height: calc(100vh - 16rem); min-height: 12rem; overflow-y: auto;
    overscroll-behavior: contain; border-radius: 8px; }
.transcript-scroll:focus-visible { outline: 2px solid var(--accent); }
.transcript-lines { list-style: none; margin: 0; padding: 0; }
.transcript-lines li { position: relative; display: flex; gap: .6rem; padding: .3rem .5rem; border-radius: 6px;
    cursor: pointer; overflow: hidden; transition: background-color .15s; }
.transcript-lines li:hover { background: var(--surface-2); }
.transcript-lines li.match .line-text { background: var(--mark); border-radius: 3px; }
.transcript-lines li.active { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.transcript-lines li.active .line-text { color: var(--text); font-weight: 600; }
/* Width is set every animation frame from the player's position: no CSS transition (it would lag). */
.transcript-lines li.active::after { content: ""; position: absolute; left: 0; bottom: 0; height: 2px;
    width: var(--progress, 0%); background: var(--accent); }
.back-to-current { position: absolute; bottom: 1.4rem; left: 50%; transform: translateX(-50%); box-shadow: 0 6px 20px rgba(0,0,0,.35); }
@media (prefers-reduced-motion: reduce) {
    .transcript-lines li { transition: none; }
}

/* Admin */
.admin { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
    display: flex; flex-direction: column; gap: 1.5rem; padding: 1.25rem; background: var(--surface);
    border-right: 1px solid var(--border);
}
.sidebar nav { display: flex; flex-direction: column; gap: .2rem; flex: 1; }
.nav-link { color: var(--muted); padding: .45rem .7rem; border-radius: 8px; }
.nav-link:hover { background: var(--surface-2); text-decoration: none; }
.nav-link.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.admin-main { padding: 1.5rem 2rem; min-width: 0; display: flex; flex-direction: column; gap: 1rem; }
.inline-form { display: flex; gap: .5rem; max-width: 720px; }
.inline-form .input { flex: 1; }
.inline-form > .muted { align-self: center; }
.section { padding: 1.25rem; display: flex; flex-direction: column; gap: .8rem; }
.section h2 { margin: 0; }
.section p { margin: 0; }
.stack { display: flex; flex-direction: column; gap: .6rem; max-width: 720px; }
.checks { display: flex; flex-wrap: wrap; gap: .4rem .9rem; }
.check { display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; }
.actions.start { justify-content: flex-start; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 1rem; }
.tile { padding: 1rem 1.2rem; display: flex; flex-direction: column; }
.tile-value { font-size: 1.6rem; font-weight: 700; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: .55rem .8rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 500; font-size: .85rem; background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.actions { display: flex; gap: .4rem; justify-content: flex-end; }
.center { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; padding: 1rem; }
.login { padding: 2rem; display: flex; flex-direction: column; gap: .8rem; width: min(360px, 100%); }

/* Toasts */
.toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 10; }
.toast {
    background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--ok);
    border-radius: 8px; padding: .6rem 1rem; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); max-width: 380px;
}
.toast-error { border-left-color: var(--danger); }

/* Phones */
@media (max-width: 760px) {
    .video-card, .video-page, .video-page.is-short, .admin { grid-template-columns: 1fr; }
    .topbar { flex-direction: column; align-items: stretch; gap: .5rem; }
    .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--border); }
    .sidebar nav { flex-direction: row; flex-wrap: wrap; }
    .admin-main { padding: 1rem; overflow-x: auto; }
    /* The transcript scrolls inside its own box, so the player above stays put. */
    .video-main { position: static; }
    .player.short { max-height: 55vh; }
    .transcript-scroll { max-height: 55vh; }
}

/* Site navigation */
.site-nav { display: flex; gap: .2rem; flex-wrap: wrap; }
.topbar .site-nav { margin-left: auto; }
.hero .site-nav { justify-content: center; }

/* Video index */
.results.wide { max-width: 1200px; }
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.toolbar h1 { margin: 0 auto 0 0; }
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.video-tile { display: flex; flex-direction: column; overflow: hidden; color: var(--text); }
.video-tile:hover { text-decoration: none; border-color: var(--accent); }
.video-tile .thumb img { border-radius: 0; }
.tile-body { display: flex; flex-direction: column; gap: .2rem; padding: .7rem .8rem .9rem; }

/* Stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .45rem; }
.bars li { display: grid; grid-template-columns: minmax(0, 10rem) 1fr 3rem; gap: .6rem; align-items: center; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: .7rem; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent-strong); border-radius: 999px; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.columns { display: flex; align-items: flex-end; gap: 4px; height: 180px; overflow-x: auto; padding-bottom: 1.6rem; }
.column { flex: 1 0 22px; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; position: relative; }
.column-bar { display: block; background: var(--accent-strong); border-radius: 4px 4px 0 0; min-height: 2px; }
.column-label { position: absolute; bottom: -1.5rem; left: 50%; transform: translateX(-50%) rotate(-45deg);
    transform-origin: center; font-size: .65rem; color: var(--muted); white-space: nowrap; }

/* Requests */
.results.narrow { max-width: 640px; }
textarea.input { resize: vertical; font: inherit; }
.ok { color: var(--ok); margin: 0; }
.segmented.start { align-self: flex-start; }
.mini-thumb { width: 64px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 4px; vertical-align: middle; margin-right: .5rem; }

/* Banners */
.banner { display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap;
    padding: .8rem 1rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.banner-warn { border-color: #d29922; background: rgba(210, 153, 34, .12); }

/* Inline player in search results */
.video-card.open { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); align-items: start; }
.video-card.open .player { position: sticky; top: 6rem; }
.video-card.open .player.short { max-height: 60vh; }
button.timestamp { border: 0; font: inherit; font-size: .8rem; }
.matches li.playing { position: relative; background: var(--surface-2); border-radius: 6px; padding: .2rem .3rem; }
.matches li.playing .snippet { color: var(--text); }
.matches li.playing::after { content: ""; position: absolute; left: 0; bottom: 0; height: 2px; width: var(--progress, 0%);
    background: var(--accent); transition: width .25s linear; }
.card-actions { display: flex; flex-wrap: wrap; gap: .2rem 1rem; margin-top: .4rem; }
.notice-line { margin: 0 0 .4rem; }
.tile-badges { display: flex; flex-wrap: wrap; gap: .3rem; }
.tile-badges:empty { display: none; }
@media (max-width: 760px) {
    .video-card.open { grid-template-columns: 1fr; }
    .video-card.open .player { position: static; }
}
@media (prefers-reduced-motion: reduce) {
    .matches li.playing::after { transition: none; }
}
