:root {
  color-scheme: dark;
  --bg: #020611;
  --panel: rgba(3, 12, 28, 0.78);
  --panel-solid: rgba(5, 15, 34, 0.94);
  --cyan: #4deeff;
  --cyan-2: #00c8ff;
  --pink: #ff4dc8;
  --pink-2: #ff149f;
  --ink: #eff8ff;
  --muted: #8fa4bc;
  --line: rgba(77, 238, 255, 0.46);
  --line-soft: rgba(77, 238, 255, 0.18);
  --line-pink: rgba(255, 77, 200, 0.5);
  --danger: #ff3d72;
  --radius: 8px;
  --font-display: "Chakra Petch", Inter, system-ui, sans-serif;
  --font-body: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --glow-cyan: 0 0 18px rgba(77, 238, 255, 0.72), 0 0 42px rgba(0, 200, 255, 0.34);
  --glow-pink: 0 0 18px rgba(255, 77, 200, 0.78), 0 0 46px rgba(255, 20, 159, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-body);
  background:
    radial-gradient(circle at 50% 42%, rgba(17, 86, 126, 0.25), transparent 22%),
    radial-gradient(circle at 12% 80%, rgba(255, 20, 159, 0.2), transparent 24%),
    radial-gradient(circle at 90% 78%, rgba(0, 200, 255, 0.18), transparent 22%),
    linear-gradient(180deg, #030814 0%, #020511 54%, #01030a 100%);
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  background:
    linear-gradient(rgba(77, 238, 255, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(77, 238, 255, 0.045) 1px, transparent 1px);
  background-size: 72px 72px;
  background-position: 0 0;
  mask-image: linear-gradient(to bottom, transparent 0%, #000 8%, #000 86%, transparent 100%);
  animation: gridDrift 18s linear infinite;
}

body::after {
  background:
    repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 8px),
    linear-gradient(90deg, transparent 0 48%, rgba(255, 77, 200, 0.09) 50%, transparent 52% 100%);
  mix-blend-mode: screen;
  opacity: 0.42;
  animation: scanNoise 2.7s steps(6) infinite;
}

button {
  font: inherit;
}

.app-shell {
  --shell-pad: clamp(14px, 2vw, 28px);
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--shell-pad);
  isolation: isolate;
  overflow-x: hidden;
  overflow-x: clip;
}

.city {
  position: fixed;
  bottom: 0;
  width: min(28vw, 360px);
  height: 48vh;
  pointer-events: none;
  z-index: -1;
  opacity: 0.72;
  background:
    linear-gradient(to top, rgba(255, 77, 200, 0.24), transparent 28%),
    linear-gradient(to top, rgba(0, 200, 255, 0.16), transparent 38%);
  clip-path: polygon(
    0 100%,
    0 42%,
    7% 42%,
    7% 28%,
    13% 28%,
    13% 55%,
    20% 55%,
    20% 34%,
    29% 34%,
    29% 72%,
    36% 72%,
    36% 46%,
    45% 46%,
    45% 18%,
    53% 18%,
    53% 64%,
    64% 64%,
    64% 39%,
    72% 39%,
    72% 76%,
    82% 76%,
    82% 31%,
    91% 31%,
    91% 100%
  );
  filter: drop-shadow(0 0 18px rgba(0, 200, 255, 0.22)) drop-shadow(0 0 24px rgba(255, 20, 159, 0.22));
  animation: cityPulse 5s ease-in-out infinite alternate;
}

.city-left {
  left: 0;
}

.city-right {
  right: 0;
  transform: scaleX(-1);
  animation-delay: -1.7s;
}

.ambient-orbit {
  position: fixed;
  inset: 7vh 8vw;
  z-index: -1;
  pointer-events: none;
  opacity: 0.34;
  background:
    conic-gradient(from 0deg at 50% 50%, transparent, rgba(77, 238, 255, 0.16), transparent 26%, rgba(255, 77, 200, 0.14), transparent 52%),
    radial-gradient(circle at 50% 50%, transparent 48%, rgba(77, 238, 255, 0.11) 49%, transparent 52%);
  filter: blur(10px);
  animation: orbitSweep 22s linear infinite;
  contain: paint;
}

.command-frame {
  position: relative;
  width: min(100%, 1500px);
  min-height: min(920px, calc(100dvh - var(--shell-pad) - var(--shell-pad)));
  display: grid;
  grid-template-columns: minmax(270px, 360px) minmax(470px, 620px) minmax(300px, 390px);
  grid-template-rows: 54px 1fr 54px;
  grid-template-areas:
    "rail rail rail"
    "brand core systems"
    "footer footer footer";
  column-gap: clamp(22px, 3vw, 48px);
  padding: clamp(18px, 2vw, 34px) clamp(22px, 3vw, 54px);
  border: 1px solid rgba(77, 238, 255, 0.18);
  background:
    linear-gradient(90deg, rgba(77, 238, 255, 0.05), transparent 18% 82%, rgba(255, 77, 200, 0.06)),
    linear-gradient(180deg, rgba(3, 10, 24, 0.9), rgba(2, 6, 15, 0.74));
  box-shadow: inset 0 0 80px rgba(0, 200, 255, 0.06), 0 0 60px rgba(0, 0, 0, 0.55);
  clip-path: polygon(2.2% 0, 97.2% 0, 100% 4.5%, 100% 94.5%, 96.5% 100%, 3.5% 100%, 0 94.5%, 0 4.5%);
  animation: bootFrame 760ms cubic-bezier(0.2, 0.9, 0.2, 1) both;
  contain: paint;
}

.command-frame::before,
.command-frame::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.command-frame::before {
  inset: 18px;
  border: 1px solid rgba(77, 238, 255, 0.08);
  clip-path: polygon(2% 0, 26% 0, 29% 5%, 68% 5%, 71% 0, 98% 0, 100% 3%, 100% 97%, 98% 100%, 72% 100%, 69% 95%, 29% 95%, 26% 100%, 2% 100%, 0 97%, 0 3%);
  animation: traceFrame 4.8s ease-in-out infinite;
}

.command-frame::after {
  right: 18px;
  top: 58px;
  bottom: 145px;
  width: 2px;
  background: linear-gradient(to bottom, transparent, var(--pink), var(--cyan), transparent);
  box-shadow: 0 0 18px rgba(255, 77, 200, 0.8);
  animation: sideBeam 2.6s ease-in-out infinite alternate;
}

.top-rail,
.system-footer {
  grid-area: rail;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--cyan);
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.top-rail i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: var(--glow-cyan);
  animation: beacon 1.5s ease-in-out infinite;
}

.system-footer {
  grid-area: footer;
  align-items: end;
  font-size: 0.72rem;
}

.brand-stack,
.core-stack,
.systems-stack {
  position: relative;
  z-index: 1;
}

.brand-stack {
  grid-area: brand;
  align-self: center;
  display: grid;
  gap: 26px;
  animation: slideInLeft 680ms cubic-bezier(0.2, 0.9, 0.2, 1) 110ms both;
}

.brand h1 {
  margin: 0;
  display: flex;
  align-items: center;
  font-family: var(--font-display);
  font-size: clamp(3rem, 4.35vw, 4.55rem);
  line-height: 0.82;
  letter-spacing: 0;
  text-transform: uppercase;
  color: #f5fbff;
  text-shadow: 0 0 16px rgba(77, 238, 255, 0.72), 0 0 40px rgba(77, 238, 255, 0.26);
  animation: titleFlicker 3.8s ease-in-out infinite;
}

.brand h1 span {
  color: var(--pink);
  font-size: 1.18em;
  line-height: 0.7;
  margin-left: -0.05em;
  text-shadow: var(--glow-pink);
  animation: infinityPulse 1.9s ease-in-out infinite;
}

.brand p {
  margin: 12px 0 0;
  color: var(--cyan);
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 1.7vw, 1.35rem);
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

.panel {
  position: relative;
  border: 1px solid var(--line-soft);
  background:
    linear-gradient(135deg, rgba(77, 238, 255, 0.08), transparent 30%),
    linear-gradient(315deg, rgba(255, 77, 200, 0.04), transparent 34%),
    var(--panel);
  box-shadow: inset 0 0 24px rgba(77, 238, 255, 0.05), 0 0 22px rgba(0, 0, 0, 0.28);
  clip-path: polygon(8% 0, 92% 0, 100% 12%, 100% 88%, 92% 100%, 8% 100%, 0 88%, 0 12%);
  transform-origin: center;
}

.panel::before,
.panel::after {
  content: "";
  position: absolute;
  pointer-events: none;
  background: var(--cyan);
  box-shadow: var(--glow-cyan);
}

.panel::before {
  top: 0;
  left: 20%;
  width: 42%;
  height: 1px;
  animation: panelTrace 3.2s ease-in-out infinite;
}

.panel::after {
  right: 0;
  bottom: 18%;
  width: 1px;
  height: 24%;
}

.panel h2,
.panel span {
  font-family: var(--font-display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel h2 {
  margin: 0 0 18px;
  color: var(--cyan);
  font-size: 1.1rem;
}

.rules-panel {
  min-height: 280px;
  padding: 34px;
}

.rules-panel p {
  margin: 0 0 14px;
  color: #dce8ff;
  font-size: 1.1rem;
  line-height: 1.34;
}

.legend-panel {
  min-height: 104px;
  padding: 20px 28px;
  display: grid;
  align-content: center;
  gap: 14px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 18px;
  color: #d8edff;
  font-family: var(--font-display);
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.legend-mark {
  width: 34px;
  font-size: 2.15rem;
  line-height: 1;
}

.legend-x {
  color: var(--cyan);
  text-shadow: var(--glow-cyan);
}

.legend-o {
  color: var(--pink);
  text-shadow: var(--glow-pink);
}

.core-stack {
  grid-area: core;
  display: grid;
  grid-template-rows: 96px minmax(470px, 590px) 70px;
  align-content: center;
  justify-items: center;
  gap: 18px;
  animation: riseIn 760ms cubic-bezier(0.2, 0.9, 0.2, 1) 180ms both;
}

.turn-card {
  width: 104px;
  height: 86px;
  padding: 16px;
  display: grid;
  place-items: center;
  color: var(--cyan);
  transition: border-color 240ms ease, box-shadow 240ms ease, color 240ms ease;
}

.turn-card span,
.score-card span {
  font-size: 0.88rem;
  font-weight: 700;
}

.turn-card strong {
  font-family: var(--font-display);
  font-size: 2.7rem;
  line-height: 1;
  text-shadow: var(--glow-cyan);
}

.turn-card.turn-x {
  border-color: rgba(77, 238, 255, 0.58);
  box-shadow: var(--glow-cyan), inset 0 0 28px rgba(77, 238, 255, 0.08);
}

.turn-card.turn-o {
  color: var(--pink);
  border-color: rgba(255, 77, 200, 0.58);
  box-shadow: var(--glow-pink), inset 0 0 28px rgba(255, 77, 200, 0.08);
}

.turn-card.turn-o strong {
  text-shadow: var(--glow-pink);
}

.turn-card.turn-swap {
  animation: turnSwap 360ms cubic-bezier(0.2, 0.9, 0.2, 1);
}

.board-frame {
  position: relative;
  width: min(100%, 590px);
  aspect-ratio: 1;
  padding: 24px;
  border: 2px solid rgba(77, 238, 255, 0.74);
  background:
    radial-gradient(circle at 50% 50%, rgba(77, 238, 255, 0.12), transparent 56%),
    linear-gradient(135deg, rgba(255, 77, 200, 0.1), transparent 24% 72%, rgba(77, 238, 255, 0.1)),
    rgba(1, 7, 18, 0.8);
  box-shadow:
    var(--glow-cyan),
    0 0 0 1px rgba(255, 77, 200, 0.65),
    inset 0 0 0 1px rgba(255, 77, 200, 0.54),
    inset 0 0 48px rgba(0, 200, 255, 0.13);
  clip-path: polygon(7% 0, 93% 0, 100% 7%, 100% 93%, 93% 100%, 7% 100%, 0 93%, 0 7%);
  transform-style: preserve-3d;
  animation: boardIdle 5.8s ease-in-out infinite;
  overflow: hidden;
  overflow: clip;
  contain: layout paint;
}

.board-frame::before,
.board-frame::after {
  content: "";
  position: absolute;
  inset: 10px;
  pointer-events: none;
  border: 1px solid rgba(255, 77, 200, 0.68);
  clip-path: polygon(5% 0, 95% 0, 100% 5%, 100% 95%, 95% 100%, 5% 100%, 0 95%, 0 5%);
  filter: drop-shadow(0 0 10px rgba(255, 77, 200, 0.62));
  animation: boardTrace 3.4s ease-in-out infinite alternate;
}

.board-frame::after {
  inset: 20px;
  border-color: rgba(77, 238, 255, 0.32);
  filter: none;
  animation-delay: -1.2s;
}

.energy-ring {
  position: absolute;
  inset: -18%;
  pointer-events: none;
  opacity: 0.42;
  background: conic-gradient(from 90deg, transparent 0 10%, rgba(77, 238, 255, 0.18) 16%, transparent 24% 44%, rgba(255, 77, 200, 0.18) 52%, transparent 62% 100%);
  filter: blur(12px);
  animation: energyRotate 12s linear infinite;
}

.board {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 13px;
}

.board::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(115deg, transparent 0 34%, rgba(77, 238, 255, 0.18) 44%, rgba(255, 77, 200, 0.12) 49%, transparent 60% 100%);
  transform: translateX(-140%);
  animation: boardSweep 4.6s ease-in-out infinite;
}

.cell {
  position: relative;
  display: grid;
  min-width: 0;
  place-items: center;
  border: 1px solid rgba(77, 238, 255, 0.72);
  color: var(--ink);
  cursor: pointer;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 50%, rgba(77, 238, 255, 0.08), transparent 45%),
    linear-gradient(180deg, rgba(9, 25, 48, 0.78), rgba(2, 8, 20, 0.9));
  box-shadow:
    inset 0 0 24px rgba(0, 200, 255, 0.08),
    0 0 16px rgba(77, 238, 255, 0.08);
  clip-path: polygon(6% 0, 94% 0, 100% 6%, 100% 94%, 94% 100%, 6% 100%, 0 94%, 0 6%);
  transition: transform 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

.cell::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.34;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(135deg, rgba(255, 77, 200, 0.14), transparent 42%);
  background-size: 11px 11px, auto;
  transform: translateZ(0);
  animation: cellStatic 2.4s steps(5) infinite;
}

.cell::after {
  content: "";
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 26px;
  height: 26px;
  border-right: 2px solid var(--cyan);
  border-bottom: 2px solid var(--cyan);
  filter: drop-shadow(0 0 10px rgba(77, 238, 255, 0.8));
}

.cell:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.01);
  border-color: rgba(255, 77, 200, 0.92);
  box-shadow: inset 0 0 28px rgba(255, 77, 200, 0.12), 0 0 28px rgba(255, 77, 200, 0.22);
}

.cell:focus-visible {
  outline: 2px solid var(--pink);
  outline-offset: 3px;
}

.cell:disabled {
  cursor: not-allowed;
}

.mark {
  position: relative;
  z-index: 2;
  font-family: var(--font-display);
  font-size: clamp(4rem, 8vw, 7.35rem);
  font-weight: 500;
  line-height: 1;
  transform-origin: center;
}

.mark-x {
  color: var(--cyan);
  text-shadow: var(--glow-cyan);
}

.mark-o {
  color: var(--pink);
  text-shadow: var(--glow-pink);
}

.cell.aging {
  border-color: rgba(255, 77, 200, 0.95);
  box-shadow: inset 0 0 30px rgba(255, 77, 200, 0.13), 0 0 22px rgba(255, 77, 200, 0.25);
  animation: agingAlert 1s ease-in-out infinite alternate;
}

.cell.winner {
  animation: winnerPulse 720ms ease-in-out infinite alternate;
}

.cell.spawn {
  animation: spawn 360ms cubic-bezier(0.2, 0.9, 0.2, 1);
}

.cell.spawn::before {
  animation: cellStatic 2.4s steps(5) infinite, impactBloom 420ms ease-out;
}

.cell.removing {
  animation: cellDischarge 300ms ease-out;
}

.cell .ripple {
  position: absolute;
  z-index: 1;
  width: 24%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid currentColor;
  pointer-events: none;
  opacity: 0.95;
  animation: rippleOut 520ms ease-out forwards;
}

.win-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.9), rgba(77, 238, 255, 0.28) 22%, rgba(255, 77, 200, 0.16) 40%, transparent 68%);
}

.win-flash.active {
  animation: flash 900ms ease-out;
}

.particle-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.particle {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--s);
  height: var(--s);
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 14px var(--c), 0 0 28px var(--c);
  transform: translate(-50%, -50%);
  animation: particleBurst 850ms cubic-bezier(0.12, 0.8, 0.28, 1) forwards;
}

.bottom-chip {
  width: min(78%, 460px);
  min-height: 44px;
  display: grid;
  grid-template-columns: 1fr 92px 1fr;
  align-items: center;
  border: 1px solid rgba(77, 238, 255, 0.38);
  color: var(--cyan);
  font-family: var(--font-display);
  font-size: 0.92rem;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
  background: rgba(4, 13, 29, 0.86);
  clip-path: polygon(5% 0, 95% 0, 100% 50%, 95% 100%, 5% 100%, 0 50%);
  animation: chipPulse 3.2s ease-in-out infinite;
}

.bottom-chip b {
  color: #dffbff;
  text-shadow: var(--glow-cyan);
}

.systems-stack {
  grid-area: systems;
  align-self: center;
  display: grid;
  gap: 24px;
  animation: slideInRight 680ms cubic-bezier(0.2, 0.9, 0.2, 1) 150ms both;
}

.score-row {
  display: grid;
  grid-template-columns: 1fr 1fr 84px;
  gap: 12px;
  align-items: stretch;
}

.score-card {
  min-height: 96px;
  padding: 22px;
  display: grid;
  align-content: center;
  gap: 8px;
}

.score-card strong {
  color: var(--cyan);
  font-family: var(--font-display);
  font-size: 2.25rem;
  line-height: 1;
  letter-spacing: 0.04em;
  text-shadow: var(--glow-cyan);
}

.score-card.score-pop strong {
  animation: scorePop 520ms cubic-bezier(0.2, 0.9, 0.2, 1);
}

.score-o span,
.score-o strong {
  color: var(--pink);
  text-shadow: var(--glow-pink);
}

.sound-card {
  min-height: 96px;
  display: grid;
  place-items: center;
  color: var(--cyan);
  cursor: pointer;
  font-size: 2.65rem;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.sound-card:hover,
.reset-button:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 77, 200, 0.78);
  box-shadow: 0 0 24px rgba(255, 77, 200, 0.24), inset 0 0 22px rgba(77, 238, 255, 0.07);
}

.sound-card.is-muted {
  color: var(--danger);
  border-color: rgba(255, 61, 114, 0.48);
  filter: saturate(0.78);
}

.status-panel {
  min-height: 182px;
  padding: 28px 30px;
}

.status-panel p {
  min-height: 34px;
  margin: 0 0 24px;
  color: #dce8ff;
  font-family: var(--font-display);
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.status-panel.status-pulse {
  animation: statusPulse 460ms ease-out;
}

.status-panel p::first-letter {
  color: var(--cyan);
}

.reset-button {
  display: block;
  min-width: 114px;
  height: 44px;
  margin-left: auto;
  border: 1px solid var(--line-pink);
  color: var(--pink);
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: rgba(34, 7, 30, 0.78);
  clip-path: polygon(12% 0, 88% 0, 100% 22%, 100% 78%, 88% 100%, 12% 100%, 0 78%, 0 22%);
}

.action-panel,
.sequence-panel {
  padding: 24px 30px;
}

.action-panel {
  min-height: 202px;
}

.mini-board {
  width: 208px;
  height: 126px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  margin: 0 auto;
  border: 1px solid rgba(77, 238, 255, 0.24);
  background: rgba(0, 8, 18, 0.45);
}

.mini-cell {
  display: grid;
  place-items: center;
  border-right: 1px solid rgba(77, 238, 255, 0.32);
  border-bottom: 1px solid rgba(77, 238, 255, 0.32);
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 1.25rem;
}

.mini-cell:nth-child(3n) {
  border-right: 0;
}

.mini-cell:nth-child(n + 7) {
  border-bottom: 0;
}

.mini-cell.x {
  color: var(--cyan);
  text-shadow: var(--glow-cyan);
  animation: miniPop 280ms ease-out;
}

.mini-cell.o {
  color: var(--pink);
  text-shadow: var(--glow-pink);
  animation: miniPop 280ms ease-out;
}

.sequence-panel {
  min-height: 205px;
}

.sequence-panel ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 0.95rem;
}

.sequence-panel li {
  display: grid;
  grid-template-columns: 34px 24px 1fr;
  gap: 8px;
  animation: sequenceIn 260ms ease-out both;
}

.sequence-panel b {
  font-weight: 700;
}

.sequence-panel .x {
  color: var(--cyan);
}

.sequence-panel .o {
  color: var(--pink);
}

.ghost-mark {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  animation: vanish 230ms ease-in forwards;
}

.shake {
  animation: shake 280ms ease-in-out;
}

.round-reset .cell {
  animation: roundReset 460ms ease-in both;
}

.round-reset .cell:nth-child(2),
.round-reset .cell:nth-child(4),
.round-reset .cell:nth-child(6),
.round-reset .cell:nth-child(8) {
  animation-delay: 45ms;
}

.round-reset .cell:nth-child(3),
.round-reset .cell:nth-child(5),
.round-reset .cell:nth-child(7) {
  animation-delay: 90ms;
}

@keyframes gridDrift {
  to {
    background-position: 72px 144px;
  }
}

@keyframes scanNoise {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  50% {
    transform: translateY(4px);
    opacity: 0.52;
  }
}

@keyframes cityPulse {
  from {
    opacity: 0.48;
    filter: drop-shadow(0 0 12px rgba(0, 200, 255, 0.18)) drop-shadow(0 0 18px rgba(255, 20, 159, 0.16));
  }
  to {
    opacity: 0.82;
    filter: drop-shadow(0 0 24px rgba(0, 200, 255, 0.28)) drop-shadow(0 0 32px rgba(255, 20, 159, 0.26));
  }
}

@keyframes orbitSweep {
  to {
    transform: rotate(360deg);
  }
}

@keyframes bootFrame {
  0% {
    opacity: 0.9;
    transform: scale(1) translateY(0);
    filter: brightness(1.1) blur(0);
  }
  48% {
    opacity: 1;
    filter: brightness(1.35) blur(0);
  }
  100% {
    transform: scale(1) translateY(0);
    filter: brightness(1);
  }
}

@keyframes traceFrame {
  0%,
  100% {
    opacity: 0.42;
  }
  50% {
    opacity: 0.86;
  }
}

@keyframes sideBeam {
  from {
    opacity: 0.45;
    transform: scaleY(0.88);
  }
  to {
    opacity: 1;
    transform: scaleY(1);
  }
}

@keyframes beacon {
  0%,
  100% {
    transform: scale(0.8);
    opacity: 0.72;
  }
  50% {
    transform: scale(1.22);
    opacity: 1;
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0.86;
    transform: translateX(0);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0.86;
    transform: translateX(0);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes riseIn {
  from {
    opacity: 0.88;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes titleFlicker {
  0%,
  100% {
    filter: brightness(1);
  }
  48% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.35);
  }
  52% {
    filter: brightness(0.82);
  }
  56% {
    filter: brightness(1.16);
  }
}

@keyframes infinityPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

@keyframes panelTrace {
  0%,
  100% {
    transform: translateX(-18%);
    opacity: 0.6;
  }
  50% {
    transform: translateX(35%);
    opacity: 1;
  }
}

@keyframes turnSwap {
  0% {
    transform: scale(0.92);
    filter: brightness(2);
  }
  65% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

@keyframes boardIdle {
  0%,
  100% {
    transform: perspective(1200px) rotateX(0deg) translateY(0);
  }
  50% {
    transform: perspective(1200px) rotateX(0.8deg) translateY(-3px);
  }
}

@keyframes boardTrace {
  from {
    opacity: 0.52;
  }
  to {
    opacity: 1;
  }
}

@keyframes energyRotate {
  to {
    transform: rotate(360deg);
  }
}

@keyframes boardSweep {
  0%,
  42% {
    transform: translateX(-140%);
  }
  72%,
  100% {
    transform: translateX(140%);
  }
}

@keyframes cellStatic {
  0%,
  100% {
    opacity: 0.28;
  }
  50% {
    opacity: 0.44;
  }
}

@keyframes impactBloom {
  from {
    opacity: 0.95;
    filter: brightness(2.4);
  }
  to {
    opacity: 0.34;
    filter: brightness(1);
  }
}

@keyframes agingAlert {
  from {
    filter: brightness(1);
  }
  to {
    filter: brightness(1.22);
  }
}

@keyframes cellDischarge {
  0% {
    filter: brightness(2);
  }
  100% {
    filter: brightness(1);
  }
}

@keyframes rippleOut {
  to {
    width: 130%;
    opacity: 0;
    filter: blur(3px);
  }
}

@keyframes particleBurst {
  to {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.25);
    filter: blur(2px);
  }
}

@keyframes chipPulse {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(77, 238, 255, 0);
  }
  50% {
    box-shadow: 0 0 26px rgba(77, 238, 255, 0.16);
  }
}

@keyframes scorePop {
  0% {
    transform: translateY(8px) scale(0.78);
    filter: brightness(2.4);
  }
  60% {
    transform: translateY(-4px) scale(1.16);
  }
  100% {
    transform: translateY(0) scale(1);
    filter: brightness(1);
  }
}

@keyframes statusPulse {
  from {
    filter: brightness(1.8);
  }
  to {
    filter: brightness(1);
  }
}

@keyframes miniPop {
  from {
    transform: scale(0.72);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes sequenceIn {
  from {
    opacity: 0;
    transform: translateX(12px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes roundReset {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0.18;
    transform: scale(0.94);
    filter: blur(4px);
  }
}

@keyframes spawn {
  0% {
    transform: scale(0.84);
    filter: brightness(2.2);
  }
  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

@keyframes vanish {
  to {
    transform: scale(0.55) rotate(7deg);
    opacity: 0;
    filter: blur(5px);
  }
}

@keyframes winnerPulse {
  from {
    transform: scale(1);
    border-color: rgba(77, 238, 255, 0.9);
    box-shadow: 0 0 24px rgba(77, 238, 255, 0.25), inset 0 0 28px rgba(77, 238, 255, 0.12);
  }
  to {
    transform: scale(1.028);
    border-color: rgba(255, 77, 200, 0.95);
    box-shadow: 0 0 34px rgba(255, 77, 200, 0.38), inset 0 0 34px rgba(255, 77, 200, 0.18);
  }
}

@keyframes flash {
  0% {
    opacity: 0;
  }
  15% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  30% {
    transform: translateX(-7px);
  }
  65% {
    transform: translateX(7px);
  }
}

@media (max-width: 1180px) {
  .command-frame {
    grid-template-columns: minmax(260px, 0.8fr) minmax(430px, 1.2fr);
    grid-template-areas:
      "rail rail"
      "brand core"
      "systems systems"
      "footer footer";
    grid-template-rows: 50px auto auto 50px;
    row-gap: 24px;
  }

  .systems-stack {
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
  }

  .score-row,
  .status-panel {
    grid-column: 1 / -1;
  }
}

@media (min-width: 1181px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .app-shell {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    overflow: clip;
  }

  .command-frame {
    height: min(920px, calc(100dvh - var(--shell-pad) - var(--shell-pad)));
    min-height: 0;
    overflow: hidden;
    overflow: clip;
  }
}

@media (min-width: 1181px) and (max-height: 820px) {
  .app-shell {
    --shell-pad: 12px;
  }

  .command-frame {
    grid-template-rows: 36px 1fr 32px;
    column-gap: clamp(18px, 2.4vw, 34px);
    padding: 18px 40px;
  }

  .brand-stack {
    gap: 14px;
  }

  .brand h1 {
    font-size: clamp(2.7rem, 3.55vw, 3.6rem);
  }

  .brand p {
    margin-top: 8px;
    font-size: 1rem;
  }

  .rules-panel {
    min-height: 210px;
    padding: 24px 28px;
  }

  .rules-panel p {
    margin-bottom: 11px;
    font-size: 1rem;
  }

  .legend-panel {
    min-height: 82px;
    padding: 14px 22px;
    gap: 8px;
  }

  .legend-mark {
    font-size: 1.85rem;
  }

  .core-stack {
    grid-template-rows: 72px minmax(380px, 470px) 48px;
    gap: 12px;
  }

  .turn-card {
    width: 92px;
    height: 70px;
    padding: 12px;
  }

  .turn-card strong {
    font-size: 2.25rem;
  }

  .board-frame {
    width: min(100%, 470px);
    padding: 18px;
  }

  .bottom-chip {
    min-height: 36px;
    font-size: 0.78rem;
  }

  .systems-stack {
    gap: 12px;
  }

  .score-row {
    grid-template-columns: 1fr 1fr 72px;
  }

  .score-card,
  .sound-card {
    min-height: 78px;
    padding: 16px;
  }

  .score-card strong {
    font-size: 1.95rem;
  }

  .sound-card {
    font-size: 2.1rem;
  }

  .status-panel {
    min-height: 140px;
    padding: 22px 26px;
  }

  .status-panel p {
    margin-bottom: 16px;
    font-size: 0.95rem;
  }

  .action-panel,
  .sequence-panel {
    padding: 18px 26px;
  }

  .action-panel {
    min-height: 156px;
  }

  .sequence-panel {
    min-height: 144px;
  }

  .mini-board {
    width: 178px;
    height: 96px;
  }

  .sequence-panel ol {
    gap: 5px;
    font-size: 0.84rem;
  }
}

@media (max-width: 820px) {
  html,
  body {
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .app-shell {
    place-items: start center;
    padding: 10px;
    overflow-x: hidden;
    overflow-x: clip;
    overflow-y: visible;
  }

  .command-frame {
    min-height: auto;
    grid-template-columns: 1fr;
    grid-template-areas:
      "rail"
      "brand"
      "core"
      "systems"
      "footer";
    grid-template-rows: auto auto auto auto auto;
    padding: 18px 14px;
    clip-path: none;
  }

  .command-frame::before,
  .command-frame::after {
    display: none;
  }

  .top-rail span:last-child {
    display: none;
  }

  .brand-stack {
    align-self: start;
    gap: 16px;
  }

  .brand h1 {
    font-size: clamp(3.05rem, 15vw, 4.7rem);
  }

  .rules-panel {
    min-height: auto;
    padding: 22px;
  }

  .rules-panel p {
    display: inline;
    margin-right: 10px;
    font-size: 1rem;
  }

  .legend-panel {
    display: none;
  }

  .core-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    width: 100%;
  }

  .turn-card {
    display: none;
  }

  .board-frame {
    width: min(100%, 540px);
    height: min(calc(100vw - 48px), 540px);
    padding: 12px;
  }

  .board {
    gap: 8px;
  }

  .mark {
    font-size: clamp(3.2rem, 18vw, 6.2rem);
  }

  .systems-stack {
    grid-template-columns: 1fr;
    gap: 14px;
    width: 100%;
  }

  .score-row {
    grid-template-columns: 1fr 1fr 62px;
  }

  .score-card,
  .sound-card {
    min-height: 76px;
    padding: 14px;
  }

  .sound-card {
    font-size: 2rem;
  }

  .status-panel,
  .action-panel,
  .sequence-panel {
    min-height: auto;
    padding: 20px;
  }

  .mini-board {
    width: min(100%, 220px);
  }
}

@media (max-width: 520px) {
  .top-rail {
    font-size: 0.68rem;
  }

  .brand p {
    font-size: 0.95rem;
  }

  .rules-panel {
    display: none;
  }

  .score-row {
    grid-template-columns: 1fr 1fr;
  }

  .sound-card {
    grid-column: 1 / -1;
    min-height: 46px;
  }

  .bottom-chip {
    width: 100%;
    grid-template-columns: 1fr 64px 1fr;
    font-size: 0.74rem;
  }
}

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