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

  :root {
    --bg: #0a0a0a;
    --surface: #141414;
    --border: #272727;
    --border-bright: #3a3a3a;
    --text: #e8e8e8;
    --muted: #666;
    --dimmed: #3d3d3d;
    --accent: #e8e8e8;
    --red:    #e05252;
    --blue:   #5b8dee;
    --green:  #5ec97a;
    --yellow: #d4aa3f;
    --orange: #d97b3a;
    --purple: #9b7fe8;
    --pink:   #d965a0;
    --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;
  }

  .page {
    display: none;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    max-width: 500px;
    animation: fadein 0.4s ease;
  }
  .page.active { display: flex; }

  @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-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    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: 14px;
    transition: border-color var(--transition), background var(--transition);
    font-family: var(--font-mono);
  }
  .nav-btn:hover { border-color: var(--border-bright); background: var(--surface); }
  .nav-btn:disabled { opacity: 0.25; cursor: not-allowed; }
  .nav-btn.hidden { visibility: hidden; }

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

  h2 {
    font-family: var(--font-mono);
    font-size: 22px;
    font-weight: 500;
    margin-bottom: 1rem;
    line-height: 1.3;
    color: var(--text);
  }

  p {
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 300;
    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: 14px;
    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: 13px;
    color: #e08080;
    margin-top: 1rem;
  }

  /* ── Buttons ── */
  .btn {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 400;
    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;
  }
  .btn:hover { background: var(--surface); border-color: #555; }
  .btn:active { transform: scale(0.97); }

  .btn-primary {
    background: var(--text);
    color: var(--bg);
    border-color: var(--text);
  }
  .btn-primary:hover { background: #ccc; border-color: #ccc; }

  /* ── Mic status bar ── */
  .mic-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    width: 100%;
    margin-bottom: 1.5rem;
  }
  .mic-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--dimmed);
    flex-shrink: 0;
    transition: background 0.3s;
  }
  .mic-dot.listening {
    background: var(--red);
    animation: pulse 1s infinite;
  }
  .mic-dot.ready { background: var(--green); }
  @keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }
  .mic-label {
    font-size: 11px;
    color: var(--muted);
    font-family: var(--font-mono);
  }
  .mic-heard {
    margin-left: auto;
    font-size: 11px;
    color: var(--dimmed);
    font-family: var(--font-mono);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

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

  #stim-word {
    font-family: var(--font-mono);
    font-size: 64px;
    font-weight: 600;
    letter-spacing: -1px;
    line-height: 1;
    transition: opacity 0.1s, transform 0.12s;
    user-select: none;
  }
  #stim-word.flash {
    opacity: 0.4;
    transform: scale(1.06);
  }

  #stim-hint {
    font-size: 10px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--dimmed);
    margin-top: 14px;
    font-family: var(--font-mono);
  }

  /* ── 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);
    border-radius: 2px;
    transition: width 0.35s ease;
  }

  /* ── Stats row ── */
  .stats-row {
    display: flex;
    gap: 10px;
    width: 100%;
    margin-bottom: 1.2rem;
  }
  .stat {
    flex: 1;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
  }
  .stat-lbl {
    display: block;
    font-size: 9px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 4px;
  }
  .stat-val {
    display: block;
    font-size: 20px;
    font-weight: 500;
    color: var(--text);
  }

  /* ── Feedback ── */
  #feedback-line {
    font-size: 12px;
    color: var(--muted);
    min-height: 18px;
    text-align: center;
    width: 100%;
    transition: color 0.2s;
    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;
    gap: 10px;
    width: 100%;
    margin: 1.2rem 0;
  }

  .result-card {
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
  }
  .result-card .rc-lbl {
    display: block;
    font-size: 9px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 6px;
  }
  .result-card .rc-val {
    display: block;
    font-size: 28px;
    font-weight: 500;
  }

  .trial-log {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-top: 0.5rem;
  }
  .trial-log-header {
    display: grid;
    grid-template-columns: 2fr 2fr 2fr 1.2fr 1.5fr;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 7px 12px;
    gap: 8px;
  }
  .trial-log-header span {
    font-size: 9px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
  }
  .trial-log-body { max-height: 180px; overflow-y: auto; }
  .trial-row {
    display: grid;
    grid-template-columns: 2fr 2fr 2fr 1.2fr 1.5fr;
    padding: 6px 12px;
    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; }
  .badge {
    display: inline-block;
    font-size: 9px;
    font-weight: 500;
    letter-spacing: 0.1em;
    padding: 2px 7px;
    border-radius: 3px;
    text-transform: uppercase;
  }
  .badge.ok  { background: #0e2a15; color: var(--green); }
  .badge.bad { background: #2a0e0e; color: var(--red); }
  .badge.type-con  { background: #1a1a2e; color: #7b94d4; }
  .badge.type-inc  { background: #2a1a10; color: #c4895a; }

  .color-dot {
    display: inline-block;
    width: 9px; height: 9px;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: middle;
  }

  /* ── Step instruction ── */
  .step-num {
    font-size: 10px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 8px;
  }
  .step-demo {
    font-family: var(--font-mono);
    font-size: 48px;
    font-weight: 600;
    margin: 1.2rem 0;
  }

  .btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

  /* scrollbar */
  .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; }
  .config-options { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0; }
.preset-btn {
  padding: 12px 20px; border: 1px solid var(--border, #444);
  background: transparent; color: var(--text, #eee); border-radius: 8px;
  cursor: pointer; font-size: 16px;
}
.preset-btn.active { background: #5ec97a; color: #111; border-color: #5ec97a; }
.custom-row { display: flex; align-items: center; gap: 10px; margin: 12px 0; }
.custom-row input { padding: 8px; width: 100px; }
.muted { color: var(--muted, #888); }
