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

:root {
    --bg: #0a0a0a;
    --surface: #141414;
    --surface-2: #233526;
    --border: #272727;
    --border-bright: #3a3a3a;
    --text: #e8e8e8;
    --muted: #666;
    --dimmed: #3d3d3d;
    --text-dim: #a59e8b;
    --label: #80766b;
    --red: #e05252;
    --green: #5ec97a;
    --yellow: #d4aa3f;
    --accent: #f6c13b;
    --font-mono: 'IBM Plex Mono', monospace;
    --font-sans: 'IBM Plex Sans', sans-serif;
    --radius: 6px;
    --transition: 0.22s ease;
}

html, body {
    width: 100%;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-mono);
    font-weight: 300;
    overflow: hidden;
}

/* ── Layout ── */
#app {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 2rem 1.5rem;
    margin: auto;
}

.page > * { margin-left: 0; }

.page {
    display: none;
    flex-direction: column;
    align-items: flex-start;
    max-width: 90vw;
    width: 550px;
    min-height: 500px;
    height: 500px;
    justify-content: space-evenly;
    animation: fadein 0.4s ease;
    margin: auto;
}

.page#pg-results {
    height: auto;
    min-height: fit-content;
    max-height: 90vh;
    overflow-y: auto;
}

.page.active { display: flex; }

#pg-task { justify-content: space-around; align-items: center; }

@keyframes fadein {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0);  }
}

/* ── Header ── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
}

.task-title {
    font-size: 11px;
    font-weight: 300;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--muted);
}

.nav-arrows { display: flex; gap: 8px; }

.nav-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-family: var(--font-mono);
    transition: border-color var(--transition), background var(--transition);
}

.nav-btn:hover {
    border-color: var(--border-bright);
    background: var(--surface);
}

.nav-btn.hidden { visibility: hidden; }

.restart-btn {
    font-size: 11px;
    width: auto;
    padding: 0 10px;
    letter-spacing: 0.05em;
}

.back-btn {
    position: absolute;
    top: 48px;
    left: 5vw;
    margin-top: 0;
}

/* ── Typography ── */
.section-label {
    font-size: 10px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 1.2rem;
}

h2 {
    font-size: 22px;
    font-weight: 300;
    margin-bottom: 1rem;
    line-height: 1.3;
}

h3 { font-weight: 300; }

p {
    font-family: var(--font-sans);
    font-size: 16px;
    font-weight: 100;
    line-height: 1.75;
    color: #bbb;
    margin-bottom: 0.85rem;
}

ul { list-style: none; margin-bottom: 1rem; }

ul li {
    font-family: var(--font-sans);
    font-size: 16px;
    color: #bbb;
    padding: 5px 0 5px 18px;
    position: relative;
    line-height: 1.6;
}

ul li::before {
    content: '—';
    position: absolute;
    left: 0;
    color: var(--dimmed);
}

.warn {
    border: 1px solid #5a3030;
    background: #1a0d0d;
    border-radius: var(--radius);
    padding: 12px 16px;
    font-family: var(--font-sans);
    font-size: 15px;
    color: #e08080;
    margin-top: 1rem;
}

.warn-yellow {
    border: 1px solid #5a5330;
    color: var(--yellow);
    background: #1a180d;
    margin-top: 1rem;
    border-radius: var(--radius);
    padding: 12px 16px;
    font-family: var(--font-sans);
    font-size: 15px;
}

.warn-yellow.tiny {
    font-size: 12px;
    font-weight: 200;
    padding: 6px 10px;
}

/* ── Buttons ── */
.btn, select {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 500;
    letter-spacing: 0.05em;
    padding: 10px 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border-bright);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), transform 0.1s;
    margin-top: 1.5rem;
}

select { border: solid 2px var(--border-bright); font-weight: 300; }

.btn:hover { background: var(--surface); border-color: #555; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn:disabled:hover { background: transparent; border-color: var(--border-bright); }

.btn-primary {
    background: var(--text);
    color: var(--bg);
    border-color: var(--text);
    margin-bottom: 0;
}

.btn-primary:hover { background: #ccc; border-color: #ccc; }

/* ── Settings page ── */
.settings-row {
    display: flex;
    width: 100%;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.attempts-info {
    width: 100%;
    margin-top: 1.5rem;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: 12px;
    letter-spacing: 0.1em;
    color: var(--muted);
    text-transform: uppercase;
    text-align: center;
}

.attempts-info.locked {
    color: var(--red);
    border-color: #5a3030;
    background: #1a0d0d;
}

/* ── Stimulus / task ── */
#stim-area {
    width: 100%;
    min-height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    margin-bottom: 1.2rem;
    padding: 1.5rem;
}

#exert {
    font-size: 18px;
    line-height: 1.6;
    word-break: break-word;
    max-height: 30vh;
    overflow: hidden;
}

#typed { color: var(--green); }
#toType { color: var(--text-dim); }

/* ── Progress ── */
.progress-wrap {
    width: 100%;
    height: 2px;
    background: var(--border);
    border-radius: 2px;
    margin-bottom: 1.2rem;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--text);
    transition: width 0.35s ease;
}

/* ── Feedback line ── */
#feedback-line {
    font-size: 14px;
    color: var(--muted);
    min-height: 18px;
    text-align: center;
    width: 100%;
    font-family: var(--font-mono);
}

#feedback-line.ok  { color: var(--green); }
#feedback-line.bad { color: var(--red); }

/* ── Results ── */
.result-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    width: 100%;
    margin: 1.2rem 0;
}

@media (max-width: 600px) {
    .result-grid { grid-template-columns: 1fr 1fr; }
}

.result-card {
    padding: 14px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
}

.result-card .rc-lbl {
    display: block;
    font-size: 10px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 6px;
}

.result-card .rc-val {
    display: block;
    font-size: 24px;
    font-weight: 500;
    color: var(--text);
}

/* ── Trial log ── */
.trial-log {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-top: 0.5rem;
    background: var(--surface);
}

.trial-log-head {
    display: grid;
    grid-template-columns: 0.6fr 1fr 1fr 1.2fr;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 9px 14px;
    gap: 8px;
}

.trial-log-head span {
    font-size: 9px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--label);
}

.trial-log-body {
    max-height: 220px;
    overflow-y: auto;
}

.trial-row {
    display: grid;
    grid-template-columns: 0.6fr 1fr 1fr 1.2fr;
    padding: 7px 14px;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    align-items: center;
}

.trial-row:last-child { border-bottom: none; }

.trial-row span {
    font-family: var(--font-mono);
    color: #aaa;
}

/* ── Badges ── */
.badge {
    display: inline-block;
    font-size: 9px;
    font-weight: 500;
    letter-spacing: 0.1em;
    padding: 2px 7px;
    border-radius: 3px;
    text-transform: uppercase;
    width: fit-content;
}

.badge.ok  { background: #0e2a15; color: var(--green); }
.badge.bad { background: #2a0e0e; color: var(--red);   }

/* ── Past attempts ── */
#past-attempts { width: 100%; }

.past-list {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
}

.past-row {
    display: grid;
    grid-template-columns: 0.5fr 1fr 1fr 0.7fr;
    padding: 8px 14px;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    align-items: center;
}

.past-row:last-child { border-bottom: none; }

.past-row span {
    font-family: var(--font-mono);
    color: #aaa;
}

/* ── Scrollbars ── */
.trial-log-body::-webkit-scrollbar { width: 4px; }
.trial-log-body::-webkit-scrollbar-track { background: var(--surface); }
.trial-log-body::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 4px; }

/* ── Check items (radio cards) ── */
.check-group {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
}

.check-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    flex: 1;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    user-select: none;
}

.check-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.16);
}

.check-item input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.check-box {
    flex: 0 0 22px;
    width: 22px;
    height: 22px;
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    background: transparent;
    transition: background 0.15s, border-color 0.15s;
    position: relative;
}

.check-box::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #111;
    transform: translate(-50%, -50%) scale(0);
    transition: transform 0.15s ease;
}

.check-item input:checked ~ .check-box {
    background: var(--green);
    border-color: var(--green);
}

.check-item input:checked ~ .check-box::after {
    transform: translate(-50%, -50%) scale(1);
}

.check-item:has(input:checked) {
    background: rgba(94, 201, 122, 0.08);
    border-color: rgba(94, 201, 122, 0.35);
}

.check-content { display: flex; flex-direction: column; gap: 4px; }

.check-title {
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.3;
}

/* ── Reaction task additions ── */
#stim-area.armed { border-color: var(--border-bright); }

.probe {
    font-size: 120px;
    font-weight: 500;
    line-height: 1;
    color: var(--accent);
    user-select: none;
    animation: probe-in 0.06s ease;
}

@keyframes probe-in { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }

.stim-hint {
    font-size: 13px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
    text-align: center;
}

.sound-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 1px solid var(--border-bright);
    background: var(--surface);
    color: var(--accent);
    font-size: 26px;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), transform 0.1s;
}

.sound-btn:hover { background: var(--surface-2); border-color: #555; }
.sound-btn:active { transform: scale(0.94); }

.sound-btn.pulsing { animation: pulse 0.9s ease-in-out infinite; }

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(246, 193, 59, 0.0); }
    50%      { box-shadow: 0 0 0 10px rgba(246, 193, 59, 0.12); }
}
