:root {
    --bg-deep: #0a0420;
    --bg-mid: #1a0a3e;
    --magenta: #ff2d92;
    --magenta-glow: #ff5fb5;
    --hot-pink: #ff1f7a;
    --yellow: #ffd23a;
    --yellow-glow: #ffe87a;
    --red: #ff3c3c;
    --cyan: #5fffe1;
    --white: #ffffff;
    --dim: #6a4d8a;
  }

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

  html, body {
    height: 100%;
    background: var(--bg-deep);
    color: var(--white);
    font-family: 'Press Start 2P', monospace;
    overflow: hidden;
    -webkit-font-smoothing: none;
    image-rendering: pixelated;
  }

  body {
    display: flex;
    align-items: center;
    justify-content: center;
    background:
      radial-gradient(ellipse at top, #2a0f5e 0%, #0a0420 60%, #000 100%);
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
  }

  /* CRT scanlines + flicker overlay */
  body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: repeating-linear-gradient(
      to bottom,
      rgba(0,0,0,0) 0px,
      rgba(0,0,0,0) 2px,
      rgba(0,0,0,0.25) 3px,
      rgba(0,0,0,0.25) 4px
    );
    pointer-events: none;
    z-index: 100;
    mix-blend-mode: multiply;
  }

  /* Subtle CRT vignette */
  body::after {
    content: '';
    position: fixed;
    inset: 0;
    background: radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.6) 100%);
    pointer-events: none;
    z-index: 101;
  }

  .cabinet {
    width: min(100vw, 480px);
    height: 100vh;
    max-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 6px;
    position: relative;
  }

  /* Score readout */
  .readout {
    background: #000;
    border: 2px solid var(--magenta);
    box-shadow:
      0 0 0 2px #000,
      0 0 12px var(--magenta),
      inset 0 0 20px rgba(255, 45, 146, 0.2);
    padding: 8px 10px;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    font-size: 8px;
    line-height: 1.4;
  }

  .readout .cell {
    text-align: center;
  }

  .readout .label {
    color: var(--magenta-glow);
    font-size: 7px;
    margin-bottom: 4px;
    text-shadow: 0 0 4px var(--magenta);
  }

  .readout .val {
    color: var(--yellow);
    font-size: 14px;
    text-shadow: 0 0 6px var(--yellow), 0 0 12px var(--yellow);
    letter-spacing: 1px;
  }

  /* Title bar */
  .title-bar {
    text-align: center;
    padding: 4px 0;
  }

  .title {
    font-size: 18px;
    color: var(--magenta);
    text-shadow:
      2px 0 0 var(--cyan),
      -2px 0 0 var(--yellow),
      0 0 12px var(--magenta);
    letter-spacing: 2px;
    line-height: 1.2;
  }

  .subtitle {
    font-size: 7px;
    color: var(--white);
    margin-top: 4px;
    opacity: 0.8;
    letter-spacing: 1px;
  }

  /* Game area */
  .game-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 0;
  }

  canvas {
    background: linear-gradient(180deg, #15093a 0%, #0a0420 50%, #0a0420 100%);
    border: 3px solid var(--magenta);
    box-shadow:
      0 0 0 1px #000,
      0 0 16px var(--magenta),
      inset 0 0 40px rgba(0,0,0,0.6);
    /* Scale up on desktop; shrink to fit on mobile.
       Internal resolution stays 360x600 so physics is unaffected;
       this only changes the display size. Aspect ratio preserved
       by the canvas's intrinsic width/height attributes. */
    height: min(85vh, 780px);
    width: auto;
    max-width: 100%;
    image-rendering: pixelated;
    display: block;
  }

  /* Photo collection strip */
  .collection {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    padding: 4px;
    background: rgba(0,0,0,0.5);
    border: 1px solid var(--dim);
  }

  .slot {
    aspect-ratio: 1;
    background: #000;
    border: 1px solid var(--dim);
    overflow: hidden;
    position: relative;
    image-rendering: auto;
  }

  .slot.collected {
    border-color: var(--magenta);
    box-shadow: 0 0 8px var(--magenta);
  }

  .slot img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: brightness(0.4) grayscale(1);
    transition: filter 0.4s;
    image-rendering: auto;
  }

  .slot.collected img {
    filter: brightness(1) grayscale(0);
  }

  .slot::after {
    content: '?';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--dim);
    font-size: 14px;
    pointer-events: none;
  }

  .slot.collected::after { display: none; }

  /* Controls */
  .controls {
    font-size: 7px;
    text-align: center;
    color: var(--dim);
    padding: 4px;
    line-height: 1.6;
  }

  .controls .key {
    color: var(--yellow);
    text-shadow: 0 0 4px var(--yellow);
  }

  /* On-screen buttons — ALWAYS visible for accessibility */
  .touch-controls {
    display: grid;
    grid-template-columns: 1fr 1.2fr 1fr;
    gap: 6px;
    padding: 6px 0 2px;
  }

  .touch-btn {
    background: linear-gradient(180deg, var(--magenta) 0%, var(--hot-pink) 100%);
    border: 3px solid var(--yellow);
    color: #000;
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    padding: 18px 4px;
    cursor: pointer;
    box-shadow: 0 0 12px var(--magenta), inset 0 -3px 0 rgba(0,0,0,0.25);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    letter-spacing: 1px;
    min-height: 56px;
    line-height: 1.2;
    transition: transform 0.05s, box-shadow 0.05s;
  }

  .touch-btn:hover {
    background: linear-gradient(180deg, var(--magenta-glow) 0%, var(--magenta) 100%);
  }

  .touch-btn:active {
    transform: translateY(3px);
    box-shadow: 0 0 6px var(--magenta), inset 0 0 0 rgba(0,0,0,0);
    background: linear-gradient(180deg, var(--yellow) 0%, var(--magenta) 100%);
  }

  .touch-btn .btn-sub {
    display: inline-block;
    font-size: 8px;
    margin-top: 6px;
    padding: 3px 6px;
    border: 1.5px solid #000;
    background: rgba(0, 0, 0, 0.18);
    border-radius: 2px;
    letter-spacing: 1px;
    box-shadow: 0 1px 0 #000;
    color: #000;
  }

  /* Keyboard hint stays for desktop users who prefer keys, but smaller */
  .controls {
    font-size: 6px;
    text-align: center;
    color: var(--dim);
    padding: 2px;
    line-height: 1.4;
    opacity: 0.7;
  }

  /* Message popup */
  .msg-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    background: #000;
    border: 3px solid var(--yellow);
    box-shadow:
      0 0 0 2px #000,
      0 0 24px var(--yellow),
      inset 0 0 20px rgba(255, 210, 58, 0.2);
    padding: 16px 20px;
    text-align: center;
    z-index: 50;
    pointer-events: none;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-width: 80%;
  }

  .msg-popup.show {
    transform: translate(-50%, -50%) scale(1);
  }

  .msg-popup .msg-text {
    color: var(--magenta);
    font-size: 10px;
    text-shadow: 0 0 6px var(--magenta);
    line-height: 1.6;
    letter-spacing: 1px;
  }

  /* Finale overlay */
  .finale {
    position: fixed;
    inset: 0;
    background: rgba(10, 4, 32, 0.92);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
    backdrop-filter: blur(2px);
  }

  .finale.show { display: flex; animation: fadeIn 0.6s ease-out; }

  @keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  .finale-card {
    background: linear-gradient(180deg, #1a0a3e 0%, #0a0420 100%);
    border: 4px solid var(--magenta);
    box-shadow:
      0 0 0 2px #000,
      0 0 40px var(--magenta),
      inset 0 0 40px rgba(255, 45, 146, 0.2);
    padding: 28px 24px;
    text-align: center;
    max-width: 420px;
    width: 100%;
    position: relative;
  }

  .finale-title {
    font-size: 16px;
    color: var(--yellow);
    text-shadow:
      2px 0 0 var(--magenta),
      -2px 0 0 var(--cyan),
      0 0 12px var(--yellow);
    margin-bottom: 16px;
    letter-spacing: 2px;
    line-height: 1.3;
  }

  .finale-msg {
    font-size: 9px;
    color: var(--white);
    line-height: 2;
    margin-bottom: 18px;
    letter-spacing: 1px;
  }

  .finale-sig {
    font-size: 8px;
    color: var(--magenta-glow);
    text-shadow: 0 0 4px var(--magenta);
    letter-spacing: 1px;
  }

  .finale-btn {
    background: linear-gradient(180deg, var(--magenta) 0%, var(--hot-pink) 100%);
    border: 2px solid var(--yellow);
    color: #000;
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    padding: 10px 16px;
    cursor: pointer;
    margin-top: 14px;
    box-shadow: 0 0 12px var(--magenta);
    letter-spacing: 1px;
  }

  .finale-btn:hover {
    background: linear-gradient(180deg, var(--hot-pink) 0%, var(--magenta) 100%);
  }

  /* Pixel flower decoration in finale */
  .flowers {
    font-size: 18px;
    margin: 8px 0;
    letter-spacing: 4px;
  }

  /* Start screen */
  .start-screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    z-index: 40;
    text-align: center;
    padding: 20px;
  }

  .start-screen.hidden { display: none; }

  .start-title {
    font-size: 22px;
    color: var(--magenta);
    text-shadow:
      3px 0 0 var(--cyan),
      -3px 0 0 var(--yellow),
      0 0 16px var(--magenta);
    letter-spacing: 3px;
    margin-bottom: 16px;
    animation: flicker 3s infinite;
  }

  @keyframes flicker {
    0%, 100% { opacity: 1; }
    72% { opacity: 1; }
    73% { opacity: 0.6; }
    74% { opacity: 1; }
    85% { opacity: 0.4; }
    86% { opacity: 1; }
  }

  .start-sub {
    font-size: 9px;
    color: var(--yellow);
    text-shadow: 0 0 6px var(--yellow);
    margin-bottom: 28px;
    letter-spacing: 1px;
    line-height: 1.8;
  }

  .blink {
    font-size: 10px;
    color: var(--white);
    animation: blink 1s steps(2) infinite;
    letter-spacing: 2px;
  }

  @keyframes blink {
    50% { opacity: 0; }
  }

  .start-hint {
    margin-top: 20px;
    font-size: 7px;
    color: var(--dim);
    line-height: 1.8;
  }

  /* Tiny credit */
  .credit {
    position: fixed;
    bottom: 4px;
    right: 6px;
    font-family: 'VT323', monospace;
    font-size: 10px;
    color: var(--dim);
    z-index: 102;
    letter-spacing: 1px;
  }

  /* Game-over message */
  .gameover-msg {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #000;
    border: 3px solid var(--red);
    box-shadow: 0 0 16px var(--red);
    padding: 14px 18px;
    text-align: center;
    z-index: 60;
    display: none;
  }

  .gameover-msg.show { display: block; }

  .gameover-msg .ttl {
    font-size: 14px;
    color: var(--red);
    text-shadow: 0 0 8px var(--red);
    margin-bottom: 10px;
  }

  .gameover-msg .sub {
    font-size: 8px;
    color: var(--white);
    margin-bottom: 12px;
    line-height: 1.6;
  }

  .gameover-msg button {
    background: var(--yellow);
    border: 2px solid var(--white);
    color: #000;
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    padding: 8px 12px;
    cursor: pointer;
    box-shadow: 0 0 8px var(--yellow);
  }
