@font-face {
  font-family: 'Press Start 2P';
  src: url('../fonts/press-start-2p.woff2') format('woff2');
  font-display: swap;
}

:root {
  --bg: #000;
  --fg: #fff;
  --muted: #9aa0b4;
  --panel: #0b0b1e;
  --edge: #2121de;
  --accent: #ffff00;
  --pixel: 'Press Start 2P', ui-monospace, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--pixel);
  font-size: 12px;
  line-height: 1.7;
  -webkit-tap-highlight-color: transparent;
}

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

button, input { font: inherit; }

[hidden] { display: none !important; }

.btn {
  display: inline-block;
  padding: 12px 18px;
  border: 3px solid var(--edge);
  border-radius: 6px;
  background: #000;
  color: var(--fg);
  text-decoration: none;
  cursor: pointer;
  letter-spacing: 1px;
}
.btn:hover, .btn:focus-visible { border-color: var(--accent); color: var(--accent); outline: none; }
.btn.primary { border-color: var(--accent); color: var(--accent); }
.btn.primary:hover, .btn.primary:focus-visible { background: var(--accent); color: #000; }
.btn:disabled { opacity: 0.5; cursor: default; }

.muted { color: var(--muted); }

/* ---------- lobby ---------- */

.lobby {
  min-height: 100dvh;
  padding: calc(16px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
  max-width: 980px;
  margin: 0 auto;
}

.marquee {
  text-align: center;
  margin: 12px 0 28px;
}
.marquee h1 {
  font-size: clamp(22px, 7vw, 44px);
  line-height: 1.3;
  margin: 0;
  color: #ffff00;
  text-shadow: 3px 3px 0 #ff00aa, 6px 6px 0 #2121de;
}
.marquee p { color: var(--muted); margin: 14px 0 0; font-size: 10px; }

.install-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.install-hint {
  max-width: 520px;
  margin: 12px auto 0;
  padding: 12px;
  border: 2px dashed var(--edge);
  font-size: 10px;
  color: var(--muted);
}

.games {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.card {
  --c: #fff;
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
  padding: 14px;
  border: 3px solid var(--c);
  border-radius: 10px;
  background: var(--panel);
  color: var(--fg);
  text-decoration: none;
  box-shadow: 0 0 0 0 var(--c);
  transition: transform 0.12s, box-shadow 0.12s;
}
.card:hover, .card:focus-visible { transform: translateY(-3px); box-shadow: 0 0 18px -2px var(--c); outline: none; }
.card canvas { width: 100%; aspect-ratio: 16 / 10; background: #000; border-radius: 6px; image-rendering: auto; }
.card h2 { margin: 0; font-size: 13px; color: var(--c); }
.card p { margin: 0; font-size: 9px; color: var(--muted); flex: 1; }
.card .best { font-size: 9px; color: var(--fg); }
.card .play { align-self: flex-start; font-size: 10px; color: var(--c); }

.boards { margin-top: 36px; }
.boards h2 { font-size: 14px; text-align: center; color: #00ffff; }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 14px; }
.tab {
  padding: 8px 10px;
  font-size: 9px;
  border: 2px solid #333;
  border-radius: 4px;
  background: #000;
  color: var(--muted);
  cursor: pointer;
}
.tab[aria-selected='true'] { border-color: var(--c, #fff); color: var(--c, #fff); }
.board { max-width: 460px; margin: 0 auto; }

footer.credits { margin-top: 36px; text-align: center; font-size: 8px; color: #555; }

/* ---------- score tables (lobby + play overlay) ---------- */

ol.scores { list-style: none; margin: 0; padding: 0; }
ol.scores li {
  display: grid;
  grid-template-columns: 2.5em 1fr auto;
  gap: 8px;
  padding: 5px 4px;
  border-bottom: 1px dotted #222;
  font-size: 10px;
}
ol.scores li:nth-child(1) { color: #ffff00; }
ol.scores li:nth-child(2) { color: #e0e0e0; }
ol.scores li:nth-child(3) { color: #ff8a3d; }
ol.scores li.me { background: #2121de; color: #fff; }
ol.scores .rank { color: var(--muted); text-align: left; }
ol.scores .pts { text-align: right; }
ol.scores li.me .rank { color: #fff; }
ol.scores .name { text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- play page ---------- */

body.play {
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(6px + var(--safe-top)) 8px 6px;
  border-bottom: 2px solid #111;
}
#bar h1 {
  flex: 1;
  margin: 0;
  font-size: 10px;
  text-align: center;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-btn {
  flex: none;
  padding: 6px 8px;
  border: 2px solid #333;
  border-radius: 4px;
  background: #000;
  color: var(--fg);
  font-size: 8px;
  text-decoration: none;
  cursor: pointer;
}
.bar-btn:hover, .bar-btn:focus-visible { border-color: var(--accent); color: var(--accent); outline: none; }

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#screen { display: block; }

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(0, 0, 0, 0.72);
  touch-action: pan-y;
  overflow-y: auto;
}
.panel {
  width: min(440px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 18px;
  border: 3px solid var(--accent);
  border-radius: 10px;
  background: var(--panel);
  text-align: center;
  font-size: 10px;
  touch-action: pan-y;
  user-select: text;
}
.panel h2 { margin: 0 0 10px; font-size: 16px; color: var(--accent); }
.panel h3 { margin: 18px 0 8px; font-size: 10px; color: #00ffff; }
.panel p { margin: 8px 0; }
.panel .buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 14px 0 4px; }
.panel .final { font-size: 22px; margin: 6px 0; }
.panel .new-best { color: #ff5ae0; animation: blink 0.6s steps(2) infinite; }
.panel .best b { color: var(--accent); }
table.help { margin: 10px auto; border-collapse: collapse; font-size: 8px; text-align: left; }
table.help th { color: var(--accent); padding: 3px 10px 3px 0; font-weight: normal; white-space: nowrap; vertical-align: top; }
table.help td { color: var(--muted); padding: 3px 0; }

form.submit { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
form.submit label { font-size: 9px; color: var(--muted); }
form.submit input {
  width: 13ch;
  padding: 10px;
  border: 3px solid var(--edge);
  border-radius: 6px;
  background: #000;
  color: #fff;
  text-transform: uppercase;
  font-size: 16px; /* 16px stops iOS zooming into the field */
  font-family: var(--pixel);
}
form.submit input:focus { border-color: var(--accent); outline: none; }

#pad {
  flex: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 12px calc(10px + var(--safe-bottom));
  border-top: 2px solid #111;
}
.pad-group { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.pad-right { justify-content: flex-end; }
.pad-btn {
  width: 62px;
  height: 62px;
  border: 3px solid #444;
  border-radius: 50%;
  background: #111;
  color: #ddd;
  font-size: 9px;
  padding: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.pad-btn.arrow { font-family: system-ui, sans-serif; font-size: 24px; }
.pad-btn.wide { width: 80px; height: 80px; border-color: var(--accent); color: var(--accent); }
.pad-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }

@media (max-width: 380px) {
  .pad-btn { width: 54px; height: 54px; font-size: 9px; }
  .pad-btn.wide { width: 68px; height: 68px; }
}

/* Phones held sideways: float the buttons over the game so it can use the full height. */
@media (orientation: landscape) and (pointer: coarse) {
  #bar { padding-top: 4px; padding-bottom: 4px; }
  #pad {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    border: 0;
    background: transparent;
    pointer-events: none;
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
  }
  .pad-group { pointer-events: auto; }
  .pad-btn { opacity: 0.55; }
}

.rotate-hint { color: #ff5ae0; }

@keyframes blink { to { visibility: hidden; } }

@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .panel .new-best { animation: none; }
}

.noscript { padding: 24px; text-align: center; }
