@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Share+Tech+Mono&display=swap');

:root {
  --neon-cyan: #00f0ff;
  --neon-magenta: #ff007f;
  --neon-purple: #a100ff;
  --neon-amber: #ffaa00;
  --neon-green: #00ff66;
  --neon-red: #ff3333;
  --neon-blue: #00aaff;
  --bg-dark: #0b0b12;
  --bg-panel: rgba(26, 26, 38, 0.65);
  --border-glow: rgba(0, 240, 255, 0.3);
  --font-header: 'Orbitron', sans-serif;
  --font-mono: 'Share Tech Mono', monospace;
}

/* Base resets & theme */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-dark);
  color: #fff;
  font-family: var(--font-mono);
  overflow-x: hidden;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  background-image:
    radial-gradient(circle at 50% 50%, rgba(24, 0, 48, 0.35) 0%, transparent 80%),
    linear-gradient(rgba(18, 18, 30, 0.4) 1px, transparent 1px),
    linear-gradient(90deg, rgba(18, 18, 30, 0.4) 1px, transparent 1px);
  background-size: 100% 100%, 30px 30px, 30px 30px;
}

/* CRT Screen Effect overlay */
.crt-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background:
    linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%),
    linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
  background-size: 100% 4px, 6px 100%;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.15;
  transition: opacity 0.3s ease;
}

.crt-overlay.disabled,
body.crt-disabled .crt-overlay {
  opacity: 0;
  visibility: hidden;
}

/* CRT Scanline Flicker animation — disabled cleanly when body.crt-disabled is set */
@keyframes crt-flicker {
  0% { opacity: 0.14; }
  50% { opacity: 0.18; }
  100% { opacity: 0.14; }
}

body:not(.crt-disabled)::after {
  content: " ";
  display: block;
  position: fixed;
  top: 0; left: 0; bottom: 0; right: 0;
  background: rgba(18, 16, 16, 0.03);
  z-index: 10000;
  pointer-events: none;
  animation: crt-flicker 0.15s infinite;
}

/* Main Container Layout */
.app-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1080px;
  padding: 12px 20px;
  gap: 14px;
}

header {
  text-align: center;
  margin-bottom: 0;
}

h1 {
  font-family: var(--font-header);
  font-size: 2.2rem;
  font-weight: 900;
  letter-spacing: 4px;
  color: #fff;
  text-transform: uppercase;
  text-shadow:
    0 0 5px #fff,
    0 0 10px var(--neon-cyan),
    0 0 20px var(--neon-cyan),
    0 0 40px var(--neon-magenta);
  animation: text-pulse 3s infinite alternate;
}

@keyframes text-pulse {
  0% {
    text-shadow: 0 0 5px #fff, 0 0 10px var(--neon-cyan), 0 0 20px var(--neon-cyan);
  }
  100% {
    text-shadow: 0 0 8px #fff, 0 0 15px var(--neon-magenta), 0 0 30px var(--neon-magenta);
  }
}

.header-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-top: 4px;
}

.subtitle {
  font-size: 0.82rem;
  letter-spacing: 4px;
  color: var(--neon-cyan);
  text-transform: uppercase;
  opacity: 0.8;
}

.active-player-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 10px;
  border-radius: 999px;
  font-family: var(--font-header);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  border: 1px solid var(--neon-cyan);
  background: rgba(0, 240, 255, 0.12);
  color: var(--neon-cyan);
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.25);
  transition: all 0.2s ease;
}

.active-player-badge.player-ai {
  border-color: var(--neon-magenta);
  background: rgba(255, 0, 127, 0.14);
  color: #ff66b2;
  box-shadow: 0 0 12px rgba(255, 0, 127, 0.3);
}

.active-player-badge.player-ml {
  border-color: var(--neon-green);
  background: rgba(0, 255, 102, 0.12);
  color: var(--neon-green);
  box-shadow: 0 0 12px rgba(0, 255, 102, 0.28);
}

.active-player-badge.player-decision {
  border-color: var(--neon-amber);
  background: rgba(255, 170, 0, 0.14);
  color: var(--neon-amber);
  box-shadow: 0 0 12px rgba(255, 170, 0, 0.3);
}

.active-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
  animation: live-dot-pulse 1.2s infinite ease-in-out;
}

@keyframes live-dot-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

/* Glassmorphism Panels */
.game-layout {
  display: grid;
  grid-template-columns: 250px 1fr 240px;
  gap: 20px;
  align-items: start;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-glow);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow:
    0 8px 32px 0 rgba(0, 0, 0, 0.37),
    inset 0 0 12px rgba(0, 240, 255, 0.05);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.panel:hover {
  border-color: rgba(255, 0, 127, 0.4);
  box-shadow:
    0 8px 32px 0 rgba(0, 0, 0, 0.5),
    inset 0 0 15px rgba(255, 0, 127, 0.1);
}

.panel-title {
  font-family: var(--font-header);
  font-size: 1rem;
  letter-spacing: 2px;
  color: var(--neon-cyan);
  text-transform: uppercase;
  border-bottom: 2px solid rgba(0, 240, 255, 0.2);
  padding-bottom: 8px;
  margin-bottom: 8px;
  text-shadow: 0 0 5px rgba(0, 240, 255, 0.5);
}

/* Matrix Center Column */
.center-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* Mission / Mode Bar */
.mission-bar {
  width: 306px;
  max-width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: rgba(161, 0, 255, 0.12);
  border: 1px solid rgba(161, 0, 255, 0.45);
  border-radius: 6px;
  font-size: 0.78rem;
  letter-spacing: 1px;
}

.mission-bar.hidden {
  display: none;
}

.mission-label {
  font-family: var(--font-header);
  color: var(--neon-cyan);
  font-weight: 700;
}

.mission-progress {
  color: var(--neon-amber);
  font-weight: bold;
}

/* AI Agent Neural Feed Bar */
.ai-hud-bar {
  width: 306px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 7px 9px;
  background: rgba(0, 240, 255, 0.08);
  border: 1px solid rgba(0, 240, 255, 0.4);
  border-radius: 6px;
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.14);
  overflow: hidden;
}

.ai-hud-bar.hidden {
  display: none;
}

.live-mode-switch {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  width: 100%;
}

.live-mode-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #aaa;
  font-family: var(--font-header);
  font-size: 0.56rem;
  letter-spacing: 0.3px;
  padding: 4px 2px;
  border-radius: 4px;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.16s ease;
}

.ai-hud-status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-width: 0;
}

.ai-hud-thought {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.68rem;
  color: #cde8f5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-mode-btn:hover {
  border-color: rgba(0, 240, 255, 0.5);
  color: #fff;
}

.live-mode-btn.active[data-live-player="human"] {
  background: rgba(0, 240, 255, 0.18);
  border-color: var(--neon-cyan);
  color: var(--neon-cyan);
  box-shadow: 0 0 8px rgba(0, 240, 255, 0.3);
}

.live-mode-btn.active[data-live-player="ai"] {
  background: rgba(255, 0, 127, 0.2);
  border-color: var(--neon-magenta);
  color: #ff66b2;
  box-shadow: 0 0 8px rgba(255, 0, 127, 0.35);
}

.live-mode-btn.active[data-live-player="ml"] {
  background: rgba(0, 255, 102, 0.16);
  border-color: var(--neon-green);
  color: var(--neon-green);
  box-shadow: 0 0 8px rgba(0, 255, 102, 0.3);
}

.live-mode-btn.active[data-live-player="decision"] {
  background: rgba(255, 170, 0, 0.18);
  border-color: var(--neon-amber);
  color: var(--neon-amber);
  box-shadow: 0 0 8px rgba(255, 170, 0, 0.35);
}

.live-ai-row,
.live-login-row {
  display: flex;
  gap: 5px;
  align-items: center;
}

.live-ai-row.hidden,
.live-login-row.hidden,
.ai-hud-thought.hidden {
  display: none;
}

.live-ai-select {
  font-size: 0.68rem;
  padding: 3px 6px;
}

.ai-hud-model {
  font-family: var(--font-header);
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--neon-cyan);
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-hud-controls {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.ai-hud-status {
  font-size: 0.6rem;
  padding: 2px 5px;
  border-radius: 4px;
  border: 1px solid rgba(0, 255, 102, 0.45);
  color: var(--neon-green);
  background: rgba(0, 255, 102, 0.1);
  letter-spacing: 0.3px;
}

.ai-hud-status.thinking {
  color: var(--neon-amber);
  border-color: rgba(255, 170, 0, 0.55);
  background: rgba(255, 170, 0, 0.12);
}

.ai-hud-status.offline {
  color: var(--neon-purple);
  border-color: rgba(161, 0, 255, 0.55);
  background: rgba(161, 0, 255, 0.14);
}

.ai-mini-btn {
  background: rgba(255, 0, 127, 0.14);
  border: 1px solid rgba(255, 0, 127, 0.5);
  color: #fff;
  font-family: var(--font-header);
  font-size: 0.6rem;
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: all 0.18s ease;
}

.ai-mini-btn:hover {
  background: var(--neon-magenta);
  border-color: var(--neon-magenta);
}

.ai-mini-btn.hidden {
  display: none;
}

.ai-mini-btn.ai-mini-cyan {
  background: rgba(0, 240, 255, 0.14);
  border-color: rgba(0, 240, 255, 0.5);
  color: var(--neon-cyan);
}

.ai-mini-btn.ai-mini-cyan:hover {
  background: var(--neon-cyan);
  border-color: var(--neon-cyan);
  color: var(--bg-dark);
}

.ml-telemetry {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 1px solid rgba(0, 240, 255, 0.18);
  padding-top: 4px;
}

.ml-telemetry.hidden {
  display: none;
}

.ml-weights-strip {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  font-size: 0.62rem;
  letter-spacing: 0.2px;
}

.ml-w-pos {
  color: var(--neon-green);
}

.ml-w-neg {
  color: var(--neon-magenta);
}

.ml-w-zero {
  color: #8899aa;
}

.ml-sparkline {
  width: 100%;
  height: 24px;
  display: block;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(0, 240, 255, 0.16);
  border-radius: 3px;
}

/* ML Learning Curve Panel (docked directly under Hack Meter) */
.ml-corner-graph {
  width: 306px;
  max-width: 100%;
  background: rgba(14, 16, 26, 0.85);
  border: 1px solid rgba(0, 255, 102, 0.42);
  border-radius: 8px;
  padding: 8px 10px;
  box-shadow: 0 0 16px rgba(0, 255, 102, 0.14);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.ml-corner-graph.hidden {
  display: none;
}

.ml-graph-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.ml-graph-title {
  font-family: var(--font-header);
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--neon-green);
  letter-spacing: 0.8px;
}

.ml-graph-meta {
  font-size: 0.64rem;
  color: #cde8f5;
  white-space: nowrap;
}

.ml-graph-canvas {
  width: 100%;
  height: 90px;
  display: block;
  background: rgba(6, 8, 16, 0.88);
  border: 1px solid rgba(0, 255, 102, 0.2);
  border-radius: 5px;
}

.ml-graph-legend {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.64rem;
}

.legend-lines {
  color: var(--neon-green);
}

.legend-avg {
  color: var(--neon-cyan);
}

.legend-eps {
  color: var(--neon-amber);
}

.canvas-container {
  position: relative;
  border: 3px solid var(--neon-cyan);
  border-radius: 8px;
  box-shadow:
    0 0 20px rgba(0, 240, 255, 0.22),
    inset 0 0 20px rgba(0, 240, 255, 0.2);
  background-color: rgba(13, 13, 21, 0.9);
  overflow: hidden;
  transition: border-color 0.25s ease, box-shadow 0.25s ease, background-color 0.25s ease;
}

.canvas-container::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.75);
  pointer-events: none;
  z-index: 2;
}

/* Dynamic Board States */
.canvas-container.state-slowmo {
  border-color: var(--neon-blue);
  background-color: rgba(6, 18, 38, 0.92);
  box-shadow:
    0 0 24px rgba(0, 170, 255, 0.4),
    inset 0 0 28px rgba(0, 170, 255, 0.25);
}

.canvas-container.state-shield {
  border-color: var(--neon-purple);
  box-shadow:
    0 0 28px rgba(161, 0, 255, 0.6),
    inset 0 0 25px rgba(161, 0, 255, 0.35);
}

.canvas-container.state-danger {
  border-color: var(--neon-red);
  animation: danger-border-pulse 0.7s infinite alternate;
}

.canvas-container.state-overclock {
  border-color: var(--neon-amber);
  animation: overclock-border-pulse 0.45s infinite alternate;
}

@keyframes overclock-border-pulse {
  0% {
    box-shadow: 0 0 20px rgba(255, 170, 0, 0.45), inset 0 0 20px rgba(255, 170, 0, 0.25);
  }
  100% {
    box-shadow: 0 0 38px rgba(255, 170, 0, 0.9), inset 0 0 32px rgba(255, 170, 0, 0.45);
  }
}

@keyframes danger-border-pulse {
  0% {
    box-shadow: 0 0 18px rgba(255, 51, 51, 0.35), inset 0 0 18px rgba(255, 51, 51, 0.2);
  }
  100% {
    box-shadow: 0 0 34px rgba(255, 0, 127, 0.8), inset 0 0 28px rgba(255, 51, 51, 0.45);
  }
}

.canvas-container.shake {
  animation: emp-shake 0.32s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes emp-shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-5px, 3px); }
  40% { transform: translate(5px, -3px); }
  60% { transform: translate(-4px, -2px); }
  80% { transform: translate(4px, 2px); }
}

/* Digital Honeycomb Shield Overlay */
.shield-honeycomb {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  opacity: 0;
  transition: opacity 0.25s ease;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='49' viewBox='0 0 28 49'%3E%3Cg fill-rule='evenodd'%3E%3Cg fill='%23a100ff' fill-opacity='0.28'%3E%3Cpath d='M13.99 9.25l13 7.5v15l-13 7.5L1 31.75v-15l12.99-7.5zM3 17.9v12.7l10.99 6.34 11-6.35V17.9l-11-6.34L3 17.9zM0 15l12.98-7.5V0h-2v6.35L0 12.69v2.3zm0 18.5L12.98 41v8h-2v-6.85L0 35.81v-2.3zM15 0v7.5L27.99 15H28v-2.31h-.01L17 6.35V0h-2zm0 49v-8l12.99-7.5H28v2.31h-.01L17 42.15V49h-2z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  box-shadow: inset 0 0 30px rgba(161, 0, 255, 0.45);
}

.canvas-container.state-shield .shield-honeycomb {
  opacity: 1;
}

/* Floating HUD Callout */
.hud-callout {
  position: absolute;
  top: 28%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.85);
  z-index: 15;
  pointer-events: none;
  font-family: var(--font-header);
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: 2px;
  text-transform: uppercase;
  text-align: center;
  color: #fff;
  text-shadow: 0 0 10px var(--neon-cyan), 0 0 20px var(--neon-magenta);
  opacity: 0;
  white-space: nowrap;
}

.hud-callout.show {
  animation: callout-pop 1.15s ease-out forwards;
}

@keyframes callout-pop {
  0% { opacity: 0; transform: translate(-50%, -35%) scale(0.75); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  75% { opacity: 1; transform: translate(-50%, -58%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -72%) scale(0.95); }
}

#matrix {
  display: block;
}

/* Hold & Next Piece Displays */
.piece-display {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.hold-display {
  max-width: 140px;
  margin: 0 auto;
  aspect-ratio: 120 / 100;
}

.next-display {
  max-width: 126px;
  margin: 0 auto;
  aspect-ratio: 120 / 240;
}

.piece-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Hack Meter */
.hack-meter-container {
  width: 306px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hack-meter-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  font-weight: bold;
  letter-spacing: 1px;
}

.hack-energy-val {
  color: var(--neon-magenta);
  text-shadow: 0 0 5px rgba(255, 0, 127, 0.5);
}

.hack-meter-bar-wrapper {
  height: 16px;
  width: 100%;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(0, 240, 255, 0.3);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.8);
}

.hack-meter-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--neon-cyan), var(--neon-magenta));
  box-shadow: 0 0 10px rgba(255, 0, 127, 0.8);
  transition: width 0.15s ease-out;
  position: relative;
}

.hack-meter-bar::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.3) 50%,
    rgba(255, 255, 255, 0) 100%
  );
  animation: bar-shine 2s infinite linear;
}

@keyframes bar-shine {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* Slotted Hacks / Powerups List */
.hacks-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hack-item {
  width: 100%;
  text-align: left;
  color: #fff;
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s ease;
  position: relative;
}

.hack-item[aria-disabled="true"] {
  opacity: 0.72;
}

.hack-item:focus-visible {
  outline: 2px solid var(--neon-cyan);
  outline-offset: 2px;
}

.hack-item:hover {
  background: rgba(0, 240, 255, 0.05);
  border-color: rgba(0, 240, 255, 0.25);
  transform: translateX(4px);
}

.hack-item.ready {
  opacity: 1;
  background: rgba(0, 240, 255, 0.09);
  border-color: var(--neon-cyan);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.18);
}

.hack-item.ready:hover {
  background: rgba(255, 0, 127, 0.1);
  border-color: var(--neon-magenta);
  box-shadow: 0 0 15px rgba(255, 0, 127, 0.28);
}

.hack-item.active-now {
  opacity: 1;
  background: rgba(255, 170, 0, 0.14);
  border-color: var(--neon-amber);
  box-shadow: 0 0 15px rgba(255, 170, 0, 0.55);
  animation: pulse-active 0.8s infinite alternate;
}

.hack-item.just-triggered {
  opacity: 1;
  background: rgba(0, 240, 255, 0.25);
  border-color: #fff;
  box-shadow: 0 0 18px var(--neon-cyan);
}

@keyframes pulse-active {
  0% { opacity: 0.85; }
  100% { opacity: 1; }
}

.hack-key {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  font-size: 0.75rem;
  font-family: var(--font-header);
  color: var(--neon-cyan);
  flex-shrink: 0;
}

.hack-info {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  min-width: 0;
}

.hack-name {
  font-size: 0.82rem;
  font-weight: bold;
  letter-spacing: 0.5px;
}

.hack-cost {
  font-size: 0.68rem;
  color: var(--neon-magenta);
}

.hack-timer {
  font-family: var(--font-header);
  font-size: 0.72rem;
  color: var(--neon-amber);
  min-width: 26px;
  text-align: right;
}

.hack-desc-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  right: 0;
  background: rgba(11, 11, 20, 0.97);
  border: 1px solid var(--neon-purple);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.72rem;
  line-height: 1.4;
  color: #e2e2f0;
  z-index: 60;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.75);
  pointer-events: none;
}

.hack-item:hover .hack-desc-tooltip,
.hack-item:focus-visible .hack-desc-tooltip {
  display: block;
}

/* Stats panel */
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.stat-label {
  font-size: 0.82rem;
  color: #999;
  text-transform: uppercase;
}

.stat-val {
  font-family: var(--font-header);
  font-size: 1.2rem;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.2);
}

.stat-val.highlight {
  color: var(--neon-cyan);
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.4);
}

.stat-val.player-val {
  font-size: 0.86rem;
  letter-spacing: 0.8px;
}

.stat-val.player-val-human {
  color: var(--neon-cyan);
  text-shadow: 0 0 8px rgba(0, 240, 255, 0.45);
}

.stat-val.player-val-ai {
  color: #ff66b2;
  text-shadow: 0 0 8px rgba(255, 0, 127, 0.45);
}

.stat-val.player-val-ml {
  color: var(--neon-green);
  text-shadow: 0 0 8px rgba(0, 255, 102, 0.45);
}

.stat-val.player-val-decision {
  color: var(--neon-amber);
  text-shadow: 0 0 8px rgba(255, 170, 0, 0.45);
}

.stat-val.glitch-bump {
  animation: stat-glitch 0.22s linear;
}

@keyframes stat-glitch {
  0% { transform: translate(0, 0); text-shadow: -2px 0 var(--neon-magenta), 2px 0 var(--neon-cyan); }
  50% { transform: translate(1px, -1px); text-shadow: 2px 0 var(--neon-magenta), -2px 0 var(--neon-cyan); }
  100% { transform: translate(0, 0); text-shadow: 0 0 10px rgba(0, 240, 255, 0.4); }
}

/* High Scores list */
.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.leaderboard-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 4px;
}

.leaderboard-rank {
  color: var(--neon-magenta);
  font-weight: bold;
  margin-right: 4px;
}

/* Settings and Bottom Controls */
.controls-panel {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.keymap-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 24px;
  font-size: 0.78rem;
  color: #888;
  width: 100%;
  max-width: 480px;
}

.keymap-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.keymap-label {
  color: #aaa;
}

.keymap-val {
  color: var(--neon-cyan);
  font-weight: bold;
  white-space: nowrap;
}

.action-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  padding: 9px 16px;
  font-family: var(--font-header);
  font-size: 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 1px;
}

.action-btn:hover,
.action-btn:focus-visible {
  background: var(--neon-cyan);
  color: var(--bg-dark);
  border-color: var(--neon-cyan);
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.4);
  outline: none;
}

.action-btn.primary {
  background: var(--neon-magenta);
  border-color: var(--neon-magenta);
  font-weight: bold;
}

.action-btn.primary:hover,
.action-btn.primary:focus-visible {
  background: #ff3399;
  color: #fff;
  border-color: #ff3399;
  box-shadow: 0 0 15px rgba(255, 0, 127, 0.55);
}

.action-btn.hidden {
  display: none;
}

.footer-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.toggle-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #999;
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.toggle-btn:hover {
  border-color: rgba(0, 240, 255, 0.4);
  color: #ddd;
}

.toggle-btn.active {
  color: var(--neon-cyan);
  border-color: var(--neon-cyan);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.2);
}

/* Game Modal / Overlay */
.overlay-screen {
  position: absolute;
  inset: 0;
  background: rgba(11, 11, 18, 0.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  gap: 14px;
  text-align: center;
  padding: 18px;
}

.overlay-screen.hidden {
  display: none;
}

.overlay-title {
  font-family: var(--font-header);
  font-size: 1.55rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--neon-magenta);
  text-shadow: 0 0 15px rgba(255, 0, 127, 0.6);
}

.overlay-title.victory {
  color: var(--neon-green);
  text-shadow: 0 0 15px rgba(0, 255, 102, 0.6);
}

.overlay-text {
  font-size: 0.82rem;
  color: #ccc;
  max-width: 260px;
  line-height: 1.5;
}

.overlay-sub {
  font-size: 0.72rem;
  color: #777;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 210px;
}

.gameover-score-box {
  font-size: 0.95rem;
  color: #ddd;
}

.final-score-val {
  font-family: var(--font-header);
  color: var(--neon-magenta);
  font-weight: bold;
  font-size: 1.15rem;
}

/* Player & Gemini AI Config Selectors */
.player-selector {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  width: 100%;
}

.player-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 0, 127, 0.3);
  color: #bbb;
  font-family: var(--font-header);
  font-size: 0.56rem;
  letter-spacing: 0.4px;
  padding: 6px 4px;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.decision-config {
  border-color: rgba(255, 170, 0, 0.42);
  background: rgba(255, 170, 0, 0.06);
}

.player-btn.active {
  background: rgba(255, 0, 127, 0.18);
  border-color: var(--neon-magenta);
  color: #fff;
  box-shadow: 0 0 12px rgba(255, 0, 127, 0.35);
}

.ai-config {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 9px 10px;
  background: rgba(0, 240, 255, 0.05);
  border: 1px solid rgba(0, 240, 255, 0.28);
  border-radius: 7px;
  text-align: left;
}

.ai-config.hidden {
  display: none;
}

.ai-config-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ai-label {
  font-family: var(--font-header);
  font-size: 0.62rem;
  color: var(--neon-cyan);
  letter-spacing: 1px;
  flex-shrink: 0;
}

.ai-select,
.ai-input {
  width: 100%;
  background: rgba(11, 11, 20, 0.92);
  border: 1px solid rgba(0, 240, 255, 0.32);
  border-radius: 4px;
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 4px 7px;
  outline: none;
}

.ai-select:focus,
.ai-input:focus {
  border-color: var(--neon-magenta);
  box-shadow: 0 0 8px rgba(255, 0, 127, 0.35);
}

.ai-key-row {
  display: flex;
  gap: 5px;
  align-items: center;
}

.ai-key-hint {
  font-size: 0.64rem;
  color: #8fb8c9;
  line-height: 1.3;
}

/* AI Mode Login Gate */
.ai-login-box,
.ai-controls-box {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
}

.ai-login-box.hidden,
.ai-controls-box.hidden,
.ai-session-bar.hidden,
.ai-login-error.hidden {
  display: none;
}

.ai-login-title {
  font-family: var(--font-header);
  font-size: 0.68rem;
  color: var(--neon-amber);
  letter-spacing: 1px;
  text-align: center;
}

.ai-login-submit {
  width: 100%;
  padding: 6px 8px;
  font-size: 0.66rem;
}

.ai-login-error {
  font-size: 0.66rem;
  color: var(--neon-red);
  text-align: center;
}

.ai-session-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 5px;
  border-bottom: 1px solid rgba(0, 240, 255, 0.2);
}

.ai-session-user {
  font-family: var(--font-header);
  font-size: 0.64rem;
  color: var(--neon-green);
  letter-spacing: 0.6px;
}

.action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.4);
}

.ml-config {
  border-color: rgba(0, 255, 102, 0.35);
  background: rgba(0, 255, 102, 0.05);
}

.ml-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.ml-boot-stats {
  font-size: 0.62rem;
  color: var(--neon-green);
  font-weight: bold;
  white-space: nowrap;
}

.ml-toggle-row {
  display: flex;
  align-items: center;
}

.ml-checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  color: #cde8f5;
  cursor: pointer;
}

.ml-checkbox-label input {
  accent-color: var(--neon-green);
  cursor: pointer;
}

.ml-btn-row {
  display: flex;
  gap: 6px;
}

.ml-btn-row .ai-mini-btn {
  flex: 1;
  padding: 5px 6px;
}

/* Mode & Campaign Selectors */
.mode-selector {
  display: flex;
  gap: 6px;
  width: 100%;
  justify-content: center;
}

.mode-btn,
.lvl-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(0, 240, 255, 0.25);
  color: #aaa;
  font-family: var(--font-header);
  font-size: 0.62rem;
  letter-spacing: 0.5px;
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-btn.active,
.lvl-btn.active {
  background: rgba(0, 240, 255, 0.16);
  border-color: var(--neon-cyan);
  color: var(--neon-cyan);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.25);
}

.campaign-levels {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.campaign-levels.hidden {
  display: none;
}

.mode-desc {
  font-size: 0.74rem;
  color: #a8d8e6;
  max-width: 250px;
  min-height: 36px;
  line-height: 1.4;
}

/* Mobile Touch Controls */
.touch-controls {
  display: none;
  flex-direction: column;
  gap: 8px;
  width: 306px;
  max-width: 100%;
}

.touch-row {
  display: flex;
  gap: 8px;
}

.touch-btn {
  flex: 1;
  background: rgba(26, 26, 38, 0.85);
  border: 1px solid rgba(0, 240, 255, 0.35);
  border-radius: 8px;
  color: var(--neon-cyan);
  font-family: var(--font-header);
  font-size: 0.85rem;
  padding: 12px 6px;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.touch-btn:active {
  background: rgba(0, 240, 255, 0.25);
  border-color: #fff;
}

.touch-btn-accent {
  border-color: var(--neon-magenta);
  color: var(--neon-magenta);
}

/* Responsive adjustments */
@media (max-width: 900px) {
  .app-container {
    max-width: 520px;
    padding: 10px 14px;
    gap: 10px;
  }

  h1 {
    font-size: 1.55rem;
    letter-spacing: 3px;
  }

  .subtitle {
    font-size: 0.65rem;
    letter-spacing: 2px;
    margin-top: 2px;
  }

  .game-layout {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .center-column {
    order: 1;
    gap: 10px;
  }

  #matrix {
    height: min(56vh, 480px);
    width: auto;
    aspect-ratio: 1 / 2;
  }

  .left-panel {
    order: 2;
  }

  .right-panel {
    order: 3;
  }

  .touch-controls {
    display: flex;
    gap: 6px;
  }

  .touch-btn {
    padding: 10px 6px;
    font-size: 0.8rem;
  }

  .controls-panel {
    flex-direction: column;
    align-items: stretch;
  }

  .keymap-panel {
    grid-template-columns: 1fr;
    max-width: 100%;
  }

  .footer-toggles {
    justify-content: center;
  }
}
