/* Balance Brain — stylesheet
   Modern dark/glass/neon casual-brain-game look, mobile-first, 60fps
   budget (GPU-friendly transforms only for anything that animates). */

:root {
  --bg-0: #0b0f1a;
  --bg-1: #121a2b;
  --bg-2: #1a2438;
  --glass: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.12);
  --text-0: #eef2f9;
  --text-1: #9fb0c9;
  --accent: #7cf7ff;
  --accent-2: #ff6bcb;
  --good: #4ade80;
  --warn: #ffb703;
  --bad: #ff4d6d;
  --gold: #ffd166;

  --obj-normal: #7cf7ff;
  --obj-heavy: #ff4d6d;
  --obj-light: #7de3ff;
  --obj-bouncy: #ffd166;
  --obj-ice: #b6f5ff;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-glow: 0 0 24px rgba(124, 247, 255, 0.25);
}

/* ---- Standing project rule: [hidden] must always win regardless of
   any other display rule that might exist on the same element (see
   claude/standing-conventions.md #3). Keep this near the top so intent
   is obvious and it's never accidentally deleted along with a later
   component rule. ---- */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(ellipse at top, var(--bg-1), var(--bg-0) 60%);
  color: var(--text-0);
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--accent); color: #001318; padding: 8px 14px;
  border-radius: 0 0 8px 0; z-index: 999;
}
.skip-link:focus { left: 0; }

button { font-family: inherit; cursor: pointer; }

/* ---- Loading screen ---- */
#app-loading {
  position: fixed; inset: 0; z-index: 500;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--bg-0);
  text-align: center;
}
.loading-title {
  font-size: 2.4rem; font-weight: 800; letter-spacing: 0.08em;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  line-height: 1.15;
}
.loading-sub { color: var(--text-1); margin-top: 10px; }
.loading-track {
  width: 220px; height: 6px; border-radius: 6px; background: var(--glass);
  overflow: hidden; margin-top: 20px; border: 1px solid var(--glass-border);
}
.loading-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.15s ease; }

/* ---- Header ---- */
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; max-width: 900px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: 0.03em; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: var(--shadow-glow);
}

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--glass); border: 1px solid var(--glass-border);
  color: var(--text-0); font-size: 1.1rem;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform 0.15s ease, background 0.15s ease;
}
.icon-btn:hover { background: rgba(255,255,255,0.12); }
.icon-btn:active { transform: scale(0.92); }

/* ---- Layout ---- */
main#main { max-width: 900px; margin: 0 auto; padding: 0 16px 24px; }

/* ---- Menu ---- */
#screen-menu { text-align: center; padding-top: 6vh; }
.game-title {
  font-size: clamp(2rem, 8vw, 3.2rem); font-weight: 900; letter-spacing: 0.05em;
  margin: 0 0 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hook { color: var(--text-1); margin: 0 0 18px; font-size: 1.05rem; }
.daily-badge {
  display: inline-block; margin: 0 auto 18px; padding: 8px 16px;
  border-radius: 999px; background: var(--glass); border: 1px solid var(--glass-border);
  color: var(--gold); font-size: 0.85rem; font-weight: 600;
}
.menu-actions { display: flex; flex-direction: column; gap: 12px; max-width: 340px; margin: 0 auto; }
.menu-best { color: var(--text-1); margin-top: 22px; }
.menu-best strong { color: var(--accent); }

.btn {
  border: none; border-radius: var(--radius-md); padding: 14px 20px;
  font-size: 1rem; font-weight: 700; letter-spacing: 0.02em;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #4fd1ff); color: #002028;
  box-shadow: 0 6px 20px rgba(124, 247, 255, 0.25);
}
.btn-secondary {
  background: linear-gradient(135deg, var(--accent-2), #ff8fd6); color: #29001d;
  box-shadow: 0 6px 20px rgba(255, 107, 203, 0.22);
}
.btn-ghost {
  background: var(--glass); color: var(--text-0); border: 1px solid var(--glass-border);
}

/* ---- Countdown ---- */
#screen-countdown {
  height: 60vh; display: flex; align-items: center; justify-content: center;
}
.countdown-number {
  font-size: 6rem; font-weight: 900; color: var(--accent);
  text-shadow: 0 0 40px rgba(124,247,255,0.5);
}
.countdown-number.pop { animation: pop 0.32s ease; }
@keyframes pop {
  0% { transform: scale(0.4); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

/* ---- HUD ---- */
.hud {
  display: flex; align-items: center; gap: 14px; padding: 10px 4px;
  flex-wrap: wrap;
}
.hud-item { display: flex; flex-direction: column; align-items: flex-start; min-width: 54px; }
.hud-label { font-size: 0.65rem; color: var(--text-1); letter-spacing: 0.08em; }
.hud-value { font-size: 1.25rem; font-weight: 800; }
.hud-value.combo { color: var(--gold); }
.hud-value.combo.is-hot { color: var(--accent-2); text-shadow: 0 0 12px rgba(255,107,203,0.6); }
.hud-controls { margin-left: auto; display: flex; gap: 8px; }

.round-timer-track {
  height: 6px; border-radius: 6px; background: var(--glass); overflow: hidden; margin: 4px 0 10px;
}
.round-timer-fill {
  height: 100%; width: 100%; transform-origin: left center;
  background: linear-gradient(90deg, var(--accent), var(--good));
  transition: transform 0.1s linear;
}
.round-timer-fill.is-low { background: linear-gradient(90deg, var(--warn), var(--bad)); }

.event-banner {
  text-align: center; font-weight: 800; letter-spacing: 0.05em;
  color: var(--gold); margin-bottom: 6px; font-size: 1rem;
}
.event-banner.pulse { animation: eventPulse 0.5s ease; }
@keyframes eventPulse {
  0% { transform: scale(0.7); opacity: 0; }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

/* ---- Beam stage ---- */
.beam-stage {
  position: relative; height: 46vh; min-height: 260px; max-height: 380px;
  margin: 6px 0 18px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--glass-border);
  overflow: hidden;
}
.particles-canvas { position: absolute; inset: 0; pointer-events: none; z-index: 5; }

/* All three pieces below share one anchor point — the top of the
   support pillar, PIVOT_HEIGHT from the floor of the stage — so the
   fulcrum wedge sits under the beam and the beam's rotation origin
   lands exactly on top of the pillar, not floating above or sunk
   below it. */
:root { --pivot-height: 38%; }

.pivot-mount {
  position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 10px; height: var(--pivot-height);
  background: linear-gradient(180deg, #3a465c, #222c3d);
  border-radius: 4px;
}
.pivot {
  position: absolute; left: 50%; bottom: calc(var(--pivot-height) - 4px); transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 16px solid transparent;
  border-right: 16px solid transparent;
  border-bottom: 22px solid #33415a;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.4));
}

.beam-rotor {
  position: absolute; left: 50%; bottom: var(--pivot-height); transform: translateX(-50%) rotate(0deg);
  width: 88%; max-width: 620px; height: 0;
  will-change: transform;
}
.beam {
  position: absolute; left: 50%; top: 0; transform: translate(-50%, -50%);
  width: 100%; height: 22px;
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(180deg, #3a4a66, #23324a);
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.08);
  padding: 0 6px;
}
.slot {
  position: relative; width: 13%; height: 52px; display: flex; align-items: center; justify-content: center;
}
.slot-peg { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,0.25); }
.slot.is-hover .slot-peg { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.slot.is-hover::before {
  content: ''; position: absolute; inset: -4px; border-radius: 10px;
  border: 2px dashed var(--accent); opacity: 0.6;
}

.obj-shape {
  width: 46px; height: 46px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1.05rem; color: #041016;
  box-shadow: 0 6px 14px rgba(0,0,0,0.35), inset 0 2px 0 rgba(255,255,255,0.35);
  position: relative; top: 0;
}
.obj-normal .obj-shape { background: linear-gradient(150deg, var(--obj-normal), #2fb8c9); }
.obj-heavy .obj-shape { background: linear-gradient(150deg, var(--obj-heavy), #b8283f); color: #fff0f2; }
.obj-light .obj-shape { background: linear-gradient(150deg, var(--obj-light), #6fb8d8); }
.obj-bouncy .obj-shape { background: linear-gradient(150deg, var(--obj-bouncy), #d99a1f); }
.obj-ice .obj-shape { background: linear-gradient(150deg, var(--obj-ice), #7fd4e6); }
.obj-shape.placed { position: absolute; bottom: 100%; margin-bottom: -12px; animation: dropIn 0.32s cubic-bezier(.2,1.4,.4,1); }
@keyframes dropIn {
  0% { transform: translateY(-40px) scale(0.6); opacity: 0; }
  70% { transform: translateY(4px) scale(1.05); opacity: 1; }
  100% { transform: translateY(0) scale(1); }
}
.slot.is-filled .slot-peg { display: none; }

/* ---- Tray ---- */
.tray {
  display: flex; gap: 12px; justify-content: center; flex-wrap: wrap;
  padding: 10px 4px 4px; min-height: 90px;
}
.tray-object {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: transparent; border: none; padding: 4px;
  touch-action: none;
}
.tray-object .obj-shape { width: 56px; height: 56px; font-size: 1.2rem; }
.obj-tag {
  font-size: 0.6rem; font-weight: 700; letter-spacing: 0.06em;
  color: var(--text-1); background: var(--glass); border-radius: 6px; padding: 1px 6px;
}
.tray-object:disabled { opacity: 0.25; pointer-events: none; }
.tray-object.is-selected .obj-shape { outline: 3px solid var(--accent); outline-offset: 2px; }
.tray-object.is-dragging-source { opacity: 0.35; }
.tray-object:focus-visible .obj-shape { outline: 3px solid var(--accent); }

.drag-ghost {
  position: fixed; z-index: 200; pointer-events: none;
  transform: scale(1.08) rotate(-4deg);
  filter: drop-shadow(0 10px 16px rgba(0,0,0,0.5));
}

/* ---- Overlays (pause / game over) ---- */
.overlay {
  /* Fixed to the true viewport, not absolute-within-#game-shell: the
     shell's own box height is just its intrinsic content height (HUD +
     beam stage + tray), which can be shorter than the overlay card
     itself needs, especially on a short mobile viewport — an
     absolutely-positioned overlay would then center the card relative
     to that too-short box and let it spill outside the shell's bounds
     instead of the actual screen. */
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 9, 16, 0.72);
  backdrop-filter: blur(6px);
  padding: 16px;
}
#game-shell { position: relative; }
.overlay-card {
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 22px; width: 100%; max-width: 380px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  max-height: 92vh; overflow-y: auto;
}
.overlay-card h2 { margin: 0 0 14px; letter-spacing: 0.04em; }
.overlay-card .btn { width: 100%; margin-top: 10px; }

.new-best-banner { color: var(--gold); font-weight: 800; margin: 0 0 10px; }
.gameover-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.stat { background: var(--glass); border-radius: var(--radius-sm); padding: 8px 4px; }
.stat-label { display: block; font-size: 0.6rem; color: var(--text-1); letter-spacing: 0.06em; }
.stat-value { display: block; font-size: 1.15rem; font-weight: 800; }
.rank-row { color: var(--accent); font-weight: 700; margin: 4px 0; }
.hook-line { color: var(--text-1); font-size: 0.85rem; margin: 10px 0 2px; }

.nickname-form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.nickname-form label { font-size: 0.75rem; color: var(--text-1); text-align: left; }
.nickname-form input {
  padding: 12px; border-radius: var(--radius-sm); border: 1px solid var(--glass-border);
  background: rgba(255,255,255,0.05); color: var(--text-0); font-size: 1rem;
}
.form-error { color: var(--bad); font-size: 0.8rem; min-height: 1em; margin: 0; }
.nickname-saved { color: var(--good); font-weight: 700; margin-top: 8px; }
.gameover-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }

.screen-shake { animation: shake 0.4s; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

/* ---- Toasts ---- */
.toast-container {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 300; display: flex; flex-direction: column; gap: 6px; align-items: center;
  pointer-events: none;
}
.toast {
  background: rgba(10,14,24,0.9); border: 1px solid var(--glass-border);
  padding: 8px 16px; border-radius: 999px; font-weight: 700; font-size: 0.9rem;
  opacity: 0; transform: translateY(-8px) scale(0.9);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateY(0) scale(1); }
.toast-perfect { color: var(--gold); border-color: rgba(255,209,102,0.5); }
.toast-good { color: var(--accent); }
.toast-warn { color: var(--warn); }
.toast-error { color: var(--bad); }

/* ---- Modals ---- */
.modal {
  position: fixed; inset: 0; z-index: 400;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6,9,16,0.75); backdrop-filter: blur(4px); padding: 16px;
}
.modal-card {
  position: relative; background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--glass-border); border-radius: var(--radius-lg);
  padding: 22px; width: 100%; max-width: 420px; max-height: 86vh; overflow-y: auto;
}
.modal-close {
  position: absolute; top: 12px; right: 12px; width: 32px; height: 32px;
  border-radius: 50%; background: var(--glass); border: 1px solid var(--glass-border); color: var(--text-0);
}
.tab-row { display: flex; gap: 8px; margin: 14px 0 6px; flex-wrap: wrap; }
.tab-row.secondary { margin-top: 4px; }
.tab {
  background: var(--glass); border: 1px solid var(--glass-border); color: var(--text-1);
  padding: 8px 14px; border-radius: 999px; font-weight: 600; font-size: 0.85rem;
}
.tab.is-active { background: linear-gradient(135deg, var(--accent), #4fd1ff); color: #002028; border-color: transparent; }

.leaderboard-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.leaderboard-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  background: var(--glass); border-radius: var(--radius-sm);
}
.leaderboard-row.top1 { background: rgba(255,209,102,0.15); }
.leaderboard-row.top2 { background: rgba(200,210,225,0.12); }
.leaderboard-row.top3 { background: rgba(205,127,50,0.14); }
.lb-rank { width: 26px; font-weight: 800; color: var(--text-1); }
.lb-name { flex: 1; text-align: left; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 800; color: var(--accent); }
.leaderboard-empty { color: var(--text-1); text-align: center; padding: 20px 0; list-style: none; }

.howto-steps { text-align: left; padding-left: 18px; line-height: 1.7; }
.howto-note { color: var(--text-1); font-size: 0.85rem; text-align: left; }

.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; }

/* ---- SEO content ---- */
.seo-content {
  max-width: 780px; margin: 30px auto 60px; padding: 0 18px; color: var(--text-1);
  line-height: 1.7;
}
.seo-content h2 { color: var(--text-0); margin-top: 34px; }
.seo-content h3 { color: var(--text-0); margin-top: 22px; }
.faq-item { margin-bottom: 14px; }
.related-games { display: flex; flex-wrap: wrap; gap: 10px; list-style: none; padding: 0; }
.related-games a {
  color: var(--accent); text-decoration: none; background: var(--glass);
  border: 1px solid var(--glass-border); padding: 8px 14px; border-radius: 999px; font-weight: 600;
}

/* ---- Responsive ---- */
@media (min-width: 640px) {
  .menu-actions { max-width: 380px; }
  .beam-stage { height: 42vh; }
}
@media (max-width: 420px) {
  .hud-value { font-size: 1.05rem; }
  .obj-shape { width: 40px; height: 40px; font-size: 0.95rem; }
  .tray-object .obj-shape { width: 50px; height: 50px; }
  .game-title { letter-spacing: 0.02em; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
