:root {
  --bg: #08090a;
  --panel: #0e1012;
  --ink: #f5f5f4;
  --dim: #868c96;
  --line: #1b1f24;
  --yellow: #ffc400;
  --orange: #ff6b2c;
  --stage-w: min(100vw, calc((100dvh - 56px) * 0.5625));
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: var(--ink);
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Inter, system-ui, sans-serif;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

body {
  display: grid;
  place-items: center;
  background:
    radial-gradient(120% 80% at 50% -10%, #16181c 0%, #08090a 55%, #000 100%);
}

#app {
  position: relative;
  width: var(--stage-w);
  height: min(calc(100dvh - var(--safe-b)), calc(var(--stage-w) * 16 / 9));
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

@media (min-width: 720px) {
  #app {
    height: min(calc(100dvh - 48px), 900px);
    width: min(calc((100dvh - 48px) * 0.5625), 506px);
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: 0 40px 120px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
  }
}

/* ---------- HUD ---------- */
#hud {
  height: 56px;
  flex: 0 0 56px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(#0c0e10, #08090a);
  font-variant-numeric: tabular-nums;
}

.hud-cell { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hud-cell--right { align-items: flex-end; }

.hud-label {
  font-size: 9px;
  letter-spacing: 0.16em;
  color: var(--dim);
  font-weight: 600;
}

.hud-value {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.hud-sub {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: #7C8088;
  font-variant-numeric: tabular-nums;
}

.hud-lives {
  letter-spacing: 0.16em;
  font-size: 17px;
  line-height: 1;
  color: #FFD24A;
}

@keyframes pulse { 50% { opacity: 0.45; } }

/* ---------- Stage ---------- */
#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: var(--bg);
  touch-action: none;
  overflow: hidden;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* ---------- Overlays ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 22px;
  text-align: center;
  background: radial-gradient(90% 60% at 50% 42%, rgba(8, 9, 10, 0.86), rgba(8, 9, 10, 0.98));
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 5;
  animation: fade 0.22s ease-out;
}

.screen[hidden] { display: none; }

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

.brand { margin-bottom: 2px; }

.wordmark {
  margin: 0;
  font-size: clamp(30px, 9.4vw, 46px);
  line-height: 0.9;
  letter-spacing: -0.035em;
  font-weight: 900;
}
.wordmark span {
  display: block;
  color: var(--yellow);
  letter-spacing: 0.14em;
  font-size: 0.52em;
  margin-top: 7px;
  padding-left: 3px;
}

.tagline {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--dim);
  letter-spacing: 0.01em;
  max-width: 24ch;
  line-height: 1.45;
}

.start-meta { display: flex; align-items: center; gap: 8px; margin: 6px 0 4px; }

.pill {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  padding: 5px 9px;
  border-radius: 999px;
  color: #0a0a0a;
  background: var(--yellow);
}

.best {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.btn {
  width: min(100%, 260px);
  border: 0;
  border-radius: 12px;
  padding: 15px 18px;
  font-size: 15px;
  font-weight: 750;
  letter-spacing: 0.01em;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease, background 0.12s;
}

.btn:active { transform: scale(0.975); }

.btn--primary {
  background: var(--yellow);
  color: #100c00;
  box-shadow: 0 8px 26px rgba(255, 196, 0, 0.18);
  margin-top: 8px;
}
.btn--primary:hover { filter: brightness(1.06); }

.btn--ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid #2a2f36;
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
}
.btn--ghost:hover { background: #12151a; }

.hint { margin: 6px 0 0; font-size: 11px; color: #5f656e; letter-spacing: 0.03em; }

/* ---------- Game over ---------- */
.screen--over { justify-content: center; gap: 9px; padding: 10px 0; overflow-y: auto; }
.screen--over[hidden] { display: none; }

.kicker {
  margin: 2px 0 0;
  font-size: 10px;
  letter-spacing: 0.32em;
  color: var(--orange);
  font-weight: 700;
}

.final-score {
  margin: 0;
  font-size: clamp(44px, 13vw, 64px);
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.final-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 300px;
  margin: 8px 0 2px;
}
.final-stats div {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 7px 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #0b0d0f;
}
.final-stats span { font-size: 8.5px; letter-spacing: 0.16em; color: var(--dim); }
.final-stats b { font-size: 15px; font-variant-numeric: tabular-nums; }

.card-preview {
  width: clamp(112px, 17dvh, 152px);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #23272d;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  margin: 6px 0 2px;
}
.card-preview canvas { display: block; width: 100%; height: auto; }

.rank-line { margin: 0; font-size: 11px; color: var(--dim); min-height: 14px; }

/* ---------- Floating controls ---------- */
.icon-btn, .pause-btn {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid #23272d;
  background: rgba(12, 14, 16, 0.82);
  color: #9aa1ab;
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 6;
  backdrop-filter: blur(6px);
  padding: 0;
}
.icon-btn svg { width: 19px; height: 19px; fill: currentColor; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; fill-rule: evenodd; }
.icon-btn[data-muted="true"] { color: #4a5058; }
.icon-btn[data-muted="true"] #sound-wave { display: none; }
.icon-btn[data-muted="true"]::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 2px;
  background: currentColor;
  transform: rotate(-45deg);
  border-radius: 2px;
}

.pause-btn { right: 56px; font-size: 11px; letter-spacing: 1px; }
.pause-btn[hidden] { display: none; }

/* ---------- Chain chip ---------- */
.chain-chip {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 8px;
  background: rgba(255, 196, 0, 0.12);
  border: 1px solid rgba(255, 196, 0, 0.35);
  color: var(--yellow);
  z-index: 4;
  font-variant-numeric: tabular-nums;
}
.chain-chip[hidden] { display: none; }
.chain-chip b { font-size: 13px; font-weight: 800; }
.chain-chip span { font-size: 9px; letter-spacing: 0.08em; color: #b99a3c; text-transform: uppercase; }

/* ---------- Power chip ---------- */
.power-chip {
  position: absolute;
  top: 44px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(8, 9, 10, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
}

.power-chip[hidden] {
  display: none;
}

.power-chip b {
  color: #FFD24A;
}

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  background: #f5f5f4;
  color: #0a0a0a;
  font-size: 12px;
  font-weight: 650;
  padding: 9px 14px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  max-width: 80vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

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

/* ---------- Landing layout ---------- */
.screen#screen-start {
  justify-content: space-between;
  padding: 0 20px calc(18px + env(safe-area-inset-bottom));
  background:
    linear-gradient(to top, rgba(8, 9, 10, 0.94) 0%, rgba(8, 9, 10, 0.55) 26%, rgba(8, 9, 10, 0.28) 100%);
}
.screen#screen-start .brand { margin-top: 13vh; }
.screen#screen-start .start-meta { margin: 0; }
.start-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.start-actions .hint { margin: 2px 0 6px; }

/* keep the playfield readable behind the menu, hide dead HUD numbers */
#hud:has(+ #stage #screen-start:not([hidden])) { visibility: hidden; }

/* sound toggle reads as app chrome */
#btn-sound {
  width: 40px;
  height: 40px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  border-radius: 12px;
  background: #111214;
  border: 1px solid #2a2a2a;
  color: var(--yellow);
  opacity: 1;
  z-index: 6;
}

@media (max-height: 700px) {
  .screen#screen-start .brand { margin-top: 6vh; }
  .wordmark { font-size: clamp(26px, 8vw, 38px); }
  .tagline { margin-top: 8px; }
}
