:root {
  --ink: #fff7ee;
  --dim: rgba(255, 240, 230, 0.66);
  --panel: rgba(24, 10, 42, 0.9);
  --edge: rgba(255, 190, 140, 0.28);
  --sun: #ff7b39;
  --gold: #ffd166;
  --mint: #7cffb2;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1d0b3a; color: var(--ink); font-family: var(--font); }
body { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

#topbar { position: fixed; top: 0; left: 0; right: 0; display: flex; padding: max(10px, env(safe-area-inset-top)) 12px 0; pointer-events: none; z-index: 5; }
#topbar .spacer { flex: 1; }
.icon { pointer-events: auto; width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--edge); background: rgba(20, 8, 36, 0.6); color: var(--ink); font-size: 16px; cursor: pointer; }
.icon.off { opacity: 0.45; text-decoration: line-through; }
.icon:hover { background: rgba(60, 24, 80, 0.8); }

.screen { position: fixed; inset: 0; display: flex; align-items: safe center; justify-content: safe center; padding: 64px 16px 24px; z-index: 4;
  background: radial-gradient(ellipse at center, rgba(20, 6, 40, 0.25), rgba(12, 4, 24, 0.7)); animation: fade 0.25s ease-out; overflow-y: auto; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.panel { width: min(460px, 100%); background: var(--panel); border: 1px solid var(--edge); border-radius: 22px; padding: 22px 22px 20px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.06); text-align: center; animation: pop 0.35s cubic-bezier(.2, 1.4, .4, 1); margin: auto; }
.panel.wide { width: min(640px, 100%); }
@keyframes pop { from { transform: translateY(12px) scale(0.96); opacity: 0; } to { transform: none; opacity: 1; } }
.kicker { text-transform: uppercase; letter-spacing: 0.22em; font-size: 11px; font-weight: 800; color: var(--gold); }
.logo { margin: 6px 0 2px; font-style: italic; font-weight: 900; font-size: clamp(46px, 11vw, 78px); line-height: 0.86; letter-spacing: -0.02em; display: flex; flex-direction: column; }
.logo span:first-child { background: linear-gradient(180deg, #fff3b0, #ff9a4d 60%, #ff5e62); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 4px 0 #2a0b30); }
.logo span:last-child { color: #fff; text-shadow: 0 4px 0 #2a0b30, 0 0 24px rgba(255, 120, 90, 0.6); }
.tag { color: var(--dim); margin: 10px 0 16px; font-size: 15px; }
h2 { margin: 6px 0 6px; font-style: italic; font-weight: 900; font-size: 34px; }
.sub { color: var(--dim); margin: 0 0 14px; font-size: 14px; }
.menu { display: flex; flex-direction: column; gap: 9px; margin: 6px 0 12px; }
.menu.row { flex-direction: row; justify-content: center; margin-bottom: 0; }
.btn { font: inherit; font-weight: 800; font-size: 16px; padding: 13px 16px; border-radius: 14px; border: 1px solid var(--edge); background: rgba(255, 255, 255, 0.07); color: var(--ink); cursor: pointer; transition: transform 0.12s, background 0.12s, box-shadow 0.12s; }
.btn:hover, .btn:focus-visible { background: rgba(255, 255, 255, 0.14); transform: translateY(-1px); outline: none; box-shadow: 0 0 0 2px rgba(255, 209, 102, 0.6); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn.primary { background: linear-gradient(180deg, #ffb35c, #ff6a3d); border-color: transparent; color: #2a0b16; box-shadow: 0 6px 0 #a63d1f, 0 10px 30px rgba(255, 106, 61, 0.35); }
.btn.primary:hover, .btn.primary:focus-visible { background: linear-gradient(180deg, #ffc27a, #ff7b4d); box-shadow: 0 6px 0 #a63d1f, 0 0 0 2px #fff3b0; }
.btn.ghost { background: transparent; }
.howto { text-align: left; font-size: 13px; color: var(--dim); display: grid; gap: 4px; border-top: 1px solid var(--edge); padding-top: 12px; }
.howto div:not(.dim) { display: grid; grid-template-columns: 8.6em minmax(0, 1fr); column-gap: 8px; align-items: start; }
.howto b { color: var(--ink); display: block; min-width: 0; }
@media (max-width: 480px) {
  .panel { padding: 18px 16px 16px; }
  .jerseys-row { flex-direction: column; gap: 8px; }
  .jersey { width: 30px; height: 30px; }
  .jerseys { gap: 6px; }
}
.green { color: var(--mint); font-style: normal; font-weight: 800; }
.dim { color: var(--dim); }
.small { font-size: 12px; }

.rungs { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 8px; }
.rung { display: grid; grid-template-columns: 34px 46px 1fr auto; align-items: center; gap: 10px; text-align: left; padding: 9px 12px; border-radius: 14px; border: 1px solid var(--edge); background: rgba(255, 255, 255, 0.05); cursor: pointer; font: inherit; color: var(--ink); width: 100%; }
.rung:hover:not(:disabled), .rung:focus-visible { background: rgba(255, 255, 255, 0.12); outline: none; box-shadow: 0 0 0 2px rgba(255, 209, 102, 0.6); }
.rung:disabled { opacity: 0.42; cursor: not-allowed; }
.rung .num { font-weight: 900; font-style: italic; font-size: 22px; color: var(--gold); text-align: center; }
.rung .face { width: 42px; height: 42px; border-radius: 50%; display: block; }
.rung .who { min-width: 0; }
.rung .who b { display: block; font-size: 15px; }
.rung .who span { display: block; font-size: 12px; color: var(--dim); }
.rung .state { font-size: 11px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; padding: 4px 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); }
.rung .state.won { background: rgba(124, 255, 178, 0.18); color: var(--mint); }
.rung .state.next { background: var(--sun); color: #2a0b16; }
.jerseys-row { display: flex; align-items: center; gap: 12px; justify-content: center; flex-wrap: wrap; margin-bottom: 12px; }
.jerseys-row .label { font-size: 12px; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); }
.jerseys { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.jersey { width: 34px; height: 34px; border-radius: 10px; border: 2px solid transparent; cursor: pointer; position: relative; }
.jersey.sel { border-color: #fff; box-shadow: 0 0 0 3px rgba(255, 209, 102, 0.6); }
.jersey:disabled { cursor: not-allowed; opacity: 0.3; }
.jersey:disabled::after { content: "🔒"; font-size: 12px; position: absolute; inset: 0; display: grid; place-items: center; }

.final { font-size: 54px; font-weight: 900; font-style: italic; letter-spacing: -0.02em; margin: 2px 0 8px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.stat { background: rgba(255, 255, 255, 0.06); border-radius: 12px; padding: 8px 4px; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.08em; }
.best { font-size: 13px; color: var(--gold); margin-bottom: 8px; min-height: 1em; }

#pad { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; align-items: flex-end; padding: 0 14px max(14px, env(safe-area-inset-bottom)); z-index: 3; pointer-events: none; }
#pad > div { display: flex; gap: 12px; align-items: flex-end; pointer-events: auto; }
.padbtn { width: 74px; height: 74px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.35); background: rgba(20, 8, 36, 0.45); color: #fff; font: 900 20px var(--font); touch-action: none; }
.padbtn.small { width: 70px; height: 70px; font-size: 11px; line-height: 1.15; }
.padbtn.big { width: 96px; height: 96px; font-size: 15px; background: rgba(255, 106, 61, 0.55); }
.padbtn.on { background: rgba(255, 209, 102, 0.75); color: #2a0b16; transform: scale(0.95); }

@media (max-width: 360px) {
  .padbtn { width: 64px; height: 64px; }
  .padbtn.small { width: 60px; height: 60px; font-size: 10px; }
  .padbtn.big { width: 80px; height: 80px; }
  #pad > div { gap: 8px; }
  .final { font-size: 42px; }
}
@media (max-height: 520px) {
  .panel { padding: 14px 16px; }
  .logo { font-size: 44px; }
  .howto { display: none; }
  .tag { margin: 6px 0 10px; }
  .btn { padding: 10px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .screen, .panel { animation: none; }
  .btn { transition: none; }
}

.howto div.touch-only { display: none; }
@media (pointer: coarse) { .howto div.touch-only { display: grid; } }
