:root {
  --bg: #1e2733;
  --panel: #2a3645;
  --line: #3d4d61;
  --text: #f1f4f8;
  --muted: #aab6c5;
  --accent: #ffbf47;
  --warn: #ff6b5e;
  --ice: #9fdcff;
  color: var(--text);
  background: var(--bg);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: radial-gradient(ellipse at 50% 30%, #283444, var(--bg) 70%); }
button { font: inherit; color: inherit; cursor: pointer; }

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  gap: 8px;
}

/* ---------- top bar ---------- */

#bar { display: flex; align-items: center; gap: 8px; }
.actions { display: flex; gap: 6px; margin-left: auto; }

.icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: var(--panel);
  font-size: 18px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25);
}
.icon svg { width: 20px; height: 20px; }
.icon:active { transform: translateY(1px); box-shadow: none; }
.icon.off, .icon:disabled { opacity: 0.45; }
.icon:disabled { cursor: default; }

.pill {
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--panel);
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}
.timer { font-variant-numeric: tabular-nums; min-width: 64px; text-align: center; }
.timer.low { color: var(--warn); animation: pulse 0.8s ease-in-out infinite alternate; }
.timer.frozen { color: var(--ice); background: #25405a; }
.timer.untimed { color: var(--muted); }
@keyframes pulse { to { transform: scale(1.08); } }

.tip {
  margin: 0;
  min-height: 1.3em;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}

/* ---------- board ---------- */

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
}
#board { touch-action: none; display: block; }
#board.tool-hammer, #board.tool-picker { cursor: crosshair; }

.toast {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(12, 16, 22, 0.92);
  border: 1px solid var(--line);
  font-size: 14px;
  text-align: center;
  pointer-events: none;
  max-width: 90%;
}

/* ---------- boosters ---------- */

#boosters { display: flex; justify-content: center; gap: 10px; }
.booster {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 2px solid transparent;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25);
  font-size: 14px;
  font-weight: 700;
}
.booster .glyph { font-size: 18px; }
.booster .count {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #3a2600;
  font-size: 12px;
}
.booster.active { border-color: var(--accent); background: #3a3a33; }
.booster:disabled { opacity: 0.4; cursor: default; }
@media (max-width: 420px) { .booster .name { display: none; } }

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 16, 22, 0.72);
  backdrop-filter: blur(4px);
}
.overlay[hidden] { display: none; }

.card {
  width: min(360px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 26px 24px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.card.wide { width: min(460px, 100%); }
.card h1, .card h2 { margin: 0; }
.card h1 { font-size: 36px; color: var(--accent); letter-spacing: 0.01em; }
.lede { margin: 0; color: var(--muted); line-height: 1.45; }

.primary, .soft {
  padding: 12px 18px;
  border: 0;
  border-radius: 14px;
  font-weight: 800;
  font-size: 16px;
}
.primary { background: var(--accent); color: #3a2600; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2); }
.soft { background: #34435a; }

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 4px;
}
.level-grid button {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #222d3b;
  font-weight: 800;
  font-size: 18px;
}
.level-grid button small { font-size: 10px; font-weight: 600; color: var(--muted); }
.level-grid button.done { border-color: var(--accent); }
.level-grid button.done small { color: var(--accent); }
