:root {
  --bg: #05060c;
  --fg: #f5f2ea;
  --muted: #a6adbf;
  --border: rgba(255, 214, 51, 0.16);
  --accent: #ffd400;
  --accent-bright: #ffe873;
  --accent-soft: rgba(255, 212, 0, 0.14);
  --cyan: #5cc8ff;
  --orange: #ffb347;
  --radius: 8px;
  --font-display: "Sora", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --font-arcade: "Press Start 2P", var(--font-mono);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-display);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

::selection { background: var(--accent); color: #000; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #7a6300; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px clamp(16px, 5vw, 48px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}

.brand em {
  font-style: normal;
  color: var(--accent-bright);
}

/* The yellow ball: glossy, with two eyes. Used for the brand, lives and intro. */
.ball-icon {
  --s: 26px;
  position: relative;
  display: inline-block;
  width: var(--s);
  height: var(--s);
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fffbb0 0 12%, #ffe633 30%, #ffc400 72%, #e89200 100%);
  box-shadow: 0 0 0 1.5px #b87400, 0 0 10px rgba(255, 210, 31, 0.45);
  flex: none;
}
.ball-icon::after {
  content: "";
  position: absolute;
  top: 38%;
  left: 52%;
  width: 13%;
  height: 22%;
  border-radius: 50%;
  background: #1a1300;
  box-shadow: calc(var(--s) * 0.2) 0 0 #1a1300;
}
.ball-icon-lg { --s: 64px; margin: 0 auto 12px; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn, .lang-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  transition: border-color 0.2s ease, transform 0.15s ease, background 0.2s ease;
}

.icon-btn { padding: 8px 10px; }

.icon-btn:hover, .lang-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.icon-btn:active, .lang-btn:active { transform: translateY(0); }

.flag { font-size: 1rem; }

/* ---------- Stage / Hero ---------- */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 20px 40px;
  gap: 30px;
}

.hero {
  text-align: center;
  max-width: 640px;
  margin-top: clamp(4px, 2vh, 18px);
}

.eyebrow {
  font-family: var(--font-mono);
  color: var(--accent-bright);
  letter-spacing: 0.25em;
  font-size: 0.72rem;
  margin: 0 0 10px;
  text-transform: uppercase;
  opacity: 0;
  animation: fadeUp 0.6s ease forwards;
}

.title {
  margin: 0 0 14px;
  font-size: clamp(2rem, 5.6vw, 3.2rem);
  line-height: 1.1;
  font-weight: 800;
}

.title-line {
  display: block;
  opacity: 0;
  transform: translateY(16px);
  animation: fadeUp 0.7s ease forwards;
}

.title-line.accent {
  background: linear-gradient(100deg, var(--accent-bright), var(--orange) 45%, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation-delay: 0.12s;
}

.tagline {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.6;
  margin: 0 auto;
  max-width: 540px;
  opacity: 0;
  animation: fadeUp 0.7s ease forwards;
  animation-delay: 0.24s;
}

@keyframes fadeUp {
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Difficulty picker ---------- */
.difficulty-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  opacity: 0;
  animation: fadeUp 0.7s ease forwards;
  animation-delay: 0.32s;
}

.diff-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 10px 18px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: all 0.2s ease;
  font-family: var(--font-display);
  border-radius: 4px;
}

.diff-btn:hover { border-color: var(--accent); transform: translateY(-2px); }

.diff-btn.is-active {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-soft), rgba(255, 212, 0, 0.04));
  box-shadow: inset 0 -3px 0 var(--accent);
}

.diff-name { font-weight: 700; font-size: 0.95rem; }
.diff-meta { font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted); }
.diff-btn.is-active .diff-meta { color: var(--accent-bright); }

.daily-btn { background: #0f2a3a; border-color: rgba(92, 200, 255, 0.55); }
.daily-btn .diff-meta { color: #bfefff; }
.daily-btn.is-active {
  border-color: #5cc8ff;
  background: linear-gradient(180deg, rgba(92, 200, 255, 0.22), rgba(92, 200, 255, 0.05));
  box-shadow: inset 0 -3px 0 #5cc8ff;
}
.daily-btn.is-active .diff-meta { color: #e8faff; }

/* ---------- Game Card ---------- */
.game-card {
  position: relative;
  width: min(560px, 94vw);
  background: #080b16;
  border: 2px solid #26365f;
  border-radius: var(--radius);
  padding: 22px clamp(14px, 4vw, 26px) 20px;
  box-shadow: 0 6px 0 #02040a, inset 0 1px 0 #42517a;
  opacity: 0;
  animation: cardIn 0.7s cubic-bezier(.16,1,.3,1) forwards;
  animation-delay: 0.4s;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(24px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.stat { display: flex; flex-direction: column; gap: 6px; }
.stat:last-child { align-items: flex-end; }

.stat-label {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #b8c6eb;
}

.stat-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.05rem;
  color: #ffe28a;
  font-variant-numeric: tabular-nums;
}

.lives {
  display: flex;
  gap: 5px;
  min-height: 18px;
}

.life-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff6a0 0 14%, #ffd21f 45%, #e89200 100%);
  box-shadow: 0 0 4px rgba(255, 210, 31, 0.7);
  animation: popIn 0.3s cubic-bezier(.34,1.56,.64,1);
}

@keyframes popIn {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ---------- Screen frame / canvas ---------- */
.screen-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #05060c;
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid #334675;
  box-shadow: 0 0 0 4px #02040a;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0px,
    rgba(0,0,0,0) 1px,
    rgba(0,0,0,0.16) 2px,
    rgba(0,0,0,0.16) 3px
  );
  mix-blend-mode: multiply;
  opacity: 0.5;
}

.overlay-layer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(1, 1, 2, 0.72);
  backdrop-filter: blur(2px);
  text-align: center;
  padding: 20px;
  transition: opacity 0.25s ease, visibility 0.25s;
  cursor: pointer;
}

.overlay-layer.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-kicker {
  font-family: var(--font-mono);
  color: var(--accent-bright);
  letter-spacing: 0.2em;
  font-size: 0.7rem;
  margin: 0;
  animation: blinkSoft 1.6s ease-in-out infinite;
}

.overlay-title {
  font-family: var(--font-arcade);
  font-size: clamp(0.85rem, 3.2vw, 1.3rem);
  color: var(--accent-bright);
  margin: 0;
}

.overlay-sub {
  font-family: var(--font-mono);
  color: var(--muted);
  font-size: 0.78rem;
  margin: 0;
}

.overlay-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
  cursor: default;
}

@keyframes blinkSoft {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.toast {
  position: absolute;
  top: 44%;
  left: 50%;
  transform: translate(-50%, -8px);
  font-family: var(--font-arcade);
  font-size: clamp(0.65rem, 2.4vw, 0.9rem);
  color: var(--cyan);
  text-shadow: 0 0 16px rgba(51, 224, 255, 0.8);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Controls row ---------- */
.controls-row {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.hint-note {
  color: var(--muted);
  font-size: 0.78rem;
  opacity: 0.7;
  text-align: center;
  font-family: var(--font-mono);
  margin: 0;
}

.dpad {
  display: grid;
  grid-template-columns: 52px 52px 52px;
  grid-template-rows: 52px 52px 52px;
  gap: 8px;
  justify-content: center;
}

.dpad-up { grid-column: 2; grid-row: 1; }
.dpad-left { grid-column: 1; grid-row: 2; }
.dpad-pause { grid-column: 2; grid-row: 2; color: var(--cyan); font-size: 0.9rem; }
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down { grid-column: 2; grid-row: 3; }

.touch-btn {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--fg);
  width: 52px;
  height: 52px;
  border-radius: 14px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

.touch-btn:hover { border-color: var(--accent); }
.touch-btn:active, .touch-btn.is-pressed {
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: scale(0.94);
}

/* ---------- Footer ---------- */
.site-footer {
  text-align: center;
  padding: 24px 20px 30px;
  color: var(--muted);
  font-size: 0.85rem;
}

.site-footer p { margin: 0 0 8px; }
.site-footer strong { color: var(--fg); }

.footer-links {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.footer-links a, .intro-links a {
  color: var(--accent-bright);
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer-links a:hover, .intro-links a:hover { color: var(--accent); text-decoration: underline; }
.footer-links .dot, .intro-links .dot { color: var(--border); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(2, 2, 4, 0.78);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.25s ease;
}

.modal-overlay.is-open { display: flex; }

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

.modal {
  position: relative;
  width: min(420px, 88vw);
  background: linear-gradient(180deg, #14141a, #0a0a10);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 26px 26px;
  text-align: center;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,0.7);
  animation: modalIn 0.4s cubic-bezier(.16,1,.3,1);
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(30px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-icon {
  font-size: 2.6rem;
  display: block;
  margin-bottom: 10px;
  animation: pop 0.5s cubic-bezier(.34,1.56,.64,1);
}

@keyframes pop {
  0% { transform: scale(0); }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.modal-title {
  font-size: 1.5rem;
  margin: 0 0 8px;
  font-weight: 800;
}

.modal-text {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 0 0 16px;
}

.modal-stats {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 22px;
  font-family: var(--font-mono);
}

.modal-stats .m-stat { display: flex; flex-direction: column; gap: 2px; }
.modal-stats .m-stat-value { font-weight: 800; font-size: 1.2rem; color: var(--accent-bright); }
.modal-stats .m-stat-label { font-size: 0.65rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------- Intro splash ---------- */
.intro-modal {
  width: min(440px, 90vw);
}

.intro-credit {
  margin: 4px 0 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.intro-credit-line {
  margin: 0 0 8px;
  font-size: 0.92rem;
  color: var(--fg);
}

.intro-credit-line strong {
  color: var(--accent-bright);
}

.intro-links {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.intro-skip {
  margin: 0 auto 16px;
  display: block;
}

.intro-progress {
  width: 100%;
  height: 3px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.intro-progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-bright));
}

.intro-progress-fill.is-running {
  animation: introFill 3.2s linear forwards;
}

@keyframes introFill {
  from { width: 0%; }
  to { width: 100%; }
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent-bright), var(--accent));
  color: #241d00;
  border: none;
  font-weight: 700;
  font-family: var(--font-display);
  padding: 0 24px;
  height: 44px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.98rem;
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
  box-shadow: 0 8px 20px -8px rgba(255, 212, 0, 0.7);
}

.primary-btn:hover { transform: translateY(-2px); filter: brightness(1.08); }
.primary-btn:active { transform: translateY(0); }

.outline-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0 16px;
  height: 44px;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  transition: all 0.2s ease;
}

.outline-btn:hover { color: var(--accent-bright); border-color: var(--accent); }

/* ---------- Responsive ---------- */
.desktop-only { display: block; }

@media (max-width: 640px) {
  .desktop-only { display: none; }
  .dpad { grid-template-columns: 46px 46px 46px; grid-template-rows: 46px 46px 46px; gap: 6px; }
  .touch-btn { width: 46px; height: 46px; font-size: 1.05rem; }
}

@media (min-width: 641px) {
  .dpad { opacity: 0.85; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

button:focus-visible, a:focus-visible { outline: 3px solid #ffe28a; outline-offset: 4px; }
#game-canvas, .dpad { touch-action: none; }
@media (max-width: 600px) {
  .topbar { padding: 12px 16px; }
  .hero .tagline { display: none; }
  .title { font-size: 1.65rem; margin-bottom: 6px; }
  .title-line { display: inline; }
  .eyebrow { margin-bottom: 6px; }
  .game-card { padding: 14px 10px; }
}

/* During a round the cabinet takes priority over the introductory copy. */
.is-playing .hero, .is-playing .difficulty-picker, .is-playing .site-footer { display: none; }
.is-playing .stage { gap: 0; padding: 8px 12px 16px; }
@media (orientation: landscape) and (max-height: 600px) {
  .is-playing .topbar { padding: 8px 16px; }
  .is-playing .game-card { width: min(700px, 96vw); display: grid; grid-template-columns: minmax(0, 1fr) 172px; gap: 8px 16px; padding: 12px; }
  .is-playing .stat-row { grid-column: 1 / -1; margin-bottom: 0; }
  .is-playing .screen-frame { width: min(100%, calc(100svh - 155px)); justify-self: center; }
  .is-playing .controls-row { justify-content: center; margin: 0; }
  .is-playing .desktop-only { display: none; }
}
