/* SF50 Study Quiz — single stylesheet, mobile first. */

:root {
    color-scheme: light dark;

    --bg: #f6f7f9;
    --bg-elevated: #ffffff;
    --bg-sunken: #eceef2;
    --text: #131922;
    --text-muted: #5b6675;
    --border: #dfe3ea;
    --border-strong: #c6ccd7;

    --accent: #1f6feb;
    --accent-text: #ffffff;
    --accent-soft: #e8f0fe;

    --good: #17845a;
    --good-soft: #e4f5ed;
    --bad: #c0362c;
    --bad-soft: #fdeceb;
    --warn: #a8620a;

    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px -12px rgba(16, 24, 40, .18);
    --tap: 48px;
    --page: 44rem;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1220;
        --bg-elevated: #141c2b;
        --bg-sunken: #1b2436;
        --text: #e8edf5;
        --text-muted: #97a3b6;
        --border: #263148;
        --border-strong: #36435e;

        --accent: #5b9dff;
        --accent-text: #08111f;
        --accent-soft: #17263f;

        --good: #4fc79a;
        --good-soft: #102b23;
        --bad: #ff7d72;
        --bad-soft: #2e1a1b;
        --warn: #e0a15b;

        --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 28px -16px rgba(0, 0, 0, .8);
    }
}

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

/* Several components set display, which would otherwise beat [hidden]. */
[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.175rem; }
h3 { font-size: 1.075rem; }
p { margin: 0 0 1rem; }
p:last-child { margin-bottom: 0; }
code { background: var(--bg-sunken); padding: .1em .35em; border-radius: 6px; font-size: .9em; }

/* ---------- chrome ---------- */

.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .75rem max(1rem, env(safe-area-inset-left)) .75rem max(1rem, env(safe-area-inset-right));
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    font-weight: 650;
    color: inherit;
    text-decoration: none;
    letter-spacing: -.01em;
}
.brand-mark { width: 22px; height: 22px; fill: var(--accent); }
.brand-muted { color: var(--text-muted); font-weight: 500; }

.header-meta { display: flex; align-items: center; gap: .5rem; }
.header-user { color: var(--text-muted); font-size: .85rem; margin-right: .25rem; }

.site-main {
    width: 100%;
    max-width: var(--page);
    margin: 0 auto;
    padding: 1.25rem max(1rem, env(safe-area-inset-left)) 2rem max(1rem, env(safe-area-inset-right));
}

.site-footer {
    max-width: var(--page);
    margin: 0 auto;
    padding: 0 1rem 2.5rem;
    color: var(--text-muted);
    font-size: .85rem;
}

/* ---------- surfaces ---------- */

.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.lede { color: var(--text-muted); }

.hero h1 { font-size: 1.75rem; }

.feature-list {
    list-style: none;
    margin: 1.5rem 0 0;
    padding: 0;
    display: grid;
    gap: .6rem;
    color: var(--text-muted);
    font-size: .925rem;
}
.feature-list li { padding-left: 1.4rem; position: relative; }
.feature-list li::before {
    content: "";
    position: absolute;
    left: 0; top: .55em;
    width: .45rem; height: .45rem;
    border-radius: 50%;
    background: var(--accent);
}
.feature-list strong { color: var(--text); font-weight: 600; }

/* ---------- form controls ---------- */

.field { border: 0; padding: 0; margin: 0 0 1.5rem; }
.field-label {
    padding: 0;
    margin-bottom: .6rem;
    font-size: .8rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
}

.chip-row { display: flex; flex-wrap: wrap; gap: .5rem; }

.chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--tap);
    padding: 0 1rem;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: var(--bg-elevated);
    font-size: .95rem;
    font-weight: 550;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip:has(input:checked),
.chip-btn.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}
.chip:has(input:focus-visible),
.chip-btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
.chip-btn { color: inherit; font-family: inherit; }

.custom-count { margin-top: .75rem; display: grid; gap: .35rem; }
.custom-count label { font-size: .9rem; color: var(--text-muted); }
.custom-count input {
    min-height: var(--tap);
    max-width: 10rem;
    padding: 0 .85rem;
    font-size: 1rem;
    color: var(--text);
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    min-height: var(--tap);
    padding: 0 1.15rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: filter .15s ease, background .15s ease;
}
.btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-quiet {
    background: var(--bg-elevated);
    border-color: var(--border-strong);
    color: var(--text);
}
.btn-quiet:hover { background: var(--bg-sunken); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 .75rem; font-size: .875rem; }

/* ---------- quiz ---------- */

.questions { list-style: none; margin: 0; padding: 0; }

.question-card { padding: 1.25rem; }
.question-index {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    margin: 0 0 .35rem;
    font-size: .8rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
}
.question-text { margin-bottom: 1rem; font-size: 1.1rem; }

.choices { display: grid; gap: .6rem; }

.choice {
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: start;
    gap: .75rem;
    min-height: var(--tap);
    padding: .8rem .9rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}
.choice input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.choice:hover { border-color: var(--accent); }
.choice:has(input:checked) {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px var(--accent);
}
.choice:has(input:focus-visible) { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }

.choice-badge {
    display: grid;
    place-items: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 50%;
    background: var(--bg-sunken);
    color: var(--text-muted);
    font-size: .8rem;
    font-weight: 700;
}
.choice:has(input:checked) .choice-badge { background: var(--accent); color: var(--accent-text); }
.choice-text { align-self: center; }

/* progress */
.progress { margin-bottom: 1rem; }
.progress-bar {
    height: 6px;
    border-radius: 999px;
    background: var(--bg-sunken);
    overflow: hidden;
}
.progress-bar span {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: var(--accent);
    transition: width .25s ease;
}
.progress-text { margin: .4rem 0 0; font-size: .85rem; color: var(--text-muted); }

/* timer */
.timer {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .3rem .6rem;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    font-size: .9rem;
}
.timer .icon { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.timer.is-warning { color: var(--warn); border-color: currentColor; }
.timer.is-critical { color: var(--bad); border-color: currentColor; }

/* navigator */
.navigator-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.navigator-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(2.75rem, 1fr));
    gap: .5rem;
    margin-bottom: .75rem;
    max-height: 10.5rem;   /* an 80-question grid should not own the page */
    overflow-y: auto;
    overscroll-behavior: contain;
}
.nav-cell {
    min-height: 2.75rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-muted);
    font: inherit;
    font-weight: 650;
    cursor: pointer;
}
.nav-cell.is-answered { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.nav-cell.is-current { box-shadow: inset 0 0 0 2px var(--accent); color: var(--text); }
.navigator-legend { margin: 0; font-size: .8rem; color: var(--text-muted); display: flex; align-items: center; gap: .4rem; }
.dot { width: .7rem; height: .7rem; border-radius: 4px; display: inline-block; border: 1px solid var(--border-strong); }
.dot-answered { background: var(--accent-soft); border-color: var(--accent); }
.dot-blank { background: var(--bg-elevated); margin-left: .75rem; }

/* footer action bar */
.quiz-footer {
    position: sticky;
    bottom: 0;
    display: flex;
    gap: .6rem;
    padding: .75rem 0 max(.75rem, env(safe-area-inset-bottom));
    /* Opaque, so a choice is never half-visible underneath it. */
    background: var(--bg);
    box-shadow: 0 -1px 0 var(--border), 0 -12px 16px -12px rgba(0, 0, 0, .25);
}
.quiz-footer .btn { flex: 1; }
.quiz-footer .btn-nav { flex: 0 0 auto; }

/* Tail space so the sticky bar can never park on top of the last answer.
   Comfortably taller than the bar itself, including a two-line button. */
form[data-quiz]::after { content: ""; display: block; height: 6rem; }

/* paged mode is switched on by JS only */
.is-paged .question-card { display: none; }
.is-paged .question-card.is-active { display: block; }

/* ---------- results ---------- */

.score-card { display: grid; gap: 1.25rem; justify-items: center; text-align: center; }

.score-ring {
    --ring: var(--accent);
    width: 8.5rem;
    aspect-ratio: 1;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: conic-gradient(var(--ring) calc(var(--score) * 1%), var(--bg-sunken) 0);
}
.score-ring.is-pass { --ring: var(--good); }
.score-ring.is-fail { --ring: var(--bad); }
.score-ring-inner {
    width: 78%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: var(--bg-elevated);
    display: grid;
    place-items: center;
    align-content: center;
}
.score-ring-inner strong { font-size: 2rem; line-height: 1; font-variant-numeric: tabular-nums; }
.score-ring-inner .pct { font-size: 1rem; }
.score-ring-inner span { color: var(--text-muted); font-size: .875rem; }

.score-actions { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: center; }
/* A form may hold several buttons (stats page) — space them like siblings. */
.score-actions form { margin: 0; display: flex; flex-wrap: wrap; gap: .6rem; justify-content: center; }

.review-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    margin: 1.75rem 0 .75rem;
}
.review-head h2 { margin: 0; }
.review-head h2 small { color: var(--text-muted); font-size: .85rem; font-weight: 550; }
.filters .chip { min-height: 40px; padding: 0 .85rem; font-size: .875rem; }

.review-card { border-left: 4px solid var(--border-strong); }
.review-card.is-correct { border-left-color: var(--good); }
.review-card.is-wrong { border-left-color: var(--bad); }
.review-card .verdict { text-transform: none; letter-spacing: 0; font-weight: 650; }
.review-card.is-correct .verdict { color: var(--good); }
.review-card.is-wrong .verdict { color: var(--bad); }

/* On phones the verdict tag drops under the answer instead of squeezing it. */
.choice-static { cursor: default; grid-template-columns: auto 1fr; }
.choice-static .tag { grid-column: 2; justify-self: start; margin-top: .3rem; }
.choice-static:hover { border-color: var(--border-strong); }
.choice-static.is-answer { border-color: var(--good); background: var(--good-soft); }
.choice-static.is-answer .choice-badge { background: var(--good); color: var(--bg-elevated); }
.choice-static.is-picked:not(.is-answer) { border-color: var(--bad); background: var(--bad-soft); }
.choice-static.is-picked:not(.is-answer) .choice-badge { background: var(--bad); color: var(--bg-elevated); }

.tag {
    align-self: center;
    padding: .15rem .5rem;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
}
.tag-answer { background: var(--good); color: var(--bg-elevated); }
.tag-picked { background: var(--bad); color: var(--bg-elevated); }

/* Collapsed source citation under each review card — never on quiz pages. */
.source-note { margin-top: .8rem; font-size: .85rem; color: var(--text-muted); }
.source-note summary { cursor: pointer; font-weight: 650; width: fit-content; }
.source-note summary:hover, .source-note[open] summary { color: var(--accent); }
.source-note p { margin: .35rem 0 0; }
.source-note a { color: var(--accent); word-break: break-all; }

.empty-filter { color: var(--text-muted); text-align: center; padding: 2rem 0; }

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

/* Same tail-space trick as form[data-quiz]: the sticky bar never covers a card. */
.deck::after { content: ""; display: block; height: 6rem; }

/* Paged (JS on), the active card lays out as a column so the flip control
   sits anchored at the bottom instead of jumping with the question length. */
.is-paged .flash-card.is-active { display: flex; flex-direction: column; min-height: 18rem; }
.is-paged .flash-card.is-active .reveal { margin-top: auto; }

.reveal { margin-top: 1rem; }
.reveal-toggle { list-style: none; }
.reveal-toggle::-webkit-details-marker { display: none; }
.reveal:not([open]) .reveal-hide,
.reveal[open] .reveal-show { display: none; }

.reveal-answer {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: .75rem;
    margin-top: .6rem;
    padding: .8rem .9rem;
    border: 1px solid var(--good);
    border-radius: var(--radius-sm);
    background: var(--good-soft);
    animation: reveal-in .18s ease;
}
.reveal-answer .choice-badge { background: var(--good); color: var(--bg-elevated); }

@keyframes reveal-in {
    from { opacity: 0; transform: translateY(-4px); }
}

/* honesty markers — semantic good/bad take over the chip's checked accent */
.mark-row { display: flex; gap: .5rem; margin-top: .6rem; }
.mark-row .chip { flex: 1; }
.mark-right:has(input:checked) { background: var(--good); border-color: var(--good); color: var(--bg-elevated); }
.mark-wrong:has(input:checked) { background: var(--bad); border-color: var(--bad); color: var(--bg-elevated); }

/* No honest mark before the flip: on the drill decks (memory/limits) the
   marks live outside the reveals, so hide them until every reveal on the
   card is open.  A card that is already marked keeps its marks visible even
   if folded back.  Cards mode needs none of this — its marks sit inside the
   <details>.  Guarded so browsers without :has() stay scorable. */
@supports selector(:has(*)) {
    .memory-page .mark-row { display: none; }
    .memory-page [data-card]:not(:has(.step-reveal:not([open]))) .mark-row,
    .memory-page [data-card]:has(.mark-row input:checked) .mark-row { display: flex; }
}

.start-cards { margin-top: .6rem; }

/* ---------- memory items drill ---------- */

/* The trigger chip mimics the CAS annunciator: red warning, yellow caution,
   neutral chip for scenario procedures without a CAS message. */
.cas {
    display: inline-block;
    margin: 0;
    padding: .35rem .75rem;
    border-radius: 8px;
    font-weight: 750;
    font-size: 1.05rem;
    letter-spacing: .04em;
}
.cas-warning { background: var(--bad); color: var(--bg-elevated); }
.cas-caution { background: var(--warn); color: var(--bg-elevated); }
.cas-procedure { background: var(--bg-sunken); color: var(--text); border: 1px solid var(--border-strong); }
.cas-context {
    margin: .4rem 0 0;
    font-size: .8rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
}

.steps { margin-top: 1rem; display: grid; gap: .5rem; }
.step-reveal {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: .6rem .85rem;
    background: var(--bg-elevated);
}
.step-reveal summary { list-style: none; cursor: pointer; font-weight: 650; color: var(--text-muted); }
.step-reveal summary::-webkit-details-marker { display: none; }
.step-reveal[open] { border-color: var(--accent); }
.step-reveal[open] summary { color: var(--accent); margin-bottom: .4rem; }

/* Checklist row: item, dotted leader, bold action — like the printed card. */
.step { display: flex; align-items: baseline; gap: .5rem; }
.step-no { font-weight: 650; color: var(--text-muted); }
.step-item { min-width: 0; }
.step-leader { flex: 1 1 1.5rem; border-bottom: 2px dotted var(--border-strong); transform: translateY(-.25em); }
.step-action { font-weight: 750; text-align: right; }

.checklist { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .45rem; }
.checklist-branch { padding-left: .75rem; }
.branch-condition { margin: .6rem 0 0; font-weight: 650; font-size: .9rem; }
.step-note { margin: .6rem 0 0; font-size: .85rem; font-weight: 550; color: var(--warn); }
.drill-source { margin-top: 1.25rem; text-align: center; font-size: .8rem; color: var(--text-muted); }

/* ---------- stats ---------- */

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

/* Phone: label + value on one line, the bar full-width beneath them. */
.stat-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: .3rem .75rem;
    align-items: center;
}
.stat-label { font-weight: 600; font-size: .95rem; }
.stat-value { justify-self: end; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-value small { margin-left: .25rem; color: var(--text-muted); font-weight: 500; }

.stat-bar {
    grid-column: 1 / -1;
    display: block;
    height: 6px;
    border-radius: 999px;
    background: var(--bg-sunken);
    overflow: hidden;
}
.stat-bar span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.stat-bar .is-good { background: var(--good); }
.stat-bar .is-bad { background: var(--bad); }

.session-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: .25rem .75rem;
    padding-bottom: .85rem;
    border-bottom: 1px solid var(--border);
}
.session-row:last-child { padding-bottom: 0; border-bottom: 0; }
.session-mode { font-weight: 650; }
.session-when { color: var(--text-muted); font-size: .875rem; }
.session-score { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- login ---------- */

.login-card { max-width: 26rem; margin: 2.5rem auto 1rem; }

.login-form { display: grid; gap: 1rem; margin-top: 1.25rem; }

.field-text {
    display: grid;
    gap: .35rem;
    font-size: .85rem;
    font-weight: 650;
    color: var(--text-muted);
}
.field-text input {
    min-height: var(--tap);
    padding: 0 .85rem;
    font: inherit;
    font-size: 1rem;
    color: var(--text);
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
}
.field-text input:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
    outline-offset: 2px;
}

.login-error { color: var(--bad); font-weight: 600; }

.site-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; }
/* Signed out there is no button — center the notice under the login card. */
.site-footer span:only-child { margin-inline: auto; text-align: center; }
.signout { margin: 0; }

/* ---------- confirm dialog ---------- */

/* Mobile first: a bottom sheet above the thumb; centered card on wide screens. */
dialog.confirm {
    width: min(26rem, calc(100% - 2rem));
    margin: auto auto max(1rem, env(safe-area-inset-bottom));
    padding: 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elevated);
    color: var(--text);
    box-shadow: var(--shadow);
    animation: sheet-up .2s ease;
}
dialog.confirm::backdrop {
    background: rgba(8, 12, 20, .45);
    backdrop-filter: blur(2px);
}

.confirm-message { margin: 0 0 1rem; font-weight: 550; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }

@keyframes sheet-up {
    from { opacity: 0; transform: translateY(12px); }
}

/* ---------- wider screens ---------- */

@media (min-width: 40rem) {
    h1 { font-size: 1.75rem; }
    .hero h1 { font-size: 2rem; }
    .card { padding: 1.75rem; }
    .site-main { padding-top: 2rem; }
    .score-card { grid-template-columns: auto 1fr; justify-items: start; text-align: left; align-items: center; }
    .score-actions { justify-content: flex-start; }
    .quiz-footer .btn { flex: 0 0 auto; min-width: 8rem; }
    .choice-static { grid-template-columns: auto 1fr auto; }
    .choice-static .tag { grid-column: auto; align-self: center; margin-top: 0; }
    .quiz-footer [data-next], .quiz-footer [data-submit], .quiz-footer [data-finish] { margin-left: auto; }
    dialog.confirm { margin: auto; }
    /* Topic rows fit on one line: label · bar · value. */
    .stat-row { grid-template-columns: minmax(9rem, 14rem) 1fr auto; }
    .stat-bar { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
