    :root {
      --bg: #eef2f7;
      --surface: #ffffff;
      --surface-2: #f8fafc;
      --border: #dfe5ee;
      --border-strong: #c7d0dd;
      --text: #1f2937;
      --text-muted: #64748b;
      --primary: #6366f1;
      --primary-dark: #4f46e5;
      --primary-soft: #eef2ff;
      --blue: #3b82f6;
      --success: #16a34a;
      --success-soft: #ecfdf3;
      --danger: #dc2626;
      --danger-soft: #fef2f2;
      --warn: #f59e0b;
      --warn-soft: #fef9c3;
      --radius: 16px;
      --radius-sm: 10px;
      --shadow-sm: 0 1px 2px rgba(15,23,42,.05), 0 1px 3px rgba(15,23,42,.07);
      --shadow-md: 0 6px 16px -6px rgba(15,23,42,.14);
      --font: 'Nunito', 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
    }

    /* Dark theme */
    [data-theme="dark"] {
      --bg: #0b1220;
      --surface: #151e2e;
      --surface-2: #1d2939;
      --border: #2a3a50;
      --border-strong: #3d5069;
      --text: #e6edf6;
      --text-muted: #93a5bf;
      --primary: #818cf8;
      --primary-dark: #6366f1;
      --primary-soft: #232b4d;
      --blue: #38bdf8;
      --success: #34d399;
      --success-soft: #123524;
      --danger: #f87171;
      --danger-soft: #3b1616;
      --warn: #fbbf24;
      --warn-soft: #3a2a08;
      --shadow-sm: 0 1px 2px rgba(0,0,0,.4), 0 1px 3px rgba(0,0,0,.45);
      --shadow-md: 0 6px 16px -6px rgba(0,0,0,.55);
    }
    /* In dark mode use the lighter indigo for text accents so they stay readable
       on dark surfaces (gradient buttons keep --primary-dark for white text). */
    [data-theme="dark"] .year-hint strong,
    [data-theme="dark"] .year-status.ok,
    [data-theme="dark"] #nav button:hover,
    [data-theme="dark"] #tabs .tab:hover,
    [data-theme="dark"] .btn-secondary:hover,
    [data-theme="dark"] .stats-tab:hover,
    [data-theme="dark"] .chip:hover,
    [data-theme="dark"] .lead strong,
    [data-theme="dark"] .op-icon,
    [data-theme="dark"] .op-ex,
    [data-theme="dark"] .page td.lv {
      color: var(--primary);
    }
    * { box-sizing: border-box; }
    body {
      margin: 0;
      font-family: var(--font);
      color: var(--text);
      background:
        radial-gradient(1100px 480px at 85% -10%, rgba(99,102,241,.12), transparent 60%),
        radial-gradient(900px 420px at -8% 5%, rgba(14,165,233,.10), transparent 60%),
        var(--bg);
      min-height: 100vh;
    }

    /* ---------- Header ---------- */
    .app-header {
      background: linear-gradient(120deg, #4338ca 0%, #6366f1 50%, #0ea5e9 100%);
      color: #fff;
      padding: 12px 0;
      box-shadow: var(--shadow-md);
    }
    .app-header-inner {
      max-width: 1240px;
      margin: 0 auto;
      padding: 0 14px;
      display: flex;
      align-items: center;
      gap: 14px;
    }
    .app-title-block { min-width: 0; }
    .app-logo {
      width: 48px;
      height: 48px;
      flex: none;
      display: grid;
      place-items: center;
      font-size: 26px;
      background: rgba(255,255,255,.18);
      border: 1px solid rgba(255,255,255,.25);
      border-radius: 14px;
    }
    .app-title { margin: 0; font-size: 24px; font-weight: 900; letter-spacing: .2px; line-height: 1.1; }
    .app-subtitle { margin: 2px 0 0; font-size: 13px; font-weight: 600; opacity: .9; }

    /* Header right-side actions: theme selector + help link */
    .header-actions {
      margin-left: auto;
      display: flex;
      align-items: center;
      gap: 10px;
      flex: none;
    }
    .help-link {
      width: 38px;
      height: 38px;
      flex: none;
      display: grid;
      place-items: center;
      font-family: var(--font);
      font-size: 20px;
      font-weight: 900;
      line-height: 1;
      color: #fff;
      text-decoration: none;
      border-radius: 50%;
      background: rgba(255,255,255,.18);
      border: 1.5px solid rgba(255,255,255,.35);
      transition: background .15s, transform .08s;
    }
    .help-link:hover { background: rgba(255,255,255,.32); }
    .help-link:active { transform: translateY(1px); }
    .help-link:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(255,255,255,.45); }
    .theme-select {
      font-family: var(--font);
      font-size: 13px;
      font-weight: 800;
      color: #fff;
      padding: 8px 30px 8px 12px;
      width: auto;
      border-radius: 10px;
      border: 1.5px solid rgba(255,255,255,.35);
      background: rgba(255,255,255,.16) url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
      cursor: pointer;
      appearance: none;
      -webkit-appearance: none;
      transition: background .15s, border-color .15s;
    }
    .theme-select:hover,
    .theme-select:focus { border-color: rgba(255,255,255,.55); background-color: rgba(255,255,255,.26); }
    .theme-select:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(255,255,255,.45); }
    .theme-select option { color: var(--text); background: var(--surface); }

    /* ---------- Layout ---------- */
    .app-main {
      max-width: 1240px;
      margin: 0 auto;
      padding: 16px 14px 40px;
      display: grid;
      grid-template-columns: minmax(280px, 340px) 1fr auto;
      gap: 18px;
      align-items: start;
    }
    .card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      box-shadow: var(--shadow-sm);
      padding: 14px;
    }
    .control-panel {
      position: sticky;
      top: 14px;
      display: flex;
      flex-direction: column;
      gap: 12px;
      min-width: 0;
    }

    /* ---------- Config tabs & school-year level bars ---------- */
    .cfg-tabs {
      display: flex;
      gap: 6px;
      background: var(--surface-2);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 4px;
    }
    .cfg-tab {
      flex: 1;
      font-family: var(--font);
      font-size: 13px;
      font-weight: 800;
      padding: 8px 10px;
      border: none;
      border-radius: 9px;
      background: transparent;
      color: var(--text-muted);
      cursor: pointer;
      transition: background .15s, color .15s, box-shadow .15s;
    }
    .cfg-tab:hover { color: var(--primary-dark); background: var(--surface); }
    .cfg-tab.active {
      background: linear-gradient(120deg, var(--primary), var(--primary-dark));
      color: #fff;
      box-shadow: 0 4px 10px -4px rgba(79,70,229,.6);
    }
    .cfg-panel { display: flex; flex-direction: column; gap: 12px; }
    .cfg-panel[hidden] { display: none; }
    .year-hint {
      margin: 6px 0 0;
      font-size: 12px;
      font-weight: 600;
      color: var(--text-muted);
      line-height: 1.5;
    }
    .year-hint strong { color: var(--primary-dark); }
    .year-bar-row { display: flex; flex-direction: column; gap: 5px; }
    .year-bar-row + .year-bar-row { margin-top: 12px; }
    .year-bar-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
    .year-bar-name { font-size: 12.5px; font-weight: 800; }
    .year-bar-value { font-size: 11.5px; font-weight: 800; color: var(--text-muted); font-variant-numeric: tabular-nums; }
    .year-bar { display: flex; gap: 3px; height: 18px; }
    .year-seg {
      flex: 1;
      height: 100%;
      padding: 0;
      border: none;
      background: var(--border);
      border-radius: 4px;
      cursor: pointer;
      transition: background .15s, transform .1s, box-shadow .15s;
    }
    .year-seg:hover { background: var(--border-strong); }
    .year-seg:active { transform: scale(.9); }
    .year-seg:focus-visible {
      outline: none;
      box-shadow: 0 0 0 2px var(--primary);
    }
    .year-seg.active { background: linear-gradient(180deg, var(--primary), var(--primary-dark)); }
    .year-seg.available { border: 2px solid var(--success); }
    .year-seg.available:hover { background: var(--success-soft); }
    .year-seg.completed { border: 2px solid; }
    .year-status {
      margin: 12px 0 0;
      font-size: 12px;
      font-weight: 700;
      line-height: 1.5;
      color: var(--text-muted);
      background: var(--surface-2);
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 9px 11px;
    }
    .year-status.ok { color: var(--primary-dark); border-color: var(--primary); background: var(--primary-soft); }
    .year-status.warn { color: #92400e; border-color: #fcd34d; background: #fffbeb; }
    .year-legend {
      margin: 14px 0 0;
      font-size: 11.5px;
      font-weight: 700;
      color: var(--text-muted);
      line-height: 1.5;
      background: var(--surface-2);
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 9px 11px;
    }
    .year-legend b { color: var(--primary-dark); }

    /* ---------- Session stats panel ---------- */
    .sr-only {
      position: absolute;
      width: 1px;
      height: 1px;
      padding: 0;
      margin: -1px;
      overflow: hidden;
      clip: rect(0 0 0 0);
      white-space: nowrap;
      border: 0;
    }
    .stats-column {
      position: relative;
      min-width: 0;
    }
    .stats-tab {
      position: fixed;
      right: 0;
      top: 50%;
      transform: translateY(-50%);
      z-index: 6;
      width: 26px;
      height: 54px;
      display: grid;
      place-items: center;
      padding: 0;
      border: 1.5px solid var(--border-strong);
      border-right: none;
      border-radius: 12px 0 0 12px;
      background: var(--surface);
      box-shadow: var(--shadow-sm);
      cursor: pointer;
      color: var(--text-muted);
      font-size: 15px;
      transition: color .15s, background .15s, border-color .15s;
    }
    .stats-tab:hover {
      color: var(--primary-dark);
      border-color: var(--primary);
      background: var(--primary-soft);
    }
    .stats-tab:focus-visible {
      outline: none;
      border-color: var(--primary);
      box-shadow: 0 0 0 3px rgba(99,102,241,.25);
    }
    .stats-tab-chevron {
      display: inline-block;
      transition: transform .32s ease;
    }
    body.stats-closed .stats-tab-chevron { transform: rotate(180deg); }
    .stats-clip {
      width: 286px;
      margin-left: 0;
      overflow: hidden;
      overflow: clip;
      transition: width .32s ease;
    }
    body.stats-closed .stats-clip { width: 0; }
    .stats-panel {
      width: 286px;
      display: flex;
      flex-direction: column;
      gap: 12px;
    }
    .stats-block { display: flex; flex-direction: column; gap: 9px; }
    .stat-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      font-size: 13px;
    }
    .stat-label { font-weight: 700; color: var(--text-muted); }
    .stat-value { font-weight: 800; font-variant-numeric: tabular-nums; }
    .stat-value.live { color: var(--primary); }
    .stat-badge {
      min-width: 42px;
      text-align: center;
      padding: 2px 9px;
      border-radius: 999px;
      font-size: 12px;
      font-weight: 800;
      font-variant-numeric: tabular-nums;
    }
    .stat-badge.ok { background: var(--success-soft); color: var(--success); }
    .stat-badge.no { background: var(--danger-soft); color: var(--danger); }
    .stat-divider { border: none; border-top: 1px solid var(--border); margin: 0; }
    .stat-bar { display: flex; flex-direction: column; gap: 5px; }
    .stat-bar-label {
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-size: 11.5px;
      font-weight: 800;
      color: var(--text-muted);
      font-variant-numeric: tabular-nums;
    }
    .stat-bar-track {
      height: 10px;
      border-radius: 999px;
      background: var(--surface-2);
      border: 1px solid var(--border);
      overflow: hidden;
    }
    .stat-bar-fill {
      height: 100%;
      width: 0%;
      border-radius: 999px;
      background: linear-gradient(90deg, var(--primary), #0ea5e9);
      transition: width .4s ease;
    }
    .stats-reset { align-self: flex-start; }
    @media (max-width: 940px) {
      .app-main {
        grid-template-columns: 1fr;
        padding: 14px 10px 40px;
      }
      .control-panel {
        position: static;
      }
      .app-header-inner { gap: 10px; padding: 0 10px; }
      .app-logo { width: 40px; height: 40px; font-size: 22px; }
      .app-title { font-size: 20px; }
      .app-subtitle { font-size: 12px; }
      .header-actions { gap: 8px; }
      .help-link { width: 34px; height: 34px; font-size: 18px; }
      .theme-select { padding: 7px 28px 7px 10px; font-size: 12px; }

      .stats-column {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        z-index: 50;
      }
      .stats-tab {
        position: fixed;
        left: auto;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 30px;
        height: 58px;
        border-left: 1.5px solid var(--border-strong);
        border-right: none;
        border-radius: 12px 0 0 12px;
      }
      .stats-clip {
        width: min(320px, 88vw);
        height: 100%;
        margin-left: 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
      }
      .stats-panel {
        width: min(320px, 88vw);
        max-height: calc(100vh - 32px);
        overflow-y: auto;
      }
    }
    .panel-title {
      margin: 0 0 8px;
      font-size: 10.5px;
      font-weight: 800;
      text-transform: uppercase;
      letter-spacing: .08em;
      color: var(--text-muted);
      display: flex;
      align-items: center;
      gap: 6px;
    }
    .panel-title::before {
      content: '';
      width: 4px;
      height: 14px;
      border-radius: 4px;
      background: linear-gradient(180deg, var(--primary), #0ea5e9);
    }

    .field-grid {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 8px 10px;
    }
    .field { display: flex; flex-direction: column; gap: 4px; }
    .field-label { font-size: 11px; font-weight: 700; color: var(--text-muted); }

    /* one-row field groupings */
    .type-row {
      display: flex;
      align-items: flex-end;
      gap: 12px;
      margin-top: 12px;
    }
    .type-field { flex: none; }
    .type-field select { width: auto; }
    .type-row .toggle-row { margin-top: 0; }
    .remax-toggle { flex: 1 1 auto; }
    .action-row {
      display: flex;
      align-items: center;
      gap: 12px;
    }
    .action-row .toggle-row { margin-top: 0; }
    .action-generate {
      flex: none;
      font-size: 13.5px;
      padding: 9px 20px;
    }

    input[type="number"],
    select {
      font-family: var(--font);
      font-size: 13px;
      font-weight: 700;
      color: var(--text);
      background: var(--surface-2);
      border: 1.5px solid var(--border-strong);
      border-radius: var(--radius-sm);
      padding: 6px 9px;
      width: 100%;
      transition: border-color .15s, box-shadow .15s, background .15s;
    }
    input[type="number"]:focus,
    select:focus {
      outline: none;
      border-color: var(--primary);
      box-shadow: 0 0 0 3px rgba(99,102,241,.18);
      background: var(--surface);
    }
    select { cursor: pointer; }

    /* ---------- Toggle switch ---------- */
    .toggle-row {
      display: flex;
      flex-direction: row;
      align-items: center;
      gap: 8px;
      margin-top: 10px;
      font-size: 12.5px;
      font-weight: 700;
      color: var(--text);
      cursor: pointer;
      user-select: none;
    }
    .toggle-row input[type="checkbox"] { position: absolute; opacity: 0; width: 0; height: 0; }
    .toggle-row .switch {
      order: 2;
      width: 34px;
      height: 20px;
      flex: none;
      border-radius: 999px;
      background: var(--border-strong);
      position: relative;
      transition: background .2s, box-shadow .2s;
    }
    .toggle-row .switch::after {
      content: '';
      position: absolute;
      top: 3px;
      left: 3px;
      width: 14px;
      height: 14px;
      border-radius: 50%;
      background: #fff;
      box-shadow: 0 1px 3px rgba(0,0,0,.3);
      transition: transform .2s;
    }
    .toggle-row input:checked + .switch { background: var(--primary); }
    .toggle-row input:checked + .switch::after { transform: translateX(14px); }
    .toggle-row input:focus-visible + .switch { box-shadow: 0 0 0 3px rgba(99,102,241,.3); }

    /* ---------- Buttons ---------- */
    .btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
    .btn {
      font-family: var(--font);
      font-size: 12.5px;
      font-weight: 800;
      padding: 7px 12px;
      border-radius: 10px;
      border: 1.5px solid transparent;
      cursor: pointer;
      transition: transform .08s, box-shadow .15s, background .15s, border-color .15s, color .15s, filter .15s;
    }
    .btn:active { transform: translateY(1px); }
    .btn-primary {
      background: linear-gradient(120deg, var(--primary), var(--primary-dark));
      color: #fff;
      box-shadow: 0 6px 14px -6px rgba(79,70,229,.55);
    }
    .btn-primary:hover { filter: brightness(1.05); box-shadow: 0 8px 18px -6px rgba(79,70,229,.65); }
    .btn-secondary {
      background: var(--surface);
      color: var(--text);
      border-color: var(--border-strong);
    }
    .btn-secondary:hover { background: var(--surface-2); border-color: var(--primary); color: var(--primary-dark); }

    /* ---------- Worksheet area ---------- */
    .worksheet-area {
      display: flex;
      flex-direction: column;
      gap: 16px;
      min-width: 0;
    }
    .worksheet-hint {
      margin: 0;
      text-align: center;
      font-size: 13px;
      font-weight: 600;
      color: var(--text-muted);
      background: var(--surface-2);
      border: 1px dashed var(--border-strong);
      border-radius: 12px;
      padding: 11px 14px;
    }
    .worksheet-hint strong { color: var(--primary-dark); }

    #TBL:empty::after {
      content: 'No worksheet yet — set your options and press "Generate Worksheet".';
      display: block;
      text-align: center;
      font-size: 15px;
      font-weight: 700;
      color: var(--text-muted);
      background: var(--surface-2);
      border: 1.5px dashed var(--border-strong);
      border-radius: var(--radius);
      padding: 64px 24px;
    }

    /* ---------- Slide ---------- */
    .slide {
      display: block;
      width: 100%;
      max-width: 460px;
      margin: 0 auto;
      padding: 26px 24px 20px;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      box-shadow: var(--shadow-md);
      overflow-x: auto;
    }
    .slide.hidden { display: none; }
    .slide-top, .slide-bottom {
      font-size: 40px;
      font-weight: 800;
      line-height: 1.4;
      text-align: right;
      width: 60%;
      margin: 0 auto;
      font-variant-numeric: tabular-nums;
    }
    .slide-op { display: inline-block; width: 1.4em; text-align: left; }
    .slide-line { border-bottom: 2px solid var(--text); width: 60%; margin: 8px auto; }
    .slide-answer { font-size: 32px; text-align: center; min-height: 40px; color: var(--success); font-weight: 800; }

    /* ---------- Columnar grid (add / sub / mul / div) ---------- */
    .addition-grid {
      display: flex;
      flex-direction: column;
      align-items: flex-end;
      width: fit-content;
      margin: 0 auto;
      padding: 4px 0;
    }
    .row { display: flex; }
    .cell {
      width: 44px;
      height: 38px;
      text-align: center;
      font-size: 26px;
      font-weight: 800;
      line-height: 38px;
      font-variant-numeric: tabular-nums;
    }
    .op-cell { width: 22px; font-size: 22px; }
    .line-cell { border-top: 2px solid var(--text); }

    .carry-input, .answer-cell, .pp-cell, .ld-cell {
      width: 38px;
      height: 30px;
      font-size: 24px;
      font-weight: 700;
      text-align: center;
      border: 1.5px solid var(--border-strong);
      border-radius: 8px;
      padding: 0;
      box-sizing: border-box;
      background: var(--surface);
      color: var(--text);
      font-family: var(--font);
      font-variant-numeric: tabular-nums;
      transition: border-color .15s, box-shadow .15s, background .15s;
    }
    .carry-input, .mul-carry, .reduced-input, .pp-carry {
      width: 32px;
      height: 24px;
      font-size: 17px;
      color: var(--blue);
      background: var(--primary-soft);
      border: 1.5px solid var(--border-strong);
      border-radius: 6px;
    }
    .answer-cell {
      border: 1.5px solid var(--border-strong);
      border-top: 2.5px solid var(--text);
      border-radius: 0 0 8px 8px;
      font-weight: 800;
    }
    .carry-input:focus, .answer-cell:focus, .pp-cell:focus, .ld-cell:focus,
    .reduced-input:focus, .borrow-one:focus, .mul-carry:focus, .pp-carry:focus {
      outline: none;
      border-color: var(--primary);
      box-shadow: 0 0 0 3px rgba(99,102,241,.2);
      background: var(--surface);
    }
    .carry-answer {
      font-size: 16px;
      color: var(--blue);
      height: 24px;
      line-height: 24px;
      font-weight: 700;
    }
    .answer-digit {
      border-top: 2px solid var(--text);
      line-height: 36px;
    }

    /* step-state highlights */
    .answer-cell.field-next, .carry-input.field-next,
    .reduced-input.field-next, .borrow-one.field-next,
    .pp-cell.field-next, .mul-carry.field-next, .ld-cell.field-next, .pp-carry.field-next {
      background-color: var(--warn-soft);
      border-color: var(--warn);
      box-shadow: 0 0 0 2px rgba(245,158,11,.28);
    }
    .carry-input.carry-correct, .reduced-input.carry-correct, .borrow-one.carry-correct,
    .pp-cell.carry-correct, .mul-carry.carry-correct, .ld-cell.carry-correct, .pp-carry.carry-correct {
      border-color: var(--success);
      color: var(--success);
      background: var(--success-soft);
      box-shadow: none;
    }
    .carry-input.carry-wrong, .reduced-input.carry-wrong, .borrow-one.carry-wrong,
    .pp-cell.carry-wrong, .mul-carry.carry-wrong, .ld-cell.carry-wrong, .pp-carry.carry-wrong {
      border-color: var(--danger);
      color: var(--danger);
      background: var(--danger-soft);
      box-shadow: none;
    }

    /* subtraction helpers */
    .top-cell {
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 0;
    }
    .borrow-one {
      position: absolute;
      left: -2px;
      top: 50%;
      transform: translateY(-50%);
      width: 15px;
      height: 22px;
      font-size: 13px;
      text-align: center;
      border: 1px solid var(--border-strong);
      border-radius: 5px;
      padding: 0;
      color: var(--blue);
      background: var(--primary-soft);
      box-sizing: border-box;
      font-family: var(--font);
    }
    .borrow-one-answer {
      position: absolute;
      left: 2px;
      top: 50%;
      transform: translateY(-50%);
      font-size: 14px;
      color: var(--blue);
      font-weight: 700;
    }
    .tdigit { font-size: 22px; font-weight: 800; line-height: 30px; }
    .reduced-answer {
      font-size: 16px;
      color: var(--blue);
      height: 24px;
      line-height: 24px;
      font-weight: 700;
    }

    /* long division */
    .ld-margin {
      width: 76px;
      text-align: right;
      font-size: 26px;
      font-weight: 800;
      line-height: 38px;
    }
    .ld-divisor { white-space: nowrap; }
    .ld-dividend-digit { border-top: 2px solid var(--text); }
    .ld-cell { font-weight: 700; }
    .ld-minus { font-size: 24px; font-weight: 800; line-height: 38px; }

    /* ---------- Answer entry ---------- */
    .answer-entry {
      margin-top: 16px;
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 10px;
    }
    .answer-input {
      font-family: var(--font);
      font-size: 22px;
      font-weight: 700;
      width: 132px;
      text-align: center;
      padding: 6px 10px;
      border: 1.5px solid var(--border-strong);
      border-radius: 12px;
      background: var(--surface);
      color: var(--text);
      transition: border-color .15s, box-shadow .15s;
    }
    .answer-input:focus {
      outline: none;
      border-color: var(--primary);
      box-shadow: 0 0 0 3px rgba(99,102,241,.2);
    }
    .check-btn {
      font-family: var(--font);
      font-size: 15px;
      font-weight: 800;
      padding: 9px 22px;
      border: none;
      border-radius: 12px;
      background: linear-gradient(120deg, var(--primary), var(--primary-dark));
      color: #fff;
      cursor: pointer;
      box-shadow: 0 6px 14px -6px rgba(79,70,229,.55);
      transition: filter .15s, transform .08s, box-shadow .15s;
    }
    .check-btn:hover { filter: brightness(1.05); }
    .check-btn:active { transform: translateY(1px); }
    .answer-feedback {
      font-size: 28px;
      font-weight: 800;
      min-width: 26px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
    }
    .answer-feedback.correct { color: var(--success); }
    .answer-feedback.wrong { color: var(--danger); }

    /* ---------- Navigation ---------- */
    #nav {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 12px;
      margin: 6px 0 4px;
    }
    #nav .nav-row { display: flex; align-items: center; gap: 10px; }
    #nav button {
      font-family: var(--font);
      font-size: 14px;
      font-weight: 800;
      padding: 10px 18px;
      border-radius: 12px;
      border: 1.5px solid var(--border-strong);
      background: var(--surface);
      color: var(--text);
      cursor: pointer;
      transition: background .15s, border-color .15s, color .15s, transform .08s;
    }
    #nav button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary-dark); background: var(--primary-soft); }
    #nav button:active:not(:disabled) { transform: translateY(1px); }
    #nav button:disabled { opacity: .4; cursor: default; }
    #counter {
      font-size: 14px;
      font-weight: 700;
      color: var(--text-muted);
      min-width: 128px;
      text-align: center;
    }
    #tabs {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      gap: 6px;
      max-width: 100%;
    }
    #tabs .tab {
      font-family: var(--font);
      font-size: 13px;
      font-weight: 800;
      width: 36px;
      height: 36px;
      padding: 0;
      display: grid;
      place-items: center;
      border-radius: 11px;
      border: 1.5px solid var(--border-strong);
      background: var(--surface);
      color: var(--text-muted);
      cursor: pointer;
      transition: background .15s, color .15s, border-color .15s, transform .08s, box-shadow .15s;
    }
    #tabs .tab:hover { border-color: var(--primary); color: var(--primary-dark); }
    #tabs .tab.done-correct {
      background: var(--success-soft);
      color: var(--success);
      border-color: #a7f3d0;
    }
    #tabs .tab.done-wrong {
      background: var(--danger-soft);
      color: var(--danger);
      border-color: #fecaca;
    }
    #tabs .tab.opened {
      background: var(--surface-2);
      color: var(--text-muted);
      border-color: var(--border-strong);
    }
    #tabs .tab.active {
      box-shadow: 0 0 0 2px var(--primary), 0 4px 10px -4px rgba(79,70,229,.55);
      font-weight: 900;
    }

    /* ---------- Footer ---------- */
    .app-footer {
      grid-column: 1 / -1;
      text-align: center;
      font-size: 12px;
      font-weight: 600;
      color: var(--text-muted);
      opacity: .85;
    }

    /* ---------- Parent level guide page ---------- */
    .page {
      max-width: 1240px;
      margin: 0 auto;
      padding: 16px 14px 40px;
      display: flex;
      flex-direction: column;
      gap: 20px;
    }
    .page .panel-title { margin: 0 0 12px; font-size: 13px; }
    .page .panel-title::before { height: 16px; }

    .lead { margin: 0; font-size: 15px; line-height: 1.6; color: var(--text); }
    .lead strong { color: var(--primary-dark); }
    .note {
      margin: 14px 0 0;
      font-size: 13px;
      line-height: 1.55;
      color: var(--text-muted);
      background: var(--warn-soft);
      border: 1px solid #fde68a;
      border-radius: 12px;
      padding: 12px 14px;
    }
    .note strong { color: #b45309; }
    .two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
    @media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }

    /* Grade selector */
    .chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 16px; }
    .chip {
      font-family: var(--font);
      font-size: 13px;
      font-weight: 800;
      padding: 8px 14px;
      border-radius: 999px;
      border: 1.5px solid var(--border-strong);
      background: var(--surface);
      color: var(--text);
      cursor: pointer;
      transition: background .15s, color .15s, border-color .15s, transform .08s, box-shadow .15s;
    }
    .chip:hover { border-color: var(--primary); color: var(--primary-dark); }
    .chip.active {
      background: linear-gradient(120deg, var(--primary), var(--primary-dark));
      color: #fff;
      border-color: transparent;
      box-shadow: 0 5px 12px -5px rgba(79,70,229,.6);
    }
    .chip small { display: block; font-size: 10.5px; font-weight: 700; opacity: .85; }

    /* Result panel */
    #result { display: none; }
    #result.show { display: block; }
    .result-head {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      padding-bottom: 14px;
      border-bottom: 1px solid var(--border);
      margin-bottom: 16px;
    }
    .result-head h3 { margin: 0; font-size: 20px; font-weight: 900; }
    .result-head .meta { color: var(--text-muted); font-weight: 700; font-size: 13px; }
    .overall-badge {
      font-size: 13px;
      font-weight: 900;
      color: #fff;
      background: linear-gradient(120deg, var(--primary), var(--primary-dark));
      padding: 8px 16px;
      border-radius: 999px;
      box-shadow: 0 5px 12px -5px rgba(79,70,229,.6);
    }
    .op-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
    @media (max-width: 560px) { .op-grid { grid-template-columns: 1fr; } }
    .op-card {
      border: 1px solid var(--border);
      border-radius: 14px;
      background: var(--surface-2);
      padding: 14px 16px;
      display: flex;
      flex-direction: column;
      gap: 8px;
    }
    .op-head { display: flex; align-items: center; gap: 8px; font-weight: 900; font-size: 15px; }
    .op-icon {
      width: 30px; height: 30px; flex: none;
      display: grid; place-items: center;
      border-radius: 9px;
      background: var(--primary-soft);
      color: var(--primary-dark);
      font-size: 15px;
    }
    .op-level { font-size: 13px; color: var(--text-muted); font-weight: 700; }
    .op-level b { color: var(--text); font-size: 16px; }
    .op-bar { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; }
    .op-bar-fill { height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, var(--primary), #0ea5e9); transition: width .35s ease; }
    .op-skill { font-size: 12.5px; font-weight: 700; line-height: 1.45; }
    .op-ex {
      font-size: 12px;
      font-weight: 800;
      color: var(--primary-dark);
      background: var(--primary-soft);
      border-radius: 8px;
      padding: 4px 8px;
      width: fit-content;
      font-variant-numeric: tabular-nums;
    }
    .op-ex.none { color: var(--text-muted); background: transparent; }
    .dec-card {
      margin-top: 14px;
      border: 1px dashed var(--border-strong);
      border-radius: 14px;
      background: #f0fdf4;
      padding: 12px 16px;
      font-size: 13px;
      font-weight: 700;
      line-height: 1.5;
      color: var(--text);
    }
    .dec-card b { color: var(--success); }
    .dec-card.none { background: var(--surface-2); }
    .dec-card.none b { color: var(--text-muted); }

    /* Legend */
    .legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
    .legend-item {
      font-size: 11px;
      font-weight: 800;
      padding: 5px 10px;
      border-radius: 999px;
      background: var(--surface-2);
      border: 1px solid var(--border);
      color: var(--text-muted);
      white-space: nowrap;
    }

    /* Tables (scoped to the guide page) */
    .page table { width: 100%; border-collapse: collapse; font-size: 13px; }
    .page th, .page td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
    .page th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 900; background: var(--surface-2); }
    .page tr:last-child td { border-bottom: none; }
    .page td.lv { font-weight: 900; color: var(--primary-dark); white-space: nowrap; }
    .tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
    .tbl-wrap table { min-width: 640px; }
    .dec-mark { color: var(--success); font-weight: 800; }
    .em-dash { color: var(--text-muted); }

    /* details/accordion */
    details.acc { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); overflow: hidden; }
    details.acc + details.acc { margin-top: 12px; }
    details.acc summary {
      cursor: pointer;
      padding: 14px 18px;
      font-weight: 900;
      font-size: 15px;
      list-style: none;
      display: flex;
      align-items: center;
      gap: 10px;
      user-select: none;
    }
    details.acc summary::-webkit-details-marker { display: none; }
    details.acc summary .acc-arrow { margin-left: auto; transition: transform .2s; color: var(--text-muted); }
    details.acc[open] summary .acc-arrow { transform: rotate(90deg); }
    details.acc summary:hover { background: var(--surface-2); }
    details.acc .acc-body { padding: 0 18px 18px; }
    details.acc .acc-emoji { font-size: 18px; }

    .footer {
      text-align: center;
      font-size: 12px;
      font-weight: 600;
      color: var(--text-muted);
      opacity: .85;
    }

    /* Dark theme tweaks for accent elements that use hardcoded light colours */
    [data-theme="dark"] .year-status.warn { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
    [data-theme="dark"] .note { border-color: var(--warn); }
    [data-theme="dark"] .note strong { color: var(--warn); }
    [data-theme="dark"] .dec-card { background: var(--success-soft); border-color: var(--success); }

    /* ---------- Print ---------- */
    @media print {
      body * { visibility: hidden; }
      #TBL, #TBL * { visibility: visible; }
      body { background: #fff; }
      .app-header, .control-panel, .worksheet-hint, .app-footer,
      #nav, #dbg, #test, .stats-column {
        display: none !important;
      }
      .app-main, .worksheet-area {
        display: block !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
        gap: 0 !important;
      }
      #TBL {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
      }
      #TBL:empty::after { content: none !important; }
      #worksheet { display: block !important; }
      .slide {
        display: inline-block !important;
        width: calc(100% / var(--cols, 3)) !important;
        max-width: none;
        border: none;
        border-radius: 0;
        padding: 12px;
        margin: 0;
        vertical-align: top;
        page-break-inside: avoid;
        box-shadow: none !important;
        background: #fff !important;
        overflow: visible !important;
      }
      .slide-top, .slide-bottom { font-size: 24px; }
      .slide-line { width: 80%; }
      .answer-entry { display: none !important; }
      .slide-mul .cell { width: 30px; }
      .slide-mul .op-cell { width: 18px; }
      .slide-mul .pp-cell, .slide-mul .mul-carry, .slide-mul .answer-cell, .slide-mul .pp-carry { width: 28px; }
      .slide-div .cell { width: 30px; }
      .slide-div .ld-cell { width: 28px; }
      .slide-div .ld-margin { width: 40px; font-size: 18px; }
      .field-next {
        background-color: #ffffff !important;
        box-shadow: none !important;
      }
    }