  * { box-sizing: border-box; margin: 0; padding: 0; }
  body {
    background: #0f0f1a;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    min-height: 100vh;
    min-height: 100svh;
    font-family: 'Courier New', monospace;
    color: #ccc; gap: 10px;
  }
  h1 { color: #f0b429; font-size: 20px; letter-spacing: 3px; margin-top: 12px; text-align: center; }
  #hud {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 32px;
    max-width: min(800px, calc(100vw - 16px));
    font-size: 15px;
    text-align: center;
  }
  #hud b { color: #f0b429; }
  #statusMsg { color: #aaa; }
  #statusMsg.unlocked { color: #2ecc71; }
  #gameShell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    max-width: calc(100vw - 12px);
  }
  body.controls-side #gameShell {
    flex-direction: row;
    align-items: center;
  }
  canvas { border: 2px solid #2a2a4a; display: block; }
  #hint { font-size: 12px; color: #444; }
  #back { font-size: 12px; color: #444; margin-bottom: 4px; }
  #back a { color: #555; text-decoration: none; }
  #back a:hover { color: #888; }
  #build { font-size: 10px; color: #333; margin-bottom: 10px; }

  #controlsPanel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 150px;
  }
  body.controls-side #controlsPanel {
    min-width: 206px;
    min-height: 238px;
    justify-content: flex-start;
  }
  #controlsToggle {
    padding: 8px 16px;
    min-width: 118px;
    background: rgba(240,180,41,0.1);
    border: 2px solid #3f3f64;
    border-radius: 8px;
    color: #cfa23a;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.08s, border-color 0.08s, color 0.08s;
  }
  #controlsToggle[aria-expanded="true"] {
    background: rgba(240,180,41,0.18);
    border-color: #f0b429;
    color: #f0b429;
  }

  /* D-pad */
  #dpad {
    display: grid;
    grid-template-columns: repeat(3, 64px);
    grid-template-rows: repeat(3, 64px);
    gap: 6px;
    margin: 0;
  }
  #dpad[hidden] { display: none; }
  body.controls-side:not(.controls-visible) #dpad {
    visibility: hidden;
    pointer-events: none;
  }
  #btn-up    { grid-column: 2; grid-row: 1; }
  #btn-left  { grid-column: 1; grid-row: 2; }
  #btn-right { grid-column: 3; grid-row: 2; }
  #btn-down  { grid-column: 2; grid-row: 3; }
  #dpad button {
    width: 64px; height: 64px;
    background: rgba(255,255,255,0.06);
    border: 2px solid #2e2e50;
    border-radius: 12px;
    color: #666;
    font-size: 22px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    transition: background 0.08s, border-color 0.08s, color 0.08s;
  }
  #dpad button.pressed {
    background: rgba(240,180,41,0.18);
    border-color: #f0b429;
    color: #f0b429;
  }

  /* Win / Game Over overlays */
  .overlay {
    display: none;
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    flex-direction: column;
    align-items: center;
    gap: 18px;
    background: rgba(10,10,20,0.93);
    border: 2px solid #f0b429;
    border-radius: 14px;
    padding: 36px 48px;
    z-index: 10;
    text-align: center;
  }
  .overlay.active { display: flex; }
  .overlay h2 { font-size: 28px; letter-spacing: 3px; }
  .overlay p  { font-size: 15px; color: #aaa; }
  .overlay button {
    margin-top: 6px;
    padding: 10px 32px;
    background: rgba(240,180,41,0.12);
    border: 2px solid #f0b429;
    border-radius: 8px;
    color: #f0b429;
    font-family: 'Courier New', monospace;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.1s;
  }
  .overlay button:hover { background: rgba(240,180,41,0.28); }
  #gameOverOverlay { border-color: #e74c3c; }
  #gameOverOverlay button { border-color: #e74c3c; color: #e74c3c; background: rgba(231,76,60,0.1); }
  #gameOverOverlay button:hover { background: rgba(231,76,60,0.25); }

  @media (max-height: 720px), (max-width: 520px) {
    body { gap: 6px; justify-content: flex-start; }
    h1 { font-size: 16px; letter-spacing: 1.5px; margin-top: 8px; }
    #hud { gap: 4px 14px; font-size: 12px; }
    #hint, #back { font-size: 11px; }
    #gameShell { gap: 6px; }
    #controlsPanel { gap: 5px; }
    #controlsToggle {
      padding: 6px 12px;
      min-width: 102px;
      font-size: 12px;
    }
    #dpad {
      grid-template-columns: repeat(3, 54px);
      grid-template-rows: repeat(3, 54px);
      gap: 5px;
      margin: 2px 0;
    }
    #dpad button {
      width: 54px;
      height: 54px;
    }
  }
