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

    :root {
      --primary: #ff6eb4;
      --secondary: #a855f7;
      --bg: #fdf0ff;
      --card: #fff;
      --text: #3b1f5e;
    }

    body {
      font-family: 'Nunito', sans-serif;
      background: var(--bg);
      min-height: 100vh;
      display: flex;
      align-items: center;
      justify-content: center;
      overflow-x: hidden;
      overflow-y: auto;
      position: relative;
    }

    /* ── Floating background stars ── */
    .bg-stars { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
    .bg-star {
      position: absolute;
      font-size: 1.4rem;
      animation: floatStar linear infinite;
      opacity: 0.18;
    }
    @keyframes floatStar {
      0%   { transform: translateY(110vh) rotate(0deg);   opacity: 0; }
      10%  { opacity: 0.18; }
      90%  { opacity: 0.18; }
      100% { transform: translateY(-10vh) rotate(360deg); opacity: 0; }
    }

    /* ── Screens ── */
    .screen {
      display: none;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      width: 100%;
      max-width: 700px;
      padding: 20px;
      position: relative;
      z-index: 1;
    }
    .screen.active { display: flex; }

    /* ── Cards ── */
    .card {
      background: var(--card);
      border-radius: 32px;
      padding: 36px 40px;
      box-shadow: 0 8px 40px rgba(168,85,247,0.18), 0 2px 8px rgba(0,0,0,0.06);
      width: 100%;
      text-align: center;
    }

    /* ── Titles ── */
    .game-title {
      font-size: 2.6rem;
      font-weight: 900;
      background: linear-gradient(135deg, #ff6eb4, #a855f7, #38bdf8);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
      line-height: 1.1;
      margin-bottom: 6px;
    }
    .subtitle { font-size: 1rem; color: #9370bb; margin-bottom: 28px; font-weight: 700; }

    /* ── Mode buttons ── */
    .mode-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 12px;
      margin: 16px 0 24px;
    }
    .mode-btn.wide { grid-column: 1 / -1; }
    .mode-btn {
      border: 3px solid #e9d5ff;
      border-radius: 16px;
      padding: 14px 8px;
      cursor: pointer;
      background: #faf5ff;
      transition: all .2s;
      font-family: 'Nunito', sans-serif;
    }
    .mode-btn:hover { border-color: #a855f7; transform: translateY(-2px); }
    .mode-btn.selected { border-color: #a855f7; background: #f3e8ff; }
    .mode-icon { font-size: 1.8rem; display: block; margin-bottom: 4px; }
    .mode-label { font-size: 0.85rem; font-weight: 800; color: #5b3a8e; }

    /* ── Buttons ── */
    .btn {
      display: inline-block;
      padding: 14px 36px;
      border-radius: 50px;
      border: none;
      cursor: pointer;
      font-family: 'Nunito', sans-serif;
      font-size: 1.1rem;
      font-weight: 800;
      transition: all .18s;
      letter-spacing: .5px;
    }
    .btn-primary {
      background: linear-gradient(135deg, #ff6eb4, #a855f7);
      color: white;
      box-shadow: 0 4px 20px rgba(168,85,247,0.35);
    }
    .btn-primary:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 8px 28px rgba(168,85,247,0.45); }
    .btn-secondary {
      background: white;
      color: #a855f7;
      border: 2.5px solid #d8b4fe;
    }
    .btn-secondary:hover { background: #f3e8ff; transform: translateY(-2px); }
    .btn:disabled { opacity: .55; cursor: not-allowed; transform: none !important; }

    /* ── HUD ── */
    .hud {
      display: flex;
      align-items: center;
      justify-content: space-between;
      width: 100%;
      margin-bottom: 14px;
      padding: 12px 20px;
      background: white;
      border-radius: 20px;
      box-shadow: 0 2px 16px rgba(168,85,247,0.12);
    }
    .hud-score { font-size: 1.3rem; font-weight: 900; color: #a855f7; }
    .hud-hearts { font-size: 1.5rem; letter-spacing: 2px; }
    .hud-streak {
      font-size: .85rem;
      font-weight: 800;
      color: #ff6eb4;
      background: #fff0f7;
      border: 2px solid #ffb3d9;
      border-radius: 20px;
      padding: 4px 12px;
    }
    .hud-char { font-size: 1.6rem; }
    .hud-icon-btn {
      background: none;
      border: none;
      cursor: pointer;
      font-size: 1.25rem;
      padding: 2px 4px;
      border-radius: 8px;
    }

    /* ── Progress bar ── */
    .progress-wrap {
      width: 100%;
      background: #f0e7ff;
      border-radius: 20px;
      height: 12px;
      margin-bottom: 18px;
      overflow: hidden;
    }
    .progress-bar {
      height: 100%;
      border-radius: 20px;
      background: linear-gradient(90deg, #ff6eb4, #a855f7);
      transition: width .4s ease;
    }

    /* ── Question area ── */
    .q-label {
      font-size: .9rem;
      font-weight: 800;
      color: #9370bb;
      margin-bottom: 6px;
      text-transform: uppercase;
      letter-spacing: 1px;
    }
    .question-box {
      font-size: 3.2rem;
      font-weight: 900;
      color: var(--text);
      background: linear-gradient(135deg, #fdf0ff, #e0f2fe);
      border-radius: 24px;
      padding: 24px 32px;
      margin: 10px 0 22px;
      box-shadow: inset 0 2px 8px rgba(168,85,247,0.08);
      min-height: 90px;
      display: flex;
      align-items: center;
      justify-content: center;
      position: relative;
    }
    .question-box .op-type {
      position: absolute;
      top: 10px;
      right: 14px;
      font-size: .75rem;
      font-weight: 800;
      color: #c084fc;
      background: #f3e8ff;
      border-radius: 10px;
      padding: 2px 8px;
    }

    /* ── Column problem (carry/borrow scratch space) ── */
    .column-problem {
      display: inline-grid;
      gap: 4px 6px;
      margin: 0 auto 14px;
      justify-content: center;
    }
    .carry-box {
      width: 38px;
      height: 38px;
      text-align: center;
      border: 2px dashed #c4b5fd;
      border-radius: 8px;
      background: #faf5ff;
      font-family: 'Nunito', sans-serif;
      font-size: 1.1rem;
      font-weight: 800;
      color: #7c3aed;
    }
    .carry-box:focus { outline: none; border-color: #a855f7; border-style: solid; background: white; }
    .digit-cell, .op-cell {
      width: 38px;
      height: 46px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 2rem;
      font-weight: 900;
      color: var(--text);
    }
    .op-cell { color: var(--primary); }
    .col-line { grid-column: 1 / -1; border-bottom: 4px solid var(--text); border-radius: 2px; margin: 2px 0 4px; }
    .answer-digit {
      width: 38px;
      height: 46px;
      text-align: center;
      border: 3px solid #e9d5ff;
      border-radius: 10px;
      background: white;
      font-family: 'Nunito', sans-serif;
      font-size: 1.7rem;
      font-weight: 900;
      color: var(--text);
      transition: all .15s;
    }
    .answer-digit:focus { outline: none; border-color: #a855f7; box-shadow: 0 0 0 4px rgba(168,85,247,0.15); }
    .answer-digit.correct { background: #d1fae5; border-color: #10b981; color: #065f46; animation: correctPop .4s ease; }
    .answer-digit.wrong   { background: #fee2e2; border-color: #ef4444; color: #991b1b; animation: shake .35s ease; }
    .answer-digit:disabled { cursor: default; }

    /* ── Answer input ── */
    .answer-form { display: flex; justify-content: center; gap: 10px; margin: 4px 0 6px; flex-wrap: wrap; }
    .answer-input {
      width: 200px;
      max-width: 70%;
      font-family: 'Nunito', sans-serif;
      font-size: 2.2rem;
      font-weight: 900;
      text-align: center;
      color: var(--text);
      border: 3px solid #e9d5ff;
      border-radius: 18px;
      padding: 12px 16px;
      background: white;
      transition: all .15s;
    }
    .answer-input:focus { outline: none; border-color: #a855f7; box-shadow: 0 0 0 4px rgba(168,85,247,0.15); }
    .answer-input.correct { background: #d1fae5; border-color: #10b981; color: #065f46; animation: correctPop .4s ease; }
    .answer-input.wrong   { background: #fee2e2; border-color: #ef4444; color: #991b1b; animation: shake .35s ease; }
    .answer-input:disabled { cursor: default; }
    @keyframes correctPop { 0%{transform:scale(1)} 40%{transform:scale(1.12)} 100%{transform:scale(1)} }
    @keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-6px)} 60%{transform:translateX(6px)} }

    /* ── On-screen number keypad ── */
    .keypad {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 10px;
      max-width: 260px;
      margin: 12px auto 0;
    }
    .keypad-btn {
      padding: 16px 0;
      border-radius: 16px;
      border: 3px solid #e9d5ff;
      background: white;
      font-family: 'Nunito', sans-serif;
      font-size: 1.4rem;
      font-weight: 900;
      color: var(--text);
      cursor: pointer;
      transition: all .15s;
    }
    .keypad-btn:hover:not(:disabled) { border-color: #a855f7; background: #faf5ff; transform: translateY(-2px); }
    .keypad-btn:active:not(:disabled) { transform: scale(0.94); }
    .keypad-btn:disabled { opacity: .5; cursor: default; }
    .keypad-backspace { color: #ef4444; }
    .keypad-check { background: #a855f7; border-color: #a855f7; color: white; }
    .keypad-check:hover:not(:disabled) { background: #9333ea; }

    /* ── Feedback message ── */
    .feedback-msg {
      min-height: 1.7rem;
      font-size: 1.3rem;
      font-weight: 900;
      text-align: center;
      opacity: 0;
      transform: translateY(-6px);
      transition: all .25s;
    }
    .feedback-msg.show { opacity: 1; transform: translateY(0); }
    .feedback-msg.correct { color: #10b981; }
    .feedback-msg.wrong { color: #ef4444; }

    /* ── Points popup ── */
    .pts-popup {
      position: fixed;
      pointer-events: none;
      font-size: 1.8rem;
      font-weight: 900;
      color: #a855f7;
      z-index: 99;
      animation: floatUp .9s ease forwards;
    }
    @keyframes floatUp { 0%{opacity:1;transform:translateY(0) scale(1)} 100%{opacity:0;transform:translateY(-80px) scale(1.3)} }

    /* ── Confetti particles ── */
    .confetti-piece {
      position: fixed;
      width: 10px;
      height: 10px;
      border-radius: 2px;
      pointer-events: none;
      z-index: 100;
      animation: confettiFall linear forwards;
    }
    @keyframes confettiFall {
      0%   { transform: translateY(-20px) rotate(0deg); opacity: 1; }
      100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
    }

    /* ── Reduced motion ──
       Respect the OS-level setting, and mirror it for the manual toggle
       (body.reduce-motion) so kids sensitive to motion can turn effects
       off even when their device's system setting doesn't. */
    @media (prefers-reduced-motion: reduce) {
      *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
      }
    }
    body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }

    .motion-toggle {
      position: fixed;
      top: 12px;
      right: 12px;
      z-index: 5;
      background: white;
      border: 2px solid #e9d5ff;
      border-radius: 50%;
      width: 40px;
      height: 40px;
      font-size: 1.1rem;
      cursor: pointer;
      box-shadow: 0 2px 10px rgba(168,85,247,0.15);
      transition: all .15s;
    }
    .motion-toggle:hover { border-color: #a855f7; transform: scale(1.06); }

    /* ── Streak badge ── */
    .streak-banner {
      position: fixed;
      top: 20px;
      left: 50%;
      transform: translateX(-50%) translateY(-80px);
      background: linear-gradient(135deg, #ff6eb4, #f59e0b);
      color: white;
      font-size: 1.1rem;
      font-weight: 900;
      border-radius: 50px;
      padding: 10px 28px;
      box-shadow: 0 6px 24px rgba(0,0,0,0.2);
      z-index: 50;
      transition: transform .4s cubic-bezier(.34,1.56,.64,1);
      white-space: nowrap;
    }
    .streak-banner.show { transform: translateX(-50%) translateY(0); }
    .emsley-banner {
      top: 74px;
      background: linear-gradient(135deg, #a855f7, #38bdf8);
      transform: translateX(-50%) translateY(-140px); /* extra offset — it sits lower than .streak-banner, so -80px alone still peeked into view */
    }
    .joke-banner {
      top: 132px; /* sits below streak-banner (20px) and emsley-banner (74px) — a perfect streak fires all three on the same question */
      background: linear-gradient(135deg, #10b981, #38bdf8);
      white-space: normal;
      text-align: center;
      line-height: 1.35;
      max-width: min(85vw, 340px);
      font-size: 1rem;
      border-radius: 20px;
      transform: translateX(-50%) translateY(-220px); /* taller box than the others, so needs a bit more offset to fully hide off-screen */
    }

    /* ── Results screen ── */
    .results-stars { font-size: 3.5rem; margin: 10px 0; }
    .results-score { font-size: 3.5rem; font-weight: 900; color: #a855f7; }
    .results-label { font-size: 1rem; color: #9370bb; font-weight: 700; margin-bottom: 4px; }
    .results-grid {
      display: grid;
      grid-template-columns: 1fr 1fr 1fr;
      gap: 12px;
      margin: 18px 0;
    }
    .stat-box {
      background: #faf5ff;
      border: 2px solid #e9d5ff;
      border-radius: 16px;
      padding: 14px 8px;
    }
    .stat-val { font-size: 1.6rem; font-weight: 900; color: #a855f7; }
    .stat-lbl { font-size: .78rem; font-weight: 700; color: #9370bb; }
    .new-high { display:none; font-size:.9rem; font-weight:800; color:#ff6eb4; margin:6px 0 14px; }
    .new-high.show { display:block; }

    /* ── Missed-problems recap ── */
    .missed-recap { margin: 16px 0; text-align: left; }
    .missed-recap-title {
      font-size: .9rem;
      font-weight: 800;
      color: #9370bb;
      text-align: center;
      margin-bottom: 10px;
    }
    .missed-list { list-style: none; max-height: 180px; overflow-y: auto; }
    .missed-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      background: #fff7f7;
      border: 2px solid #fecdd3;
      border-radius: 14px;
      padding: 10px 16px;
      margin-bottom: 8px;
      font-weight: 800;
    }
    .missed-problem { color: #3b1f5e; }
    .missed-answer { color: #10b981; white-space: nowrap; }

    /* ── Scoreboard ── */
    .board-list { list-style: none; width: 100%; margin: 18px 0; }
    .board-item {
      display: flex;
      align-items: center;
      gap: 12px;
      background: #faf5ff;
      border: 2px solid #e9d5ff;
      border-radius: 16px;
      padding: 12px 18px;
      margin-bottom: 10px;
      font-weight: 800;
    }
    .board-rank { font-size: 1.4rem; width: 36px; text-align: center; }
    .board-emoji { font-size: 1.6rem; }
    .board-name { flex: 1; color: #3b1f5e; font-size: 1rem; }
    .board-pts { color: #a855f7; font-size: 1.1rem; }
    .board-empty { color: #c4a8e0; font-size: 1rem; font-style: italic; padding: 20px; }

    /* ── Name input ── */
    .name-input {
      font-family: 'Nunito', sans-serif;
      font-size: 1.2rem;
      font-weight: 800;
      border: 3px solid #d8b4fe;
      border-radius: 16px;
      padding: 12px 20px;
      color: #3b1f5e;
      outline: none;
      width: 100%;
      margin: 12px 0 20px;
      text-align: center;
      transition: border-color .2s;
    }
    .name-input:focus { border-color: #a855f7; }

    /* ── Character themes applied to body ── */
    body.theme-bluey      { background: linear-gradient(135deg, #dbeafe, #e0f2fe, #bfdbfe); }
    body.theme-mickey     { background: linear-gradient(135deg, #fee2e2, #fef3c7, #fde8d8); }
    body.theme-cinderella { background: linear-gradient(135deg, #dbeafe, #e0f7ff, #f0e7ff); }
    body.theme-moana      { background: linear-gradient(135deg, #d1fae5, #e0f7fa, #fef3c7); }
    body.theme-rapunzel   { background: linear-gradient(135deg, #f3e8ff, #fce7f3, #fef9c3); }
    body.theme-belle      { background: linear-gradient(135deg, #fef9c3, #fef3c7, #f3e8ff); }

    /* ── Keyboard focus states ──
       :focus-visible so mouse/touch clicks don't show a ring, only
       keyboard (Tab) navigation does. */
    .mode-btn:focus-visible,
    .btn:focus-visible,
    .keypad-btn:focus-visible,
    .hud-icon-btn:focus-visible,
    .motion-toggle:focus-visible {
      outline: 3px solid #a855f7;
      outline-offset: 2px;
    }
    .name-input:focus { box-shadow: 0 0 0 4px rgba(168,85,247,0.15); }

    /* ── Responsive ── */
    @media(max-width:500px) {
      body { overflow-y: auto; align-items: flex-start; padding: 12px 0 28px; }
      .screen { padding: 12px 14px; }
      .card { padding: 18px 14px; }
      .game-title { font-size: 1.9rem; }
      .subtitle { font-size: .85rem; margin-bottom: 14px; }
      .mode-btn { padding: 10px 6px; }
      .mode-icon { font-size: 1.5rem; }
      .mode-label { font-size: .78rem; }
      .question-box { font-size: 2.4rem; padding: 18px 20px; }
      .carry-box, .digit-cell, .op-cell, .answer-digit { width: 30px; }
      .digit-cell, .op-cell { height: 38px; font-size: 1.6rem; }
      .carry-box { height: 32px; font-size: 1rem; }
      .answer-digit { height: 38px; font-size: 1.4rem; }
      .answer-input { font-size: 1.8rem; width: 160px; }
      .keypad { max-width: 220px; gap: 8px; }
      .keypad-btn { padding: 12px 0; font-size: 1.2rem; }
      .hud { padding: 8px 12px; }
      .results-grid { gap: 8px; }
    }

    /* ── Landscape tablets (iPad etc.) & short laptop windows ──
       These are wide but short, so lean on the extra width (more grid
       columns) instead of stacking everything tall like portrait does. */
    @media (orientation: landscape) and (max-height: 900px) {
      body { align-items: flex-start; padding: 16px 0; }
      .screen { max-width: 900px; padding: 10px 16px; }
      .card { padding: 18px 28px; }
      .game-title { font-size: 1.8rem; }
      .subtitle { font-size: .8rem; margin-bottom: 10px; }

      .mode-grid { grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 8px 0 14px; }
      .mode-btn.wide { grid-column: auto; }
      .mode-btn { padding: 8px 4px; }
      .mode-icon { font-size: 1.3rem; margin-bottom: 2px; }
      .mode-label { font-size: .68rem; }

      .name-input { padding: 10px 16px; margin-bottom: 10px; }
      .btn { padding: 10px 28px; }

      .hud { padding: 8px 16px; margin-bottom: 8px; }
      .progress-wrap { margin-bottom: 10px; }
      .q-label { margin-bottom: 2px; }
      .question-box { font-size: 2.2rem; padding: 14px 24px; margin: 6px 0 12px; min-height: 60px; }
      .column-problem { margin-bottom: 8px; }
      .carry-box, .digit-cell, .op-cell, .answer-digit { width: 32px; }
      .digit-cell, .op-cell { height: 36px; font-size: 1.5rem; }
      .carry-box { height: 30px; font-size: 1rem; }
      .answer-digit { height: 36px; font-size: 1.4rem; }
      .answer-input { font-size: 1.8rem; padding: 8px 14px; }
      .answer-form { margin: 4px 0; }
      .feedback-msg { min-height: 1.3rem; font-size: 1.1rem; }
      .keypad { max-width: 230px; gap: 8px; margin-top: 8px; }
      .keypad-btn { padding: 10px 0; font-size: 1.2rem; }

      .results-score { font-size: 2.2rem; }
      .results-grid { gap: 8px; margin: 10px 0; }
    }
