:root {
  --bg: #0b1a2e;
  --bg2: #12294a;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-line: rgba(255, 255, 255, 0.1);
  --text: #eaf4ff;
  --muted: #8fa9c8;
  --accent: #7fd8ff;
  --gold: #ffd166;
  --gem: #ff5fa8;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(120% 80% at 50% 0%, var(--bg2), var(--bg) 70%);
  background-color: var(--bg);
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; cursor: pointer; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.hidden { display: none !important; }

/* HUD */
.hud {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 16px 4px;
}
.icon-btn, .ctl {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 14px;
}
.icon-btn { width: 48px; height: 48px; display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; fill: var(--text); }
#lvl-name { font-size: 20px; font-weight: 700; }
#lvl-tier { font-size: 13px; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.hud-stats { text-align: right; font-variant-numeric: tabular-nums; }
.hud-stats > div:first-child { font-size: 22px; font-weight: 700; }
.hud-stats small { font-size: 13px; color: var(--muted); font-weight: 500; }
.gems { font-size: 13px; color: var(--gem); min-height: 16px; }

#stage { position: relative; flex: 1; min-height: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#toast {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translate(-50%, 8px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(8, 18, 34, 0.92);
  border: 1px solid var(--panel-line);
  font-size: 15px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 8px 16px 16px;
}
.ctl {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
}
.ctl svg, .icon-btn svg { flex: none; }
.ctl svg { width: 20px; height: 20px; fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ctl:active, .icon-btn:active, .lvl:active, .btn:active { transform: scale(0.96); }
.ctl:disabled { opacity: 0.4; }

/* Menu */
#menu {
  overflow-y: auto;
  touch-action: pan-y;
  z-index: 10;
  background: radial-gradient(120% 80% at 50% 0%, var(--bg2), var(--bg) 70%) fixed;
  background-color: var(--bg);
}
.menu-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 20px 16px 4px;
}
.menu-head h1 { margin: 0; font-size: 34px; letter-spacing: -0.01em; }
.total-stars { color: var(--gold); font-weight: 700; font-size: 18px; }
.tier { padding: 12px 16px 4px; }
.tier h2 {
  margin: 8px 0 10px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.tier-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 10px; }
.lvl {
  aspect-ratio: 1;
  border-radius: 16px;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 20px;
  font-weight: 700;
}
.lvl.done { background: rgba(127, 216, 255, 0.14); border-color: rgba(127, 216, 255, 0.35); }
.lvl .s { font-size: 11px; letter-spacing: 1px; color: var(--gold); min-height: 13px; }
.lvl .s .off { color: rgba(255, 255, 255, 0.18); }
.lvl.locked { opacity: 0.45; cursor: default; }
.lvl.locked:active { transform: none; }
.lvl .s svg { width: 12px; height: 12px; fill: none; stroke: var(--muted); stroke-width: 2.4; stroke-linejoin: round; }

/* Daily challenge */
.daily-card {
  margin: 12px 16px 4px;
  padding: 16px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, rgba(127, 216, 255, 0.22), rgba(255, 95, 168, 0.14));
  border: 1px solid rgba(127, 216, 255, 0.35);
}
.daily-info { flex: 1; min-width: 0; }
.daily-kicker { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.daily-date { font-size: 20px; font-weight: 700; margin: 2px 0; }
.daily-meta { font-size: 14px; color: var(--muted); }
.daily-play { flex: none; min-width: 96px; padding: 0 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.daily-stars { font-size: 12px; letter-spacing: 1px; color: #9a6a00; }
.daily-stars .off { color: rgba(6, 32, 56, 0.25); }
.win-extra { display: flex; justify-content: space-between; gap: 8px; margin: -6px 0 18px; padding: 10px 12px; border-radius: 12px; background: var(--panel); font-size: 14px; }
.win-extra span { color: var(--muted); }
.how { color: var(--muted); font-size: 14px; text-align: center; line-height: 1.5; padding: 16px 24px 32px; margin: 0; }

/* Win card */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(4, 10, 20, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade 0.25s ease-out;
}
.card {
  width: min(360px, 100%);
  background: linear-gradient(180deg, #17345c, #10243f);
  border: 1px solid var(--panel-line);
  border-radius: 24px;
  padding: 24px 20px 20px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  animation: pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.card h2 { margin: 0 0 8px; font-size: 28px; }
.stars { font-size: 44px; letter-spacing: 6px; color: var(--gold); margin: 4px 0 12px; }
.stars .off { color: rgba(255, 255, 255, 0.15); }
.stars span { display: inline-block; animation: pop 0.4s both cubic-bezier(0.2, 1.6, 0.4, 1); }
.stars span:nth-child(2) { animation-delay: 0.12s; }
.stars span:nth-child(3) { animation-delay: 0.24s; }
.goals { list-style: none; padding: 0; margin: 0 0 20px; text-align: left; display: grid; gap: 8px; }
.goals li { display: flex; gap: 10px; align-items: center; font-size: 15px; color: var(--muted); }
.goals li.met { color: var(--text); }
.goals li::before { content: "○"; width: 18px; text-align: center; color: var(--muted); }
.goals li.met::before { content: "★"; color: var(--gold); }
.lose-icon { font-size: 48px; margin-bottom: 4px; }
.lose-text { color: var(--muted); font-size: 15px; line-height: 1.45; margin: 0 0 20px; }
.card-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
.btn {
  height: 52px;
  border-radius: 14px;
  border: 0;
  background: var(--accent);
  color: #062038;
  font-weight: 700;
  font-size: 17px;
}
.btn.secondary { background: var(--panel); color: var(--text); border: 1px solid var(--panel-line); }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }

@media (min-width: 700px) {
  .hud, .controls { max-width: 560px; width: 100%; margin: 0 auto; }
  #menu > * { max-width: 640px; width: 100%; margin-left: auto; margin-right: auto; }
}
