@font-face {
  font-family: "Space Grotesk";
  src: url("../fonts/SpaceGrotesk.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}

@font-face {
  font-family: "Outfit";
  src: url("../fonts/Outfit.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --sky-top: #090d13;
  --sky-bottom: #13261f;
  --accent: #10e896;
  --accent-text: #03190f;
  --text: #e7fdf4;
  --panel: #0b1312db;
  --danger: #ff5468;
  --glow: #87ffbd;
  --amber: #ffba3d;
  --muted: #a9bdb4;
  --faint: #8aa39a;
  --surface: #10141a;
  --surface-high: #181c22;
  --well: #05080c;
  --line: rgba(75, 227, 233, 0.18);
  --line-soft: rgba(132, 149, 136, 0.28);
  --font: "Outfit", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Space Grotesk", "Outfit", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sky-top);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

body { position: fixed; inset: 0; }

#stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  touch-action: none;
}

.screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 16px) calc(env(safe-area-inset-right) + 16px) calc(env(safe-area-inset-bottom) + 16px) calc(env(safe-area-inset-left) + 16px);
  overflow-y: auto;
  z-index: 10;
}

.screen.active { display: flex; animation: rise 0.22s ease-out; }
.screen.dim { background: rgba(4, 7, 10, 0.78); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
#loading, #error { background: radial-gradient(circle at 50% 30%, var(--sky-bottom) 0%, var(--sky-top) 75%); }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.stack, .card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(100%, 380px);
  text-align: center;
  margin: auto;
}

.card {
  background: rgba(18, 26, 26, 0.86);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 26px 20px 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.card.slim { width: min(100%, 300px); }

h1, h2, .big-score, .best-value, .countdown { font-family: var(--font-display); }

h1 {
  margin: 0;
  font-size: 40px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--glow);
  text-shadow: 0 0 18px color-mix(in srgb, var(--accent) 45%, transparent);
}

h2 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--glow);
  text-shadow: 0 0 18px color-mix(in srgb, var(--accent) 40%, transparent);
}

.tagline { margin: 0; font-size: 15px; line-height: 1.45; color: var(--muted); max-width: 32ch; }

.eyebrow {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.row { display: flex; gap: 10px; width: 100%; justify-content: center; flex-wrap: wrap; }
.row > .btn { flex: 1 1 0; min-width: 0; }
.row.tight { flex-wrap: nowrap; }

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
  background: rgba(20, 31, 29, 0.7);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  min-height: 48px;
  padding: 10px 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
  touch-action: manipulation;
}

.btn:hover { background: rgba(32, 46, 43, 0.85); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.btn:active { transform: translateY(2px); }
.btn:focus-visible, .dock-btn:focus-visible, .icon-btn:focus-visible { outline: 3px solid var(--glow); outline-offset: 3px; }
.btn:disabled { opacity: 0.5; }

.btn.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 80%, #ffffff) 0%, var(--accent) 100%);
  color: var(--accent-text);
  border-color: transparent;
  font-weight: 700;
  box-shadow: 0 4px 20px color-mix(in srgb, var(--accent) 40%, transparent), 0 0 40px color-mix(in srgb, var(--accent) 18%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.btn.primary:hover { filter: brightness(1.05); }
.btn.huge { width: 100%; min-height: 64px; font-family: var(--font-display); font-size: 24px; letter-spacing: 0.04em; text-transform: uppercase; }
.btn.ghost { background: transparent; }
.btn.outline { background: rgba(5, 8, 12, 0.5); }

.btn .i { width: 20px; height: 20px; flex: none; }

svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.btn.toggle .pill {
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.4);
  color: var(--muted);
}

.btn.toggle[aria-pressed="true"] { border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.btn.toggle[aria-pressed="true"] .pill { background: var(--accent); color: var(--accent-text); }
.btn.toggle[aria-pressed="false"] .ico { text-decoration: line-through; }

.ico { font-size: 18px; }

.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-all; margin: 0; color: var(--amber); }
.hidden { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.best-line { margin: 0; font-weight: 600; color: var(--muted); min-height: 1.2em; }
.best-line.new { color: var(--amber); font-family: var(--font-display); font-weight: 700; letter-spacing: 0.04em; text-shadow: 0 0 16px rgba(255, 186, 61, 0.45); animation: pulse 0.9s ease-in-out infinite alternate; }

@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.08); } }

#title { padding: 0; align-items: stretch; justify-content: flex-start; flex-direction: column; }
#title.active { display: flex; }

.title-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(100%, 480px);
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) calc(env(safe-area-inset-right) + 16px) 18px calc(env(safe-area-inset-left) + 16px);
  text-align: center;
}

.brand {
  width: 100%;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
}

.brand-mark { width: 30px; height: 30px; color: var(--faint); justify-self: start; margin-left: 6px; }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line-soft);
  background: rgba(20, 31, 29, 0.65);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  touch-action: manipulation;
}

.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.hidden { display: inline-flex !important; visibility: hidden; }

.title-space { flex: 1; min-height: 24px; }

.best-card {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-radius: 24px;
  background: rgba(18, 26, 26, 0.78);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
}

.best-main { display: flex; align-items: center; gap: 12px; min-width: 0; }

.trophy {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--amber);
  background: radial-gradient(circle, rgba(255, 186, 61, 0.22), rgba(255, 186, 61, 0.05));
  box-shadow: 0 0 20px rgba(255, 186, 61, 0.18);
}

.trophy svg { width: 24px; height: 24px; }

.best-text { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; }

.best-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  color: var(--text);
}

.best-card .btn { flex: none; min-height: 44px; padding: 8px 16px; font-family: var(--font-display); font-size: 14px; letter-spacing: 0.06em; text-transform: uppercase; }

.btn.play { min-height: 68px; gap: 14px; }

.play-dot {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 25, 15, 0.14);
}

.play-dot svg { width: 22px; height: 22px; fill: currentColor; stroke-width: 1.5; }

.keys { color: var(--muted); padding: 4px 12px; border-radius: 999px; background: rgba(5, 8, 12, 0.72); }

.dock {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  width: min(100%, 480px);
  margin: 0 auto;
  padding: 12px calc(env(safe-area-inset-right) + 12px) calc(env(safe-area-inset-bottom) + 12px) calc(env(safe-area-inset-left) + 12px);
  background: rgba(16, 20, 26, 0.94);
  border: 1px solid var(--line-soft);
  border-bottom: 0;
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.35);
}

.dock.three { grid-template-columns: repeat(3, 1fr); }

.dock-btn {
  font: inherit;
  background: none;
  border: 0;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  min-width: 0;
  cursor: pointer;
  border-radius: 16px;
  touch-action: manipulation;
}

.dock-ico {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 31, 29, 0.65);
  border: 1px solid var(--line-soft);
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.dock-ico svg { width: 24px; height: 24px; }
.dock-lbl { font-size: 13px; font-weight: 500; line-height: 1.2; max-width: 100%; text-align: center; overflow-wrap: anywhere; }

.dock-btn:hover .dock-ico { border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
.dock-btn:active .dock-ico { transform: translateY(1px); }

.dock-btn.toggle[aria-pressed="true"] { color: var(--glow); }
.dock-btn.toggle[aria-pressed="true"] .dock-ico {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1.5px solid var(--accent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 30%, transparent);
}

.dock-btn.toggle .off { display: none; }
.dock-btn.toggle[aria-pressed="false"] .on { display: none; }
.dock-btn.toggle[aria-pressed="false"] .off { display: inline; }

.badge {
  position: absolute;
  top: -6px;
  right: -8px;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 1px 6px;
  border-radius: 99px;
  background: var(--surface-high);
  border: 1px solid var(--line-soft);
  color: var(--glow);
}

.big-score {
  font-size: 68px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--text);
  text-shadow: 0 0 24px color-mix(in srgb, var(--accent) 35%, transparent);
}

#overStats { line-height: 1.5; }

form { width: 100%; display: flex; flex-direction: column; gap: 8px; }
label { font-weight: 600; }

input {
  font: inherit;
  font-size: 18px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--line-soft);
  background: var(--well);
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.8);
  color: var(--text);
  user-select: text;
  -webkit-user-select: text;
}

input::placeholder { color: var(--faint); }
input:focus { outline: none; border-color: var(--accent); }

.saved { margin: 0; font-weight: 700; color: var(--glow); }

.ad-slot {
  width: 100%;
  max-width: 320px;
  aspect-ratio: 320 / 100;
  border: 1.5px dashed var(--line-soft);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
  background: var(--well);
}

#breakAd { aspect-ratio: 300 / 250; max-width: 300px; }

.scores {
  list-style: none;
  margin: 0;
  padding: 6px;
  width: 100%;
  counter-reset: rank;
  border-radius: 18px;
  background: var(--well);
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.7);
}

.scores li {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 2.2em 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.scores li:nth-child(odd) { background: rgba(255, 255, 255, 0.04); }
.scores li::before { content: counter(rank); font-family: var(--font-display); color: var(--faint); text-align: left; }
.scores li:first-child::before { color: var(--amber); }
.scores li .n { text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scores li > :last-child { font-family: var(--font-display); font-weight: 700; }
.scores li.me { background: color-mix(in srgb, var(--accent) 16%, transparent); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 70%, transparent); }

#creditsBody p { margin: 0 0 10px; line-height: 1.5; color: var(--muted); }

.spinner {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.bar { width: 100%; height: 8px; border-radius: 8px; background: var(--well); overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--accent); box-shadow: 0 0 12px var(--accent); transition: width 0.15s ease; }

.warnings {
  width: 100%;
  text-align: left;
  font-size: 12px;
  background: rgba(255, 84, 104, 0.12);
  border: 1px solid rgba(255, 84, 104, 0.5);
  border-radius: 16px;
  padding: 8px 12px;
}

.warnings p { margin: 4px 0; }
.warnings ul { margin: 2px 0 6px; padding-left: 18px; }

.hud-btn {
  position: fixed;
  right: calc(env(safe-area-inset-right) + 14px);
  bottom: calc(env(safe-area-inset-bottom) + 14px);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  background: var(--panel);
  z-index: 5;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.hud-btn span {
  width: 14px;
  height: 16px;
  border-left: 4px solid var(--text);
  border-right: 4px solid var(--text);
}

.countdown {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 96px;
  font-weight: 700;
  color: var(--glow);
  text-shadow: 0 0 30px color-mix(in srgb, var(--accent) 50%, transparent), 0 4px 24px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  z-index: 6;
}

.toast {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 76px);
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  background: rgba(18, 26, 26, 0.92);
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 16px;
  font-size: 14px;
  z-index: 20;
  pointer-events: none;
}

@media (orientation: landscape) and (max-height: 500px) {
  .stack, .card { width: min(100%, 560px); gap: 8px; }
  .card { padding: 14px; }
  h1 { font-size: 30px; }
  .btn.huge { min-height: 52px; font-size: 20px; }
  .big-score { font-size: 44px; }
  .title-wrap { gap: 8px; padding-top: calc(env(safe-area-inset-top) + 8px); padding-bottom: 8px; width: min(100%, 620px); }
  .title-space { display: none; }
  .best-card { padding: 10px 14px; }
  .best-value { font-size: 24px; }
  .trophy { width: 36px; height: 36px; }
  .btn.play { min-height: 52px; }
  .play-dot { width: 32px; height: 32px; }
  .keys { display: none; }
  .dock { width: min(100%, 620px); padding-top: 8px; padding-bottom: calc(env(safe-area-inset-bottom) + 8px); }
  .dock-btn { flex-direction: row; justify-content: center; gap: 8px; }
  .dock-ico { width: 38px; height: 38px; }
  .dock-ico svg { width: 20px; height: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .screen.active, .best-line.new, .spinner { animation: none; }
}
