  :root {
    --bg: #07080c;
    --bg-2: #0d1018;
    --ink: #e8ecf2;
    --ink-dim: #6b7689;
    --accent: #ff3864;
    --accent-2: #2de2e6;
    --accent-3: #f9c80e;
    --danger: #ff3864;
  }

  * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

  html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--ink);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    user-select: none;
    -webkit-user-select: none;
    overscroll-behavior: none;
    touch-action: none;
  }

  #game {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
  }

  canvas {
    display: block;
    width: 100%;
    height: 100%;
    background:
      radial-gradient(ellipse at center, #0f1320 0%, #07080c 60%, #04050a 100%);
  }

  /* ───── HUD ───── */
  .hud {
    position: fixed;
    top: 0; left: 0; right: 0;
    padding: 18px 18px 0;
    padding-top: max(18px, env(safe-area-inset-top));
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: none;
    z-index: 10;
  }

  .hud-block {
    background: rgba(7, 8, 12, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 1px solid rgba(232, 236, 242, 0.08);
    padding: 8px 12px;
    border-radius: 2px;
    min-width: 70px;
  }

  .label {
    font-size: 9px;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--ink-dim);
    margin-bottom: 4px;
  }

  .value {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.05em;
    line-height: 1;
  }
  .value.accent { color: var(--accent-2); }
  .value.warn { color: var(--accent-3); }
  .value.danger { color: var(--accent); }

  .hud-center { text-align: center; }
  .hud-right { text-align: right; }

  /* ───── Bottom controls ───── */
  .controls {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    padding: 18px;
    padding-bottom: max(18px, env(safe-area-inset-bottom));
    display: flex;
    justify-content: center;
    gap: 12px;
    z-index: 10;
    pointer-events: none;
  }
  .icon-btn {
    background: rgba(7, 8, 12, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 1px solid rgba(232, 236, 242, 0.12);
    color: var(--ink);
    width: 48px; height: 48px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
    pointer-events: auto;
  }
  .icon-btn:active { transform: scale(0.94); background: rgba(45, 226, 230, 0.08); }
  .icon-btn svg { width: 20px; height: 20px; }
  .icon-btn[disabled] { opacity: 0.3; pointer-events: none; }

  /* ───── Overlays ───── */
  .overlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 30;
    gap: 24px;
    padding: 32px;
    text-align: center;
  }
  .overlay.hidden { display: none; }

  .title {
    font-family: 'Major Mono Display', monospace;
    font-size: 44px;
    letter-spacing: 0.08em;
    line-height: 0.95;
    color: var(--ink);
    text-shadow:
      0 0 24px rgba(45, 226, 230, 0.3),
      0 0 60px rgba(45, 226, 230, 0.15);
  }
  .subtitle {
    font-size: 11px;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    color: var(--ink-dim);
    max-width: 300px;
    line-height: 1.8;
  }
  .btn {
    background: transparent;
    border: 1px solid var(--ink);
    color: var(--ink);
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    padding: 14px 32px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.18s ease;
    min-width: 200px;
  }
  .btn:active {
    background: var(--ink);
    color: var(--bg);
    transform: scale(0.97);
  }
  .btn.ghost {
    border-color: var(--ink-dim);
    color: var(--ink-dim);
    font-size: 10px;
    padding: 10px 22px;
    letter-spacing: 0.25em;
    min-width: auto;
  }
  .stats-line {
    font-size: 11px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--ink-dim);
  }
  .stats-line strong {
    color: var(--accent-2);
    font-weight: 700;
  }
  .stats-line.fail strong {
    color: var(--accent);
  }

  /* level announce */
  .level-announce {
    position: fixed;
    top: 38%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 15;
    text-align: center;
    opacity: 0;
  }
  .level-announce.show { animation: levelPop 1.8s ease forwards; }
  @keyframes levelPop {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
    15%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    80%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.05); }
  }
  .level-announce .la-label {
    font-size: 10px;
    letter-spacing: 0.5em;
    color: var(--ink-dim);
    margin-bottom: 6px;
  }
  .level-announce .la-num {
    font-family: 'Major Mono Display', monospace;
    font-size: 64px;
    color: var(--accent-2);
    letter-spacing: 0.05em;
    text-shadow: 0 0 30px rgba(45, 226, 230, 0.5);
    margin-bottom: 12px;
  }
  .level-announce .la-goal {
    font-size: 11px;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: var(--ink);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
  }
  .la-goal .goal-orb {
    border-radius: 50%;
    display: inline-block;
  }

  /* ───── Level select grid ───── */
  .grid-wrap {
    width: 100%;
    max-width: 380px;
    max-height: 60vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px;
    scrollbar-width: thin;
  }
  .grid-wrap::-webkit-scrollbar { width: 6px; }
  .grid-wrap::-webkit-scrollbar-track { background: transparent; }
  .grid-wrap::-webkit-scrollbar-thumb { background: rgba(45, 226, 230, 0.2); }

  .level-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    width: 100%;
  }
  .level-cell {
    aspect-ratio: 1;
    border: 1px solid rgba(232, 236, 242, 0.12);
    background: rgba(7, 8, 12, 0.55);
    color: var(--ink);
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: all 0.15s ease;
  }
  .level-cell:active {
    transform: scale(0.95);
    background: rgba(45, 226, 230, 0.1);
  }
  .level-cell.locked {
    opacity: 0.25;
    cursor: not-allowed;
    color: var(--ink-dim);
  }
  .level-cell.locked:active { transform: none; background: rgba(7, 8, 12, 0.55); }
  .level-cell.cleared {
    border-color: rgba(45, 226, 230, 0.4);
  }
  .level-cell.cleared::after {
    content: '';
    position: absolute;
    top: 6px; right: 6px;
    width: 5px; height: 5px;
    background: var(--accent-2);
    box-shadow: 0 0 6px var(--accent-2);
  }
  .level-cell.current {
    border-color: var(--accent-2);
    box-shadow: 0 0 12px rgba(45, 226, 230, 0.25);
  }

  .corner {
    position: fixed;
    bottom: 6px;
    right: 8px;
    font-size: 9px;
    letter-spacing: 0.3em;
    color: var(--ink-dim);
    opacity: 0.5;
    text-transform: uppercase;
    pointer-events: none;
  }

  @media (max-height: 640px) {
    .title { font-size: 36px; }
    .overlay { gap: 18px; }
  }
