:root {
  color-scheme: dark;
  --bg: #07090d;
  --panel: rgba(13, 17, 24, .82);
  --panel-strong: rgba(17, 22, 31, .94);
  --line: rgba(122, 244, 255, .18);
  --line-hot: rgba(122, 244, 255, .52);
  --ink: #eef8ff;
  --muted: #8da2b0;
  --cyan: #58f2ff;
  --lime: #9bff6a;
  --pink: #ff4fd8;
  --amber: #ffd166;
  --red: #ff5c7a;
  --violet: #8b7cff;
  --cell: clamp(20px, 4.1vw, 36px);
  --radius: 8px;
  --font-ui: "Inter", "Noto Sans SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: var(--font-ui);
  background:
    radial-gradient(circle at 12% 18%, rgba(88, 242, 255, .12), transparent 26%),
    radial-gradient(circle at 82% 12%, rgba(255, 79, 216, .12), transparent 25%),
    radial-gradient(circle at 72% 82%, rgba(155, 255, 106, .08), transparent 27%),
    linear-gradient(135deg, #07090d 0%, #101018 46%, #090d0f 100%);
}

button {
  color: inherit;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

select {
  color: inherit;
  font: inherit;
}

canvas {
  display: block;
}

.ambient-canvas,
.scanline {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.ambient-canvas {
  z-index: 0;
}

.scanline {
  z-index: 1;
  opacity: .38;
  background:
    linear-gradient(rgba(255, 255, 255, .04) 1px, transparent 1px) 0 0 / 100% 4px,
    linear-gradient(90deg, transparent, rgba(88, 242, 255, .08), transparent);
  mix-blend-mode: screen;
  animation: scan 7s linear infinite;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(88, 242, 255, .07) 1px, transparent 1px) 0 0 / 48px 48px,
    linear-gradient(90deg, rgba(88, 242, 255, .06) 1px, transparent 1px) 0 0 / 48px 48px;
  mask-image: radial-gradient(circle at center, black 0%, transparent 72%);
}

.app-shell {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(236px, 300px) minmax(320px, 560px) minmax(230px, 300px);
  gap: 18px;
  width: min(1240px, calc(100% - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px 0;
  align-items: center;
}

.command-panel,
.game-stage,
.intel-panel {
  min-width: 0;
}

.command-panel,
.terminal-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .34), inset 0 1px 0 rgba(255, 255, 255, .04);
  backdrop-filter: blur(18px);
}

.command-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 1px solid rgba(88, 242, 255, .52);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(88, 242, 255, .22), rgba(255, 79, 216, .12));
  color: var(--cyan);
  font-weight: 900;
  box-shadow: 0 0 26px rgba(88, 242, 255, .22);
}

.brand-lockup p,
.brand-lockup h1,
.stage-header h2,
.module-heading,
.terminal-title {
  margin: 0;
}

.brand-lockup p,
.module-heading,
.terminal-title,
.signal-dot,
.stats-grid span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.brand-lockup h1 {
  margin-top: 2px;
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1;
}

.status-readout {
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid rgba(255, 209, 102, .22);
  border-radius: var(--radius);
  padding: 14px;
  background: linear-gradient(135deg, rgba(255, 209, 102, .12), rgba(88, 242, 255, .06));
}

.status-readout span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.status-readout strong {
  color: var(--amber);
  font-size: 22px;
  line-height: 1;
  text-shadow: 0 0 18px rgba(255, 209, 102, .42);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stats-grid article,
.side-module {
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .035);
}

.stats-grid article {
  display: grid;
  min-height: 84px;
  align-content: space-between;
  padding: 12px;
}

.stats-grid strong {
  color: var(--ink);
  font-size: clamp(22px, 2.7vw, 32px);
  line-height: 1;
}

.stats-grid select {
  width: 100%;
  min-width: 0;
  height: 38px;
  border: 1px solid rgba(88, 242, 255, .26);
  border-radius: var(--radius);
  padding: 0 34px 0 10px;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(88, 242, 255, .13), rgba(155, 255, 106, .08)),
    #111822;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 0 18px rgba(88, 242, 255, .08);
  cursor: pointer;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
  outline: 0;
}

.stats-grid select:focus {
  border-color: var(--line-hot);
  box-shadow: 0 0 0 3px rgba(88, 242, 255, .12), 0 0 22px rgba(88, 242, 255, .16);
}

.stats-grid select option {
  color: #0d1118;
  background: #eef8ff;
}

.side-module {
  padding: 12px;
}

.module-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.module-heading b {
  color: var(--cyan);
  font-size: 12px;
}

#nextCanvas,
#holdCanvas {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  background: rgba(1, 5, 9, .62);
}

.game-stage {
  display: grid;
  gap: 14px;
}

.stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  background: var(--panel-strong);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .3);
}

.stage-header h2 {
  margin-top: 4px;
  font-size: clamp(24px, 4vw, 42px);
  line-height: 1;
}

.signal-dot {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--lime);
}

.signal-dot i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--lime);
  box-shadow: 0 0 18px var(--lime);
  animation: pulseDot 1.5s ease-in-out infinite;
}

.stage-actions,
.touch-controls {
  display: flex;
  gap: 8px;
}

.stage-actions button,
.touch-controls button,
.game-overlay button {
  min-height: 42px;
  border: 1px solid rgba(88, 242, 255, .28);
  border-radius: var(--radius);
  background: rgba(88, 242, 255, .08);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
  transition: transform .16s ease, border-color .16s ease, background .16s ease, box-shadow .16s ease;
}

.stage-actions button {
  min-width: 70px;
  padding: 0 12px;
}

.stage-actions button:hover,
.touch-controls button:hover,
.game-overlay button:hover {
  transform: translateY(-1px);
  border-color: var(--line-hot);
  background: rgba(88, 242, 255, .15);
  box-shadow: 0 0 24px rgba(88, 242, 255, .18);
}

.board-shell {
  position: relative;
  width: min(100%, calc(var(--cell) * 10 + 34px));
  margin: 0 auto;
  border: 1px solid var(--line-hot);
  border-radius: var(--radius);
  padding: 16px;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(88, 242, 255, .08), rgba(255, 79, 216, .06)),
    rgba(3, 8, 12, .86);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, .04) inset,
    0 0 48px rgba(88, 242, 255, .18),
    0 28px 90px rgba(0, 0, 0, .46);
}

.board-shell::before,
.board-shell::after {
  content: "";
  position: absolute;
  inset: 16px;
  pointer-events: none;
  border-radius: calc(var(--radius) - 2px);
}

.board-shell::before {
  border: 1px solid rgba(255, 255, 255, .08);
}

.board-shell::after {
  background: linear-gradient(180deg, transparent 0%, rgba(88, 242, 255, .09) 50%, transparent 100%);
  animation: boardSweep 3.4s linear infinite;
}

#gameCanvas {
  width: calc(var(--cell) * 10);
  height: calc(var(--cell) * 20);
  max-width: 100%;
  margin: 0 auto;
  border-radius: calc(var(--radius) - 2px);
  background: #03070a;
}

.game-overlay {
  position: absolute;
  inset: 16px;
  display: grid;
  place-items: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  background: rgba(2, 6, 10, .76);
  backdrop-filter: blur(10px);
  transition: opacity .2s ease;
}

.game-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.game-overlay div {
  display: grid;
  gap: 12px;
  justify-items: center;
}

.game-overlay span {
  color: var(--cyan);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .18em;
}

.game-overlay strong {
  font-size: clamp(28px, 6vw, 54px);
  line-height: 1;
}

.game-overlay button {
  min-width: 132px;
  padding: 0 18px;
  background: linear-gradient(135deg, rgba(88, 242, 255, .2), rgba(155, 255, 106, .16));
}

.touch-controls {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.touch-controls button {
  min-width: 0;
  padding: 0 6px;
  font-size: 13px;
}

.intel-panel {
  display: grid;
  gap: 14px;
}

.terminal-card {
  padding: 14px;
}

.terminal-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--cyan);
}

.terminal-title span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--pink);
  box-shadow: 0 0 14px var(--pink);
}

dl,
ul {
  margin: 0;
}

dl {
  display: grid;
  gap: 8px;
}

dl div,
.compact-feed li {
  border: 1px solid rgba(255, 255, 255, .07);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .035);
}

dl div {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 11px;
}

dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

dd {
  margin: 0;
  color: var(--ink);
  font-weight: 900;
}

.compact-feed ul {
  display: grid;
  gap: 8px;
  padding: 0;
  list-style: none;
}

.compact-feed li {
  padding: 10px;
  color: #c8d6df;
  font-size: 13px;
  line-height: 1.55;
}

.compact-feed li:first-child {
  border-color: rgba(155, 255, 106, .2);
  color: var(--lime);
}

.shake {
  animation: shake .18s linear 2;
}

.line-flash {
  animation: lineFlash .32s ease;
}

@keyframes scan {
  from { transform: translateY(-12px); }
  to { transform: translateY(12px); }
}

@keyframes pulseDot {
  0%, 100% { transform: scale(.86); opacity: .66; }
  50% { transform: scale(1.25); opacity: 1; }
}

@keyframes boardSweep {
  from { transform: translateY(-100%); opacity: 0; }
  22%, 60% { opacity: 1; }
  to { transform: translateY(100%); opacity: 0; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

@keyframes lineFlash {
  from { box-shadow: 0 0 0 rgba(155, 255, 106, 0); }
  45% { box-shadow: 0 0 48px rgba(155, 255, 106, .5); }
  to { box-shadow: 0 0 0 rgba(155, 255, 106, 0); }
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: minmax(240px, 320px) minmax(320px, 1fr);
    align-items: start;
  }

  .intel-panel {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  :root {
    --cell: min(8.8vw, 31px);
  }

  body {
    min-height: 100svh;
  }

  .app-shell {
    grid-template-columns: 1fr;
    width: min(100% - 18px, 520px);
    padding: 10px 0 18px;
  }

  .command-panel {
    order: 2;
  }

  .game-stage {
    order: 1;
  }

  .intel-panel {
    order: 3;
    grid-template-columns: 1fr;
  }

  .stage-header {
    align-items: flex-start;
  }

  .stage-actions {
    flex-direction: column;
  }

  .touch-controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .hold-module {
    display: none;
  }
}

@media (max-width: 380px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

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