/* ===========================================================================
   Neurodivertest — calm, low-stimulation screening portal
   Design intent: built for neurodivergent readers. High legibility, generous
   spacing, muted colour, strong focus states, reduced motion respected.
   Dark is the genuine default; everything is theme-driven (no hardcoded colours).
   =========================================================================== */

:root,
:root[data-theme="dark"] {
    --bg: #13161b;
    --surface: #1a1e25;
    --surface-2: #21262f;
    --elevate: #272d38;
    --text: #e6eaf0;
    --muted: #9aa4b2;
    --faint: #69727f;
    --border: #2b313b;
    --accent: #5cb3a3;
    --accent-strong: #74c8b8;
    --accent-soft: rgba(92, 179, 163, 0.15);
    --ok: #5db292;
    --info: #6aa4d6;
    --warn: #d8a657;
    --alert: #d98a80;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.25);
}

:root[data-theme="light"] {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #eef1f5;
    --elevate: #e7ebf1;
    --text: #1f2c3b;
    --muted: #586675;
    --faint: #8b97a5;
    --border: #dde3ea;
    --accent: #2f9686;
    --accent-strong: #237f70;
    --accent-soft: rgba(47, 150, 134, 0.12);
    --ok: #2f8f6b;
    --info: #2f74b0;
    --warn: #ab771c;
    --alert: #c4564c;
    --shadow: 0 1px 2px rgba(20,40,60,.06), 0 10px 28px rgba(20,40,60,.08);
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    display: flex;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 17px;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

/* ---------- Sidebar ---------- */
.sidebar {
    width: 264px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 22px 16px 40px;
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    overflow-y: auto;
}
.sidebar-header { padding: 6px 8px 18px; }
.sidebar-header h2 {
    margin: 0;
    font-size: 1.18rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.sidebar-header h2 .dot { color: var(--accent); }
.sidebar-sub {
    color: var(--faint);
    font-size: .72rem;
    letter-spacing: .14em;
    text-transform: uppercase;
    padding: 0 8px 14px;
    margin: 0;
}
.sidebar-menu { list-style: none; margin: 0; padding: 0; }
.category-header {
    color: var(--faint);
    margin: 22px 8px 8px;
    font-size: .7rem;
    font-weight: 600;
    letter-spacing: .14em;
    text-transform: uppercase;
}
.menu-item {
    display: flex;
    align-items: baseline;
    gap: 8px;
    color: var(--muted);
    padding: 9px 12px;
    margin: 2px 0;
    text-decoration: none;
    border-radius: 8px;
    font-size: .95rem;
    transition: background .15s, color .15s;
}
.menu-item:hover { background: var(--surface-2); color: var(--text); }
.menu-item.active {
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-weight: 600;
    box-shadow: inset 2px 0 0 var(--accent);
}
.menu-item .yr { color: var(--faint); font-size: .78rem; font-weight: 400; }

/* ---------- Main ---------- */
.main-content { flex: 1; min-width: 0; padding: 18px clamp(16px, 4vw, 48px) 80px; }

.top-bar {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-bottom: 8px;
}
.lang-btn {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 11px;
    font-size: .95rem;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.lang-btn:hover { background: var(--surface-2); border-color: var(--accent); }

.view-container { max-width: 820px; margin: 0 auto; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: clamp(22px, 4vw, 40px);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

h1 { font-size: clamp(1.6rem, 3.5vw, 2.1rem); font-weight: 700; letter-spacing: -0.025em; margin: 0 0 6px; }
.test-header { margin-bottom: 8px; }
.test-header h1, .card > h1 { margin-bottom: 4px; }
.card > p, .test-header p { color: var(--muted); margin: 0 0 4px; font-size: 1.05rem; }

.instructions {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    padding: 14px 18px;
    border-radius: 10px;
    color: var(--muted);
    font-size: .96rem;
    margin: 22px 0 8px;
}

/* ---------- Educational boxes (home) ---------- */
.lede { font-size: 1.12rem; color: var(--text); margin: 4px 0 26px; }
.educational-box {
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    padding: 16px 20px;
    background: var(--surface-2);
    border-radius: 10px;
    margin-bottom: 16px;
}
.educational-box h4 { margin: 0 0 6px; font-size: 1rem; letter-spacing: -0.01em; }
.educational-box p { margin: 0; color: var(--muted); font-size: .97rem; }
.educational-box.note { border-left-color: var(--warn); }

.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 26px 0; }
.tile {
    display: block;
    text-decoration: none;
    color: inherit;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 18px;
    transition: border-color .15s, transform .15s, background .15s;
}
.tile:hover { border-color: var(--accent); transform: translateY(-2px); background: var(--elevate); }
.tile .tile-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.tile strong { font-size: 1.02rem; letter-spacing: -0.01em; }
.tile .yr { color: var(--faint); font-size: .82rem; }
.tile span.desc { display: block; color: var(--muted); font-size: .9rem; margin-top: 4px; }

/* ---------- Questions ---------- */
.progress-wrap {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--surface);
    padding: 10px 0 12px;
    margin: 6px 0 4px;
}
.progress-track { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .25s ease; }
.progress-label { font-size: .82rem; color: var(--muted); margin-top: 6px; }

.question-block {
    border-top: 1px solid var(--border);
    padding: 20px 0;
    margin: 0;
    border-radius: 0;
}
.question-block.answered .qnum { color: var(--accent); }

.section-head {
    margin: 30px 0 4px;
    padding: 14px 18px;
    background: var(--accent-soft);
    border: 1px solid var(--border);
    border-radius: 11px;
}
.section-head h3 { margin: 0 0 4px; font-size: 1.05rem; letter-spacing: -0.01em; color: var(--accent-strong); }
.section-head p { margin: 0; color: var(--muted); font-size: .9rem; }
.question-text, .question-block > p {
    margin: 0 0 12px;
    font-size: 1.02rem;
    line-height: 1.55;
}
.qnum { color: var(--faint); font-variant-numeric: tabular-nums; font-weight: 600; margin-right: 4px; }

.options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
    gap: 8px;
}
.option-label {
    position: relative;
    background: var(--surface-2);
    border: 1.5px solid var(--border);
    padding: 11px 10px;
    border-radius: 9px;
    text-align: center;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    font-size: .9rem;
    color: var(--muted);
    transition: border-color .12s, background .12s, color .12s;
    user-select: none;
}
.option-label:hover { border-color: var(--accent); color: var(--text); }
.option-label input { position: absolute; opacity: 0; width: 0; height: 0; }
.option-label:has(input:checked) {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-weight: 600;
}
.option-label input:focus-visible + span { outline: none; }
.option-label:has(input:focus-visible) {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

/* ---------- Buttons ---------- */
.btn-container { margin-top: 28px; }
.calc-btn {
    appearance: none;
    background: var(--accent);
    color: #07110f;
    border: none;
    border-radius: 10px;
    padding: 14px 26px;
    font-size: 1.02rem;
    font-weight: 650;
    cursor: pointer;
    margin-top: 28px;
    transition: background .15s, transform .05s;
    font-family: inherit;
}
.calc-btn:hover { background: var(--accent-strong); }
.calc-btn:active { transform: translateY(1px); }
.calc-btn:focus-visible { outline: 3px solid var(--accent-strong); outline-offset: 3px; }

/* ---------- Results ---------- */
.result-panel {
    margin-top: 30px;
    border-top: 2px solid var(--accent);
    padding-top: 22px;
    animation: rise .35s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.result-panel h2 { margin: 0 0 14px; font-size: 1.3rem; letter-spacing: -0.02em; }
.score-line { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.score-line .lbl { color: var(--muted); }
.score-highlight {
    font-size: 2.1rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
    color: var(--text);
}
.score-highlight .max { font-size: 1.1rem; color: var(--faint); font-weight: 500; }

/* Meter */
.meter { margin: 16px 0 4px; }
.meter-track {
    position: relative;
    height: 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 99px;
    overflow: visible;
}
.meter-fill { height: 100%; border-radius: 99px; background: var(--band, var(--accent)); transition: width .5s ease; }
.meter-cut {
    position: absolute;
    top: -6px;
    bottom: -6px;
    width: 2px;
    background: var(--text);
    opacity: .55;
}
.meter-cut::after {
    content: attr(data-label);
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: .68rem;
    color: var(--muted);
    white-space: nowrap;
}
.meter-scale { display: flex; justify-content: space-between; font-size: .72rem; color: var(--faint); margin-top: 8px; }

.analysis-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 4px solid var(--band, var(--accent));
    padding: 14px 18px;
    border-radius: 10px;
    margin-top: 18px;
    font-size: .98rem;
}
.analysis-card strong { color: var(--text); }
.band-ok { --band: var(--ok); }
.band-info { --band: var(--info); }
.band-warn { --band: var(--warn); }
.band-alert { --band: var(--alert); }

.subscales { margin-top: 18px; display: grid; gap: 10px; }
.subscale-result {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 11px 14px;
    font-size: .92rem;
}
.subscale-result .sname { color: var(--muted); }
.subscale-result .sval { float: right; font-weight: 650; font-variant-numeric: tabular-nums; }
.subscale-result .sbar { height: 5px; background: var(--border); border-radius: 99px; margin-top: 8px; overflow: hidden; }
.subscale-result .sbar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

.disclaimer {
    margin-top: 22px;
    font-size: .85rem;
    color: var(--faint);
    border-top: 1px solid var(--border);
    padding-top: 14px;
}
.ref {
    margin-top: 14px;
    font-size: .82rem;
    color: var(--faint);
}
.ref a { color: var(--accent); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    body { flex-direction: column; font-size: 16px; }

    /* Show theme/language switchers + page content first, navigation menu below */
    .main-content { order: 1; }
    .sidebar {
        order: 2;
        width: 100%;
        height: auto;
        position: static;
        border-right: none;
        border-bottom: none;
        border-top: 1px solid var(--border);
        margin-top: 8px;
        padding: 18px 16px 24px;
    }
    .sidebar-menu { display: flex; flex-wrap: wrap; gap: 6px; }
    .category-header { width: 100%; margin: 10px 4px 2px; }
    .menu-item { margin: 0; padding: 7px 11px; }
    .menu-item.active { box-shadow: inset 0 -2px 0 var(--accent); }
    .home-grid { grid-template-columns: 1fr; }
}

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