:root {
  --bg: #05060f;
  --panel: #0c1030;
  --fg: #e8ecff;
  --muted: #8a93b8;
  --accent: #3dff7a;
  --danger: #ff3b3b;
  --gold: #ffd23f;
  --pixel: 'Press Start 2P', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: radial-gradient(ellipse at 50% 0%, #121a4a 0%, var(--bg) 60%) fixed var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.55;
}

.hidden { display: none !important; }

/* ---------- App shell: fills exactly one screen ---------- */
.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
}
.topbar h1 {
  margin: 0;
  font: 14px var(--pixel);
  color: var(--danger);
  text-shadow: 0 0 8px rgba(255, 59, 59, .6);
}
.toplink { color: var(--muted); font-size: 13px; }
.toplinks { display: flex; gap: 16px; }

.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  justify-content: center;
  gap: 150px; /* keeps the wide-screen side ad 150px from the game */
  padding: 0 8px;
}
.stage {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 1280px;
  display: flex;
}

#gameWrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
  border-radius: 10px;
  box-shadow: 0 0 0 1px rgba(120, 140, 255, .18), 0 0 40px rgba(61, 255, 122, .08), 0 10px 40px rgba(0, 0, 0, .6);
}
#gameWrap:fullscreen { border-radius: 0; }

#game {
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  cursor: none;
}

/* ---------- In-game buttons ---------- */
.corner-btns {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  z-index: 5;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 8px;
  background: rgba(10, 14, 40, .65);
  color: var(--fg);
  font-size: 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: rgba(40, 50, 110, .8); }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 56px 16px 16px;
  text-align: center;
  background: rgba(2, 3, 14, .62);
  overflow-y: auto;
}
#menu { background: rgba(2, 3, 14, .35); }

.title {
  font: clamp(26px, 6vw, 56px)/1.25 var(--pixel);
  color: var(--danger);
  text-shadow: 0 0 18px rgba(255, 59, 59, .7), 4px 4px 0 #400;
}
.title.small { font-size: clamp(22px, 5vw, 40px); color: var(--accent); text-shadow: 0 0 14px rgba(61, 255, 122, .6); }
.title.red { color: var(--danger); text-shadow: 0 0 14px rgba(255, 59, 59, .7); }

.tag { margin: 0; color: var(--muted); font-size: 14px; }
.best, .final { margin: 0; font: 13px var(--pixel); color: var(--gold); }
.final { font-size: 18px; color: var(--fg); }
.newbest { color: var(--accent); animation: blink .6s steps(2) infinite; }
.hint { margin: 0; max-width: 460px; color: var(--muted); font-size: 13px; }

.btn {
  min-width: 220px;
  padding: 14px 22px;
  font: 14px var(--pixel);
  color: var(--accent);
  background: rgba(0, 0, 0, .4);
  border: 2px solid var(--accent);
  border-radius: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover, .btn:focus-visible { background: var(--accent); color: #000; outline: none; }
.btn-dim { color: var(--muted); border-color: var(--muted); font-size: 11px; padding: 11px 18px; }
.btn-dim:hover, .btn-dim:focus-visible { background: var(--muted); color: #000; }
.btn-gold { color: var(--gold); border-color: var(--gold); font-size: 11px; animation: pulse 1.4s ease-in-out infinite; }
.btn-gold:hover, .btn-gold:focus-visible { background: var(--gold); color: #000; }

@keyframes blink { 50% { opacity: 0; } }
@keyframes pulse { 50% { box-shadow: 0 0 18px rgba(255, 210, 63, .6); } }

/* ---------- Ad slots ---------- */
.ad-slot { text-align: center; }
.ad-label {
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  opacity: .7;
}
/* At least 150px between the play area and any ad (AdSense game-page guidance).
   computer: banner stays on screen under the game, with a 150px empty gap.
   phone/tablet: game fills the screen; banner sits below it, reached by scrolling (swipe the strip under the game). */
.ad-banner { flex: 0 0 auto; margin-top: 150px; padding-bottom: max(4px, env(safe-area-inset-bottom)); }
.scroll-hint { display: none; }
@media (pointer: coarse) {
  .app { height: auto; }
  .topbar { height: 36px; padding-top: 0; padding-bottom: 0; white-space: nowrap; }
  .layout { flex: none; height: calc(100vh - 70px); height: calc(100dvh - 70px); }
  .scroll-hint { display: block; height: 34px; line-height: 34px; text-align: center; font-size: 12px; color: var(--muted); }
  .ad-banner { margin-top: 116px; }
}
@media (pointer: coarse) and (max-width: 480px) {
  .topbar { padding: 0 10px; }
  .topbar h1 { font-size: 11px; }
  .toplinks { gap: 10px; }
  .toplink { font-size: 12px; }
}
@media (pointer: coarse) and (max-height: 500px) {
  .layout { height: calc(100vh - 34px); height: calc(100dvh - 34px); }
}
.ad-banner ins { display: inline-block; width: 320px; height: 50px; }
@media (min-width: 768px) and (min-height: 600px) {
  .ad-banner ins { width: 728px; height: 90px; }
}

.side-ad { display: none; flex: 0 0 160px; flex-direction: column; justify-content: center; }
.side-ad ins { display: inline-block; width: 160px; height: 600px; }
@media (min-width: 1400px) and (min-height: 760px) { .side-ad { display: flex; } }

/* Shown during development, before your AdSense IDs are set */
.ad-placeholder ins {
  background: repeating-linear-gradient(45deg, #0c1030, #0c1030 10px, #10153d 10px, #10153d 20px);
  border: 1px dashed #2a3370;
}

/* Landscape phones: give the game every pixel we can */
@media (max-height: 500px) {
  .topbar { display: none; }
  .overlay { gap: 8px; padding-top: 52px; }
  .btn { padding: 10px 18px; }
}

/* ---------- Content below the game (also helps AdSense approval) ---------- */
.content {
  max-width: 820px;
  margin: 0 auto;
  padding: 40px 20px 60px;
}
.content h2 { font: 16px var(--pixel); color: var(--accent); margin: 36px 0 12px; }
.content li { margin-bottom: 6px; }
.content a { color: var(--gold); }
kbd {
  display: inline-block;
  padding: 1px 6px;
  font: 12px ui-monospace, monospace;
  border: 1px solid #3a4280;
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--panel);
}
footer { margin-top: 48px; color: var(--muted); font-size: 13px; text-align: center; }

/* ---------- Upgrade cards ---------- */
.cards {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  max-width: 760px;
}
.card {
  position: relative;
  width: 210px;
  padding: 18px 14px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--fg);
  font-family: inherit;
  text-align: center;
  background: linear-gradient(180deg, rgba(20, 28, 70, .92), rgba(6, 9, 28, .92));
  border: 2px solid rgba(61, 255, 122, .55);
  border-radius: 12px;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s, border-color .12s;
  -webkit-tap-highlight-color: transparent;
}
.card:hover, .card:focus-visible {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 0 22px rgba(61, 255, 122, .35);
  outline: none;
}
.card .icon { font-size: 36px; line-height: 1; }
.card .name { font: 11px/1.4 var(--pixel); color: var(--gold); }
.card .desc { font-size: 13px; color: #c8cde8; }
.card .key {
  position: absolute;
  top: 6px;
  left: 8px;
  font: 10px var(--pixel);
  color: var(--muted);
}
.pips { display: flex; gap: 4px; }
.pips i { width: 10px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .18); }
.pips i.on { background: var(--accent); box-shadow: 0 0 6px var(--accent); }

@media (max-width: 640px) {
  .cards { flex-direction: column; align-items: center; gap: 10px; }
  .card {
    width: 100%;
    max-width: 340px;
    display: grid;
    grid-template-columns: 44px 1fr;
    grid-template-rows: auto auto auto;
    column-gap: 10px;
    row-gap: 4px;
    align-items: center;
    text-align: left;
    padding: 12px 14px;
  }
  .card .icon { grid-row: 1 / span 3; font-size: 32px; }
}
@media (max-height: 500px) {
  .card { width: 180px; padding: 10px; gap: 4px; }
  .card .icon { font-size: 26px; }
}

.icon-btn.off { opacity: .4; text-decoration: line-through; }

/* ---------- Leaderboard ---------- */
.title.gold { color: var(--gold); text-shadow: 0 0 14px rgba(255, 210, 63, .6); }
.name-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border: 2px solid var(--gold);
  border-radius: 10px;
  background: rgba(30, 24, 4, .55);
  animation: pulse 1.6s ease-in-out infinite;
}
.name-form label { font: 11px/1.5 var(--pixel); color: var(--gold); }
.name-row { display: flex; gap: 8px; }
.name-form input {
  width: 200px;
  padding: 10px 12px;
  font: 14px var(--pixel);
  text-transform: uppercase;
  color: var(--fg);
  background: rgba(0, 0, 0, .6);
  border: 2px solid var(--muted);
  border-radius: 6px;
  outline: none;
}
.name-form input:focus { border-color: var(--gold); }
.btn-small { min-width: 0; padding: 10px 14px; font-size: 12px; }

.board { width: min(440px, 100%); }
.board table { width: 100%; border-collapse: collapse; font: 11px/1 var(--pixel); }
.board th { padding: 6px 8px; color: var(--muted); font-size: 9px; text-align: left; border-bottom: 1px solid rgba(255, 255, 255, .15); }
.board td { padding: 7px 8px; color: var(--fg); text-align: left; }
.board th:nth-child(3), .board td:nth-child(3), .board th:nth-child(4), .board td:nth-child(4) { text-align: right; }
.board tbody tr:nth-child(odd) td { background: rgba(255, 255, 255, .04); }
.board tbody tr:first-child td { color: var(--gold); }
.board tr.me td { color: #000; background: var(--accent); }
.board-empty { margin: 0; color: var(--muted); font-size: 14px; }
@media (max-width: 420px) {
  .name-form input { width: 150px; }
  .board table { font-size: 9px; }
}

/* Tall overlays (game over + leaderboard) scroll from the top instead of clipping it */
.overlay { justify-content: flex-start; }
.overlay > :first-child { margin-top: auto; }
.overlay > :last-child { margin-bottom: auto; }

/* Menu text stays readable over the bright daytime skin */
.overlay .tag, .overlay .hint, .overlay .best {
  color: #e4e9ff;
  text-shadow: 0 1px 2px #000, 0 0 10px rgba(0, 0, 0, .85);
}
.overlay .best { color: var(--gold); }
