:root {
  --gold: #f2c14e;
  --gold-deep: #c98a1b;
  --ember: #e2552a;
  --stone: #120d09;
  --ink: #fbf1dc;
  --muted: rgba(251, 241, 220, 0.66);
  --panel: rgba(20, 13, 8, 0.78);
  --line: rgba(242, 193, 78, 0.35);
  --display: "Cinzel", "Times New Roman", serif;
  --sans: "Manrope", system-ui, sans-serif;
  --mono: "DM Mono", ui-monospace, monospace;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--stone);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}
button, a { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; overflow: hidden; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.vignette {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    radial-gradient(ellipse 120% 90% at 50% 45%, transparent 55%, rgba(10, 6, 2, 0.55) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.28) 0%, transparent 18%, transparent 80%, rgba(0, 0, 0, 0.35) 100%);
}
.flash {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 2;
  background: radial-gradient(ellipse at center, rgba(255, 60, 20, 0) 30%, rgba(200, 30, 10, 0.55) 100%);
  opacity: 0;
  transition: opacity 0.5s ease;
}
.flash.on { opacity: 1; transition: opacity 0.05s; }
.danger {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 2;
  box-shadow: inset 0 -120px 140px -60px rgba(190, 30, 10, 0.75);
  opacity: 0;
  transition: opacity 0.4s;
}
.danger.on { opacity: 1; animation: pulse 0.8s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

.top-chrome {
  position: absolute;
  z-index: 8;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(12px + var(--st)) calc(16px + var(--sr)) 0 calc(16px + var(--sl));
  pointer-events: none;
}
.top-chrome > * { pointer-events: auto; }
.top-chrome.playing .back-link,
.top-chrome.playing .brand { opacity: 0; pointer-events: none; }
.brand {
  font: 800 19px/1 var(--sans);
  letter-spacing: -0.06em;
  text-decoration: none;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  transition: opacity 0.3s;
}
.brand span:first-child { font-weight: 500; }
.brand .dot { color: var(--gold); }
.chrome-actions { display: flex; align-items: center; gap: 12px; }
.back-link {
  font: 700 11px/1 var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--ink);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
  transition: opacity 0.3s;
}
.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: rgba(20, 12, 6, 0.55);
  color: var(--gold);
  font-size: 13px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.icon-btn.off { color: var(--muted); text-decoration: line-through; }

.hud {
  position: absolute;
  z-index: 6;
  top: calc(60px + var(--st));
  left: calc(16px + var(--sl));
  right: calc(16px + var(--sr));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}
.hud-score { display: flex; flex-direction: column; }
.hud-label {
  font: 500 10px/1 var(--mono);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
}
.hud-value {
  font: 900 clamp(30px, 7vw, 44px)/1 var(--display);
  letter-spacing: 0.02em;
  color: #fff8e6;
  text-shadow: 0 3px 0 rgba(90, 50, 10, 0.85), 0 6px 22px rgba(0, 0, 0, 0.6);
  font-variant-numeric: tabular-nums;
}
.hud-sub {
  margin-top: 4px;
  font: 500 11px/1 var(--mono);
  color: var(--muted);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
}
.hud-right { display: flex; align-items: center; gap: 10px; pointer-events: auto; }
.hud-coins {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px 7px 8px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(40, 24, 8, 0.75), rgba(16, 10, 4, 0.75));
  border: 1.5px solid var(--line);
  font: 900 20px/1 var(--display);
  color: var(--gold);
  text-shadow: 0 2px 0 rgba(80, 40, 0, 0.9);
  font-variant-numeric: tabular-nums;
}
.hud-coins.pop { animation: pop 0.25s ease; }
@keyframes pop { 40% { transform: scale(1.12); } }
.coin-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3b0 0 18%, #f5c542 40%, #b97a12 100%);
  box-shadow: inset 0 0 0 3px rgba(120, 70, 0, 0.55), 0 0 12px rgba(242, 193, 78, 0.55);
}

.zone-banner {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 28%;
  transform: translate(-50%, -10px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease, transform 0.5s ease;
  text-align: center;
  white-space: nowrap;
}
.zone-banner.on { opacity: 1; transform: translate(-50%, 0); }
.zb-kicker {
  font: 500 11px/1 var(--mono);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--gold);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}
#zone-name {
  font: 900 clamp(30px, 8vw, 54px)/1 var(--display);
  color: #fff6dc;
  text-shadow: 0 4px 0 rgba(90, 50, 10, 0.9), 0 10px 30px rgba(0, 0, 0, 0.7);
}

.turn-hint {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%) scale(0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.turn-hint.on { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#turn-arrow {
  font: 900 74px/1 var(--sans);
  color: var(--gold);
  text-shadow: 0 4px 0 rgba(90, 50, 10, 0.9), 0 0 30px rgba(242, 193, 78, 0.7);
  animation: nudge 0.6s ease-in-out infinite;
}
.turn-hint em {
  font: 700 12px/1 var(--mono);
  font-style: normal;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9);
}
@keyframes nudge { 50% { transform: translateY(-6px); } }

.screen {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  padding: calc(64px + var(--st)) calc(18px + var(--sr)) calc(20px + var(--sb)) calc(18px + var(--sl));
  opacity: 0;
  transition: opacity 0.45s ease;
  pointer-events: none;
}
.screen.active { opacity: 1; pointer-events: auto; }

#screen-loading { background: radial-gradient(ellipse at 50% 40%, #2a1d10 0%, #0c0805 75%); }
.loading { width: min(420px, 100%); text-align: center; }
.kicker {
  margin: 0 0 10px;
  font: 500 11px/1.3 var(--mono);
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--gold);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}
.logo {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  font: 900 clamp(46px, 13vw, 92px)/0.88 var(--display);
  letter-spacing: 0.02em;
  color: #fff4d6;
  text-shadow: 0 4px 0 #6b3d0e, 0 8px 0 rgba(40, 20, 4, 0.7), 0 18px 40px rgba(0, 0, 0, 0.7);
}
.logo em {
  font-style: normal;
  color: var(--gold);
  text-shadow: 0 -1px 0 #fff1b8, 0 4px 0 #8a520e, 0 8px 0 #4a2804, 0 18px 40px rgba(0, 0, 0, 0.7);
}
.bar {
  height: 8px;
  margin: 34px auto 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold), #fff1b8);
  box-shadow: 0 0 16px rgba(242, 193, 78, 0.6);
  transition: width 0.25s ease;
}
.load-text { margin: 0; font: 500 11px/1 var(--mono); letter-spacing: 0.1em; color: var(--muted); }

#screen-title { place-items: stretch; background: linear-gradient(180deg, rgba(0, 0, 0, 0.35) 0%, transparent 35%, transparent 55%, rgba(8, 5, 2, 0.8) 100%); }
.title-wrap { display: flex; flex-direction: column; justify-content: space-between; height: 100%; text-align: center; }
.title-top { padding-top: 2vh; }
.tagline {
  margin: 14px 0 0;
  font: 700 14px/1.4 var(--sans);
  letter-spacing: 0.06em;
  color: var(--ink);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}
.title-bottom { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.cta {
  position: relative;
  min-width: min(320px, 86vw);
  padding: 18px 28px;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffe08a 0%, #f2c14e 45%, #c98a1b 100%);
  color: #2a1604;
  font: 900 20px/1 var(--display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: 0 5px 0 #7a4a0c, 0 14px 30px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  transition: transform 0.1s, box-shadow 0.1s;
}
.cta:active { transform: translateY(4px); box-shadow: 0 1px 0 #7a4a0c, 0 6px 16px rgba(0, 0, 0, 0.5); }
#btn-play { animation: breathe 1.8s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.035); } }
.ghost {
  min-width: min(320px, 86vw);
  padding: 13px 20px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: rgba(20, 12, 6, 0.5);
  color: var(--ink);
  font: 700 13px/1 var(--sans);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.stats-row { display: flex; gap: 10px; }
.stats-row div {
  min-width: 110px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(16, 10, 5, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.stats-row span, .scoreboard span, .final-score span {
  display: block;
  font: 500 9px/1 var(--mono);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}
.stats-row strong { display: block; margin-top: 6px; font: 900 22px/1 var(--display); color: var(--gold); }
.controls { font: 600 12px/1.6 var(--sans); color: var(--muted); }
.ctrl-group { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; }
.ctrl-group span { margin-right: 10px; }
kbd {
  display: inline-grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  font: 700 12px/1 var(--sans);
  color: var(--ink);
}
.ctrl-group.touch { display: none; max-width: 320px; }
@media (hover: none) and (pointer: coarse) {
  .ctrl-group.desk { display: none; }
  .ctrl-group.touch { display: flex; }
}
.credits { margin: 0; max-width: 520px; font: 400 9px/1.5 var(--mono); letter-spacing: 0.04em; color: rgba(251, 241, 220, 0.4); }

#screen-pause, #screen-over { background: rgba(8, 5, 2, 0.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.panel {
  width: min(400px, 100%);
  padding: 26px 22px 22px;
  border-radius: 20px;
  border: 1.5px solid var(--line);
  background:
    radial-gradient(ellipse at 50% 0%, rgba(242, 193, 78, 0.16), transparent 60%),
    linear-gradient(180deg, rgba(44, 28, 14, 0.95), rgba(18, 11, 6, 0.96));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 230, 170, 0.12);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}
.panel h2 {
  margin: 0 0 4px;
  font: 900 38px/1 var(--display);
  color: #fff4d6;
  text-shadow: 0 3px 0 #6b3d0e;
}
.panel .cta, .panel .ghost { width: 100%; min-width: 0; }
.final-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 2px 0 4px;
}
.final-score strong {
  font: 900 54px/1 var(--display);
  color: var(--gold);
  text-shadow: 0 -1px 0 #fff1b8, 0 3px 0 #8a520e, 0 6px 0 #4a2804;
}
.final-score em {
  font: 800 11px/1 var(--mono);
  font-style: normal;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #2a1604;
  background: var(--gold);
  padding: 5px 10px;
  border-radius: 999px;
  animation: breathe 1.2s ease-in-out infinite;
}
.scoreboard { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; margin-bottom: 6px; }
.scoreboard div {
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid rgba(242, 193, 78, 0.18);
  background: rgba(0, 0, 0, 0.25);
  text-align: left;
}
.hud-mult {
  align-self: flex-start;
  margin-top: 8px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(242, 193, 78, 0.18);
  border: 1px solid var(--line);
  font: 900 13px/1 var(--display);
  color: var(--gold);
}
.hud-mult.boost { background: rgba(125, 255, 106, 0.2); border-color: rgba(125, 255, 106, 0.6); color: #b8ffae; }
.hud-powers { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.pw-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 128px;
  padding: 5px 8px;
  border-radius: 10px;
  background: rgba(16, 10, 5, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font: 700 10px/1 var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.pw-chip .meter { flex: 1; height: 4px; border-radius: 99px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.pw-chip .meter i { display: block; height: 100%; background: currentColor; }
.pw { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: none; }
.pw.magnet, .pw-chip.magnet { color: #ff6b5a; }
.pw.shield, .pw-chip.shield { color: #6ad4ff; }
.pw.double, .pw-chip.double { color: #9dff8e; }
.pw.magnet { background: #ff4b3a; box-shadow: 0 0 10px #ff4b3a; }
.pw.shield { background: #46c8ff; box-shadow: 0 0 10px #46c8ff; }
.pw.double { background: #7dff6a; box-shadow: 0 0 10px #7dff6a; }
.power-legend { display: flex; gap: 14px; font: 600 11px/1 var(--sans); color: var(--muted); }
.power-legend span { display: flex; align-items: center; gap: 6px; }

.tip, .toast {
  position: absolute;
  z-index: 6;
  left: 50%;
  transform: translate(-50%, 8px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(16, 10, 5, 0.78);
  border: 1.5px solid var(--line);
  font: 800 14px/1.2 var(--sans);
  letter-spacing: 0.04em;
  color: var(--ink);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.tip { top: 27%; font-size: 16px; }
.tip b { color: var(--gold); }
.toast { top: calc(120px + var(--st)); }
.tip.on, .toast.on { opacity: 1; transform: translate(-50%, 0); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
.btn-row .ghost { min-width: 0; padding: 13px 8px; font-size: 12px; }

.scoreboard strong { display: block; margin-top: 6px; font: 800 19px/1 var(--display); color: var(--ink); }
