/* Board + game layout */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #1a1a2e;
  --panel-bg: #16213e;
  --text: #e0e0e0;
  --text-dim: #8888aa;
  --accent: #6a0dad;
  --border: #333355;
  --base-font: 16px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: var(--base-font);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ─── Header ─── */
.game-header {
  text-align: center;
  padding: 0.8rem 1rem 0.4rem;
  width: 100%;
  max-width: 900px;
}
.game-header h1 {
  font-size: 1.6rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
.game-header .subtitle {
  font-size: 0.9rem;
  color: var(--text-dim);
  font-style: italic;
}
.access-code {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  font-size: 1.2rem;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  padding: 0.25rem 0.9rem;
  border-radius: 4px;
  display: inline-block;
  margin-top: 0.3rem;
  letter-spacing: 0.2em;
  cursor: pointer;
}
.access-code:hover::after {
  content: ' (click to copy)';
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ─── Main Layout ─── */
.game-container {
  display: flex;
  gap: 1rem;
  max-width: 1100px;
  width: 100%;
  padding: 0 1rem;
  flex: 1;
  align-items: flex-start;
}

.board-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

svg.board {
  width: 100%;
  max-width: 650px;
  height: auto;
}

.side-panel {
  width: 240px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* ─── Hex styling ─── */
.hex-cell {
  cursor: default;
  transition: filter 0.15s;
}
.hex-cell.empty {
  fill: #2a2a44;
  stroke: #444466;
  stroke-width: 1.5;
}
.hex-cell.ring-0 { fill: var(--accent); stroke: #4a007d; stroke-width: 2.5; }
.hex-cell.ring-1 { fill: #3a3a5a; }
.hex-cell.ring-2 { fill: #333350; }
.hex-cell.ring-3 { fill: #2d2d48; }
.hex-cell.ring-4 { fill: #282840; }

.hex-cell.selectable { cursor: pointer; filter: brightness(1.3); }
.hex-cell.selected { filter: brightness(1.5); stroke: #fff; stroke-width: 3; }
.hex-cell.valid-target { cursor: pointer; }
.hex-cell.valid-target-marker { fill: rgba(0,255,100,0.25); stroke: #00ff66; stroke-width: 2; pointer-events: none; }
.hex-cell.last-move { filter: brightness(1.15); }

.hex-cell.edge-p1 { stroke: #447799; stroke-width: 2; stroke-dasharray: 4 2; }
.hex-cell.edge-p2 { stroke: #994444; stroke-width: 2; stroke-dasharray: 4 2; }

/* ─── Stones ─── */
.stone {
  pointer-events: none;
}
.stone circle {
  stroke-width: 2.5;
}
.stone text {
  font-size: 16px;
  text-anchor: middle;
  dominant-baseline: central;
  fill: white;
  font-weight: bold;
  pointer-events: none;
}

/* ─── Player panels ─── */
.player-panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.8rem;
}
.player-panel h3 {
  font-size: 1rem;
  margin-bottom: 0.3rem;
  letter-spacing: 0.08em;
}
.player-panel .score {
  font-size: 2rem;
  font-weight: bold;
  text-align: center;
}
.player-panel.active {
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(106, 13, 173, 0.4);
}
.player-panel.you-active {
  border-color: #4ade80;
  box-shadow: 0 0 12px rgba(74, 222, 128, 0.4);
  animation: panelPulse 2s ease-in-out infinite;
}
@keyframes panelPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(74, 222, 128, 0.3); }
  50% { box-shadow: 0 0 20px rgba(74, 222, 128, 0.6); }
}

.holding-area {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.3rem;
  min-height: 32px;
}
.holding-stone {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
}
.holding-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-top: 0.4rem;
}
.holding-stone.not-interactive { cursor: default; opacity: 0.6; }
.holding-stone.restorable {
  cursor: pointer;
  animation: restorePulse 1.2s ease-in-out infinite;
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.4);
}
@keyframes restorePulse {
  0%, 100% { box-shadow: 0 0 4px rgba(74, 222, 128, 0.3); transform: scale(1); }
  50% { box-shadow: 0 0 12px rgba(74, 222, 128, 0.7); transform: scale(1.1); }
}

.holding-hint {
  font-size: 0.75rem;
  color: #4ade80;
  margin-top: 0.2rem;
  padding-left: 0.2rem;
}
.holding-hint-flash {
  animation: hintFlash 2s ease-in-out infinite;
}
.holding-hint::before {
  content: '\25B6  ';
  font-size: 0.6rem;
}
@keyframes hintFlash {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* ─── Status bar ─── */
.status-bar {
  background: var(--panel-bg);
  border: 2px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 1rem;
  text-align: center;
  font-size: 1rem;
  width: 100%;
  max-width: 900px;
  margin: 0.5rem 0;
  transition: border-color 0.3s, background 0.3s, box-shadow 0.3s;
}
.status-bar .turn-info {
  font-weight: bold;
  line-height: 1.4;
}

/* Timeout warning */
.timeout-warning {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 4px;
  padding: 0.4rem 0.8rem;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  color: #fca5a5;
  animation: timeoutPulse 2s ease-in-out infinite;
}
@keyframes timeoutPulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

/* Your turn — green glow, flashing text + border */
.status-bar.your-turn {
  border-color: #4ade80;
  background: linear-gradient(135deg, rgba(74,222,128,0.1), var(--panel-bg));
  animation: statusFlash 1.5s ease-in-out infinite;
}
.status-bar.your-turn .turn-info {
  color: #4ade80;
}
@keyframes statusFlash {
  0%, 100% {
    border-color: #4ade80;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.2);
  }
  50% {
    border-color: #86efac;
    box-shadow: 0 0 24px rgba(74, 222, 128, 0.5);
    background: linear-gradient(135deg, rgba(74,222,128,0.18), var(--panel-bg));
  }
}

/* Opponent's turn — subdued grey */
.status-bar.opponent-turn {
  border-color: var(--border);
  background: var(--panel-bg);
  box-shadow: none;
  opacity: 0.55;
}
.status-bar.opponent-turn .turn-info {
  color: var(--text-dim);
}

/* Turn just changed to you — brief flash */
.status-bar.turn-flash {
  animation: turnFlash 0.8s ease;
}
@keyframes turnFlash {
  0% { background: rgba(74, 222, 128, 0.3); box-shadow: 0 0 30px rgba(74, 222, 128, 0.6); }
  100% { background: linear-gradient(135deg, rgba(74,222,128,0.08), var(--panel-bg)); }
}

/* ─── Lore callout (bottom of page) ─── */
.lore-callout {
  background: linear-gradient(135deg, rgba(106,13,173,0.08), rgba(106,13,173,0.02));
  border: 1px solid rgba(106,13,173,0.25);
  border-radius: 8px;
  padding: 0.9rem 1.5rem;
  margin: 0.6rem auto;
  max-width: 750px;
  width: calc(100% - 2rem);
  text-align: center;
  font-style: italic;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text-dim);
  transition: opacity 0.4s ease;
}
.lore-callout.lore-flash {
  animation: loreFlash 0.6s ease;
}
@keyframes loreFlash {
  0% { opacity: 0.3; border-color: rgba(106,13,173,0.6); }
  50% { opacity: 1; border-color: rgba(106,13,173,0.8); }
  100% { opacity: 1; border-color: rgba(106,13,173,0.25); }
}

/* ─── Move log ─── */
.move-log {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
  max-height: 200px;
  overflow-y: auto;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.move-log .log-entry {
  padding: 0.2rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

/* ─── Buttons ─── */
.btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 0.55rem 1.3rem;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn:hover { background: #7b1fa2; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-secondary:hover { background: rgba(255,255,255,0.05); }

.btn-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin: 0.3rem 0;
}

/* ─── Setup screens ─── */
.setup-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.setup-card {
  background: var(--panel-bg);
  border: 2px solid var(--accent);
  border-radius: 10px;
  padding: 2rem;
  max-width: 480px;
  text-align: center;
}
.setup-card h2 {
  font-size: 1.4rem;
  margin-bottom: 1rem;
}
.setup-card p {
  font-size: 1rem;
  line-height: 1.5;
}
.split-choice {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin: 1rem 0;
}
.split-option {
  background: #2a2a44;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 1.1rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  flex: 1;
}
.split-option:hover { border-color: var(--accent); background: #333355; }
.split-option .count { font-size: 2.2rem; font-weight: bold; }
.split-option .label { font-size: 0.9rem; color: var(--text-dim); }

/* ─── Waiting screen ─── */
.waiting-pulse {
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* ─── Help popup ─── */
#help-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  padding: 1rem;
}
.help-panel {
  background: var(--panel-bg);
  border: 2px solid var(--accent);
  border-radius: 10px;
  max-width: 620px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
.help-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.2rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.help-header h2 {
  font-size: 1.2rem;
  letter-spacing: 0.08em;
}
.help-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.8rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 0.3rem;
}
.help-close:hover { color: var(--text); }
.help-body {
  padding: 1rem 1.2rem 1.5rem;
  overflow-y: auto;
  font-size: 0.9rem;
  line-height: 1.6;
}
.help-body h3 {
  font-size: 1rem;
  margin-top: 1.2rem;
  margin-bottom: 0.3rem;
  color: var(--text);
  letter-spacing: 0.05em;
}
.help-body h3:first-child { margin-top: 0; }
.help-body p { margin-bottom: 0.5rem; color: var(--text); }
.help-body ul {
  margin: 0.3rem 0 0.5rem 1.2rem;
  color: var(--text);
}
.help-body li { margin-bottom: 0.25rem; }
.help-body strong { color: #fff; }
.help-cycle {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin: 0.5rem 0;
  padding: 0.6rem;
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
}
.help-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 0.2rem;
}
.help-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0;
  font-size: 0.85rem;
}
.help-table th {
  text-align: left;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
}
.help-table td {
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

/* ─── Poll status ─── */
.poll-status {
  text-align: center;
  font-size: 0.75rem;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  color: var(--text-dim);
  opacity: 0.5;
  padding: 0.3rem 0 0;
  letter-spacing: 0.03em;
  transition: opacity 0.3s;
}
.poll-status:hover { opacity: 0.9; }

/* ─── Site Footer ─── */
.site-footer {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-dim);
  padding: 0.8rem 0;
  margin-top: 0.5rem;
}
.site-footer a {
  color: var(--accent);
  text-decoration: none;
}
.site-footer a:hover { text-decoration: underline; }
.site-footer span { margin: 0 0.4rem; }

/* ─── Build tag ─── */
.build-tag {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-dim);
  opacity: 0.5;
  padding: 0.3rem 0;
  letter-spacing: 0.05em;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .game-container {
    flex-direction: column;
    align-items: center;
  }
  .side-panel {
    width: 100%;
    max-width: 650px;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .side-panel > * { flex: 1; min-width: 140px; }
}
