:root {
  color-scheme: dark;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-raised: #27354d;
  --line: rgba(148, 163, 184, 0.16);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #818cf8;
  --accent-strong: #a5b4fc;
  --accent-soft: rgba(129, 140, 248, 0.16);
  --accent-ink: #0b1020;
  --gold: #fde68a;
  --radius: 12px;
  --shadow: 0 14px 34px rgba(2, 6, 23, 0.5);
  --shadow-soft: 0 4px 14px rgba(2, 6, 23, 0.32);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --t-fast: 150ms;
  --t-slow: 250ms;
  --gutter: 16px;
  --panel: 260px;
  --controls-h: 44px;
  --play-gap: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(129, 140, 248, 0.12), transparent 70%),
    var(--bg);
  color: var(--text);
}

h1,
h2,
p {
  margin: 0;
}

kbd {
  display: inline-block;
  padding: 1px 7px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-bottom-width: 2px;
  border-radius: 7px;
  background: #0b1222;
  color: #e0e7ff;
  font: 600 0.78rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: nowrap;
}

/* Buttons */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 40px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-soft);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.15;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease),
    box-shadow var(--t-fast) var(--ease),
    transform var(--t-fast) var(--ease);
}

.button:active:not(:disabled) {
  transform: translateY(1px) scale(0.98);
}

.button:focus-visible,
.footer-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.button:disabled {
  opacity: 0.45;
  cursor: default;
  box-shadow: none;
}

.button[aria-pressed="true"] {
  border-color: rgba(129, 140, 248, 0.6);
  background: var(--accent-soft);
  color: #e0e7ff;
}

.button-primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 6px 18px rgba(129, 140, 248, 0.35);
}

.button-large {
  min-height: 46px;
  padding: 0 28px;
  font-size: 1.05rem;
}

.button-square {
  width: 40px;
  padding: 0;
  font-weight: 700;
  letter-spacing: 0.04em;
}

@media (hover: hover) {
  .button:hover:not(:disabled) {
    border-color: rgba(129, 140, 248, 0.45);
    background: var(--surface-raised);
  }

  .button-primary:hover:not(:disabled) {
    border-color: transparent;
    background: var(--accent-strong);
  }

  .footer-link:hover {
    color: var(--text);
  }
}

.icon {
  flex: none;
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.icon-stroke {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Header and footer */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px var(--gutter);
  border-bottom: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.8);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand-mark {
  flex: none;
  width: 28px;
  height: 28px;
  fill: var(--accent);
  filter: drop-shadow(0 0 6px rgba(129, 140, 248, 0.55));
}

.brand-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  flex: none;
  gap: 8px;
}

.footer {
  display: flex;
  justify-content: center;
  padding: 0 var(--gutter) 4px;
}

.footer-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 10px;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.875rem;
  text-decoration: none;
  transition: color var(--t-fast) var(--ease);
}

/* Layout: the play column is as large as the screen allows at 9:16 */

.layout {
  /* A zero flex basis keeps the size container's height definite for the cqh units below. */
  flex: 1 1 0;
  min-height: 380px;
  container-type: size;
}

.layout-inner {
  display: grid;
  grid-template-columns: auto;
  justify-content: center;
  align-items: center;
  gap: 24px;
  height: 100%;
  padding: 8px var(--gutter);
}

.panel {
  display: none;
}

.play {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--play-gap);
  width: min(calc(100vw - 2 * var(--gutter)), calc((100vh - 230px) * 9 / 16));
  container: play / inline-size;
}

@supports (width: 1cqw) {
  .play {
    width: min(
      calc(100cqw - 2 * var(--gutter)),
      calc((100cqh - 16px - var(--controls-h) - var(--play-gap)) * 9 / 16)
    );
  }
}

@media (min-width: 960px) {
  .layout-inner {
    grid-template-columns: var(--panel) auto var(--panel);
  }

  .panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  @supports (width: 1cqw) {
    .play {
      width: min(
        calc(100cqw - 2 * var(--gutter) - 2 * var(--panel) - 48px),
        calc((100cqh - 16px - var(--controls-h) - var(--play-gap)) * 9 / 16)
      );
    }
  }
}

/* Play area */

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 9 / 16;
  overflow: hidden;
  border-radius: var(--radius);
  background: #0b1020;
  box-shadow: var(--shadow), 0 0 0 1px rgba(129, 140, 248, 0.22);
  outline: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  container-type: inline-size;
}

.stage:focus-visible {
  box-shadow: var(--shadow), 0 0 0 2px var(--accent);
}

.stage canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

/* HUD */

.hud {
  position: absolute;
  inset: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 6px;
  padding: 3cqw 3.6cqw 0;
  font-size: clamp(11px, 4.3cqw, 17px);
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 3px rgba(2, 6, 23, 0.95);
  pointer-events: none;
  transition: opacity var(--t-slow) var(--ease);
}

.stage[data-screen="title"] .hud {
  opacity: 0;
}

.hud-block {
  display: flex;
  flex-direction: column;
  gap: 0.2em;
  min-width: 0;
}

.hud-start {
  align-items: flex-start;
}

.hud-center {
  align-items: center;
}

.hud-end {
  align-items: flex-end;
}

.hud-label {
  color: var(--muted);
  font-size: max(11px, 0.72em);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hud-score {
  color: #f8fafc;
  font-size: 1.55em;
  font-weight: 800;
  line-height: 1.05;
}

.hud-best {
  color: var(--muted);
  font-size: max(11px, 0.8em);
}

.hud-multiplier {
  min-width: 2.7em;
  padding: 0.18em 0.6em;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.6);
  color: var(--muted);
  font-weight: 800;
  text-align: center;
  transition:
    color var(--t-fast) var(--ease),
    background-color var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease),
    box-shadow var(--t-fast) var(--ease);
}

.hud-multiplier[data-level="2"] {
  border-color: rgba(129, 140, 248, 0.55);
  background: rgba(129, 140, 248, 0.2);
  color: #c7d2fe;
}

.hud-multiplier[data-level="3"] {
  border-color: rgba(165, 180, 252, 0.85);
  background: rgba(129, 140, 248, 0.34);
  color: #eef2ff;
  box-shadow: 0 0 14px rgba(129, 140, 248, 0.45);
}

.hud-multiplier[data-level="4"] {
  border-color: transparent;
  background: var(--gold);
  color: #422006;
  text-shadow: none;
  box-shadow: 0 0 16px rgba(253, 230, 138, 0.5);
}

.hud-weapon {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  color: var(--tone);
  font-size: max(11px, 0.78em);
  font-weight: 700;
}

.hud-weapon[data-weapon="spread"] {
  --tone: #22d3ee;
}

.hud-weapon[data-weapon="rapid"] {
  --tone: #facc15;
}

.hud-weapon[data-weapon="beam"] {
  --tone: #c084fc;
}

.hud-wave {
  font-weight: 700;
}

.pips {
  display: inline-flex;
  gap: 0.28em;
}

.pip {
  width: 0.5em;
  height: 0.5em;
  border-radius: 2px;
  background: rgba(148, 163, 184, 0.35);
  transform: rotate(45deg);
}

.pip.is-on {
  background: var(--tone);
  box-shadow: 0 0 6px var(--tone);
}

.pips-shield {
  --tone: #34d399;
}

.lives {
  display: inline-flex;
  gap: 0.3em;
}

.life {
  width: 0.85em;
  height: 0.95em;
  background: linear-gradient(#eef2ff, var(--accent));
  clip-path: polygon(50% 0, 62% 38%, 100% 78%, 100% 100%, 60% 86%, 40% 86%, 0 100%, 0 78%, 38% 38%);
}

/* Boss bar */

.bossbar {
  position: absolute;
  top: 22cqw;
  right: 4cqw;
  left: 4cqw;
  display: grid;
  gap: 4px;
  font-size: clamp(11px, 3.3cqw, 13px);
  pointer-events: none;
}

.bossbar-head {
  display: flex;
  justify-content: space-between;
  color: #fecdd3;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow: 0 1px 3px rgba(2, 6, 23, 0.95);
}

.bossbar-track {
  position: relative;
  height: 7px;
  overflow: hidden;
  border: 1px solid rgba(244, 63, 94, 0.4);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.8);
}

.bossbar-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #f43f5e, #fb923c);
  transform-origin: left center;
  transition: transform var(--t-fast) linear;
}

.bossbar-mark {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 1;
  width: 2px;
  margin-left: -1px;
  background: rgba(226, 232, 240, 0.6);
}

/* Banner */

.banner {
  position: absolute;
  top: 37%;
  right: 0;
  left: 0;
  padding: 0 6cqw;
  color: #eef2ff;
  font-size: clamp(18px, 8cqw, 34px);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-align: center;
  text-transform: uppercase;
  text-shadow: 0 0 18px rgba(129, 140, 248, 0.8), 0 2px 4px rgba(2, 6, 23, 0.95);
  opacity: 0;
  pointer-events: none;
}

/* Overlay screens */

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 5cqw;
  background: radial-gradient(ellipse at center, rgba(15, 23, 42, 0.5), rgba(15, 23, 42, 0.85));
  animation: fade-in var(--t-slow) var(--ease);
}

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 3cqw, 12px);
  width: 100%;
  max-width: 340px;
  padding: clamp(14px, 5.5cqw, 24px) clamp(12px, 5cqw, 22px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(30, 41, 59, 0.92);
  box-shadow: var(--shadow);
  text-align: center;
  animation: rise-in var(--t-slow) var(--ease);
}

.card h2 {
  font-size: clamp(20px, 7.5cqw, 30px);
  line-height: 1.15;
  letter-spacing: 0.01em;
}

.card-mark {
  width: clamp(34px, 12cqw, 48px);
  height: clamp(34px, 12cqw, 48px);
  fill: var(--accent);
  filter: drop-shadow(0 0 10px rgba(129, 140, 248, 0.6));
}

.card-text {
  color: var(--muted);
  font-size: clamp(12px, 3.9cqw, 15px);
}

.card-best,
.card-meta {
  color: var(--muted);
  font-size: clamp(12px, 3.7cqw, 14px);
  font-variant-numeric: tabular-nums;
}

.card-best {
  color: #c7d2fe;
  font-weight: 600;
}

.hint-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 12px;
  margin: 0;
  padding: 0;
  color: var(--muted);
  font-size: clamp(11px, 3.5cqw, 13px);
  list-style: none;
}

.hint-list li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.card-hint-touch {
  display: none;
  color: var(--muted);
  font-size: clamp(11px, 3.5cqw, 13px);
}

@media (pointer: coarse) {
  .hint-list {
    display: none;
  }

  .card-hint-touch {
    display: block;
  }
}

.end-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.end-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.end-score strong {
  color: #f8fafc;
  font-size: clamp(26px, 10cqw, 40px);
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.badge {
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--gold);
  color: #422006;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

#screen-end[data-outcome="victory"] h2 {
  color: var(--gold);
}

/* Controls under the play area */

.controls {
  display: flex;
  gap: 8px;
}

.control {
  flex: 1 1 auto;
  min-width: 0;
  height: var(--controls-h);
  padding: 0 10px;
  font-size: 0.875rem;
  text-align: center;
  white-space: nowrap;
}

.control > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* In a narrow play column each control stacks its icon over a smaller label, so labels never wrap. */
@container play (max-width: 339px) {
  .control {
    flex-direction: column;
    gap: 2px;
    padding: 0 4px;
    font-size: 0.75rem;
  }
}

#pause-button[data-paused="true"] .icon-pause,
#pause-button:not([data-paused="true"]) .icon-play,
#sound-button[aria-pressed="false"] .icon-sound-on,
#sound-button[aria-pressed="true"] .icon-sound-off {
  display: none;
}

/* Side panels (wide screens) */

.panel-card {
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(30, 41, 59, 0.85);
  box-shadow: var(--shadow-soft);
}

.panel-card h2 {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.key-list {
  display: grid;
  gap: 9px;
  margin: 0;
}

.key-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.key-list dd {
  margin: 0;
  font-size: 0.9rem;
  text-align: right;
}

.panel-note,
.panel-text {
  color: var(--muted);
  font-size: 0.86rem;
}

.panel-note {
  margin-top: 14px;
}

.panel-text + .panel-text {
  margin-top: 8px;
}

.power-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.power-list li {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 10px;
  align-items: start;
}

.power-spread {
  --tone: #22d3ee;
}

.power-rapid {
  --tone: #facc15;
}

.power-beam {
  --tone: #c084fc;
}

.power-shield {
  --tone: #34d399;
}

.power-icon {
  width: 30px;
  height: 30px;
  color: var(--tone);
  fill: currentColor;
  filter: drop-shadow(0 0 5px var(--tone));
}

.power-badge {
  fill: #0f172a;
  stroke: currentColor;
  stroke-width: 1.5;
}

.power-list strong {
  color: var(--tone);
  font-size: 0.92rem;
}

.power-list p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.84rem;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-property: opacity, color, background-color, border-color !important;
  }

  .card {
    animation-name: fade-in;
  }

  .button:active:not(:disabled) {
    transform: none;
  }
}
