:root {
  --bg: #0a0f0a;
  --crt: #101610;
  --phosphor: #35e07a;
  --phosphor-dim: #1f8f4d;
  --amber: #ffb347;
  --food: #ff5c5c;
  --frame: #1c251c;
  --dpad-size: clamp(44px, 14vw, 56px);
}

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

body {
  background: var(--bg);
  color: var(--phosphor);
  font-family: "Courier New", ui-monospace, monospace;
  min-height: 100vh;
  min-height: 100dvh; /* iOS Safari: keeps the cabinet inside the visible viewport */
  display: flex;
  justify-content: center;
  align-items: center;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  overflow-x: hidden; /* no horizontal scrolling on phones */
}

.cabinet {
  width: min(680px, 100%);
  background: var(--crt);
  border: 2px solid var(--frame);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 0 40px rgba(53, 224, 122, 0.15);
}

.marquee .title-short { display: none; }

.marquee {
  font-size: 1.4rem;
  letter-spacing: 0.25em;
  text-align: center;
  color: var(--amber);
  text-shadow: 0 0 12px rgba(255, 179, 71, 0.5);
  margin-bottom: 12px;
}

.hud {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.9rem;
  margin-bottom: 10px;
}

.hud-item {
  background: #0c120c;
  border: 1px solid var(--frame);
  border-radius: 8px;
  padding: 8px 12px;
  flex: 1;
  text-align: center;
}

.hud-item span { color: var(--amber); font-weight: bold; }

.screen-wrap { position: relative; }

canvas {
  display: block;
  width: 100%;
  height: auto;
  background: #070b07;
  border: 2px solid var(--frame);
  border-radius: 10px;
  image-rendering: pixelated;
  touch-action: none;
}

/* Scanline overlay */
.screen-wrap::after {
  content: "";
  position: absolute;
  inset: 2px;
  pointer-events: none;
  border-radius: 10px;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.18) 0px,
    rgba(0, 0, 0, 0.18) 1px,
    transparent 1px,
    transparent 3px
  );
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 11, 7, 0.88);
  border-radius: 10px;
  z-index: 5;
}

.overlay.hidden { display: none; }

.overlay-inner { text-align: center; }

.overlay-title {
  font-size: 1.5rem;
  letter-spacing: 0.2em;
  color: var(--food);
  text-shadow: 0 0 14px rgba(255, 92, 92, 0.6);
  margin-bottom: 8px;
}

.overlay-score { margin-bottom: 14px; color: var(--amber); }

#restart {
  font-family: inherit;
  font-size: 1rem;
  letter-spacing: 0.15em;
  background: #0c120c;
  color: var(--phosphor);
  border: 2px solid var(--phosphor-dim);
  border-radius: 8px;
  padding: 10px 22px;
  cursor: pointer;
}

#restart:hover { background: var(--phosphor-dim); color: #eafff0; }

.dpad {
  margin-top: 14px;
  display: grid;
  grid-template-areas:
    ". up ."
    "left mid right"
    ". down .";
  grid-template-columns: repeat(3, var(--dpad-size));
  justify-content: center;
  gap: 8px;
}

.dpad-center {
  grid-area: mid;
  width: var(--dpad-size);
  height: var(--dpad-size);
  border: 2px solid var(--frame);
  border-radius: 10px;
  background: #0c120c;
}

.dpad-btn {
  width: var(--dpad-size);
  height: var(--dpad-size);
  font-size: 1.1rem;
  font-family: inherit;
  background: #0c120c;
  color: var(--phosphor);
  border: 2px solid var(--phosphor-dim);
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.dpad-btn.up { grid-area: up; }
.dpad-btn.left { grid-area: left; }
.dpad-btn.right { grid-area: right; }
.dpad-btn.down { grid-area: down; }

.dpad-btn:active { background: var(--phosphor-dim); color: #eafff0; }

.hint {
  margin-top: 12px;
  font-size: 0.75rem;
  color: var(--phosphor-dim);
  text-align: center;
}

@media (max-width: 480px) {
  /* iPhone portrait sizes: compact vertical stack, D-pad stays a 3x3 grid. */
  .marquee .title-full { display: none; }
  .marquee .title-short { display: inline; }
  .cabinet { padding: 12px; }
  .marquee {
    font-size: 1.05rem;
    letter-spacing: 0.15em;
    margin-bottom: 8px;
  }
  .hud { gap: 6px; margin-bottom: 8px; font-size: 0.75rem; }
  .hud-item { padding: 6px 8px; }
  .dpad { margin-top: 10px; gap: 6px; }
  .hint { margin-top: 8px; font-size: 0.7rem; }
  #restart { padding: 10px 18px; }
}
