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

:root {
    --bg: #0a0c12;
    --surface: #13151f;
    --surface2: #1c1f2e;
    --surface3: #242840;
    --border: #252837;
    --border-hover: #3a3f5c;
    --accent: #5b7fff;
    --accent-hover: #7b9aff;
    --accent-glow: rgba(91, 127, 255, 0.18);
    --accent-glow-strong: rgba(91, 127, 255, 0.32);
    --text: #dde1f0;
    --text-muted: #636880;
    --text-dim: #4a4f6a;
    --match-bg: #1e2d14;
    --match-border: #3a5220;
    --mark-bg: #e8c000;
    --mark-color: #0a0c12;
    --success: #1a3a2a;
    --success-text: #86efac;
    --error-bg: #2a1010;
    --error-text: #fca5a5;
    --radius: 8px;
    --radius-lg: 12px;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ── Top accent bar ─────────────────────────────── */
.top-bar {
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, var(--accent) 30%, var(--accent-hover) 60%, transparent 100%);
    opacity: 0.7;
}

/* ── Layout ─────────────────────────────────────── */
.container {
    max-width: 880px;
    margin: 0 auto;
    padding: 40px 24px 100px;
}

/* ── Header ─────────────────────────────────────── */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 48px;
}

.header-brand h1 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.4px;
    color: #fff;
    line-height: 1.2;
}

.header-tagline {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
    letter-spacing: 0.02em;
    margin-top: 2px;
}

.btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: 1px solid var(--border-hover);
    color: var(--text-muted);
    background: transparent;
    padding: 7px 14px;
    border-radius: var(--radius);
    font-size: 0.82rem;
    font-weight: 500;
    text-decoration: none;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
    font-family: inherit;
}
.btn-ghost:hover {
    border-color: var(--accent);
    color: var(--accent-hover);
    background: var(--accent-glow);
}

/* keep .btn for upload.php */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 9px 18px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s;
    font-family: inherit;
}
.btn:hover { background: var(--accent-hover); }
.btn-sm { padding: 6px 14px; font-size: 0.82rem; }

/* ── Search ─────────────────────────────────────── */
.search-wrap {
    margin-bottom: 40px;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 18px;
    color: var(--text-muted);
    pointer-events: none;
    flex-shrink: 0;
    transition: color 0.2s;
}

#search {
    width: 100%;
    padding: 15px 20px 15px 50px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 50px;
    color: var(--text);
    font-size: 0.98rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
#search:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow), 0 0 20px var(--accent-glow);
}
#search:focus ~ .search-icon,
.search-box:focus-within .search-icon {
    color: var(--accent);
}
#search::placeholder { color: var(--text-dim); }

.search-clear {
    position: absolute;
    right: 14px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 50%;
    transition: color 0.15s, background 0.15s;
}
.search-clear:hover {
    color: var(--text);
    background: var(--surface2);
}

/* ── Alerts ─────────────────────────────────────── */
.alert {
    padding: 11px 15px;
    border-radius: var(--radius);
    margin-bottom: 18px;
    font-size: 0.88rem;
    border: 1px solid transparent;
}
.alert-success {
    background: var(--success);
    color: var(--success-text);
    border-color: #2a5a3a;
}
.alert-error {
    background: var(--error-bg);
    color: var(--error-text);
    border-color: #4a1a1a;
}

/* ── Card (upload.php) ──────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
}
.card label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.card input[type="file"] {
    display: block;
    width: 100%;
    padding: 10px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    margin-bottom: 16px;
    cursor: pointer;
    font-family: inherit;
}

/* ── Search options ─────────────────────────────── */
.search-options {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
}
.search-options-toggles {
    display: flex;
    gap: 6px;
}

.opt-toggle {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
}
.opt-toggle input[type="checkbox"] {
    display: none;
}
.opt-toggle span {
    padding: 4px 11px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-family: 'SF Mono', 'Consolas', 'Fira Code', monospace;
    font-weight: 500;
    letter-spacing: 0.04em;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.opt-toggle input:checked + span {
    border-color: var(--accent);
    background: var(--accent-glow);
    color: var(--accent-hover);
}
.opt-toggle:hover span {
    border-color: var(--border-hover);
    color: var(--text);
}
.opt-disabled {
    opacity: 0.35;
    pointer-events: none;
}

.opt-context-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.opt-context-label select {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text);
    font-size: 0.8rem;
    font-family: inherit;
    padding: 4px 10px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s;
    appearance: none;
    -webkit-appearance: none;
}
.opt-context-label select:focus,
.opt-context-label select:hover {
    border-color: var(--accent);
}

/* ── Section header ─────────────────────────────── */
.section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}
.section-label {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-dim);
}

/* ── Video list (cards grid) ────────────────────── */
.video-list {
    list-style: none;
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.video-card {
    display: flex;
    align-items: stretch;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: border-color 0.15s, background 0.15s, transform 0.15s, box-shadow 0.15s;
}
.video-card:hover {
    border-color: var(--border-hover);
    background: var(--surface2);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.35);
}
.video-card-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex: 1;
    padding: 14px 16px;
    text-decoration: none;
    color: var(--text);
    min-width: 0;
}
.btn-transcript {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 14px;
    background: none;
    border: none;
    border-left: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
}
.btn-transcript:hover {
    color: var(--accent);
    background: var(--accent-glow);
}
.video-card-title {
    font-size: 0.88rem;
    font-weight: 500;
    line-height: 1.4;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.video-card-arrow {
    color: var(--text-dim);
    flex-shrink: 0;
    transition: color 0.15s, transform 0.15s;
}
.video-list li a:hover .video-card-arrow {
    color: var(--accent);
    transform: translateX(2px);
}

/* ── Results ─────────────────────────────────────── */
.results-header {
    font-size: 0.88rem;
    color: var(--text-muted);
    margin-bottom: 24px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}
.results-header em {
    font-style: normal;
    color: var(--text);
    font-weight: 500;
}
.results-count {
    font-weight: 700;
    color: var(--accent);
    font-size: 1rem;
}

.loading  { color: var(--text-muted); font-size: 0.88rem; padding: 8px 0; }
.no-results { color: var(--text-muted); font-size: 0.88rem; padding: 8px 0; }
.error    { color: var(--error-text); font-size: 0.88rem; }
.hint     { font-size: 0.8rem; color: var(--text-dim); }

/* ── Result group ────────────────────────────────── */
.result-group {
    margin-bottom: 32px;
}

.result-video-title {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}
.result-video-title a {
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.92rem;
    transition: color 0.15s;
}
.result-video-title a:hover { color: var(--accent); }

.yt-icon {
    width: 20px;
    height: 14px;
    flex-shrink: 0;
    border-radius: 3px;
}

/* ── Hit card ─────────────────────────────────────── */
a.hit {
    display: flex;
    align-items: stretch;
    margin-bottom: 8px;
    border-radius: var(--radius);
    overflow: hidden;
    text-decoration: none;
    border: 1px solid var(--border);
    border-left: 3px solid transparent;
    transition: border-color 0.15s, border-left-color 0.15s, background 0.15s;
    cursor: pointer;
}
a.hit:hover {
    border-color: var(--border-hover);
    border-left-color: var(--accent);
    background: rgba(91, 127, 255, 0.03);
}

.hit-ts {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 64px;
    padding: 0 10px;
    background: var(--surface2);
    border-right: 1px solid var(--border);
    font-family: 'SF Mono', 'Consolas', 'Fira Code', monospace;
    font-size: 0.75rem;
    color: var(--accent);
    white-space: nowrap;
    flex-shrink: 0;
    letter-spacing: 0.02em;
}

.hit-body { flex: 1; min-width: 0; }

.context {
    padding: 6px 13px;
    font-size: 0.85rem;
    line-height: 1.55;
}
.context-before { background: var(--surface); color: var(--text-muted); }
.context-match  {
    background: var(--match-bg);
    color: var(--text);
    font-weight: 500;
    border-top: 1px solid var(--match-border);
    border-bottom: 1px solid var(--match-border);
}
.context-after  { background: var(--surface); color: var(--text-muted); }
.ctx-line { display: block; }

.ts {
    font-family: 'SF Mono', 'Consolas', 'Fira Code', monospace;
    font-size: 0.75rem;
    color: var(--accent);
    margin-right: 6px;
    letter-spacing: 0.02em;
}

mark {
    background: #e8c000 !important;
    background-color: #e8c000 !important;
    color: #0a0c12 !important;
    -webkit-text-fill-color: #0a0c12 !important;
    border-radius: 2px;
    padding: 0 2px;
    font-weight: 600;
}

/* ── Context modal ───────────────────────────────────── */
.ctx-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.ctx-modal-backdrop[hidden] { display: none; }

.ctx-modal {
    background: var(--surface);
    border: 1px solid var(--border-hover);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 640px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}

.ctx-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.ctx-modal-header span {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 12px;
}
.ctx-modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    flex-shrink: 0;
    transition: color 0.15s;
}
.ctx-modal-close:hover { color: var(--text); }

.ctx-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    line-height: 1.7;
}
.ctx-modal-loading {
    color: var(--text-muted);
    font-size: 0.88rem;
}
.ctx-p {
    margin: 0 0 6px;
    font-size: 0.9rem;
}
.ctx-p-dim   { color: var(--text-muted); }
.ctx-p-match { color: var(--text); font-weight: 500; }

.ctx-modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    gap: 8px;
}

/* ── Transcript modal ──────────────────────────────── */
.tr-modal-backdrop { z-index: 110; }
.tr-modal {
    max-width: 780px;
    max-height: 90vh;
}
.tr-modal-body {
    padding: 0;
}
.tr-modal .ctx-modal-footer {
    justify-content: flex-end;
}
.tr-table {
    width: 100%;
    border-collapse: collapse;
}
.tr-row {
    cursor: pointer;
    transition: background 0.1s;
}
.tr-row:hover { background: var(--surface2); }
.tr-row-active { background: var(--match-bg); }
.tr-row-active .tr-ts { color: var(--accent-hover); }
.tr-ts {
    font-family: 'SF Mono', 'Consolas', 'Fira Code', monospace;
    font-size: 0.78rem;
    color: var(--accent);
    white-space: nowrap;
    padding: 5px 16px 5px 20px;
    vertical-align: top;
    width: 72px;
    border-bottom: 1px solid var(--border);
}
.tr-text {
    font-size: 0.88rem;
    color: var(--text);
    padding: 5px 20px 5px 0;
    border-bottom: 1px solid var(--border);
    line-height: 1.5;
}

/* ── Compact hits ─────────────────────────────────── */
.compact-video { margin-bottom: 22px; }
.compact-hits {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 10px;
}
a.compact-hit {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 5px 11px;
    font-size: 0.83rem;
    color: var(--text);
    text-decoration: none;
    transition: border-color 0.15s, background 0.15s;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
a.compact-hit:hover {
    border-color: var(--accent);
    background: var(--surface2);
    color: var(--text);
}
