:root {
  --bg-deep: #040711;
  --bg-panel: #091021;
  --grid-line: rgba(56, 189, 248, 0.14);
  --grid-border: rgba(56, 189, 248, 0.42);
  --red-core: #ff3b30;
  --red-glow: rgba(255, 59, 48, 0.65);
  --red-soft: #ff8a65;
  --blue-core: #0ea5e9;
  --blue-glow: rgba(14, 165, 233, 0.65);
  --blue-soft: #38bdf8;
  --gold: #fbbf24;
  --gold-glow: rgba(251, 191, 36, 0.8);
  --valid-step: rgba(52, 211, 153, 0.25);
  --valid-step-border: #34d399;
  --valid-jump: rgba(251, 191, 36, 0.26);
  --valid-jump-border: #fbbf24;
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --cell-size: clamp(32px, min(calc((100vw - 80px) / 11), calc((100dvh - 210px) / 7)), 68px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 50%, rgba(255, 59, 48, 0.2), transparent 40%),
    radial-gradient(circle at 80% 50%, rgba(14, 165, 233, 0.2), transparent 40%),
    radial-gradient(circle at 50% 50%, rgba(99, 102, 241, 0.12), transparent 55%),
    var(--bg-deep);
  color: var(--text-main);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 8px 16px;
  overflow-x: hidden;
}

.app {
  width: 100%;
  max-width: 940px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* HUD */
.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.92), rgba(7, 11, 24, 0.94));
  border: 1px solid var(--grid-border);
  border-radius: 14px;
  padding: 8px 16px;
  box-shadow:
    0 0 24px rgba(14, 165, 233, 0.12),
    0 10px 32px rgba(0, 0, 0, 0.55);
  position: relative;
}

.hud::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 14px;
  padding: 1px;
  background: linear-gradient(90deg, rgba(255, 59, 48, 0.45), rgba(56, 189, 248, 0.15) 50%, rgba(14, 165, 233, 0.45));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.player-card {
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0.62;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.player-card.active-turn {
  opacity: 1;
  transform: translateY(-1px);
}

.player-right {
  justify-content: flex-end;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

.avatar-red {
  background: radial-gradient(circle at 30% 30%, #ff8a65, #dc2626 65%, #7f1d1d);
  border: 2px solid var(--red-soft);
  box-shadow: 0 0 18px var(--red-glow), inset 0 0 8px rgba(255, 255, 255, 0.3);
}

.avatar-blue {
  background: radial-gradient(circle at 30% 30%, #7dd3fc, #0284c7 65%, #0c4a6e);
  border: 2px solid var(--blue-soft);
  box-shadow: 0 0 18px var(--blue-glow), inset 0 0 8px rgba(255, 255, 255, 0.3);
}

.player-meta {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

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

.player-name {
  font-size: 0.92rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.side-tag {
  font-size: 0.62rem;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 4px;
  padding: 1px 5px;
}

.node-pips {
  display: flex;
  gap: 6px;
}

.pip {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.pip.red {
  background: radial-gradient(circle at 35% 35%, #fca5a5, var(--red-core));
  box-shadow: 0 0 8px var(--red-glow);
}

.pip.blue {
  background: radial-gradient(circle at 35% 35%, #bae6fd, var(--blue-core));
  box-shadow: 0 0 8px var(--blue-glow);
}

.pip.lost {
  opacity: 0.16;
  box-shadow: none;
  transform: scale(0.75);
}

.hud-center {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.game-title {
  font-size: 1.05rem;
  letter-spacing: 0.22em;
  font-weight: 900;
  background: linear-gradient(90deg, #fca5a5, #f8fafc 50%, #7dd3fc);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 20px rgba(56, 189, 248, 0.25);
}

.turn-pill {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 14px;
  border-radius: 999px;
  border: 1px solid var(--red-soft);
  background: rgba(255, 59, 48, 0.18);
  color: #fecaca;
  box-shadow: 0 0 14px rgba(255, 59, 48, 0.25);
}

.turn-pill.ai-turn {
  border-color: var(--blue-soft);
  background: rgba(14, 165, 233, 0.18);
  color: #bae6fd;
  box-shadow: 0 0 14px rgba(14, 165, 233, 0.25);
}

/* Board */
.arena {
  display: flex;
  justify-content: center;
}

.board-frame {
  position: relative;
  background:
    radial-gradient(circle at 22% 50%, rgba(255, 59, 48, 0.12), transparent 36%),
    radial-gradient(circle at 78% 50%, rgba(14, 165, 233, 0.12), transparent 36%),
    rgba(6, 10, 22, 0.94);
  border: 1px solid var(--grid-border);
  border-radius: 16px;
  padding: 8px 14px 10px;
  box-shadow:
    inset 0 0 50px rgba(14, 165, 233, 0.1),
    0 18px 50px rgba(0, 0, 0, 0.65);
}

.board-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.64rem;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 5px;
  padding: 0 4px;
}

.zone-red { color: #fca5a5; }
.zone-blue { color: #7dd3fc; }

.board-wrapper {
  position: relative;
  display: inline-block;
  overflow: hidden;
  border-radius: 8px;
}

/* Subtle energy bridge in the middle of the board */
.board-wrapper::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 36.36%;
  width: 27.27%;
  background: linear-gradient(
    90deg,
    rgba(255, 59, 48, 0.04),
    rgba(139, 92, 246, 0.08) 50%,
    rgba(14, 165, 233, 0.04)
  );
  pointer-events: none;
  z-index: 0;
}

.tether-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.tether-flow {
  stroke-dasharray: 6 6;
  animation: tetherFlow 1.4s linear infinite;
}

@keyframes tetherFlow {
  from { stroke-dashoffset: 24; }
  to { stroke-dashoffset: 0; }
}

.board {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(11, var(--cell-size));
  grid-template-rows: repeat(7, var(--cell-size));
  border: 1px solid rgba(56, 189, 248, 0.4);
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: var(--cell-size) var(--cell-size);
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  position: relative;
  display: grid;
  place-items: center;
  cursor: default;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

.cell.back-edge-left {
  background: rgba(255, 59, 48, 0.06);
  border-right: 1px dashed rgba(255, 122, 89, 0.3);
}

.cell.back-edge-right {
  background: rgba(14, 165, 233, 0.06);
  border-left: 1px dashed rgba(56, 189, 248, 0.3);
}

.cell.neutral-col {
  background: rgba(148, 163, 184, 0.025);
}

/* Valid move highlights */
.cell.valid-step {
  cursor: pointer;
  background: var(--valid-step);
  box-shadow: inset 0 0 14px rgba(52, 211, 153, 0.35), inset 0 0 0 2px var(--valid-step-border);
}

.cell.valid-step::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--valid-step-border);
  box-shadow: 0 0 12px var(--valid-step-border);
  animation: pulseDot 1.2s ease-in-out infinite;
  z-index: 4;
  pointer-events: none;
}

.cell.valid-jump {
  cursor: pointer;
  background: var(--valid-jump);
  box-shadow: inset 0 0 16px rgba(251, 191, 36, 0.4), inset 0 0 0 2px var(--valid-jump-border);
}

.cell.valid-jump::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2.5px solid var(--valid-jump-border);
  box-shadow: 0 0 14px var(--gold-glow);
  animation: pulseDot 0.9s ease-in-out infinite;
  z-index: 4;
  pointer-events: none;
}

@keyframes pulseDot {
  0%, 100% { transform: scale(0.9); opacity: 0.75; }
  50% { transform: scale(1.15); opacity: 1; }
}

.cell.jump-target {
  background: rgba(251, 191, 36, 0.14);
}

.cell.blocked-prev {
  cursor: not-allowed;
  background: rgba(239, 68, 68, 0.12);
  outline: 1.5px dashed rgba(248, 113, 113, 0.65);
  outline-offset: -3px;
}

.cell.blocked-prev::after {
  content: "✕";
  position: absolute;
  font-size: 0.95rem;
  font-weight: 800;
  color: rgba(248, 113, 113, 0.78);
  text-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
  pointer-events: none;
  z-index: 4;
}

/* Cores (Multi-ring reactor look) */
.core {
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 2;
}

.core::before {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.45);
  animation: spin 14s linear infinite;
}

.core::after {
  content: "";
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.16);
  animation: corePulse 2.4s ease-in-out infinite;
}

@keyframes corePulse {
  0%, 100% { transform: scale(0.96); opacity: 0.45; }
  50% { transform: scale(1.06); opacity: 0.9; }
}

.core-player {
  background: radial-gradient(circle at 35% 35%, #ff9e80, #ef4444 52%, #7f1d1d 92%);
  border: 2px solid #fecaca;
  box-shadow:
    0 0 26px var(--red-glow),
    0 0 48px rgba(255, 59, 48, 0.35),
    inset 0 0 14px rgba(255, 255, 255, 0.45);
}

.core-ai {
  background: radial-gradient(circle at 35% 35%, #bae6fd, #0ea5e9 52%, #0c4a6e 92%);
  border: 2px solid #e0f2fe;
  box-shadow:
    0 0 26px var(--blue-glow),
    0 0 48px rgba(14, 165, 233, 0.35),
    inset 0 0 14px rgba(255, 255, 255, 0.45);
}

.core-label {
  font-size: 0.56rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.85);
}

.core.destroyed {
  opacity: 0;
  transform: scale(0.2);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.core.threatened::after {
  inset: -14px;
  border: 2.5px solid #fbbf24;
  box-shadow: 0 0 20px rgba(251, 191, 36, 0.85);
  animation: threatPulse 0.75s ease-in-out infinite;
}

@keyframes threatPulse {
  0%, 100% { transform: scale(0.95); opacity: 0.65; }
  50% { transform: scale(1.12); opacity: 1; }
}

/* Neutral Energy Pads */
.energy-pad {
  position: absolute;
  width: 56%;
  height: 56%;
  border-radius: 10px;
  transform: rotate(45deg);
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 1;
  animation: padFloat 2.2s ease-in-out infinite;
}

.energy-pad span {
  transform: rotate(-45deg);
  font-size: 0.75rem;
  font-weight: 900;
}

.pad-shield {
  background: rgba(34, 211, 238, 0.18);
  border: 1.5px solid #22d3ee;
  box-shadow: 0 0 14px rgba(34, 211, 238, 0.55);
  color: #a5f3fc;
}

.pad-overcharge {
  background: rgba(251, 191, 36, 0.18);
  border: 1.5px solid #fbbf24;
  box-shadow: 0 0 14px rgba(251, 191, 36, 0.55);
  color: #fef08a;
}

@keyframes padFloat {
  0%, 100% { transform: rotate(45deg) scale(0.95); opacity: 0.82; }
  50% { transform: rotate(45deg) scale(1.06); opacity: 1; }
}

.piece.shielded {
  box-shadow:
    0 0 0 3px rgba(34, 211, 238, 0.85),
    0 0 18px rgba(34, 211, 238, 0.75);
}

.board-frame.shake {
  animation: boardShake 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes boardShake {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(-6px, 4px); }
  30% { transform: translate(6px, -4px); }
  45% { transform: translate(-5px, -3px); }
  60% { transform: translate(4px, 3px); }
  75% { transform: translate(-2px, 1px); }
}

/* Circles (Multi-layered neon nodes) */
.piece {
  width: 70%;
  height: 70%;
  border-radius: 50%;
  position: relative;
  display: grid;
  place-items: center;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
  z-index: 3;
}

.piece::before {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.28);
  pointer-events: none;
}

.piece.selectable {
  cursor: pointer;
}

.piece.selectable:hover {
  transform: scale(1.1);
}

.piece-player {
  background: radial-gradient(circle at 32% 32%, #fdba74, #ef4444 58%, #7f1d1d 95%);
  border: 2px solid #fed7aa;
  box-shadow:
    0 0 14px var(--red-glow),
    inset 0 0 8px rgba(255, 255, 255, 0.35);
}

.piece-ai {
  background: radial-gradient(circle at 32% 32%, #a5f3fc, #0284c7 58%, #082f49 95%);
  border: 2px solid #bae6fd;
  box-shadow:
    0 0 14px var(--blue-glow),
    inset 0 0 8px rgba(255, 255, 255, 0.35);
}

.piece.selected {
  transform: scale(1.14);
  box-shadow:
    0 0 0 3px #ffffff,
    0 0 24px rgba(255, 255, 255, 0.85);
}

.piece.capturing-core {
  transform: scale(1.18);
  border-color: #ffffff;
  box-shadow:
    0 0 0 3px rgba(251, 191, 36, 0.9),
    0 0 28px #ffffff,
    0 0 46px var(--gold-glow);
  z-index: 6;
}

/* Promoted (Direction Changed / King) */
.piece.promoted {
  border: 2.5px solid var(--gold);
  box-shadow:
    0 0 18px var(--gold-glow),
    inset 0 0 10px rgba(254, 240, 138, 0.45);
}

.piece.promoted::before {
  border-color: rgba(254, 240, 138, 0.65);
}

.piece.promoted::after {
  content: "⇄";
  font-size: 0.95rem;
  font-weight: 900;
  color: #fef9c3;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
}

.piece.last-moved {
  outline: 2px solid rgba(255, 255, 255, 0.55);
  outline-offset: 3px;
}

/* FX Layer (Shockwaves & Sparks) */
.fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  overflow: hidden;
}

.fx-ring {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0.2);
  opacity: 0.95;
  animation: fxRingExpand 0.52s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes fxRingExpand {
  to {
    transform: translate(-50%, -50%) scale(2.2);
    opacity: 0;
  }
}

.fx-spark {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: fxSparkFly 0.55s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes fxSparkFly {
  to {
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.15);
    opacity: 0;
  }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Footer Controls */
.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.92), rgba(7, 11, 24, 0.94));
  border: 1px solid var(--grid-border);
  border-radius: 12px;
  padding: 8px 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

.status-bar {
  font-size: 0.85rem;
  color: var(--text-main);
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 6px 11px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: transform 0.1s ease, filter 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover {
  filter: brightness(1.14);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  color: #ffffff;
  box-shadow: 0 0 14px rgba(14, 165, 233, 0.35);
}

.btn-secondary {
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(148, 163, 184, 0.35);
  color: var(--text-main);
}

.btn-accent {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #0f172a;
  box-shadow: 0 0 14px rgba(245, 158, 11, 0.45);
}

.btn.hidden {
  display: none;
}

.difficulty-select {
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 18, 0.78);
  backdrop-filter: blur(5px);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  width: 100%;
  max-width: 480px;
  background: #0f172a;
  border: 1px solid var(--grid-border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-header h2 {
  font-size: 1.1rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-body ul {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.9rem;
  line-height: 1.45;
  color: #cbd5e1;
}

.gameover-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.gameover-card h2 {
  font-size: 1.5rem;
}

.gameover-card p {
  color: #cbd5e1;
  font-size: 0.95rem;
}

@media (max-width: 640px) {
  .hud {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
  }
  .hud-center {
    grid-column: 1 / -1;
    order: -1;
  }
  .controls {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }
  .btn-group {
    justify-content: center;
  }
  .board-labels {
    display: none;
  }
}
