:root {
  --bg: #0a0a0f;
  --surface: #13131c;
  --surface2: #1c1c2e;
  --border: #2a2a40;
  --accent: #e8c547;
  --accent2: #ff6b35;
  --blue: #4fc3f7;
  --green: #69f0ae;
  --red: #ff5252;
  --text: #e8e8f0;
  --text2: #8888aa;
  --white-piece: #f0f0f0;
  --black-piece: #1a1a2e;
  --pruned: rgba(255, 82, 82, 0.25);
  --evaluated: rgba(105, 240, 174, 0.15);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Background grid pattern */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(232,197,71,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(232,197,71,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
}

/* ─── LANDING SCREEN ─── */
#landing {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: opacity 0.6s ease, transform 0.6s ease;
}
#landing.hide {
  opacity: 0;
  transform: scale(1.04);
  pointer-events: none;
}
/* Animated grid bg */
#landing::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(232,197,71,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(232,197,71,0.05) 1px, transparent 1px);
  background-size: 60px 60px;
  animation: gridPan 20s linear infinite;
}
@keyframes gridPan {
  from { background-position: 0 0; }
  to   { background-position: 60px 60px; }
}

/* Glow blob */
#landing::after {
  content: '';
  position: absolute;
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(232,197,71,0.08) 0%, transparent 70%);
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  animation: blobPulse 4s ease-in-out infinite;
}
@keyframes blobPulse {
  0%,100% { transform: translate(-50%,-50%) scale(1); }
  50%      { transform: translate(-50%,-50%) scale(1.15); }
}

.landing-inner {
  position: relative;
  z-index: 2;
  text-align: center;
  max-width: 560px;
  padding: 0 24px;
}

/* Mini board preview */
.mini-board {
  display: grid;
  grid-template-columns: repeat(6,1fr);
  gap: 5px;
  width: 160px;
  margin: 0 auto 36px;
  animation: boardFloat 3s ease-in-out infinite;
}
@keyframes boardFloat {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}
.mini-cell {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: rgba(255,255,255,0.03);
}
.mini-cell.b { background: radial-gradient(circle at 35% 35%, #3a3a5c, #0a0a1a); border-color: var(--accent); box-shadow: 0 0 8px rgba(232,197,71,0.3); }
.mini-cell.w { background: radial-gradient(circle at 35% 35%, #ffffff, #c8c8c8); border-color: rgba(255,255,255,0.4); box-shadow: 0 0 6px rgba(255,255,255,0.2); }

/* Title */
.landing-title {
  font-family: 'Bebas Neue', cursive;
  font-size: clamp(5rem, 16vw, 9rem);
  line-height: 0.9;
  letter-spacing: 0.05em;
  color: var(--accent);
  text-shadow: 0 0 60px rgba(232,197,71,0.25);
  margin-bottom: 8px;
  animation: titleIn 0.8s cubic-bezier(0.16,1,0.3,1) both;
}
@keyframes titleIn {
  from { opacity:0; transform: translateY(30px); }
  to   { opacity:1; transform: translateY(0); }
}

.landing-tagline {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  letter-spacing: 0.25em;
  color: var(--text2);
  text-transform: uppercase;
  margin-bottom: 48px;
  animation: titleIn 0.8s 0.1s cubic-bezier(0.16,1,0.3,1) both;
}

/* Feature pills */
.landing-features {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 48px;
  animation: titleIn 0.8s 0.2s cubic-bezier(0.16,1,0.3,1) both;
}
.feat-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.72rem;
  font-family: 'IBM Plex Mono', monospace;
  color: var(--text2);
  white-space: nowrap;
}
.feat-pill.hot { border-color: rgba(232,197,71,0.4); color: var(--accent); background: rgba(232,197,71,0.06); }

/* Enter button */
.landing-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  padding: 16px 40px;
  font-family: 'Bebas Neue', cursive;
  font-size: 1.4rem;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: all 0.2s;
  animation: titleIn 0.8s 0.3s cubic-bezier(0.16,1,0.3,1) both;
  box-shadow: 0 8px 32px rgba(232,197,71,0.25);
}
.landing-btn:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 12px 40px rgba(232,197,71,0.4);
  background: #f5d06e;
}
.landing-btn:active { transform: scale(0.98); }
.landing-btn-arrow { font-size: 1.2rem; transition: transform 0.2s; }
.landing-btn:hover .landing-btn-arrow { transform: translateX(4px); }

/* Bottom info */
.landing-bottom {
  position: absolute;
  bottom: 28px;
  left: 0; right: 0;
  text-align: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  color: rgba(136,136,170,0.4);
}

/* Floating decorative pieces */
.deco-pieces { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.deco-piece {
  position: absolute;
  border-radius: 50%;
  opacity: 0.06;
  animation: floatDeco linear infinite;
}
@keyframes floatDeco {
  from { transform: translateY(110vh) rotate(0deg); opacity: 0; }
  10%  { opacity: 0.06; }
  90%  { opacity: 0.06; }
  to   { transform: translateY(-10vh) rotate(360deg); opacity: 0; }
}

/* ─── HEADER ─── */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,10,15,0.8);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-family: 'Bebas Neue', cursive;
  font-size: 2.2rem;
  letter-spacing: 0.1em;
  color: var(--accent);
  text-shadow: 0 0 30px rgba(232,197,71,0.4);
}
.logo span { color: var(--text2); font-size: 0.9rem; font-family: 'IBM Plex Mono', monospace; display: block; margin-top: -6px; letter-spacing: 0.2em; }

.header-stats {
  display: flex;
  gap: 24px;
}
.stat-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 14px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  color: var(--text2);
}
.stat-chip strong { color: var(--text); display: block; font-size: 1rem; }

/* ─── MAIN LAYOUT ─── */
.app {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  gap: 24px;
  padding: 24px 32px;
  max-width: 1400px;
  margin: 0 auto;
}

/* ─── PANELS ─── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.panel-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  color: var(--text2);
  text-transform: uppercase;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ─── CONTROLS ─── */
.control-group {
  margin-bottom: 20px;
}

.control-label {
  font-size: 0.75rem;
  color: var(--text2);
  margin-bottom: 8px;
  font-family: 'IBM Plex Mono', monospace;
}

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

.btn {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: 'IBM Plex Sans', sans-serif;
  transition: all 0.15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.active { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 700; }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.danger:hover { background: var(--red); color: white; }

.range-container {
  display: flex;
  align-items: center;
  gap: 12px;
}
input[type=range] {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}
.range-val {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1rem;
  color: var(--accent);
  font-weight: 700;
  min-width: 24px;
  text-align: center;
}

/* ─── NODE COUNTER ─── */
.node-counters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}
.node-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}
.node-card .label {
  font-size: 0.65rem;
  font-family: 'IBM Plex Mono', monospace;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.node-card .value {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 4px;
}
.node-card.minimax .value { color: var(--blue); }
.node-card.alphabeta .value { color: var(--green); }
.savings-bar {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}
.savings-bar .label { font-size: 0.65rem; font-family: 'IBM Plex Mono', monospace; color: var(--text2); }
.savings-bar .pct { font-size: 2rem; font-weight: 700; font-family: 'IBM Plex Mono', monospace; color: var(--green); }
.progress-bar {
  margin-top: 8px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--green));
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* ─── TURN INDICATOR ─── */
.turn-indicator {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.turn-piece {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 3px solid transparent;
  flex-shrink: 0;
  transition: all 0.3s;
}
.turn-piece.white { background: var(--white-piece); border-color: rgba(240,240,240,0.3); box-shadow: 0 0 16px rgba(240,240,240,0.3); }
.turn-piece.black { background: var(--black-piece); border-color: var(--accent); box-shadow: 0 0 16px rgba(232,197,71,0.4); }
.turn-info { flex: 1; }
.turn-name { font-weight: 700; font-size: 0.9rem; }
.turn-sub { font-size: 0.75rem; color: var(--text2); font-family: 'IBM Plex Mono', monospace; }

/* ─── STATUS BADGE ─── */
.status-badge {
  text-align: center;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-weight: 700;
  font-size: 0.85rem;
  border: 1px solid;
  transition: all 0.3s;
}
.status-badge.playing { background: rgba(79,195,247,0.1); border-color: var(--blue); color: var(--blue); }
.status-badge.win { background: rgba(105,240,174,0.15); border-color: var(--green); color: var(--green); animation: pulse 1s infinite; }
.status-badge.lose { background: rgba(255,82,82,0.1); border-color: var(--red); color: var(--red); }
.status-badge.draw { background: rgba(232,197,71,0.1); border-color: var(--accent); color: var(--accent); }

@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(105,240,174,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(105,240,174,0); }
}

/* ─── GAME BOARD AREA ─── */
.game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.phase-indicator {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 24px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85rem;
  color: var(--text2);
  text-align: center;
  width: 100%;
}
.phase-indicator .phase-name {
  font-size: 1rem;
  color: var(--accent);
  font-weight: 700;
}

/* ─── PENTAGO BOARD ─── */
.board-wrapper {
  position: relative;
}

.board {
  display: grid;
  grid-template-columns: 1fr 16px 1fr;
  grid-template-rows: 1fr 16px 1fr;
  gap: 0;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  position: relative;
}

.board-divider-v {
  grid-column: 2;
  grid-row: 1 / -1;
  background: var(--border);
  border-radius: 2px;
}
.board-divider-h {
  grid-row: 2;
  grid-column: 1 / -1;
  background: var(--border);
  border-radius: 2px;
}

.quadrant-wrapper {
  position: relative;
}

.quadrant {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 8px;
  background: var(--surface2);
  border-radius: 10px;
  border: 1px solid var(--border);
  transition: all 0.3s;
}
.quadrant:hover { border-color: rgba(232,197,71,0.3); }
.quadrant.rotating {
  animation: rotateQuadrant 0.5s ease-in-out;
}
@keyframes rotateQuadrant {
  0% { transform: rotate(0deg); }
  30% { transform: scale(0.95); }
  60% { transform: rotate(var(--rot-deg)); }
  100% { transform: rotate(var(--rot-deg)) scale(1); }
}
.quadrant.highlight-quadrant {
  border-color: var(--accent);
  box-shadow: 0 0 20px rgba(232,197,71,0.2);
}

/* ─── CELLS ─── */
.cell {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: rgba(255,255,255,0.03);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  position: relative;
}
.cell:hover:not(.occupied) {
  border-color: var(--accent);
  background: rgba(232,197,71,0.1);
}
.cell.occupied { cursor: default; }
.cell.winning {
  animation: winPulse 0.8s infinite alternate;
}
@keyframes winPulse {
  from { box-shadow: 0 0 0 0 rgba(105,240,174,0.5); }
  to { box-shadow: 0 0 20px 8px rgba(105,240,174,0.2); border-color: var(--green); }
}

.piece {
  width: 38px; height: 38px;
  border-radius: 50%;
  position: relative;
  transition: all 0.3s;
}
.piece.white {
  background: radial-gradient(circle at 35% 35%, #ffffff, #c8c8c8);
  box-shadow: inset -3px -3px 6px rgba(0,0,0,0.3), inset 2px 2px 4px rgba(255,255,255,0.8), 0 4px 12px rgba(0,0,0,0.4);
}
.piece.black {
  background: radial-gradient(circle at 35% 35%, #3a3a5c, #0a0a1a);
  box-shadow: inset -3px -3px 6px rgba(0,0,0,0.5), inset 2px 2px 4px rgba(100,100,160,0.3), 0 4px 12px rgba(0,0,0,0.5);
}
.piece.placed {
  animation: placePiece 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes placePiece {
  0% { transform: scale(0) translateY(-20px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}
.piece.ai-move {
  animation: aiPlace 0.4s ease;
  box-shadow: inset -3px -3px 6px rgba(0,0,0,0.5), inset 2px 2px 4px rgba(100,100,160,0.3), 0 0 20px rgba(79,195,247,0.6);
}

/* ─── ROTATION CONTROLS ─── */
.rotation-controls {
  display: none;
  position: absolute;
  inset: -2px;
  border-radius: 12px;
  pointer-events: none;
  z-index: 10;
}
.rotation-controls.active {
  display: block;
  pointer-events: all;
}
.rot-btn {
  position: absolute;
  width: 36px; height: 36px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  box-shadow: 0 4px 12px rgba(232,197,71,0.4);
}
.rot-btn:hover { transform: scale(1.15); background: #f5d06e; }
.rot-btn.ccw { top: -18px; left: 50%; transform: translateX(-50%); }
.rot-btn.cw  { bottom: -18px; left: 50%; transform: translateX(-50%); }
.rot-overlay {
  position: absolute;
  inset: 0;
  background: rgba(232,197,71,0.05);
  border: 2px dashed rgba(232,197,71,0.5);
  border-radius: 12px;
}

/* ─── GAME TREE ─── */
.tree-container {
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  min-height: 220px;
  max-height: 380px;
}

svg.tree-svg text {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
}

.tree-empty {
  color: var(--text2);
  font-size: 0.8rem;
  font-family: 'IBM Plex Mono', monospace;
  text-align: center;
  padding: 40px 0;
}

/* ─── MOVE LOG ─── */
.move-log {
  max-height: 200px;
  overflow-y: auto;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  color: var(--text2);
}
.move-log::-webkit-scrollbar { width: 4px; }
.move-log::-webkit-scrollbar-track { background: var(--bg); }
.move-log::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.log-entry {
  padding: 4px 8px;
  border-left: 2px solid var(--border);
  margin-bottom: 4px;
}
.log-entry.white { border-color: rgba(240,240,240,0.4); }
.log-entry.black { border-color: var(--accent); }
.log-entry .move-num { color: var(--text2); }
.log-entry .move-desc { color: var(--text); margin-left: 6px; }

/* ─── SCORE BOARD ─── */
.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}
.score-player {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}
.score-player .name { font-size: 0.75rem; color: var(--text2); }
.score-player .score { font-family: 'Bebas Neue', cursive; font-size: 2.5rem; color: var(--text); line-height: 1; }
.score-player.active { border-color: var(--accent); background: rgba(232,197,71,0.05); }
.vs-divider { font-family: 'Bebas Neue', cursive; font-size: 1.2rem; color: var(--text2); }

/* ─── THINKING INDICATOR ─── */
.thinking {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: rgba(79,195,247,0.05);
  border: 1px solid rgba(79,195,247,0.2);
  border-radius: 8px;
  font-size: 0.8rem;
  color: var(--blue);
  font-family: 'IBM Plex Mono', monospace;
  margin-bottom: 12px;
}
.thinking.active { display: flex; }
.thinking-dots { display: flex; gap: 4px; }
.thinking-dot {
  width: 6px; height: 6px;
  background: var(--blue);
  border-radius: 50%;
  animation: blink 1.2s infinite;
}
.thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.thinking-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%,100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* ─── MODAL / OVERLAY ─── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  animation: modalIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes modalIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.modal-icon { font-size: 4rem; margin-bottom: 16px; }
.modal-title { font-family: 'Bebas Neue', cursive; font-size: 2.5rem; color: var(--accent); margin-bottom: 8px; }
.modal-sub { color: var(--text2); margin-bottom: 24px; font-size: 0.9rem; }
.modal-btns { display: flex; gap: 12px; justify-content: center; }

/* ─── HOW TO PLAY HINT ─── */
.how-to {
  font-size: 0.75rem;
  color: var(--text2);
  line-height: 1.7;
  font-family: 'IBM Plex Mono', monospace;
}
.how-to .step {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}
.how-to .step-num {
  color: var(--accent);
  font-weight: 700;
  flex-shrink: 0;
}

/* ─── RESPONSIVE ─── */
@media (max-width: 1100px) {
  .app { grid-template-columns: 1fr; }
  .header-stats { display: none; }
  .cell { width: 44px; height: 44px; }
  .piece { width: 32px; height: 32px; }
}
@media (max-width: 600px) {
  header { padding: 12px 16px; }
  .app { padding: 12px 16px; }
  .cell { width: 38px; height: 38px; }
  .piece { width: 28px; height: 28px; }
  .board { padding: 6px; }
  .quadrant { gap: 2px; padding: 4px; }
  .logo { font-size: 1.6rem; }
  .panel { padding: 14px; }
}