:root {
  --bg0: #0e1f1c;
  --bg1: #17332d;
  --ink: #fff4dc;
  --ink-dim: rgba(255, 244, 220, 0.62);
  --gold: #ffc24a;
  --coral: #ff7a6b;
  --card: rgba(255, 244, 220, 0.07);
  --card-line: rgba(255, 244, 220, 0.14);
  --radius: 18px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  --pulse: 0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg0);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  background: radial-gradient(120% 80% at 50% 0%, var(--bg1) 0%, var(--bg0) 60%) fixed;
}

button { font: inherit; color: inherit; }

#app { position: relative; height: 100dvh; max-width: 640px; margin: 0 auto; overflow: hidden; }

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
}
.screen.active { display: flex; }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--card-line);
  background: var(--card);
  border-radius: 999px;
  padding: 14px 28px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease;
}
.btn:hover { background: rgba(255, 244, 220, 0.12); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--gold); color: #3a2400; border-color: transparent; box-shadow: 0 6px 24px rgba(255, 194, 74, 0.28); }
.btn.primary:hover { background: #ffd070; }
.btn.ghost { background: transparent; }
.btn:focus-visible, .icon-btn:focus-visible, .level-btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.icon-btn {
  appearance: none;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  border: 1px solid var(--card-line);
  background: var(--card);
  font-size: 1.2rem;
  cursor: pointer;
}
.icon-btn.muted { opacity: 0.45; text-decoration: line-through; }
.corner { position: absolute; top: max(14px, env(safe-area-inset-top)); right: 16px; }

/* ---------- title ---------- */
.title-wrap { margin: auto; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.title-blooms { position: relative; width: 190px; height: 90px; margin-bottom: 4px; }
.tb {
  position: absolute;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #fff3d6 0 26%, transparent 27%),
    conic-gradient(from 0deg, var(--c) 0 20%, var(--d) 20% 21%, var(--c) 21% 40%, var(--d) 40% 41%, var(--c) 41% 60%, var(--d) 60% 61%, var(--c) 61% 80%, var(--d) 80% 81%, var(--c) 81% 100%);
  animation: bob 2.4s ease-in-out infinite;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}
.tb0 { --c: #ff7a6b; --d: #c9483b; left: 0; top: 34px; animation-delay: 0s; }
.tb1 { --c: #ffc24a; --d: #d99522; left: 36px; top: 8px; animation-delay: 0.2s; }
.tb2 { --c: #5fcf80; --d: #2f9b52; left: 72px; top: 30px; animation-delay: 0.4s; }
.tb3 { --c: #5aa9ff; --d: #2c76cc; left: 108px; top: 4px; animation-delay: 0.6s; }
.tb4 { --c: #b68cff; --d: #7f55d0; left: 144px; top: 32px; animation-delay: 0.8s; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(0deg); } 50% { transform: translateY(-8px) rotate(18deg); } }

h1 { font-size: clamp(3rem, 14vw, 4.6rem); line-height: 0.95; margin: 0; letter-spacing: -0.02em; }
h1 em { font-style: normal; color: var(--gold); }
.tagline { margin: 4px 0 18px; color: var(--ink-dim); font-size: 1.05rem; }
.menu { display: flex; flex-direction: column; gap: 10px; width: min(300px, 100%); }
.best { color: var(--ink-dim); min-height: 1.2em; margin-top: 8px; }

/* ---------- bars ---------- */
.bar { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.bar h2 { flex: 1; text-align: center; margin: 0; font-size: 1.2rem; }
.bar-spacer { width: 44px; flex: none; }
.hud-title { flex: 1; min-width: 0; text-align: center; display: flex; flex-direction: column; }
#level-label { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-sub { font-size: 0.8rem; color: var(--ink-dim); }

/* ---------- level select ---------- */
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 12px;
  padding: 16px 0 24px;
  overflow-y: auto;
}
.level-btn {
  appearance: none;
  aspect-ratio: 1;
  border-radius: var(--radius);
  border: 1px solid var(--card-line);
  background: var(--card);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.level-btn .num { font-size: 1.5rem; font-weight: 800; }
.level-btn .stars { color: var(--gold); letter-spacing: 1px; font-size: 0.9rem; }
.level-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.level-btn.next { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }

/* ---------- game ---------- */
.stats { display: flex; gap: 10px; margin-top: 8px; }
.stat {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 14px;
  padding: 6px 12px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.stat-label { font-size: 0.8rem; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.08em; }
.stat-value { font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-value.low { color: var(--coral); }

.goals { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 10px 0 6px; min-height: 36px; }
.goal {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px 5px 6px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--card-line);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transition: background 0.3s ease;
}
.goal svg { width: 24px; height: 24px; flex: none; }
.goal.done { background: rgba(95, 207, 128, 0.2); border-color: rgba(95, 207, 128, 0.6); }
.goal.done .goal-text::after { content: " ✓"; color: #7ee39c; }

.board-wrap { flex: 1; min-height: 0; display: grid; place-items: center; }
.board-stack { display: flex; flex-direction: column; align-items: center; }
#board {
  display: block;
  touch-action: none;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.18);
  box-shadow: 0 0 0 2px rgba(255, 194, 74, calc(0.08 + var(--pulse) * 0.5)), 0 0 calc(10px + var(--pulse) * 26px) rgba(255, 194, 74, calc(var(--pulse) * 0.35));
}

.beat { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 0 2px; }
.beat-dot { width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 244, 220, 0.18); transition: background 0.08s, transform 0.08s; }
.beat-dot.on { background: var(--gold); transform: scale(1.35); }
.beat-text { margin-left: 8px; font-size: 0.8rem; color: var(--ink-dim); }

/* ---------- modal ---------- */
.modal { position: absolute; inset: 0; background: rgba(5, 12, 11, 0.7); display: grid; place-items: center; padding: 16px; z-index: 10; backdrop-filter: blur(3px); }
.modal[hidden] { display: none; }
.modal-card {
  width: min(380px, 100%);
  max-height: calc(100% - 16px);
  overflow-y: auto;
  background: linear-gradient(180deg, #21443c, #17332d);
  border: 1px solid var(--card-line);
  border-radius: 24px;
  padding: 24px 22px 20px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  animation: pop 0.25s ease-out;
}
@keyframes pop { from { transform: scale(0.92); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-card h2 { margin: 0 0 10px; font-size: 1.6rem; }
.modal-body { color: var(--ink-dim); line-height: 1.5; }
.modal-body p { margin: 8px 0; }
.modal-body strong { color: var(--ink); }
.modal-body .goal-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 12px 0; }
.modal-body .big-stars { font-size: 2.6rem; color: var(--gold); letter-spacing: 6px; margin: 6px 0; }
.modal-body .big-stars .off { color: rgba(255, 244, 220, 0.18); }
.modal-body .big-score { font-size: 2.2rem; font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums; }
.modal-body ul { text-align: left; padding-left: 20px; margin: 8px 0; }
.modal-body li { margin: 6px 0; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 18px; }
.modal-actions .btn { padding: 12px 22px; }

@media (max-height: 640px) {
  .beat-text { display: none; }
  .goals { margin: 6px 0 4px; }
}
