
  :root {
    --bg: #050510;
    --grid: #151530;
    --neon-blue: #00e5ff;
    --neon-pink: #ff2fd4;
    --neon-green: #4dff4d;
    --neon-yellow: #ffe74d;
    --neon-orange: #ff9f1c;
    --neon-purple: #b967ff;
    --neon-red: #ff3366;
  }

  * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  }

  html, body {
    height: 100%;
    overflow-x: hidden;
  }

  body {
    background: radial-gradient(circle at top, #1a1a3a 0, #050510 60%);
    color: #f5f5ff;
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 8px;
  }

  .wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 900px;
  }

  h1 {
    font-size: clamp(1.2rem, 3vw, 2rem);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    text-align: center;
    color: var(--neon-blue);
    text-shadow: 0 0 8px rgba(0,229,255,0.9), 0 0 16px rgba(0,229,255,0.7);
    flex-shrink: 0;
  }

  /* ── DESKTOP: side-by-side ── */
  .game-layout {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
  }

  .game-shell {
    /* Let the canvas drive its own width; don't grow beyond what the canvas needs */
    flex-shrink: 0;
    border-radius: 16px;
    padding: 6px;
    background: linear-gradient(135deg,rgba(0,229,255,0.2),rgba(255,47,212,0.2));
    box-shadow: 0 0 12px rgba(0,229,255,0.4), 0 0 24px rgba(255,47,212,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .canvas-wrapper {
    /* Width is set dynamically by JS */
    line-height: 0;
  }

  #gameCanvas {
    display: block;
    background: radial-gradient(circle at top, #151530 0, #050510 70%);
    border-radius: 10px;
    /* canvas sized via width/height attributes – never stretch with CSS */
  }

  .hud {
    flex: 1;
    min-width: 160px;
    max-width: 240px;
    border-radius: 16px;
    padding: 10px;
    background: linear-gradient(145deg,rgba(21,21,48,0.9),rgba(5,5,16,0.95));
    box-shadow: 0 0 10px rgba(0,0,0,0.7);
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .hud-section {
    border-radius: 10px;
    padding: 8px 10px;
    border: 1px solid rgba(0,229,255,0.3);
    background: radial-gradient(circle at top left,rgba(0,229,255,0.12),transparent 60%);
  }

  .hud-title {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--neon-pink);
    margin-bottom: 4px;
  }

  .hud-value {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--neon-yellow);
    text-shadow: 0 0 6px rgba(255,231,77,0.8);
  }

  .next-preview {
    width: 100%;
    aspect-ratio: 1/1;
    background: #050510;
    border-radius: 8px;
    border: 1px solid rgba(0,229,255,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }

  #nextCanvas {
    width: 100%;
    height: 100%;
    display: block;
  }

  .controls {
    font-size: 0.75rem;
    line-height: 1.5;
    color: #cfd3ff;
  }

  .controls span { color: var(--neon-green); }

  .btn-row {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    flex-wrap: wrap;
  }

  button {
    border-radius: 999px;
    border: 1px solid rgba(0,229,255,0.6);
    background: radial-gradient(circle at top,rgba(0,229,255,0.25),rgba(5,5,16,0.95));
    color: #f5f5ff;
    padding: 6px 10px;
    font-size: 0.78rem;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    transition: transform 0.08s ease, box-shadow 0.08s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }

  button:hover  { transform: translateY(-1px); box-shadow: 0 0 10px rgba(0,229,255,0.7); }
  button:active { transform: translateY(1px);  box-shadow: 0 0 4px rgba(0,229,255,0.4); }

  .status {
    font-size: 0.78rem;
    color: var(--neon-orange);
    min-height: 1.2em;
  }

  /* ── MOBILE CONTROLS: always in DOM, visibility toggled by JS ── */
  .mobile-controls {
    flex-shrink: 0;
    display: none;        /* JS will set display:flex when needed */
    flex-direction: column;
    gap: 6px;
    width: 100%;
    padding: 4px 0;
  }

  .mobile-row {
    display: flex;
    justify-content: center;
    gap: 8px;
  }

  .mobile-btn {
    flex: 1;
    max-width: 100px;
    padding: 12px 6px;
    font-size: 0.9rem;
    touch-action: manipulation;
  }

  /* ── MOBILE LAYOUT: stack canvas + hud vertically ── */
  /* triggered by JS, not media query, so it works regardless of render timing */
  .game-layout.mobile {
    flex-direction: column;
    align-items: center;
  }

  .game-layout.mobile .game-shell {
    width: 100%;
    display: flex;
    justify-content: center;
  }

  .game-layout.mobile .hud {
    width: 100%;
    max-width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }

  .game-layout.mobile .hud-section {
    flex: 1 1 120px;
  }

  .game-layout.mobile .next-preview {
    max-width: 80px;
    aspect-ratio: 1/1;
  }
