/* YouTube Chat AI — same design language as akhilrajs.com. Colours are tokens only. */

:root {
    --bg: #f6f3ec;
    --bg-sunk: #eeeae0;
    --surface: #fbf9f4;
    --ink: #1c1b18;
    --ink-2: #4b4840;
    --muted: #6f6b62;
    --rule: #dcd6c9;
    --rule-strong: #c4bdac;
    --accent: #a8441e;
    --accent-soft: #f0e0d4;
    --user-bubble: #efe6d8;
    --ok: #2f7a55;
    --warn: #8a5a00;
    --error: #b42318;
    --on-ink: #f6f3ec;
    --mark-dot: #e58a62;
    --link-line: color-mix(in srgb, var(--accent) 80%, transparent);
    --font-display: 'Fraunces', Georgia, serif;
    --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --radius: 14px;
    color-scheme: light;
}

/* Light is the default; dark applies only when the visitor picks it. */
:root[data-theme="dark"] {
    --bg: #12110f;
    --bg-sunk: #1a1916;
    --surface: #1d1c19;
    --ink: #eeeae1;
    --ink-2: #c3bdb0;
    --muted: #9a9488;
    --rule: #2f2d28;
    --rule-strong: #46423a;
    --accent: #e58a62;
    --accent-soft: #3a2419;
    --user-bubble: #2a241d;
    --ok: #6fcb9a;
    --warn: #e8b45a;
    --error: #f1897c;
    --on-ink: #12110f;
    --mark-dot: #c4572a;
    color-scheme: dark;
}

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

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

body {
    font: 400 16px/1.6 var(--font-body);
    background: var(--bg);
    color: var(--ink);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration-color: var(--link-line);
    text-decoration-thickness: 1.5px;
    text-underline-offset: 3px;
}
a:hover { color: var(--accent); }

.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: 12px; top: -48px;
    padding: 8px 12px;
    background: var(--ink);
    color: var(--on-ink);
    border-radius: 8px;
    z-index: 10;
    text-decoration: none;
}
.skip-link:focus { top: 12px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- Header & hero ---------- */
.topbar { border-bottom: 1px solid var(--rule); }
.topbar .wrap {
    max-width: 1120px;
    margin: 0 auto;
    padding: 0 16px;
    height: 60px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.brand { font-family: var(--font-display); font-size: 1.2rem; text-decoration: none; }
.brand span { color: var(--accent); }
.brand { display: inline-flex; align-items: center; }
.brand-mark { width: 28px; height: 28px; margin-right: 10px; flex: none; }
.brand-mark rect { fill: var(--ink); }
.brand-mark path { fill: var(--on-ink); }
.brand-mark circle { fill: var(--mark-dot); }
.topbar nav { display: flex; gap: 18px; margin-left: auto; font-size: 0.9rem; color: var(--ink-2); }
.theme-toggle {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    width: 38px; height: 38px; margin-left: 6px; border: 1px solid var(--rule); border-radius: 999px;
    background: transparent; color: var(--ink-2); cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--rule-strong); background: var(--bg-sunk); }
.theme-toggle svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .icon-sun, :root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
.topbar nav a { text-decoration: none; }

.hero {
    width: 100%;
    max-width: calc(780px + 32px); /* content lines up with the 780px input below */
    margin: 0 auto;
    padding: clamp(32px, 6vw, 56px) 16px 8px;
}
.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 0.76rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}
.live-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--ok);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 18%, transparent);
}
h1 {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: clamp(2rem, 5vw, 3.1rem);
    line-height: 1.08;
    letter-spacing: -0.02em;
    margin: 14px 0 14px;
}
h1 em { color: var(--accent); }
.tagline { color: var(--ink-2); font-size: 1.05rem; max-width: 40em; }

main {
    flex: 1;
    width: 100%;
    max-width: 1120px;
    margin: 0 auto;
    padding: 20px 16px 40px;
}

.intro, .how, .disclaimers {
    max-width: 780px;
    margin-left: auto;
    margin-right: auto;
}

/* ---------- Inputs & buttons ---------- */
.input-bar, .chat-input-bar { display: flex; gap: 8px; }

.input-bar input, .chat-input-bar input {
    flex: 1;
    min-width: 0;
    padding: 13px 16px;
    background: var(--surface);
    border: 1px solid var(--rule-strong);
    border-radius: 999px;
    color: var(--ink);
    font: 400 1rem var(--font-body);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.input-bar input:focus, .chat-input-bar input:focus {
    outline: none;
    border-color: var(--ink);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder { color: var(--muted); }

.input-bar button, .chat-input-bar button {
    padding: 0 22px;
    min-height: 48px;
    background: var(--ink);
    border: 1px solid var(--ink);
    border-radius: 999px;
    color: var(--on-ink);
    font: 500 0.95rem var(--font-body);
    cursor: pointer;
    white-space: nowrap;
    transition: transform 0.15s;
}
.input-bar button:hover, .chat-input-bar button:hover { transform: translateY(-1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* ---------- Samples ---------- */
.samples {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
}
.samples-label { color: var(--muted); font-size: 0.85rem; margin-right: 2px; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 13px;
    background: var(--surface);
    border: 1px solid var(--rule-strong);
    border-radius: 999px;
    color: var(--ink);
    font: 500 0.85rem var(--font-body);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.chip:hover:not(:disabled) { border-color: var(--ink); }
.chip-meta { color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }

/* ---------- Status ---------- */
.server-status, .status {
    font-size: 0.86rem;
    color: var(--muted);
}
.server-status:not(:empty), .status:not(:empty) { padding: 12px 2px 0; }
.server-status.ready { color: var(--ok); }
.status.error, .server-status.error { color: var(--error); }
.status.working::after, .msg.loading::after {
    content: '';
    animation: dots 1.2s steps(4) infinite;
}
@keyframes dots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

.spinner {
    display: inline-block;
    width: 0.9em; height: 0.9em;
    margin-right: 6px;
    vertical-align: -0.1em;
    border: 2px solid var(--rule-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Workspace: video + chat ---------- */
.workspace {
    margin-top: 24px;
    display: grid;
    gap: 24px;
}
.workspace[hidden] { display: none; }

.video-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: var(--radius);
    overflow: hidden;
    background: #000;
    border: 1px solid var(--rule);
}
.video-wrapper iframe, .video-wrapper #player {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

.video-meta { margin-top: 12px; }
.video-title { font-family: var(--font-display); font-weight: 400; font-size: 1.3rem; line-height: 1.3; }
.video-sub { margin-top: 2px; font-size: 0.84rem; color: var(--muted); }

.chat-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 2px 0;
}

.msg {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.95rem;
    line-height: 1.6;
    max-width: 92%;
    overflow-wrap: anywhere;
}
.msg.user {
    align-self: flex-end;
    background: var(--user-bubble);
    border-bottom-right-radius: 4px;
    color: var(--ink);
}
.msg.bot {
    align-self: flex-start;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-bottom-left-radius: 4px;
}
.msg.hint { color: var(--muted); font-size: 0.9rem; }
.msg.loading { color: var(--muted); }
.msg.error { border-color: color-mix(in srgb, var(--error) 40%, transparent); color: var(--error); }
.msg.refused .answer { color: var(--ink-2); }

.answer p { margin-bottom: 8px; }
.answer p:last-child { margin-bottom: 0; }
.answer ul, .answer ol { padding-left: 20px; margin: 6px 0; }
.answer li { margin-bottom: 3px; }
.answer code {
    background: var(--bg-sunk);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.88em;
}

/* Timestamp links (inline and source chips) */
.ts {
    font: inherit;
    font-variant-numeric: tabular-nums;
    color: var(--accent);
    background: none;
    border: none;
    padding: 0 1px;
    cursor: pointer;
    font-weight: 600;
    text-decoration: underline;
    text-decoration-color: var(--link-line);
    text-decoration-thickness: 1.5px;
    text-underline-offset: 3px;
    border-radius: 4px;
}
.ts:hover { color: var(--ink); }

.sources {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--rule);
}
.sources-label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    margin-right: 4px;
}
.ts.chip-source {
    font-size: 0.78rem;
    font-weight: 500;
    padding: 3px 10px;
    border: 1px solid var(--rule-strong);
    border-radius: 999px;
    text-decoration: none;
    color: var(--ink-2);
    background: var(--bg);
}
.ts.chip-source.cited {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
}
.ts.chip-source:hover { border-color: var(--ink); color: var(--ink); }

.note {
    margin-top: 8px;
    font-size: 0.8rem;
    color: var(--warn);
}
.usage {
    margin-top: 10px;
    font-size: 0.76rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}
.session-total {
    font-size: 0.78rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}
.session-total:empty { display: none; }

/* ---------- How it works & notes ---------- */
.how {
    margin-top: 32px;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    font-size: 0.92rem;
    color: var(--ink-2);
}
.how summary {
    cursor: pointer;
    padding: 16px 20px;
    font-family: var(--font-display);
    font-size: 1.2rem;
    color: var(--ink);
    border-radius: var(--radius);
}
.how[open] summary { border-bottom: 1px solid var(--rule); }
.how ol { padding: 14px 20px 0 42px; }
.how li { margin-bottom: 8px; }
.how li strong { color: var(--ink); }
.how p { padding: 4px 20px 0; }
.how p:last-child { padding-bottom: 16px; }
.how code { background: var(--bg-sunk); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; color: var(--ink); }

.disclaimers {
    margin-top: 16px;
    padding: 18px 20px;
    border-top: 1px solid var(--rule);
    font-size: 0.85rem;
    color: var(--muted);
    line-height: 1.6;
}
.disclaimers strong {
    color: var(--ink-2);
    font-size: 0.72rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}
.disclaimers ul { margin: 8px 0 0; padding-left: 18px; }
.disclaimers li { margin-bottom: 4px; }

footer {
    padding: 20px 16px 28px;
    border-top: 1px solid var(--rule);
    font-size: 0.85rem;
    color: var(--muted);
    text-align: center;
}
footer a { color: var(--ink-2); }

/* ---------- Wide screens: video left (sticky), chat right ---------- */
@media (min-width: 980px) {
    .workspace {
        grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
        align-items: start;
    }
    .video-area { position: sticky; top: 16px; }
    .messages {
        max-height: calc(100vh - 230px);
        min-height: 200px;
        overflow-y: auto;
        padding-right: 4px;
    }
}

@media (max-width: 600px) {
    main { padding: 12px 16px 32px; }
    .input-bar { flex-direction: column; }
    .input-bar button { width: 100%; }
    .msg { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
