:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-alt: #f7f8fc;
    --border: #e6e9f2;
    --text: #171b2e;
    --text-dim: #6b7280;
    --text-faint: #9aa1b5;

    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef0ff;

    --success: #16a34a;
    --success-light: #e8f8ee;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fdecec;

    --shadow-sm: 0 1px 2px rgba(23, 27, 46, 0.06), 0 1px 3px rgba(23, 27, 46, 0.04);
    --shadow-md: 0 4px 12px rgba(23, 27, 46, 0.08), 0 2px 4px rgba(23, 27, 46, 0.04);
    --shadow-lg: 0 12px 32px rgba(23, 27, 46, 0.12);

    --radius: 16px;
    --radius-sm: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ── Header / brand / step wizard ─────────────────────────────────────── */

#appHeader {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(244, 246, 251, 0.85);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}

.app-header-inner {
    max-width: 1080px;
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 14px;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-weight: 700; font-size: 15px; color: var(--text); }
.brand-role { font-size: 12px; color: var(--text-dim); }

.step-wizard { display: flex; align-items: center; gap: 6px; }

.step-pill {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 12px 6px 6px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-faint);
    font-size: 13px;
    font-weight: 600;
}
.step-pill.active { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.step-pill.done { color: var(--success); }

.step-index {
    width: 20px; height: 20px;
    border-radius: 50%;
    background: var(--surface-alt);
    display: flex; align-items: center; justify-content: center;
    font-size: 11px;
}
.step-pill.active .step-index { background: var(--primary); color: white; }
.step-pill.done .step-index { background: var(--success-light); color: var(--success); }

.step-connector { width: 16px; height: 1px; background: var(--border); }

/* ── Layout shell ──────────────────────────────────────────────────────── */

.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 36px 24px 80px; }

h1 { font-size: 26px; font-weight: 700; margin: 0 0 6px; letter-spacing: -0.02em; }
h2 { font-size: 17px; font-weight: 700; margin: 0 0 14px; }
.subtitle { color: var(--text-dim); margin-bottom: 28px; font-size: 15px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 26px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

button.primary-btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: 12px;
    padding: 13px 26px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-md);
    transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}
button.primary-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
button.primary-btn:disabled { background: #c7cadd; box-shadow: none; cursor: not-allowed; }

/* ── Landing page ──────────────────────────────────────────────────────── */

.hero-badges { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 28px; }
.hero-badge {
    display: flex; align-items: center; gap: 8px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 999px; padding: 8px 16px;
    font-size: 13px; font-weight: 600; color: var(--text-dim);
    box-shadow: var(--shadow-sm);
}
.hero-badge svg { flex-shrink: 0; }

.lang-toggle { display: flex; gap: 10px; }
.lang-option {
    flex: 1;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    background: var(--surface); border: 1.5px solid var(--border);
    border-radius: var(--radius-sm); padding: 14px 16px;
    font-size: 14.5px; font-weight: 600; color: var(--text-dim);
    cursor: pointer; transition: border-color 150ms ease, background 150ms ease, color 150ms ease;
}
.lang-option:hover { border-color: var(--primary-light); }
.lang-option.active { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
.lang-option .lang-native { color: var(--text-faint); font-weight: 500; }
.lang-option.active .lang-native { color: var(--primary); opacity: 0.75; }

.question-list { list-style: none; padding: 0; margin: 0; }
.question-list li {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: 14.5px;
}
.question-list li:last-child { border-bottom: none; }
.q-index {
    flex-shrink: 0;
    width: 24px; height: 24px; border-radius: 50%;
    background: var(--primary-light); color: var(--primary);
    font-size: 12px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}

.status-line { color: var(--text-dim); font-size: 13px; margin-top: 14px; }
.status-line.error { color: var(--danger); }

/* ── Interview screen ──────────────────────────────────────────────────── */

.rec-banner {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; font-weight: 600; color: var(--danger);
    margin-bottom: 18px;
}
.rec-dot {
    width: 9px; height: 9px; border-radius: 50%; background: var(--danger);
    animation: pulse-dot 1.4s ease-in-out infinite;
}
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.interview-layout { display: block; }

/* Floating "picture-in-picture" tile — the AI interviewer's video pinned to the bottom-right
   corner of .self-tile (its positioned ancestor; see .self-tile below), the same pattern used by
   Meet/Zoom/Teams for a secondary video over the main one. Replaces the old separate side-panel
   column: nested inside .self-tile in the markup now (not a sibling in its own grid column), so
   position:absolute here is relative to the self-camera tile specifically, not the whole layout —
   it stays correctly pinned to that tile's own corner regardless of how tall the question card
   below happens to be. Sized by width + its own aspect-ratio (not stretched via top/bottom AND
   left/right insets) for the same reason .avatar-layer inside it is: deriving the box's height
   from its own width means the box is the correct shape by construction, nothing for an
   aspect-ratio mismatch to squish. */
.video-tile {
    position: absolute;
    right: 12px;
    bottom: 12px;
    width: 30%;
    max-width: 200px;
    min-width: 92px;
    aspect-ratio: 1920 / 1078; /* matches .avatar-stage's own ratio — see its comment */
    z-index: 5; /* above video#selfPreview, which has no z-index of its own (auto, stacks below) */
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #111420;
    border: 2px solid var(--surface); /* a light "frame" so the PiP tile visibly separates from the video behind it, like Meet/Zoom's own self-view tile */
    box-shadow: var(--shadow-lg);
}

/* .tile-label's own default sizing (padding/font-size) was tuned for a full-size tile — too big
   once .video-tile shrinks down to a small corner PiP here, so it's scaled down specifically in
   this nested context (same idea as the phone breakpoint already does for .self-tile's own
   label). Scoped to `.self-tile .video-tile .tile-label` rather than a bare `.video-tile
   .tile-label` since .video-tile only exists in this nested PiP form now — the qualifier just
   makes the intent (label-inside-the-PiP) explicit for a future reader. */
.self-tile .video-tile .tile-label { left: 6px; bottom: 6px; padding: 2px 7px; font-size: 10px; }

.avatar-stage { position: relative; width: 100%; aspect-ratio: 1920 / 1078; } /* exact source-clip ratio — not the rounded 16/9, so the container is never a hair off from the frames' own aspect ratio (that tiny mismatch was part of what read as "distorted") */

/* Sized by width + its OWN aspect-ratio (matching the canvas's real 1920x1078 pixel buffer)
   instead of stretching to fill .avatar-stage via inset:0/width:100%/height:100% — that approach
   forced the box into whatever height the PARENT happened to compute, and relied on
   object-fit:cover to then fit the canvas's content into that box without distorting it.
   object-fit support for <canvas> specifically (as opposed to <img>/<video>) has been
   inconsistent across engines, and cover CROPS on any aspect mismatch rather than ever
   letterboxing, so any drift between the parent's rendered ratio and the canvas's own true ratio
   (even a fraction of a pixel from rounding at an odd container width) showed up as content
   silently cropped or, if object-fit didn't apply at all, stretched to fill. Deriving the box's
   height directly from its own width + aspect-ratio means the box IS the correct shape by
   construction — there's no fitting math left for object-fit to get wrong, and nothing to crop or
   squish regardless of what the parent's own box rounds to. Centered via transform since it no
   longer stretches via inset:0. */
.avatar-layer {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    aspect-ratio: 1920 / 1078;
    max-height: 100%;
    transition: opacity 150ms ease;
}

.avatar-placeholder {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(160deg, #1c2036, #111420);
    color: #9aa4c7; font-size: 16px; font-weight: 600;
}

.tile-label {
    position: absolute; left: 12px; bottom: 12px;
    background: rgba(17, 20, 32, 0.72);
    color: white; font-size: 12.5px; font-weight: 600;
    padding: 5px 12px; border-radius: 999px;
    backdrop-filter: blur(4px);
}

.self-tile { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
video#selfPreview { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #000; transform: scaleX(-1); display: block; }

.qa-panel-card { padding: 24px; }

.q-progress-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.q-progress-label { font-size: 12.5px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }

.progress-bar-track { height: 6px; border-radius: 999px; background: var(--surface-alt); overflow: hidden; margin-bottom: 20px; }
.progress-bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #7c3aed); border-radius: 999px; transition: width 300ms ease; }

.question-text { font-size: 19px; font-weight: 700; line-height: 1.4; margin-bottom: 18px; }

.listen-indicator {
    display: flex; align-items: center; gap: 12px;
    background: var(--surface-alt); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 14px 16px;
    min-height: 24px;
}
/* Real-time frequency graph of the candidate's own mic input (see interview.html's
   startMicLevelMeter) — each bar is one frequency band's current live level, not a decorative
   animation, so the candidate can see for themselves whether their voice is actually being
   picked up. Height/opacity are set inline per-frame from real AnalyserNode data. */
.wave-bars { display: flex; align-items: flex-end; gap: 2px; height: 20px; }
.wave-bars span {
    flex: 1; min-width: 2px; max-width: 4px;
    border-radius: 2px; background: var(--primary);
    height: 10%; opacity: 0.25;
    transition: height 80ms ease, opacity 80ms ease;
}

.listen-text { font-size: 13.5px; font-weight: 600; color: var(--text-dim); }
.listen-indicator.active .listen-text { color: var(--primary); }
.listen-indicator:not(.active) .wave-bars { display: none; }

.controls { margin-top: 20px; display: flex; justify-content: flex-end; }

/* ── Finishing overlay ─────────────────────────────────────────────────── */

.finishing-overlay {
    position: fixed;
    inset: 0;
    background: rgba(23, 27, 46, 0.55);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 20px;
}

.finishing-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 36px 40px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    max-width: 360px;
    width: 100%;
    text-align: center;
}

.spinner {
    width: 40px; height: 40px;
    border: 4px solid var(--primary-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.finishing-title { font-size: 16px; font-weight: 700; color: var(--text); }

.finishing-steps { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; width: 100%; text-align: left; }
.finishing-step { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--text-faint); transition: color 150ms ease; }
.finishing-step .step-icon {
    width: 18px; height: 18px; flex-shrink: 0;
    border-radius: 50%; border: 2px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; color: white; font-weight: 700;
    transition: background 150ms ease, border-color 150ms ease;
}
.finishing-step.active { color: var(--text); font-weight: 600; }
.finishing-step.active .step-icon { border-color: var(--primary); animation: pulse-dot 1s ease-in-out infinite; }
.finishing-step.done { color: var(--success); }
.finishing-step.done .step-icon { background: var(--success); border-color: var(--success); }
.finishing-step.done .step-icon::after { content: '✓'; }

.finishing-note { font-size: 12px; color: var(--text-faint); margin: 0; }

/* ── Report screen ─────────────────────────────────────────────────────── */

.score-hero { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; }

.score-ring-wrap { position: relative; width: 118px; height: 118px; flex-shrink: 0; }
.score-ring-wrap svg { transform: rotate(-90deg); }
.score-ring-value {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 30px; font-weight: 800;
}

.tag {
    display: inline-block; padding: 5px 14px; border-radius: 999px;
    font-size: 12.5px; font-weight: 700; letter-spacing: 0.02em;
}
.tag.strong-fit, .tag.good-fit { background: var(--success-light); color: var(--success); }
.tag.possible-fit { background: var(--warning-light); color: var(--warning); }
.tag.not-a-fit { background: var(--danger-light); color: var(--danger); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 720px) { .two-col { grid-template-columns: 1fr; } } /* .interview-layout is no longer a grid (see its own rule — now a plain PiP-style stage), so it no longer belongs in this selector */

.bullet-list { list-style: none; margin: 0; padding: 0; }
.bullet-list li { display: flex; gap: 10px; padding: 7px 0; font-size: 14px; }
.bullet-list.strengths li::before { content: '✓'; color: var(--success); font-weight: 800; flex-shrink: 0; }
.bullet-list.improve li::before { content: '↑'; color: var(--warning); font-weight: 800; flex-shrink: 0; }

.qa-item { padding: 16px 0; border-bottom: 1px solid var(--border); }
.qa-item:last-child { border-bottom: none; }
.qa-question { font-weight: 700; margin-bottom: 6px; font-size: 14.5px; }
.qa-answer { color: var(--text-dim); font-size: 13.5px; margin-bottom: 10px; font-style: italic; }
.qa-score-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.qa-score-track { flex: 1; height: 6px; border-radius: 999px; background: var(--surface-alt); overflow: hidden; }
.qa-score-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary), #7c3aed); }
.qa-score-num { font-size: 12.5px; font-weight: 700; color: var(--primary); white-space: nowrap; }
.qa-feedback { font-size: 13.5px; color: var(--text-dim); }

table.usage-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.usage-table th, table.usage-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
table.usage-table th { color: var(--text-faint); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
table.usage-table td.svc { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.svc-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.svc-dot.tts { background: #22c55e; }
.svc-dot.stt { background: #3b82f6; }
.svc-dot.llm { background: #a855f7; }
td.cost { font-variant-numeric: tabular-nums; font-weight: 600; }
.total-row td { font-weight: 800; color: var(--text); border-top: 2px solid var(--border); border-bottom: none; }

.recording-note { font-size: 12.5px; color: var(--text-faint); margin-top: 10px; }

/* ── Recording + synced transcript ─────────────────────────────────────── */

.recording-layout { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }

.recording-video-wrap video { width: 100%; display: block; border-radius: var(--radius-sm); background: #000; }

.transcript-panel {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    max-height: 480px;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.transcript-line {
    display: flex;
    gap: 10px;
    padding: 10px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 120ms ease;
    align-items: flex-start;
}
.transcript-line:hover { background: var(--surface); }
.transcript-line.active { background: var(--primary-light); }

.transcript-body { flex: 1; min-width: 0; }
.transcript-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.transcript-speaker { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.transcript-line.speaker-ai .transcript-speaker { color: var(--primary); }
.transcript-line.speaker-candidate .transcript-speaker { color: var(--success); }
.transcript-time { font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.transcript-text { font-size: 13.5px; line-height: 1.55; color: var(--text-dim); }
.transcript-line.active .transcript-text { color: var(--text); }

.transcript-word { transition: color 100ms ease, background 100ms ease; border-radius: 3px; }
.transcript-word.spoken { color: var(--text); }
.transcript-word.current { background: var(--primary); color: white; font-weight: 600; }

.transcript-empty { padding: 28px 16px; text-align: center; color: var(--text-faint); font-size: 13.5px; }

@media (max-width: 900px) {
    .recording-layout { grid-template-columns: 1fr; }
    .transcript-panel { max-height: 320px; }
}

a.link { color: var(--primary); text-decoration: none; font-weight: 600; }
a.link:hover { text-decoration: underline; }

.disclaimer { font-size: 12px; color: var(--text-faint); text-align: center; margin-top: 8px; }

/* ── Responsive breakpoints ────────────────────────────────────────────── */

/* Tablet: the PiP layout (see .video-tile) already reads correctly at this width without
   restructuring anything — just a smaller cap on the PiP tile and a shorter candidate-video
   ratio so everything still fits a portrait tablet viewport without scrolling. */
@media (max-width: 900px) {
    .video-tile { max-width: 150px; }
    /* Full 4:3 (the desktop ratio) runs too tall to fit a portrait tablet's viewport alongside
       the question card below — still plenty tall for reviewing the candidate at 2:1. */
    video#selfPreview { aspect-ratio: 2 / 1; }
    .qa-panel-card { padding: 16px; }
    .question-text { margin-bottom: 10px; }
    .progress-bar-track { margin-bottom: 12px; }
    .wrap { padding: 10px 20px 28px; }

    .app-header-inner { padding: 6px 20px; }
    .brand-mark { width: 30px; height: 30px; }
    .brand-role { display: none; }
}

/* Phones */
@media (max-width: 640px) {
    .wrap { padding: 14px 16px 40px; }
    h1 { font-size: 21px; }
    .card { padding: 18px; border-radius: 14px; }

    .app-header-inner { padding: 8px 16px; justify-content: center; text-align: center; gap: 6px; }
    .brand { flex-direction: row; gap: 8px; text-align: left; }
    .brand-mark { width: 26px; height: 26px; }
    .brand-text { align-items: flex-start; }
    .brand-role { display: none; } /* free up header height on phones — the step wizard already conveys progress */
    .step-wizard { width: 100%; justify-content: center; }
    .step-label { display: none; }
    .step-connector { width: 10px; }
    .step-pill { padding: 4px; }

    .hero-badges { flex-direction: column; align-items: stretch; }
    .hero-badge { justify-content: center; }

    button.primary-btn { width: 100%; justify-content: center; }

    /* Interview screen: the candidate's own video stays the one large, full-width tile — this is
       a PROCTORED recording, so it's deliberately never shrunk down to make room for anything
       else — with the AI interviewer as a small PiP pinned to its corner (see .video-tile). */
    /* Slightly shorter than the desktop 4:3 so the candidate's video still stays comfortably the
       largest thing on screen without needing to scroll. */
    video#selfPreview { aspect-ratio: 16 / 10; }
    .video-tile { width: 32%; max-width: 108px; right: 8px; bottom: 8px; }
    .rec-banner { margin-bottom: 8px; font-size: 12.5px; }
    .tile-label { left: 8px; bottom: 8px; padding: 3px 9px; font-size: 11px; }

    .qa-panel-card { padding: 12px; }
    .q-progress-row { margin-bottom: 8px; }
    .progress-bar-track { margin-bottom: 10px; }
    .question-text { font-size: 16px; margin-bottom: 10px; }
    .listen-indicator { padding: 8px 12px; }
    .controls { margin-top: 10px; }

    .score-hero { flex-direction: column; text-align: center; }
    .two-col { gap: 16px; }

    table.usage-table { font-size: 12.5px; }
    table.usage-table th, table.usage-table td { padding: 8px 6px; }
}

/* Small phones */
@media (max-width: 380px) {
    .brand-name { font-size: 14px; }
    .brand-role { font-size: 11px; }
    .score-ring-wrap { width: 100px; height: 100px; }
    .score-ring-value { font-size: 26px; }
}
