:root {
  --bg: #0a0f1c;
  --panel: #151d31;
  --line: #27355a;
  --text: #e8f0ff;
  --muted: #8ea0c4;
  --beam: #ff3b5c;
  --target: #3ff2d0;
  --alarm: #ffb020;
  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%, #16203a, 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;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- 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.3);
}
.icon svg { width: 20px; height: 20px; }
.icon:active { transform: translateY(1px); box-shadow: none; }
.icon.off, .icon:disabled { opacity: 0.4; }
.icon:disabled { cursor: default; }

.pill {
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--panel);
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}
.status { font-variant-numeric: tabular-nums; color: var(--muted); }
.status.all { color: var(--target); box-shadow: 0 0 12px rgba(63, 242, 208, 0.35); }
.status.alarm { color: #ff6b5e; }

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

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

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

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

/* ---------- tray ---------- */

#tray { display: flex; justify-content: center; gap: 10px; min-height: 64px; }
.piece {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 76px;
  padding: 6px 4px 6px;
  border: 2px solid transparent;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.3);
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  touch-action: none;
}
.piece svg { width: 38px; height: 38px; }
.piece .count {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--beam);
  color: #fff;
  font-size: 12px;
}
.piece.selected { border-color: var(--target); color: var(--text); }
.piece.empty { opacity: 0.35; cursor: default; }
.piece.empty .count { background: #3a4766; }

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

.overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(6, 9, 18, 0.75);
  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.5);
}
.card.wide { width: min(460px, 100%); }
.card h1, .card h2, .card h3 { margin: 0; }
.card h1 { font-size: 38px; letter-spacing: 0.01em; text-shadow: 0 0 18px rgba(255, 59, 92, 0.6); }
.card h1 span { color: var(--beam); }
.card h2 { color: var(--target); text-shadow: 0 0 14px rgba(63, 242, 208, 0.5); }
.card h3 { margin-top: 6px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
.lede { margin: 0; color: var(--muted); line-height: 1.45; }

.rules { margin: 0; padding: 0; list-style: none; text-align: left; display: grid; gap: 6px; font-size: 14px; }
.rules li { display: flex; align-items: center; gap: 10px; }
.rules b { flex: none; width: 14px; height: 14px; border-radius: 50%; }
.r-target { background: var(--target); box-shadow: 0 0 8px var(--target); }
.r-piece { background: #dfe8f5; border-radius: 3px !important; transform: rotate(45deg) scale(0.8); }
.r-alarm { background: var(--alarm); clip-path: polygon(50% 0, 100% 100%, 0 100%); border-radius: 0 !important; }

.primary, .soft {
  padding: 12px 18px;
  border: 0;
  border-radius: 14px;
  font-weight: 800;
  font-size: 16px;
}
.primary { background: var(--beam); color: #fff; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25), 0 0 18px rgba(255, 59, 92, 0.35); }
.soft { background: #2a3657; }
.soft:disabled { opacity: 0.5; }

.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: #1c2640;
  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(--target); }
.level-grid button.done small { color: var(--target); }
.level-grid button.current { box-shadow: 0 0 0 2px var(--beam); }

.endless { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.endless button { padding: 10px 6px; font-size: 14px; }
.endless small { display: block; font-size: 11px; font-weight: 600; color: var(--muted); }

.keys { margin: 4px 0 0; font-size: 12px; color: var(--muted); line-height: 1.6; }
