:root {
  --night: #1b1747;
  --ink: #f5f3ff;
  --muted: #cfc8f2;
  --card: rgba(27, 23, 71, 0.82);
  --card-edge: rgba(255, 255, 255, 0.16);
  --gold: #f6c453;
  --gold-ink: #2a1d00;
  --club: #2f7d5b;
  --club-hover: #276a4d;
  --danger: #ff8a8a;
  --focus: #9ee7ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); color: var(--ink);
  font: 16px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
canvas#stage { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; }
[hidden] { display: none !important; }
button { font: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Screens */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px;
  overflow-y: auto; background: radial-gradient(ellipse at center, rgba(20, 16, 60, 0.15), rgba(10, 8, 34, 0.55)); }
.card { width: min(560px, 100%); background: var(--card); border: 1px solid var(--card-edge); border-radius: 20px; padding: 24px 24px 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); backdrop-filter: blur(6px); text-align: center; }
.card.small { width: min(360px, 100%); }
.studio { margin: 0; color: var(--muted); letter-spacing: 0.12em; text-transform: uppercase; font-size: 12px; }
h1 { margin: 4px 0 6px; font-size: clamp(36px, 8vw, 54px); line-height: 1.05; letter-spacing: -0.01em; }
h2 { margin: 0 0 10px; font-size: 22px; }
.star-glyph { color: var(--gold); text-shadow: 0 0 18px rgba(246, 196, 83, 0.7); }
.tagline { margin: 0 0 18px; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 12px 0 4px; }
.btn { border: 0; border-radius: 999px; padding: 12px 20px; font-weight: 600; cursor: pointer; min-height: 44px; }
.btn.primary { background: var(--gold); color: var(--gold-ink); }
.btn.primary:hover { background: #ffd36e; }
.btn.club { background: var(--club); color: #fff; }
.btn.club:hover { background: var(--club-hover); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--card-edge); }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.08); }
.club-note, .hint { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.club-error { color: var(--danger); font-size: 14px; margin: 8px 0 0; }
.club-panel { margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--card-edge); }
.animal-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; text-align: left; }
.animal { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; border: 2px solid var(--card-edge);
  background: rgba(255, 255, 255, 0.05); color: var(--ink); cursor: pointer; }
.animal[aria-checked="true"] { border-color: var(--gold); background: rgba(246, 196, 83, 0.14); }
.animal .emoji { font-size: 22px; }
.animal small { display: block; color: var(--muted); }
.how { margin-top: 16px; text-align: left; color: var(--muted); font-size: 14px; }
.how summary { cursor: pointer; color: var(--ink); }
.how ul { padding-left: 20px; margin: 8px 0 0; }
kbd { border: 1px solid var(--card-edge); border-radius: 4px; padding: 0 5px; font-size: 12px; background: rgba(255, 255, 255, 0.08); }
.foot { margin-top: 14px; font-size: 12px; color: var(--muted); text-align: center; max-width: 560px; }
.foot a { color: var(--gold); }

/* Game over */
.final { font-size: 42px; font-weight: 700; margin: 0; color: var(--gold); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 14px 0; }
.stats div { background: rgba(255, 255, 255, 0.06); border-radius: 12px; padding: 8px 4px; }
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { margin: 0; font-size: 20px; font-weight: 700; }
.save-status { min-height: 1.4em; color: var(--muted); font-size: 14px; margin: 4px 0; }
.save-status.ok { color: #9be8b8; }
.save-status.err { color: var(--danger); }
.awards { list-style: none; padding: 0; margin: 6px 0; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.awards li { background: rgba(246, 196, 83, 0.16); border: 1px solid rgba(246, 196, 83, 0.5); border-radius: 999px; padding: 3px 10px; font-size: 13px; }
.board { text-align: left; margin: 8px auto; max-width: 300px; font-size: 14px; color: var(--muted); }
.board .mine { color: var(--ink); font-weight: 700; }

/* HUD */
.hud { position: fixed; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 16px 0; pointer-events: none; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.45); }
.hud > div { flex: 1; }
.hud-center { text-align: center; }
.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.badge { display: inline-flex; align-items: center; gap: 8px; background: rgba(27, 23, 71, 0.6); border-radius: 999px; padding: 4px 12px 4px 4px;
  font-weight: 600; }
.badge img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; border: 2px solid var(--gold); }
.badge span { padding-left: 8px; }
.badge img:not([hidden]) + span { padding-left: 0; }
.lives { margin-top: 6px; font-size: 20px; letter-spacing: 2px; color: #ff9fb6; }
.lives .lost { opacity: 0.25; }
.score { display: inline-block; font-size: 38px; font-weight: 800; line-height: 1; padding: 4px 16px; border-radius: 16px; background: rgba(27, 23, 71, 0.55); }
.combo { font-size: 15px; color: var(--gold); min-height: 1.2em; font-weight: 700; }
.level { font-weight: 700; }
.timer { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.timer.low { color: var(--danger); }
.icon-btn { pointer-events: auto; background: rgba(27, 23, 71, 0.6); color: var(--ink); border: 1px solid var(--card-edge); border-radius: 50%;
  width: 40px; height: 40px; cursor: pointer; margin-top: 4px; }
.icon-btn[aria-pressed="true"] { opacity: 0.5; text-decoration: line-through; }

.banner { position: fixed; top: 32%; left: 0; right: 0; text-align: center; font-size: clamp(32px, 7vw, 56px); font-weight: 800; color: var(--gold);
  text-shadow: 0 4px 22px rgba(0, 0, 0, 0.5); opacity: 0; transform: scale(0.9); transition: opacity 0.25s, transform 0.25s; pointer-events: none; }
.banner.show { opacity: 1; transform: scale(1); }
.floaters { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.floater { position: absolute; font-weight: 800; font-size: 20px; color: #fff; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
  animation: rise 0.9s ease-out forwards; transform: translate(-50%, -50%); }
.floater.golden { color: var(--gold); font-size: 26px; }
@keyframes rise { to { transform: translate(-50%, -160%); opacity: 0; } }
.flash { position: fixed; inset: 0; background: rgba(255, 70, 90, 0.35); opacity: 0; pointer-events: none; transition: opacity 0.3s; }
.flash.show { opacity: 1; transition: none; }

.touch { position: fixed; bottom: max(14px, env(safe-area-inset-bottom)); left: 0; right: 0; display: flex; justify-content: space-between; padding: 0 16px;
  pointer-events: none; }
.touch-btn { pointer-events: auto; width: 76px; height: 76px; border-radius: 50%; border: 2px solid var(--card-edge); background: rgba(27, 23, 71, 0.55);
  color: var(--ink); font-size: 28px; touch-action: none; }

@media (max-width: 480px) {
  .card { padding: 18px 16px 16px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .score { font-size: 30px; }
  .badge img { width: 32px; height: 32px; }
}
@media (prefers-reduced-motion: reduce) {
  .floater { animation-duration: 0.01s; }
  .banner, .flash { transition: none; }
}

/* Headset buttons (shown only where WebXR offers the mode) */
.xr-row { margin-top: 0; }
.btn.xr { border-color: var(--focus); }
.btn.xr small { font-weight: 400; color: var(--muted); }
