/* ============================================================
   1. RESET
   ============================================================ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ============================================================
   2. THEME DEFINITIONS
   ============================================================ */

/* --- Neon Arcade (default) --- */
:root,
[data-theme="neon"] {
  --bg: #0a0a2e;
  --bg-gradient: linear-gradient(135deg, #0a0a2e 0%, #1a0a3e 50%, #2d1b69 100%);
  --surface: #1a1040;
  --surface-elevated: #251560;

  --text: #e8e0ff;
  --text-muted: #9a8cbf;

  --accent: #00ffff;
  --accent-dim: rgba(0, 255, 255, 0.12);
  --accent-glow: rgba(0, 255, 255, 0.4);

  --hex-empty: #1e1250;
  --hex-fill: #160e3a;
  --hex-edge: rgba(255, 255, 255, 0.18);
  --hex-border: rgba(255, 255, 255, 0.35);
  --hex-hover: #2a1a70;

  --particle-primary: #00ffff;
  --particle-secondary: #ff0066;
  --hint-safe: #47f3a2;
  --hint-safe-glow: rgba(71, 243, 162, 0.42);
  --hint-danger: #ff6b7d;
  --hint-danger-glow: rgba(255, 107, 125, 0.4);
  --enemy-dim: rgba(255, 0, 102, 0.16);

  --btn-gradient: linear-gradient(135deg, #ff0066 0%, #cc0052 100%);
  --btn-text: #fff;

  --overlay-bg: rgba(5, 5, 20, 0.88);

  --heading-font: 'Courier New', monospace;

  --scanline: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 255, 255, 0.015) 2px,
    rgba(0, 255, 255, 0.015) 4px
  );
}

/* --- Elegant Minimalist --- */
[data-theme="elegant"] {
  --bg: #fef9ef;
  --bg-gradient: linear-gradient(180deg, #fef9ef 0%, #f5ead6 100%);
  --surface: #fff8ee;
  --surface-elevated: #f0e6d2;

  --text: #3a3028;
  --text-muted: #8a7a6a;

  --accent: #c4a874;
  --accent-dim: rgba(196, 168, 116, 0.15);
  --accent-glow: rgba(196, 168, 116, 0.3);

  --hex-empty: #f5ead6;
  --hex-fill: #f5ead6;
  --hex-edge: rgba(196, 168, 116, 0.4);
  --hex-border: rgba(100, 80, 50, 0.7);
  --hex-hover: #ede0c8;

  --particle-primary: #c4a874;
  --particle-secondary: #8b6914;
  --hint-safe: #2f996b;
  --hint-safe-glow: rgba(47, 153, 107, 0.28);
  --hint-danger: #c65b4f;
  --hint-danger-glow: rgba(198, 91, 79, 0.26);
  --enemy-dim: rgba(198, 91, 79, 0.16);

  --btn-gradient: linear-gradient(135deg, #c4a874 0%, #a88a50 100%);
  --btn-text: #fff;

  --overlay-bg: rgba(254, 249, 239, 0.92);

  --heading-font: Georgia, 'Times New Roman', serif;

  --scanline: none;
}

/* --- Modern Gaming --- */
[data-theme="modern"] {
  --bg: #1b2838;
  --bg-gradient: linear-gradient(135deg, #1b2838 0%, #2a475e 100%);
  --surface: #1e3044;
  --surface-elevated: #253d54;

  --text: #c7d5e0;
  --text-muted: #7a8fa0;

  --accent: #66c0f4;
  --accent-dim: rgba(102, 192, 244, 0.12);
  --accent-glow: rgba(102, 192, 244, 0.35);

  --hex-empty: #1e3348;
  --hex-fill: #18293a;
  --hex-edge: rgba(255, 255, 255, 0.15);
  --hex-border: rgba(255, 255, 255, 0.45);
  --hex-hover: #2c4a65;

  --particle-primary: #66c0f4;
  --particle-secondary: #4fa3d6;
  --hint-safe: #6ee7b7;
  --hint-safe-glow: rgba(110, 231, 183, 0.28);
  --hint-danger: #ff7f7f;
  --hint-danger-glow: rgba(255, 127, 127, 0.28);
  --enemy-dim: rgba(255, 127, 127, 0.16);

  --btn-gradient: linear-gradient(135deg, #66c0f4 0%, #4fa3d6 100%);
  --btn-text: #0e1c28;

  --overlay-bg: rgba(15, 22, 32, 0.9);

  --heading-font: system-ui, -apple-system, sans-serif;

  --scanline: none;
}

/* --- Dark Fantasy --- */
[data-theme="fantasy"] {
  --bg: #0d0a14;
  --bg-gradient: linear-gradient(135deg, #2d1f3d 0%, #1a1128 50%, #0d0a14 100%);
  --surface: #1a1228;
  --surface-elevated: #251a38;

  --text: #e8d8f0;
  --text-muted: #9a7eb5;

  --accent: #ff4d6d;
  --accent-dim: rgba(255, 77, 109, 0.12);
  --accent-glow: rgba(255, 77, 109, 0.4);

  --hex-empty: #201535;
  --hex-fill: #180f28;
  --hex-edge: rgba(255, 255, 255, 0.18);
  --hex-border: rgba(255, 255, 255, 0.45);
  --hex-hover: #2d1a45;

  --particle-primary: #ff4d6d;
  --particle-secondary: #ff8fa3;
  --hint-safe: #73f7b5;
  --hint-safe-glow: rgba(115, 247, 181, 0.34);
  --hint-danger: #ff7a93;
  --hint-danger-glow: rgba(255, 122, 147, 0.34);
  --enemy-dim: rgba(120, 140, 255, 0.2);

  --btn-gradient: linear-gradient(135deg, #ff4d6d 0%, #cc3055 100%);
  --btn-text: #fff;

  --overlay-bg: rgba(8, 5, 12, 0.9);

  --heading-font: system-ui, -apple-system, sans-serif;

  --scanline: none;
}

/* ============================================================
   3. BASE LAYOUT
   ============================================================ */
html, body {
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-gradient);
  background-color: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  overflow: hidden;
  line-height: 1.45;
}

.sidebar {
  width: 220px;
  min-width: 220px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--hex-edge);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 10;
  flex-shrink: 0;
}

.main-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 16px;
}

.board-wrapper {
  position: relative;
  background: var(--surface);
  border-radius: 16px;
  padding: clamp(14px, 2.5vw, 24px);
  border: 1px solid var(--hex-edge);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

.board-wrapper::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 16px;
  background: var(--scanline);
  pointer-events: none;
  z-index: 0;
}

#particleCanvas {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  border-radius: 16px;
}

/* ============================================================
   4. SIDEBAR STYLING
   ============================================================ */
.sidebar-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--hex-edge);
}

.sidebar-section:last-child {
  border-bottom: none;
}

.sidebar-title {
  font-family: var(--heading-font);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.sidebar-game-title {
  font-family: var(--heading-font);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 10px var(--accent-glow);
  letter-spacing: 0.04em;
  line-height: 1.2;
  padding: 16px 16px 12px;
}

/* Stats */
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
  padding: 0 16px;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stat-value.accent {
  color: var(--accent);
  text-shadow: 0 0 8px var(--accent-glow);
}

/* Item picker in sidebar */
.item-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.item-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--surface-elevated);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.15s ease;
}

.item-btn img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
}

.item-btn:hover {
  border-color: var(--accent-dim);
  transform: translateX(2px);
}

.item-btn.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 0 1px var(--accent-glow) inset;
}

.item-btn:focus {
  outline: none;
}

.item-btn:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.has-selection .item-btn:not(.selected) {
  opacity: 0.5;
}

/* Settings */
.settings-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.settings-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  flex: 1;
}

.theme-select,
.difficulty-select {
  background: var(--surface-elevated);
  color: var(--text);
  border: 1px solid var(--hex-edge);
  border-radius: 6px;
  padding: 4px 8px;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%239a8cbf'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 22px;
}

.theme-select:focus,
.difficulty-select:focus {
  outline: 1px solid var(--accent);
}

kbd {
  font-family: ui-monospace, monospace;
  font-size: 0.75em;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--surface-elevated);
  border: 1px solid var(--hex-edge);
  color: var(--text-muted);
}

/* ============================================================
   5. HEX GRID AND HEX CELL STYLING
   ============================================================ */
:root {
  --hex-w: clamp(32px, 6vw, 48px);
  --hex-h: calc(var(--hex-w) * 1.15);
  --row-overlap: calc(var(--hex-h) * -0.25);
  --row-shift: calc(var(--hex-w) * 0.51);
}

.hex-grid {
  position: relative;
  z-index: 1;
}

button.hex {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  font: inherit;
  color: inherit;
  padding: 0;
  background: transparent;
}

.hex {
  width: var(--hex-w);
  height: var(--hex-h);
  position: relative;
  margin: 0;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  cursor: pointer;
  transition: transform 0.2s ease, filter 0.2s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  isolation: isolate;
  background: linear-gradient(165deg, var(--hex-empty) 0%, var(--hex-fill) 100%);
  /* drop-shadow renders OUTSIDE clip-path — this IS the visible border */
  filter:
    drop-shadow(0 0 0 var(--hex-border))
    drop-shadow(1px 0 0 var(--hex-border))
    drop-shadow(-1px 0 0 var(--hex-border))
    drop-shadow(0 1px 0 var(--hex-border))
    drop-shadow(0 -1px 0 var(--hex-border));
}

/* Fill layer */
.hex::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  background: linear-gradient(165deg, var(--hex-empty) 0%, var(--hex-fill) 100%);
  pointer-events: none;
  transition: background 0.2s ease;
}

.hex::after {
  display: none;
}

.hex.empty:hover::before {
  background: linear-gradient(165deg, var(--hex-hover) 0%, var(--hex-empty) 100%);
}

.hex:hover {
  transform: scale(1.06);
  z-index: 10;
  filter:
    drop-shadow(0 0 0 var(--accent))
    drop-shadow(1px 0 0 var(--accent))
    drop-shadow(-1px 0 0 var(--accent))
    drop-shadow(0 1px 0 var(--accent))
    drop-shadow(0 -1px 0 var(--accent))
    drop-shadow(0 0 6px var(--accent-glow));
}

.hex:focus {
  outline: none;
}

.hex:focus-visible {
  z-index: 12;
  filter: drop-shadow(0 0 0 2px var(--accent)) drop-shadow(0 0 8px var(--accent-glow));
}

.hex img.player {
  position: relative;
  z-index: 1;
  width: 58%;
  height: 58%;
  object-fit: contain;
  pointer-events: none;
}

/* Player cell — highlighted background (flat, lighter shade) */
.hex.player-cell::before {
  background: var(--accent-dim) !important;
}

/* AI cell (battle mode) — contrasting flat highlight */
.hex.ai-cell::before {
  background: var(--enemy-dim) !important;
}

.hex img:not(.player) {
  position: relative;
  z-index: 1;
  width: 58%;
  height: 58%;
  object-fit: contain;
  pointer-events: none;
}

.hex .preview-ghost {
  position: relative;
  z-index: 1;
  width: 58%;
  height: 58%;
  object-fit: contain;
  pointer-events: none;
  opacity: 0.48;
  transform: scale(0.94);
  filter: saturate(0.9) brightness(1.08);
}

.hex.preview-anchor {
  z-index: 11;
  filter:
    drop-shadow(0 0 0 var(--accent))
    drop-shadow(1px 0 0 var(--accent))
    drop-shadow(-1px 0 0 var(--accent))
    drop-shadow(0 1px 0 var(--accent))
    drop-shadow(0 -1px 0 var(--accent))
    drop-shadow(0 0 10px var(--accent-glow));
}

.hex.preview-anchor::before {
  background: linear-gradient(165deg, color-mix(in srgb, var(--accent) 28%, var(--hex-empty)) 0%, var(--hex-fill) 100%);
}

.hex.preview-capture {
  z-index: 9;
  filter:
    drop-shadow(0 0 0 var(--hint-safe))
    drop-shadow(1px 0 0 var(--hint-safe))
    drop-shadow(-1px 0 0 var(--hint-safe))
    drop-shadow(0 1px 0 var(--hint-safe))
    drop-shadow(0 -1px 0 var(--hint-safe))
    drop-shadow(0 0 10px var(--hint-safe-glow));
}

.hex.preview-capture::before {
  background: linear-gradient(165deg, color-mix(in srgb, var(--hint-safe) 24%, var(--hex-empty)) 0%, var(--hex-fill) 100%);
}

.hex.preview-threat {
  z-index: 9;
  filter:
    drop-shadow(0 0 0 var(--hint-danger))
    drop-shadow(1px 0 0 var(--hint-danger))
    drop-shadow(-1px 0 0 var(--hint-danger))
    drop-shadow(0 1px 0 var(--hint-danger))
    drop-shadow(0 -1px 0 var(--hint-danger))
    drop-shadow(0 0 10px var(--hint-danger-glow));
}

.hex.preview-threat::before {
  background: linear-gradient(165deg, color-mix(in srgb, var(--hint-danger) 20%, var(--hex-empty)) 0%, var(--hex-fill) 100%);
}

.preview-gain {
  position: absolute;
  top: -8px;
  right: -10px;
  z-index: 2;
  min-width: 30px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(6, 16, 22, 0.88);
  border: 1px solid var(--hint-safe);
  color: var(--hint-safe);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  box-shadow: 0 0 12px var(--hint-safe-glow);
  pointer-events: none;
}

.hex.is-clearing {
  pointer-events: none;
}

/* ============================================================
   6. ANIMATIONS (@keyframes)
   ============================================================ */

/* Piece pop in */
@keyframes popIn {
  0% {
    transform: scale(0.3);
    opacity: 0;
  }
  70% {
    transform: scale(1.08);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.pop-in {
  animation: popIn 250ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Piece vanish */
@keyframes pieceVanish {
  0% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
    filter: blur(0);
  }
  55% {
    opacity: 0.85;
    transform: scale(0.88) rotate(-6deg);
  }
  100% {
    opacity: 0;
    transform: scale(0.35) rotate(-14deg);
    filter: blur(2px);
  }
}

.piece-vanish {
  animation: pieceVanish 400ms cubic-bezier(0.4, 0, 0.8, 0.45) forwards;
  transform-origin: center center;
}

/* Hex ripple on match */
@keyframes hexRipple {
  0% {
    box-shadow: inset 0 0 0 0 var(--accent-glow);
  }
  50% {
    box-shadow: inset 0 0 0 4px var(--accent);
  }
  100% {
    box-shadow: inset 0 0 0 0 transparent;
  }
}

.hex-ripple {
  animation: hexRipple 300ms ease forwards;
}

/* Screen shake */
@keyframes screenShake {
  0%   { transform: translateX(0) translateY(0); }
  15%  { transform: translateX(-3px) translateY(1px); }
  30%  { transform: translateX(3px) translateY(-1px); }
  45%  { transform: translateX(-2px) translateY(2px); }
  60%  { transform: translateX(2px) translateY(-2px); }
  75%  { transform: translateX(-1px) translateY(1px); }
  90%  { transform: translateX(1px) translateY(-1px); }
  100% { transform: translateX(0) translateY(0); }
}

.screen-shake {
  animation: screenShake 200ms ease forwards;
}

/* Button pulse */
@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 var(--accent-glow);
  }
  50% {
    box-shadow: 0 0 0 8px transparent;
  }
}

@keyframes pickerPulse {
  0%,
  100% {
    transform: translateY(0);
    box-shadow: none;
  }
  35% {
    transform: translateY(-1px);
    box-shadow: 0 0 0 4px var(--accent-dim);
  }
  70% {
    transform: translateY(0);
    box-shadow: 0 0 0 8px transparent;
  }
}

/* Float hex for title screen */
@keyframes floatHex {
  0%   { transform: translateY(0px) rotate(0deg); }
  25%  { transform: translateY(-12px) rotate(3deg); }
  50%  { transform: translateY(-20px) rotate(-2deg); }
  75%  { transform: translateY(-8px) rotate(4deg); }
  100% { transform: translateY(0px) rotate(0deg); }
}

.float-hex {
  animation: floatHex 20s ease-in-out infinite;
}

/* Record bounce (high score) */
@keyframes recordBounce {
  0%   { transform: scale(0.5); opacity: 0; }
  60%  { transform: scale(1.2); opacity: 1; }
  80%  { transform: scale(0.95); }
  100% { transform: scale(1); opacity: 1; }
}

.record-bounce {
  animation: recordBounce 500ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* ============================================================
   7. OVERLAYS
   ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

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

.overlay-box {
  background: var(--surface);
  border: 1px solid var(--hex-edge);
  border-radius: 20px;
  padding: clamp(24px, 5vw, 40px);
  max-width: 480px;
  width: 100%;
  text-align: center;
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.04);
  transform: scale(0.9);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.overlay.visible .overlay-box {
  transform: scale(1);
}

/* Title screen */
.title-overlay .overlay-box {
  position: relative;
  overflow: hidden;
}

.title-hex-decorations {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.title-hex-dec {
  position: absolute;
  width: 60px;
  height: 69px;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  opacity: 0.06;
}

.title-hex-dec:nth-child(1) {
  top: -20px; left: -20px;
  background: var(--accent);
  animation: floatHex 18s ease-in-out infinite;
}

.title-hex-dec:nth-child(2) {
  top: 20px; right: -15px;
  background: var(--particle-secondary);
  animation: floatHex 22s ease-in-out infinite reverse;
}

.title-hex-dec:nth-child(3) {
  bottom: -10px; left: 30%;
  background: var(--accent);
  animation: floatHex 25s ease-in-out infinite;
  width: 40px; height: 46px;
}

.overlay-title {
  font-family: var(--heading-font);
  font-size: clamp(1.5rem, 5vw, 2.4rem);
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow);
  margin-bottom: 8px;
  letter-spacing: 0.04em;
}

.overlay-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 16px;
}

.overlay-rule {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.6;
}

/* Tutorial overlay */
.tutorial-steps {
  text-align: left;
  margin: 16px 0;
}

.tutorial-step {
  display: none;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text);
}

.tutorial-step.active {
  display: block;
}

.tutorial-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin: 12px 0;
}

.tutorial-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--hex-edge);
  transition: background 0.2s ease;
}

.tutorial-dot.active {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
}

/* Game over overlay */
.game-over-score {
  font-family: var(--heading-font);
  font-size: clamp(2rem, 8vw, 3.5rem);
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 24px var(--accent-glow);
  margin: 12px 0;
  font-variant-numeric: tabular-nums;
}

.game-over-stats-row {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin: 12px 0;
  flex-wrap: wrap;
}

.game-over-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.game-over-stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.game-over-stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.end-best {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 8px;
}

/* ============================================================
   7b. LEADERBOARD & NAME INPUT
   ============================================================ */
.go-name-section {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  margin: 12px 0;
}

.go-name-input {
  padding: 8px 12px;
  border: 1px solid var(--hex-edge);
  border-radius: 8px;
  background: var(--surface-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  width: 160px;
  outline: none;
  transition: border-color 0.2s;
}

.go-name-input:focus {
  border-color: var(--accent);
}

.go-name-input::placeholder {
  color: var(--text-muted);
}

.go-submit-btn {
  padding: 8px 16px;
  white-space: nowrap;
}

.leaderboard {
  margin: 12px 0;
}

.leaderboard h3 {
  font-family: var(--heading-font);
  font-size: 0.9rem;
  color: var(--accent);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.leaderboard-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--hex-edge);
}

.leaderboard-table tr:last-child td {
  border-bottom: none;
}

.leaderboard-table .lb-rank {
  width: 28px;
  text-align: center;
  color: var(--text-muted);
  font-weight: 700;
}

.leaderboard-table .lb-name {
  text-align: left;
  color: var(--text);
  font-weight: 600;
}

.leaderboard-table .lb-score {
  text-align: right;
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.leaderboard-table .lb-date {
  text-align: right;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.leaderboard-table .lb-highlight {
  background: var(--accent-dim);
}

.lb-empty {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 8px;
}

/* ============================================================
   8. BUTTONS
   ============================================================ */
.btn,
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  background: var(--btn-gradient);
  color: var(--btn-text);
  transition: transform 0.15s ease, filter 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  filter: brightness(1.1);
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(0);
  filter: brightness(0.95);
}

.btn:focus {
  outline: none;
}

.btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px var(--accent-dim);
}

.btn.pulse {
  animation: pulse 2s ease infinite;
}

.btn-secondary {
  background: var(--surface-elevated);
  color: var(--text);
  border: 1px solid var(--hex-edge);
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
  filter: none;
  transform: translateY(-1px);
}

.btn-sm {
  padding: 8px 16px;
  font-size: 0.85rem;
  border-radius: 8px;
}

/* Legacy IDs used in existing JS */
#startButton,
#restartButton {
  margin-top: 20px;
  padding: 12px 28px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  background: var(--btn-gradient);
  color: var(--btn-text);
  transition: transform 0.15s ease, filter 0.15s ease;
}

#startButton:hover,
#restartButton:hover {
  filter: brightness(1.1);
  transform: translateY(-2px);
}

#startButton:focus-visible,
#restartButton:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ============================================================
   9. MOBILE RESPONSIVE (< 768px)
   ============================================================ */
@media (max-width: 767px) {
  :root {
    --hex-w: clamp(28px, 8vw, 38px);
  }

  body {
    flex-direction: column;
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
  }

  .sidebar {
    display: none;
  }

  .main-area {
    padding-top: 48px;
    padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px));
    align-items: center;
    justify-content: center;
    overflow: hidden;
    height: calc(100dvh - 48px - 68px - env(safe-area-inset-bottom, 0px));
    height: calc(100vh - 48px - 68px);
  }

  .board-wrapper {
    max-width: calc(100vw - 16px);
    max-height: 100%;
    overflow: auto;
  }

  /* Mobile top bar */
  .mobile-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(44px + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--surface);
    border-bottom: 1px solid var(--hex-edge);
    padding-left: 12px;
    padding-right: 12px;
    z-index: 20;
  }

  .mobile-top-title {
    font-family: var(--heading-font);
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--accent);
    text-shadow: 0 0 8px var(--accent-glow);
  }

  .mobile-top-score {
    font-size: 0.9rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text);
  }

  /* Mobile bottom bar */
  .mobile-bottom-bar {
    display: flex;
    align-items: center;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(64px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--surface);
    border-top: 1px solid var(--hex-edge);
    padding-left: 12px;
    padding-right: 12px;
    gap: 8px;
    z-index: 20;
    overflow-x: auto;
  }

  .mobile-bottom-bar .item-btn {
    flex-direction: column;
    gap: 2px;
    padding: 6px 12px;
    font-size: 0;
    flex-shrink: 0;
    min-width: 56px;
  }

  .mobile-bottom-bar .item-btn img {
    width: 32px;
    height: 32px;
  }

  .mobile-bottom-bar .item-btn span {
    font-size: 0.65rem;
  }

  .hamburger-btn {
    margin-left: auto;
    flex-shrink: 0;
    background: none;
    border: 1px solid var(--hex-edge);
    border-radius: 8px;
    color: var(--text);
    font-size: 1.3rem;
    padding: 6px 10px;
    cursor: pointer;
  }

  /* Mobile slide-up panel */
  .mobile-panel {
    display: none;
    position: fixed;
    bottom: 64px;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--hex-edge);
    border-radius: 16px 16px 0 0;
    padding: 20px 16px;
    z-index: 30;
    max-height: 60vh;
    overflow-y: auto;
  }

  .mobile-panel.open {
    display: block;
  }

}

/* Desktop hides mobile bars */
@media (min-width: 768px) {
  .mobile-top-bar,
  .mobile-bottom-bar,
  .mobile-panel {
    display: none;
  }
}

/* ============================================================
   MISSING CLASS ALIASES (align CSS to HTML)
   ============================================================ */

/* Sidebar */
.sidebar-logo {
  font-family: var(--heading-font);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 10px var(--accent-glow);
  padding: 16px 16px 12px;
  letter-spacing: 0.02em;
  line-height: 1.3;
  white-space: nowrap;
}

.sidebar-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.sidebar-bottom {
  margin-top: auto;
  padding: 14px 16px;
  border-top: 1px solid var(--hex-edge);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.status-text {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  padding: 10px 16px;
  min-height: 2.4em;
}

.picker-pulse .item-btn,
.picker-pulse {
  animation: pickerPulse 380ms ease;
}

.difficulty-badge {
  display: inline-block;
  padding: 4px 12px;
  margin: 0 16px 14px;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--accent-dim);
  color: var(--accent);
  text-align: center;
}

.toggle-btn {
  background: var(--surface-elevated);
  border: 1px solid var(--hex-edge);
  border-radius: 6px;
  color: var(--text);
  padding: 4px 10px;
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.toggle-btn:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.toggle-btn.is-active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-glow) inset;
}

/* Mode + AI level pickers (title screen) */
.mode-picker {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 14px 0 6px;
}

.mode-btn {
  background: var(--surface-elevated);
  border: 1px solid var(--hex-edge);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 22px;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.mode-btn:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.mode-btn.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-glow) inset;
}

.ai-level-picker {
  display: none;
  gap: 8px;
  justify-content: center;
  margin-bottom: 6px;
}

.ai-level-picker.visible {
  display: flex;
}

.ai-level-btn {
  background: var(--surface-elevated);
  border: 1px solid var(--hex-edge);
  border-radius: 6px;
  color: var(--text-muted);
  padding: 5px 14px;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.ai-level-btn.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}

/* Battle UI bits */
.stat-value.ai {
  color: var(--hint-danger);
}

.battle-result {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 6px 0;
}

.battle-result.win  { color: var(--hint-safe); }
.battle-result.lose { color: var(--hint-danger); }
.battle-result.draw { color: var(--text-muted); }

.gameover-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* Skin selector */
.skin-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 8px 0;
}

.skin-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s;
}

.skin-dot:hover { transform: scale(1.15); }

.skin-dot.active {
  border-color: var(--text);
  box-shadow: 0 0 8px var(--accent-glow);
}

.skin-dot[data-skin="neon"] { background: linear-gradient(135deg, #0a0a2e, #00ffff); }
.skin-dot[data-skin="elegant"] { background: linear-gradient(135deg, #fef9ef, #c4a874); }
.skin-dot[data-skin="modern"] { background: linear-gradient(135deg, #1b2838, #66c0f4); }
.skin-dot[data-skin="fantasy"] { background: linear-gradient(135deg, #2d1f3d, #ff4d6d); }

/* Title screen */
.title-screen { z-index: 200; }

.title-bg-hexes {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.title-bg-hexes .float-hex {
  position: absolute;
  width: 60px;
  height: 69px;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  background: var(--accent-dim);
  opacity: 0.3;
}

.title-bg-hexes .float-hex:nth-child(1) { left: 10%; top: 15%; animation: floatHex 20s ease-in-out infinite; }
.title-bg-hexes .float-hex:nth-child(2) { width: 80px; height: 92px; left: 70%; top: 20%; animation: floatHex 25s ease-in-out infinite -5s; }
.title-bg-hexes .float-hex:nth-child(3) { width: 40px; height: 46px; left: 20%; top: 60%; animation: floatHex 18s ease-in-out infinite -10s; }
.title-bg-hexes .float-hex:nth-child(4) { width: 50px; height: 57px; left: 80%; top: 70%; animation: floatHex 22s ease-in-out infinite -15s; }

.title-content { position: relative; z-index: 1; }

.title-content h1 {
  font-family: var(--heading-font);
  font-size: clamp(1.8rem, 5vw, 2.5rem);
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow);
}

[data-theme="fantasy"] .title-content h1 {
  background: linear-gradient(135deg, #ff4d6d, #ff8fa3);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: none;
}

/* Game over */
.score-countup {
  font-family: var(--heading-font);
  font-size: clamp(2rem, 8vw, 3.5rem);
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 24px var(--accent-glow);
  margin: 12px 0;
  font-variant-numeric: tabular-nums;
}

.new-record-flash {
  color: #ffd700;
  font-weight: 700;
  font-size: 1.2rem;
  animation: recordBounce 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.gameover-stats {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin: 16px 0;
  flex-wrap: wrap;
}

.gameover-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.gameover-stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
}

.gameover-stat span:last-child {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* Tutorial */
.tutorial-overlay { z-index: 150; }

.tutorial-step h3 {
  font-family: var(--heading-font);
  font-size: 1.2rem;
  margin-bottom: 10px;
  color: var(--accent);
}

.tutorial-step p { margin-bottom: 12px; }

.tutorial-step div {
  font-size: 36px;
  margin: 12px 0;
}

.tutorial-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--hex-edge);
  display: inline-block;
  transition: background 0.2s;
}

.tutorial-dots span.active {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
}

.tutorial-nav {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 12px;
}

/* Mobile hamburger */
.hamburger-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px 8px;
  margin-left: auto;
}

/* Board shake alias */
.board-wrapper.shake {
  animation: screenShake 200ms ease forwards;
}

/* ============================================================
   10. PREFERS-REDUCED-MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .screen-shake {
    animation: none !important;
  }

  .float-hex {
    animation: none !important;
  }

  .hex img.piece-vanish,
  .piece-vanish {
    animation: none !important;
    opacity: 0;
    transform: scale(0.92);
  }

  .pop-in {
    animation: none !important;
  }
}
