:root {
  --bg: #14231a;
  --panel: #1c2c22;
  --panel-2: #24382b;
  --line: rgba(255, 255, 255, 0.14);
  --accent: #f59e0b;
  --accent-2: #fbbf24;
  --green: #4ade80;
  --red: #f87171;
  --text: #f8fafc;
  --muted: #a8b8ad;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; width: 100%; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text); font-family: var(--font);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; overscroll-behavior: none;
}
#app { position: fixed; inset: 0; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }

/* Buttons */
.btn {
  font: inherit; font-weight: 700; font-size: 15px; color: var(--text);
  background: rgba(28, 44, 34, 0.94); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 16px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35); transition: transform 0.08s, background 0.15s, border-color 0.15s;
}
.btn:hover { background: #2c4435; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35); }
.btn:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent-2); color: #1b1203; }
.btn.primary:hover { background: #fbb026; }
.btn.big { font-size: 18px; padding: 14px 20px; width: 100%; }
.btn.big small { display: block; font-size: 12px; font-weight: 600; opacity: 0.75; }
.btn.big:has(small) { flex-direction: column; gap: 2px; }
.btn.icon { width: 44px; height: 44px; padding: 0; font-size: 20px; }
.btn.danger { background: transparent; border-color: rgba(248, 113, 113, 0.5); color: var(--red); font-size: 13px; box-shadow: none; }
.btn.toggle.off { opacity: 0.55; text-decoration: line-through; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.pill {
  background: rgba(15, 26, 19, 0.86); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 14px; font-weight: 800; font-size: 15px; display: inline-flex; gap: 6px; align-items: center; white-space: nowrap;
}

/* HUD */
#hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10; display: flex; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 8px calc(10px + env(safe-area-inset-left));
  pointer-events: none;
}
#hud > * { pointer-events: auto; }
.hud-group { display: flex; gap: 8px; align-items: center; }
.pill.score { min-width: 96px; justify-content: center; color: #fde68a; }
#banner {
  position: absolute; top: calc(62px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 9;
  max-width: min(92vw, 760px); padding: 6px 16px; border-radius: 999px; text-align: center;
  background: rgba(17, 24, 39, 0.82); border: 1px solid rgba(245, 158, 11, 0.5); color: #fde68a; font-size: 12.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; transition: opacity 0.6s;
}
#banner.fade { opacity: 0; }
#hint {
  position: absolute; bottom: calc(18px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 9;
  max-width: 92vw; padding: 9px 18px; border-radius: 999px; text-align: center;
  background: rgba(15, 26, 19, 0.9); border: 1px solid var(--line); font-size: 14px; font-weight: 700; pointer-events: none;
  animation: bob 1.6s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateX(-50%) translateY(-4px); } }

/* Screens and overlays */
.screen, .overlay {
  position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: calc(14px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
  overflow-y: auto;
}
.screen { background: linear-gradient(180deg, rgba(12, 22, 16, 0.55), rgba(12, 22, 16, 0.86)); }
.overlay { z-index: 30; background: rgba(8, 14, 10, 0.72); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
.title-card, .panel, .modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  max-height: 100%; overflow-y: auto;
}
.title-card { width: min(440px, 100%); padding: 22px 24px; text-align: center; }
.logo canvas { width: 110px; height: 110px; margin-bottom: -8px; }
.logo h1 {
  margin: 0; font-size: clamp(38px, 9vw, 54px); font-weight: 900; letter-spacing: 0.02em; line-height: 1;
  background: linear-gradient(90deg, #4ade80, #fbbf24 55%, #f87171); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo h2 { margin: 4px 0 0; font-size: 15px; letter-spacing: 0.32em; text-transform: uppercase; color: #cbd5e1; font-weight: 800; }
.tagline { color: var(--muted); font-size: 14px; line-height: 1.45; margin: 12px 0 16px; }
.menu { display: grid; gap: 10px; }
.menu-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.total { margin-top: 14px; font-size: 13px; color: var(--muted); }
.total strong { color: var(--accent-2); }

.panel { width: min(900px, 100%); padding: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; font-size: clamp(16px, 3vw, 22px); text-align: center; flex: 1; }
.blurb { margin: 0 0 12px; color: var(--muted); text-align: center; font-size: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.grid.levels { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.card {
  font: inherit; color: inherit; text-align: left; cursor: pointer; background: var(--panel-2); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px; display: flex; flex-direction: column; gap: 6px; min-height: 108px; transition: transform 0.1s, border-color 0.15s;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}
.card:hover:not(.locked) { transform: translateY(-2px); border-color: var(--accent); }
.card:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }
.card .top { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 800; color: var(--accent-2); text-transform: uppercase; letter-spacing: 0.05em; }
.card h3 { margin: 0; font-size: 16px; line-height: 1.25; }
.card p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.card .foot { margin-top: auto; font-size: 12px; color: var(--green); font-weight: 700; }
.card.locked { opacity: 0.55; cursor: not-allowed; }
.card.locked .foot { color: var(--muted); }
.card.level { align-items: center; text-align: center; min-height: 118px; }
.card.level .num { font-size: 30px; font-weight: 900; line-height: 1; }
.card.level h3 { font-size: 12.5px; font-weight: 700; color: #dbe6de; }
.stars { color: var(--accent-2); letter-spacing: 2px; font-size: 16px; }
.stars .dim { color: rgba(255, 255, 255, 0.2); }
.badge { font-size: 10px; background: var(--accent); color: #1b1203; border-radius: 999px; padding: 2px 8px; font-weight: 900; }

.modal { width: min(640px, 100%); padding: 22px; text-align: center; }
.modal.small { width: min(420px, 100%); }
.modal h2 { margin: 0 0 6px; font-size: 26px; font-weight: 900; }
.muted { color: var(--muted); margin: 0 0 12px; font-size: 14px; line-height: 1.45; }
.small-text { font-size: 12px; }
.stack { display: grid; gap: 10px; margin: 14px 0; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.toggles { display: flex; gap: 10px; justify-content: center; }
.toggles.col { flex-direction: column; margin: 14px 0; }
.stars-row { font-size: 54px; line-height: 1; margin: 6px 0; letter-spacing: 6px; }
.stars-row span { color: rgba(255, 255, 255, 0.16); display: inline-block; transition: transform 0.25s, color 0.25s; }
.stars-row span.on { color: var(--accent-2); transform: scale(1.18) rotate(-6deg); text-shadow: 0 0 22px rgba(251, 191, 36, 0.6); }
.result-score { font-size: 34px; font-weight: 900; color: var(--green); }
.detail { margin: 4px 0 0; font-size: 13px; color: #fde68a; min-height: 18px; }
.extra { margin: 8px 0 0; font-size: 14px; font-weight: 800; color: var(--green); min-height: 18px; }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: 0.2em; font-size: 12px; font-weight: 900; color: var(--accent-2); }
#intro-canvas { width: 200px; height: 157px; }
.ability { margin: 0 0 6px; font-weight: 900; color: var(--green); font-size: 16px; }
.howto { text-align: left; margin: 10px 0 14px; padding-left: 22px; font-size: 14px; line-height: 1.5; color: #dbe6de; }
.howto li { margin-bottom: 6px; }
.roster { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; margin-bottom: 12px; text-align: left; }
.roster .r { display: flex; gap: 8px; align-items: center; background: rgba(0, 0, 0, 0.22); border-radius: 12px; padding: 6px 8px; font-size: 11.5px; line-height: 1.35; color: var(--muted); }
.roster .r strong { display: block; color: #fde68a; font-size: 12.5px; }
.roster .r canvas { width: 44px; height: 44px; flex: none; }
.roster .r.locked { opacity: 0.45; }

#rotate {
  position: absolute; inset: 0; z-index: 50; background: rgba(8, 14, 10, 0.94); display: flex; align-items: center; justify-content: center;
  text-align: center; font-size: 48px;
}
#rotate p { font-size: 17px; font-weight: 800; margin: 12px 0 0; }

@media (max-width: 700px), (max-height: 460px) {
  .btn { font-size: 13px; padding: 8px 12px; }
  .btn .lbl { display: none; }
  .btn.icon { width: 40px; height: 40px; }
  .pill { padding: 6px 11px; font-size: 13px; }
  .pill.score { min-width: 78px; }
  #banner { top: calc(54px + env(safe-area-inset-top)); font-size: 11px; max-width: 70vw; }
  .title-card { padding: 14px 18px; }
  .logo canvas { width: 70px; height: 70px; }
  .tagline { margin: 6px 0 10px; font-size: 12.5px; }
  .btn.big { font-size: 15px; padding: 9px 14px; }
  .modal, .panel { padding: 14px; }
  .stars-row { font-size: 40px; }
  .modal h2 { font-size: 21px; }
}
@media (max-height: 460px) {
  .title-card { width: min(680px, 100%); display: grid; grid-template-columns: 1fr 1.1fr; gap: 0 18px; align-items: center; }
  .title-card .total { grid-column: 1 / -1; margin-top: 8px; }
  .title-card .menu { grid-row: 1 / span 2; grid-column: 2; }
  .logo h1 { font-size: 34px; }
}
@media (prefers-reduced-motion: reduce) { #hint { animation: none; } .card, .btn { transition: none; } }
