:root {
  --space: #0b0d2a;
  --navy: #062b46;
  --white: #f4f4f4;
  --grey: #b8c0c8;
  --cyan: #3ff0ff;
  --amber: #ffc93b;
  --green: #4cff6a;
  --red: #ff3b4a;
  --magenta: #ff4fd8;
  --purple: #6b2bd9;
  --purple-l: #a46bff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--space);
  color: var(--white);
  font-family: "Press Start 2P", monospace;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body { display: grid; place-items: center; overflow: hidden; }

#app {
  position: relative;
  width: min(100vw, calc(100dvh * 9 / 16));
  height: min(100dvh, calc(100vw * 16 / 9));
  background: var(--space);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game, #game canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
#game canvas { image-rendering: pixelated; }

/* CRT scanlines */
#app::after {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,.18) 0 1px, transparent 1px 3px);
  z-index: 20;
}

.screen {
  position: absolute; inset: 0;
  z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px;
  padding: 18px 16px;
  text-align: center;
  background: radial-gradient(ellipse at 50% 20%, #241a6b 0%, var(--space) 60%);
  overflow-y: auto;
  touch-action: pan-y;
  user-select: text;
}
.hidden { display: none !important; }

.logo { width: 64px; image-rendering: auto; }
.kicker { font-size: 9px; color: var(--purple-l); margin: 0; letter-spacing: 1px; }
.title {
  margin: 0; font-size: clamp(28px, 11vw, 44px); line-height: 1.15;
  color: var(--amber);
  text-shadow: 3px 3px 0 var(--magenta), 6px 6px 0 var(--purple);
}
h2 { font-size: 13px; color: var(--cyan); margin: 0 0 4px; }
p { font-size: 10px; line-height: 1.7; margin: 0; }
.small { font-size: 8px; }
.muted { color: var(--grey); }
.big { font-size: 34px; color: var(--amber); text-shadow: 3px 3px 0 var(--magenta); }
.warn { color: var(--amber); font-size: 11px; }
.err { color: var(--red); font-size: 9px; min-height: 1em; }
.c-cyan { color: var(--cyan); } .c-amber { color: var(--amber); } .c-green { color: var(--green); }

.blink { color: var(--magenta); font-size: 10px; animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }

.buttons { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 280px; }

.btn {
  display: block; width: 100%;
  font: inherit; font-size: 11px; line-height: 1.4;
  padding: 12px 10px;
  color: var(--white); background: var(--navy);
  border: 3px solid var(--white);
  box-shadow: 4px 4px 0 #000;
  cursor: pointer; text-decoration: none;
  touch-action: manipulation;
}
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 #000; }
.btn.primary { background: var(--purple); border-color: var(--amber); color: var(--amber); }
.btn.join { background: var(--amber); color: #14161a; border-color: var(--white); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.box {
  width: 100%; max-width: 300px;
  border: 3px solid var(--purple-l); background: rgba(6, 43, 70, .7);
  padding: 10px; box-shadow: 4px 4px 0 #000;
}
.scores { list-style: none; margin: 0; padding: 0; font-size: 9px; text-align: left; }
.scores li { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; }
.scores li:nth-child(1) { color: var(--amber); }
.scores li:nth-child(2) { color: var(--grey); }
.scores li:nth-child(3) { color: #e0a370; }

.steps { text-align: left; font-size: 9px; line-height: 1.8; padding-left: 18px; margin: 0; max-width: 320px; }
.steps li { margin-bottom: 8px; }
.steps b { color: var(--amber); }

form { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 300px; text-align: left; }
label { font-size: 9px; color: var(--cyan); display: flex; flex-direction: column; gap: 6px; }
input[type=email], input:not([type]), input[inputmode] {
  font: inherit; font-size: 12px; /* ≥12px avoids iOS zoom with this font */
  padding: 10px 8px;
  color: var(--white); background: #000;
  border: 3px solid var(--grey); border-radius: 0;
}
input:focus { outline: none; border-color: var(--amber); }
label.check { flex-direction: row; align-items: flex-start; gap: 8px; color: var(--grey); font-size: 7px; line-height: 1.7; }
label.check input { width: 18px; height: 18px; flex: none; accent-color: var(--purple); }

.breakdown { font-size: 8px; border-collapse: collapse; width: 100%; max-width: 300px; }
.breakdown td { padding: 4px 2px; border-bottom: 1px dashed #333a6b; text-align: left; }
.breakdown td:last-child { text-align: right; color: var(--green); }

.mute {
  position: absolute; top: 10px; right: 10px;
  font: inherit; font-size: 8px; color: var(--grey);
  background: none; border: 0; cursor: pointer;
}
.mute.control { left: 10px; right: auto; color: var(--cyan); }
.mute:focus-visible { outline: 1px solid var(--amber); outline-offset: 3px; }

a { color: var(--cyan); }

/* Keep expanded screens reachable even on short phones. */
.screen { justify-content: flex-start; }
#scr-title { padding-top: 42px; }
.screen > * { flex-shrink: 0; }
#scr-title > .logo, #scr-result > h2, #scr-badges > h2 { margin-top: auto; }
#scr-title > .box:last-of-type, #scr-result > p:last-child, #scr-badges > .btn { margin-bottom: auto; }
#badge-grid, #res-badges { width: 100%; max-width: 340px; min-width: 0; }
#res-badges:empty { display: none; }
#scr-badges > .btn { max-width: 280px; }
.badge-count { color: var(--amber); margin: 0 0 12px; font-size: 10px; }
.badge-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px; list-style: none; padding: 0; margin: 0; width: 100%;
}
.badge-tile {
  min-width: 0; padding: 9px 5px;
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  border: 2px solid var(--cyan); box-shadow: 3px 3px 0 #000;
  background: var(--navy); overflow-wrap: anywhere;
}
.badge-icon { font-family: sans-serif; font-size: 26px; line-height: 1.2; }
.badge-tile strong { color: var(--amber); font-size: 7px; line-height: 1.7; }
.badge-desc { font-size: 6px; line-height: 1.8; }
.badge-tile.locked { border-color: #626b7a; background: #181c30; color: var(--grey); }
.badge-tile.locked strong { color: var(--grey); }
.badge-tile.locked .badge-icon { filter: grayscale(1); opacity: .5; }
.new-badges { border: 2px solid var(--amber); padding: 10px; background: #171338; }
.new-badges h2 { color: var(--amber); font-size: 10px; margin-bottom: 12px; }
.new-badges .badge-tile { animation: badge-pop .35s steps(5, end) both; }
@keyframes badge-pop { from { opacity: 0; transform: scale(.8); } to { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .new-badges .badge-tile { animation: none; } }
