:root {
  --bg: #0b1020;
  --panel: rgba(16, 20, 48, 0.78);
  --panel-border: rgba(160, 180, 255, 0.22);
  --text: #eef1ff;
  --muted: rgba(238, 241, 255, 0.62);
  --accent: #ffd166;
  --accent-2: #7c6cff;
  --accent-3: #4fd1ff;
  --danger: #ff6b6b;
  --font: "Nunito", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --board-left: 0px;
  --board-right: 0px;
  --board-top: 0px;
  --board-width: 0px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font-family: inherit; }
canvas { display: block; }

#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ------------------------------------------------------------------ HUD */
#hud {
  position: relative; z-index: 3;
  height: 62px; flex: 0 0 62px;
  display: grid; grid-template-columns: 1fr auto 1fr auto; align-items: center; gap: 10px;
  padding: 6px 12px 0;
  opacity: 0.55; transition: opacity .3s;
}
#hud.playing { opacity: 1; }
.hud-item { display: flex; flex-direction: column; line-height: 1.05; }
.hud-right { align-items: flex-end; }
.hud-next { align-items: center; }
.label { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.value { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
#score.bump { transform: scale(1.12); color: var(--accent); }
#score { transition: transform .12s, color .3s; display: inline-block; transform-origin: left center; }
#next-canvas { width: 44px; height: 44px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--panel-border);
  background: var(--panel); color: var(--text); font-size: 15px; cursor: pointer;
  display: grid; place-items: center; backdrop-filter: blur(8px);
}
.icon-btn:hover { background: rgba(60, 70, 130, 0.8); }
body.in-menu #btn-pause { visibility: hidden; }

/* ---------------------------------------------------------------- stage */
#stage { position: relative; flex: 1 1 auto; min-height: 0; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.hint {
  position: absolute; left: 50%; bottom: 10%; transform: translate(-50%, 10px);
  background: var(--panel); border: 1px solid var(--panel-border); color: var(--text);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity .35s, transform .35s; backdrop-filter: blur(8px);
}
.hint.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------- side panels */
.side-panel {
  display: none; position: absolute; top: calc(var(--board-top) + 10px); width: 230px;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 18px;
  padding: 16px 18px; backdrop-filter: blur(10px); z-index: 2; color: var(--text);
}
.side-panel h2 { margin: 0 0 10px; font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.side-panel ul { margin: 0; padding-left: 18px; font-size: 13.5px; line-height: 1.45; color: var(--text); }
.side-panel .keys { margin: 12px 0 0; font-size: 12px; color: var(--muted); }
#side-left { left: calc(var(--board-left) - 250px); }
#side-right { left: calc(var(--board-right) + 20px); }
@media (min-width: 980px) and (min-aspect-ratio: 1/1) {
  .side-panel { display: block; }
  body.in-menu .side-panel { display: none; }
}

/* -------------------------------------------------------------- overlays */
#overlays { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.overlay {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px;
  background: rgba(6, 8, 22, 0.55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  pointer-events: auto; animation: fade .25s ease-out; overflow: auto; touch-action: pan-y;
}
.overlay.hidden { display: none; }
.hidden { display: none !important; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translateY(16px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }

.panel {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 24px; padding: 26px 22px 22px; text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  display: flex; flex-direction: column; gap: 10px; animation: rise .32s cubic-bezier(.2,.8,.2,1);
}
.panel.wide { width: min(440px, 100%); }
.panel h2 { margin: 0 0 4px; font-size: 24px; font-weight: 800; }
.panel h3 { margin: 10px 0 0; font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); margin: 0; font-size: 14px; }

.logo {
  margin: 4px 0 0; font-size: 48px; line-height: 1; font-weight: 900; letter-spacing: -0.02em;
  background: linear-gradient(180deg, #fff 0%, #ffe9a8 45%, #ffb347 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.45));
}
.logo span { background: linear-gradient(180deg, #e9f0ff 0%, #9fb4ff 60%, #7c6cff 100%); -webkit-background-clip: text; background-clip: text; }
.tagline { margin: 2px 0 14px; color: var(--muted); font-weight: 600; }

.btn {
  position: relative; border: 1px solid var(--panel-border); border-radius: 16px; padding: 12px 18px;
  background: rgba(255, 255, 255, 0.06); color: var(--text); font-weight: 800; font-size: 16px;
  cursor: pointer; transition: transform .12s, background .2s, box-shadow .2s; width: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.btn:hover { background: rgba(255, 255, 255, 0.11); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.big { padding: 15px 18px; font-size: 18px; }
.btn.primary {
  background: linear-gradient(180deg, #ffd97a, #ffb347); color: #2b1a05; border-color: transparent;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}
.btn.primary:hover { background: linear-gradient(180deg, #ffe39a, #ffbd5c); }
.btn.secondary {
  background: linear-gradient(180deg, #6451e0, #4d3ec4); border-color: transparent;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}
.btn.secondary:hover { background: linear-gradient(180deg, #7262ea, #5848cf); }
.btn.ghost { background: transparent; }
.btn.reward {
  background: linear-gradient(180deg, #4fd1ff, #2c9ee0); border-color: transparent; color: #05202e;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}
.reward-sub { font-size: 12px; font-weight: 600; opacity: .85; }
.btn.toggle { flex-direction: row; justify-content: space-between; }
.btn.toggle strong { color: var(--accent); }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }
.daily-btn em { font-style: normal; opacity: .85; font-weight: 700; }
.daily-sub { font-size: 12.5px; font-weight: 700; opacity: .9; }
.menu-footer { display: flex; justify-content: space-between; margin-top: 8px; font-size: 12px; color: var(--muted); }
.menu-footer a { color: var(--muted); }

.badge {
  align-self: center; background: linear-gradient(180deg, #ffd97a, #ffb347); color: #2b1a05;
  padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
  animation: pop .5s cubic-bezier(.2,1.6,.4,1);
}
@keyframes pop { from { transform: scale(.4); } to { transform: none; } }
.go-score { font-size: 52px; font-weight: 900; line-height: 1; margin: 2px 0; font-variant-numeric: tabular-nums; }
.go-score .unit { font-size: 16px; color: var(--muted); margin-left: 6px; font-weight: 700; }
.go-meta { display: flex; justify-content: center; gap: 28px; }
.go-meta div, .go-biggest > div { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.go-meta strong, .go-biggest strong { font-size: 18px; }
.go-biggest {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  background: rgba(255, 255, 255, 0.05); border-radius: 18px; padding: 10px 14px;
}
.go-biggest > div { align-items: flex-start; text-align: left; }

.steps { text-align: left; margin: 0; padding-left: 22px; line-height: 1.5; font-size: 15px; }
.steps li { margin: 4px 0; }
#evo-howto { margin: 4px auto 0; }
.legend {
  list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px;
  font-size: 12.5px; color: var(--muted); text-align: left;
}

/* ------------------------------------------------------------ toast etc */
#toast {
  position: absolute; left: 50%; top: 80px; transform: translate(-50%, -10px);
  background: rgba(20, 24, 60, 0.95); border: 1px solid var(--panel-border); color: var(--text);
  padding: 10px 16px; border-radius: 14px; font-weight: 700; font-size: 14px; opacity: 0; transition: .25s; pointer-events: none;
  max-width: 90vw; text-align: center; white-space: pre-line;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.loading {
  position: absolute; right: 14px; bottom: 14px; font-size: 12px; color: var(--muted); pointer-events: none;
}
#ad-sim {
  position: absolute; inset: 0; background: #000; display: grid; place-items: center; z-index: 10;
  pointer-events: auto; color: #fff; text-align: center; font-weight: 800;
}
#ad-sim .ad-sim-count { font-size: 64px; }

@media (max-height: 600px) {
  #hud { height: 52px; flex-basis: 52px; }
  .value { font-size: 20px; }
  .logo { font-size: 38px; }
}
@media (prefers-reduced-motion: reduce) {
  .overlay, .panel, .badge { animation: none; }
}
