:root {
  --ink: #f8f2df;
  --muted: #b3b6bd;
  --night: #111522;
  --surface: #1a2030;
  --surface-2: #232a3d;
  --line: rgba(255,255,255,.12);
  --amber: #f4c95d;
  --green: #75d69c;
  --red: #ef6b68;
  --blue: #76a7ff;
  --shadow: 0 20px 55px rgba(0,0,0,.34);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--night); -webkit-font-smoothing: antialiased; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; overflow-x: hidden; color: var(--ink); font-family: "Segoe UI", Arial, sans-serif; background: radial-gradient(circle at 50% -20%, #313754 0, var(--night) 48%); }
button { font: inherit; }
button:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }
.game-shell { width: min(1180px, 100%, calc((100dvh - 270px) * 1.25)); margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) clamp(12px, 3vw, 32px) max(18px, env(safe-area-inset-bottom)); }
.topbar { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 38px; color: var(--red); filter: drop-shadow(0 0 12px rgba(239,107,104,.28)); }
.eyebrow { display: block; color: var(--amber); font-size: 11px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
h1, h2, p { margin: 0; }
h1 { font-family: Georgia, serif; font-size: clamp(21px, 3vw, 28px); line-height: 1; letter-spacing: -.03em; }
h2 { font-family: Georgia, serif; font-size: clamp(30px, 6vw, 54px); line-height: .98; letter-spacing: -.045em; text-wrap: balance; }
.player-card { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 5px 7px 5px 5px; border: 1px solid var(--line); border-radius: 28px; background: rgba(26,32,48,.86); box-shadow: 0 8px 24px rgba(0,0,0,.18); backdrop-filter: blur(10px); }
.player-card img { width: 40px; height: 40px; border-radius: 50%; background: #323b50; outline: 1px solid rgba(255,255,255,.14); outline-offset: -1px; }
.player-copy { min-width: 74px; }
.player-copy strong, .player-copy span { display: block; }
.player-copy strong { font-size: 13px; }
.player-copy span { color: var(--muted); font-size: 11px; }
.small-button, footer button { min-height: 40px; border: 0; color: var(--ink); background: transparent; font-weight: 750; cursor: pointer; }
.small-button { padding: 0 12px; border-radius: 20px; background: var(--amber); color: #28200d; }

.status-strip { display: grid; grid-template-columns: repeat(3, minmax(74px, 1fr)) minmax(150px, 1.8fr); gap: 1px; overflow: hidden; border: 1px solid var(--line); border-radius: 16px 16px 0 0; background: var(--line); }
.status-strip > div { min-width: 0; min-height: 58px; padding: 9px 14px; background: rgba(26,32,48,.96); }
.status-strip span { display: block; color: var(--muted); font-size: 11px; }
.status-strip strong { font-family: Georgia, serif; font-size: 24px; font-variant-numeric: tabular-nums; }
.pressure-wrap { display: flex; flex-direction: column; justify-content: center; }
.pressure-track { height: 8px; margin-top: 8px; overflow: hidden; border-radius: 999px; background: #0e111b; box-shadow: inset 0 1px 2px #000; }
.pressure-track i { display: block; width: 0%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--green), var(--amber) 60%, var(--red)); transition: width .2s ease-out; }

.stage-wrap { position: relative; overflow: hidden; aspect-ratio: 5 / 4; min-height: 430px; background: #171b27; box-shadow: var(--shadow); }
canvas { display: block; width: 100%; height: 100%; touch-action: manipulation; }
.stage-vignette { position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 90px rgba(7,8,14,.58); }
.panel { position: absolute; z-index: 5; left: 50%; top: 50%; width: min(520px, calc(100% - 30px)); padding: clamp(22px, 5vw, 42px); transform: translate(-50%, -50%); border: 1px solid rgba(255,255,255,.16); border-radius: 26px; background: rgba(18,22,34,.94); box-shadow: 0 30px 90px rgba(0,0,0,.55); backdrop-filter: blur(18px); }
.panel[hidden] { display: none; }
.intro-panel p, .game-over > p { margin-top: 14px; color: #d1d2d6; line-height: 1.55; text-wrap: pretty; }
.how-to { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 20px 0; color: var(--muted); font-size: 13px; }
kbd { display: inline-grid; min-width: 25px; height: 25px; margin-right: 3px; place-items: center; border: 1px solid #596176; border-bottom-width: 3px; border-radius: 5px; background: #30384c; color: #fff; font-family: inherit; font-weight: 800; }
.primary-button, .secondary-button { min-height: 50px; padding: 0 20px; border: 1px solid transparent; border-radius: 14px; font-weight: 850; cursor: pointer; transition-property: transform, background-color, box-shadow; transition-duration: 150ms; transition-timing-function: ease-out; }
.primary-button { background: var(--amber); color: #211a08; box-shadow: 0 8px 24px rgba(244,201,93,.18); }
.secondary-button { border-color: var(--line); background: var(--surface-2); color: var(--ink); }
.primary-button:hover { background: #ffd978; }
.primary-button:active, .secondary-button:active, .signal-button:active { transform: scale(.97); }
.intro-panel .primary-button { width: 100%; }
.event-toast { position: absolute; z-index: 4; top: 18px; left: 50%; min-width: 180px; padding: 9px 16px; transform: translate(-50%, -16px); border: 1px solid rgba(255,255,255,.13); border-radius: 999px; background: rgba(17,21,34,.9); color: var(--ink); font-size: 13px; font-weight: 750; text-align: center; opacity: 0; pointer-events: none; transition-property: opacity, transform; transition-duration: 200ms; }
.event-toast.show { opacity: 1; transform: translate(-50%, 0); }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 22px 0 16px; }
.result-grid div { padding: 14px 8px; border: 1px solid var(--line); border-radius: 14px; text-align: center; background: rgba(255,255,255,.035); }
.result-grid strong, .result-grid span { display: block; }
.result-grid strong { font-family: Georgia, serif; font-size: 30px; font-variant-numeric: tabular-nums; }
.result-grid span { color: var(--muted); font-size: 11px; }
.save-message { min-height: 22px; color: var(--amber) !important; font-size: 13px; }
.panel-actions { display: flex; gap: 10px; margin-top: 16px; }
.panel-actions button { flex: 1; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.icon-button { width: 48px; height: 48px; border: 1px solid var(--line); border-radius: 50%; background: var(--surface-2); color: var(--ink); font-size: 28px; line-height: 1; cursor: pointer; }
.leaderboard ol { max-height: 280px; margin: 22px 0 0; padding: 0; overflow: auto; list-style: none; }
.leaderboard li { display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; min-height: 46px; padding: 7px 4px; border-bottom: 1px solid var(--line); font-size: 13px; }
.leaderboard li strong { font-variant-numeric: tabular-nums; }
.leaderboard .empty-row { display: block; color: var(--muted); text-align: center; border: 0; }
.leaderboard .you { color: var(--amber); }

.signal-console { display: grid; grid-template-columns: 1fr minmax(180px, .7fr) 1fr; gap: 10px; padding: 12px; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 18px 18px; background: rgba(26,32,48,.97); }
.signal-button { position: relative; min-height: 70px; display: flex; align-items: center; gap: 10px; padding: 10px 16px; border: 1px solid var(--line); border-radius: 14px; background: #202638; color: var(--muted); text-align: left; cursor: pointer; transition-property: transform, border-color, background-color, color; transition-duration: 150ms; }
.signal-button svg { width: 32px; flex: 0 0 auto; fill: currentColor; }
.signal-button span, .signal-button small { display: block; }
.signal-button span { font-weight: 800; }
.signal-button small { margin-bottom: 2px; color: inherit; font-size: 10px; font-weight: 600; opacity: .75; }
.signal-button .lamp { width: 12px; height: 12px; margin-left: auto; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 4px rgba(239,107,104,.12), 0 0 15px rgba(239,107,104,.45); }
.signal-button.active { border-color: rgba(117,214,156,.58); background: #1d322e; color: var(--ink); }
.signal-button.active .lamp { background: var(--green); box-shadow: 0 0 0 4px rgba(117,214,156,.12), 0 0 18px rgba(117,214,156,.62); }
.signal-button.switching .lamp { background: var(--amber); box-shadow: 0 0 16px rgba(244,201,93,.7); }
.spirit-meter { align-self: center; text-align: center; }
.spirit-meter span, .spirit-meter small { display: block; }
.spirit-meter span { font-family: Georgia, serif; font-weight: 700; }
.spirit-meter small { margin-top: 4px; color: var(--muted); font-size: 10px; }
footer { display: flex; min-height: 48px; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; }
footer button { color: var(--amber); }

@media (max-width: 680px) {
  .game-shell { padding-left: 0; padding-right: 0; }
  .topbar { padding: 0 12px; }
  .player-copy { display: none; }
  .status-strip { border-radius: 0; border-left: 0; border-right: 0; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .pressure-wrap { grid-column: 1 / -1; min-height: 42px !important; }
  .stage-wrap { min-height: 0; height: auto; aspect-ratio: 5 / 4; }
  .signal-console { grid-template-columns: repeat(2, minmax(0, 1fr)); border-radius: 0; border-left: 0; border-right: 0; }
  .spirit-meter { grid-column: 1 / -1; grid-row: 1; min-height: 34px; }
  .signal-button { min-width: 0; min-height: 72px; padding: 8px 10px; }
  .signal-button svg { width: 26px; }
  footer { display: none; }
}

@media (max-width: 390px) {
  .brand-mark { width: 32px; }
  h1 { font-size: 20px; }
  .status-strip > div { padding-inline: 9px; }
  .status-strip strong { font-size: 21px; }
  .panel { padding: 22px; }
  .how-to { display: none; }
  .signal-button span { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
