  :root { color-scheme: dark; }
  * { box-sizing: border-box; }
  html, body { margin: 0; height: 100%; overflow: hidden; font-family: system-ui, sans-serif; }
  #scene { position: fixed; inset: 0; z-index: 0; }

  #ui { position: fixed; inset: 0; z-index: 1; pointer-events: none; }

  .topbar {
    position: absolute; top: 0; left: 0; right: 0;
    display: flex; justify-content: center; gap: 48px;
    padding: 16px; color: #fff; text-shadow: 0 2px 6px rgba(0,0,0,.7); text-align: center;
  }
  .stat { font-size: 14px; line-height: 1.4; }
  .stat b { font-size: 22px; }
  #timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 28px; }
  #timer.low { color: #ff5b5b; animation: pulse .5s infinite alternate; }
  @keyframes pulse { to { transform: scale(1.12); } }

  /* Question panel — left side */
  #panel {
    pointer-events: auto; position: absolute; left: 24px; top: 50%;
    transform: translateY(-50%); width: min(420px, 40vw);
    background: rgba(18,18,24,.92); border: 1px solid #2c2c38;
    border-radius: 16px; padding: 20px; color: #f2f2f5;
    box-shadow: 0 18px 50px rgba(0,0,0,.55); backdrop-filter: blur(6px);
    display: none;
  }
  #section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #8a8aa0; }
  #prompt { font-size: 17px; line-height: 1.4; margin: 8px 0 14px; }
  #prompt .blank {
    display: inline-block; min-width: 1.6em; padding: 0 .3em;
    border-bottom: 2px solid #ffcf33; color: #ffcf33; font-weight: 700; text-align: center;
  }
  #prompt mjx-container { margin: 0 .15em; }
  #imgs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
  #imgs img { max-height: 100px; background: #fff; border-radius: 8px; padding: 4px; }
  #options { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
  .opt {
    pointer-events: auto; cursor: pointer; border: 1px solid #39394a;
    background: #23232e; color: #f2f2f5; padding: 12px; border-radius: 10px;
    font-size: 15px; text-align: center; transition: transform .08s, background .15s, border-color .15s;
  }
  .opt:hover:not(:disabled) { background: #2d2d3c; transform: translateY(-1px); }
  .opt.correct { background: #1f7a3d; border-color: #2fcf6a; }
  .opt.wrong { background: #7a1f25; border-color: #ff5b5b; }
  .opt:disabled { cursor: default; }

  /* Leaderboard — right side */
  #board {
    pointer-events: auto; position: absolute; right: 24px; top: 50%;
    transform: translateY(-50%); width: min(300px, 28vw);
    background: rgba(18,18,24,.9); border: 1px solid #2c2c38;
    border-radius: 16px; padding: 16px 18px; color: #f2f2f5;
    box-shadow: 0 18px 50px rgba(0,0,0,.5); backdrop-filter: blur(6px);
  }
  #board h2 { margin: 0 0 10px; font-size: 16px; display: flex; align-items: center; gap: 6px; }
  #board ol { margin: 0; padding-left: 22px; font-size: 14px; }
  #board li { padding: 4px 0; border-bottom: 1px solid #26262f; }
  #board li:last-child { border-bottom: none; }
  .lb-name { font-weight: 600; }
  .lb-score { float: right; color: #ffcf33; font-variant-numeric: tabular-nums; }
  .lb-empty { font-size: 13px; opacity: .6; }

  /* Overlays */
  #overlay, .screen {
    position: fixed; inset: 0; z-index: 2; display: none;
    align-items: center; justify-content: center; flex-direction: column;
    background: rgba(0,0,0,.8); color: #fff; text-align: center; pointer-events: auto; padding: 20px;
  }
  #overlay h1, .screen h1 { font-size: 50px; margin: 0 0 8px; }
  #overlay p, .screen p { font-size: 19px; opacity: .85; margin: 0 0 22px; }
  .btn {
    pointer-events: auto; cursor: pointer; font-size: 18px; padding: 12px 28px;
    border: none; border-radius: 999px; background: #ffcf33; color: #1a1a1a; font-weight: 700;
  }
  #start { background: rgba(0,0,0,.86); display: flex; }
  .hint { font-size: 14px; opacity: .65; max-width: 460px; margin-top: 14px; line-height: 1.5; }
  #nameForm { display: flex; gap: 10px; margin-bottom: 16px; }
  #nameInput {
    font-size: 18px; padding: 12px 16px; border-radius: 999px; border: 1px solid #444;
    background: #1c1c24; color: #fff; width: 240px;
  }
  #ovBoard { margin-top: 18px; width: min(360px, 90vw); text-align: left; }
  #ovBoard li { padding: 5px 0; border-bottom: 1px solid #2a2a33; }

  /* Floating draggable window (formula sheet) */
  .win {
    pointer-events: auto; position: fixed; z-index: 3;
  }
  .win-frame {
    position: relative; background: #1a1a22; border: 1px solid #33333f;
    border-radius: 14px; box-shadow: 0 30px 80px rgba(0,0,0,.7);
    overflow: hidden;
  }
  .win-head {
    display: flex; align-items: center; justify-content: space-between;
    color: #f2f2f5; gap: 12px; padding: 10px 12px;
    background: #23232e; border-bottom: 1px solid #33333f;
    cursor: grab; user-select: none;
  }
  .win-head.dragging { cursor: grabbing; }
  .win-head h2 { margin: 0; font-size: 15px; white-space: nowrap; }
  .win-pageno { font-size: 13px; opacity: .6; margin-left: auto; }
  .win-btn {
    cursor: pointer; border: none; color: #fff; border-radius: 8px;
    width: 28px; height: 28px; font-size: 15px; font-weight: 700; flex: none;
    background: #44445a;
  }
  .win-btn:hover { background: #54546a; }
  .win-body { padding: 16px; }
  .win.collapsed .win-body { display: none; }

  /* Formula sheet specifics */
  .fw-book {
    perspective: 2600px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
  }
  .fw-page {
    position: relative; transform-style: preserve-3d;
    transition: transform .7s cubic-bezier(.4,.05,.2,1);
    transform-origin: center center;
  }
  .fw-page.flipped { transform: rotateY(180deg); }
  .fw-face {
    position: absolute; inset: 0; backface-visibility: hidden;
    background: #fff; border-radius: 6px; overflow: hidden;
    box-shadow: 0 8px 30px rgba(0,0,0,.4);
  }
  .fw-face.front {}
  .fw-face.back { transform: rotateY(180deg); }
  .fw-face canvas { display: block; width: 100%; height: 100%; }
  .fw-hint { text-align: center; color: #f2f2f5; opacity: .55; font-size: 12px; margin-top: 10px; }
  .fw-loading { color: #f2f2f5; padding: 60px 40px; font-size: 15px; }

  /* ---- Mobile layout ----
     Narrow screens can't fit the floating formula window or the side
     leaderboard, and the centered panel is cramped. So on mobile we hide the
     formula sheet and the always-on leaderboard (the leaderboard still shows
     at game end via the overlay's #ovBoard), and move the question panel to the
     top, full-width, so it has room to breathe. */
  @media (max-width: 768px) {
    .topbar { gap: 24px; padding: 10px; }
    .stat b { font-size: 19px; }
    #timer { font-size: 24px; }

    /* Formula sheet window: gone on mobile. */
    #formulaWin { display: none !important; }

    /* Side leaderboard: hidden during play (shown at the end via #ovBoard). */
    #board { display: none !important; }

    /* Question panel: pinned to the BOTTOM, full width (the 3D strike Xes are
       raised to the top of the scene on mobile to clear it). */
    #panel {
      left: 8px; right: 8px; bottom: 12px; top: auto;
      transform: none;
      width: auto;
      max-height: 55vh;
      overflow-y: auto;
      padding: 16px;
    }
    #prompt { font-size: 18px; }
    #options { gap: 8px; }
    .opt { padding: 14px 10px; }

    #overlay h1, .screen h1 { font-size: 34px; }
    #overlay p, .screen p { font-size: 16px; }
  }
