:root {
  --bg-deep: #0a1628;
  --bg-panel: #122238;
  --gold: #e8c547;
  --gold-dim: #b8932e;
  --grid-ink: #3d2817;
  --river-teal: #0d9488;
  --river-blue: #1e40af;
  --wood-dark: #3d2914;
  --wood-mid: #6b4423;
  --wood-light: #a67c52;
  --piece-red: #dc2626;
  --piece-black: #1f2937;
  --text: #f0f4ff;
  --shadow-ink: rgba(0, 0, 0, 0.55);
  --board-pad: 6%;
  --font-display: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

html.animations-paused *,
html.animations-paused *::before,
html.animations-paused *::after {
  animation-play-state: paused !important;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-display);
  background: radial-gradient(ellipse 120% 80% at 50% 0%, #1a3050 0%, var(--bg-deep) 55%);
  color: var(--text);
  overflow-x: hidden;
}

#app {
  min-height: 100vh;
}

.screen {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen.hidden {
  display: none;
}

/* ——— Home ——— */
#screen-home {
  overflow: hidden;
  isolation: isolate;
}

/* Optional full-screen clip (see index.html comment + HOME_BG_VIDEO_REMOTE in app.js) */
.home-bg-video {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  opacity: 1;
  display: block;
}

.home-bg-video.is-hidden {
  display: none;
}

/* Panning hills / ridges — full screen, above optional video */
.home-battlefield {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background-color: #0a1524;
  background-image:
    linear-gradient(105deg, rgba(0, 0, 0, 0.2) 0 40px, transparent 40px 120px),
    linear-gradient(180deg, transparent 35%, rgba(15, 8, 4, 0.92) 100%),
    radial-gradient(ellipse 90% 55% at 15% 100%, rgba(0, 0, 0, 0.55), transparent 58%),
    radial-gradient(ellipse 70% 50% at 55% 100%, rgba(30, 15, 8, 0.5), transparent 55%),
    radial-gradient(ellipse 85% 45% at 88% 100%, rgba(0, 0, 0, 0.5), transparent 52%),
    repeating-linear-gradient(
      88deg,
      rgba(255, 200, 120, 0.04) 0 1px,
      transparent 1px 22px
    );
  background-size:
    140% 100%,
    100% 100%,
    100% 100%,
    100% 100%,
    100% 100%,
    100% 100%;
  background-repeat: no-repeat;
  animation: battlefield-pan 30s linear infinite;
}

.home-bg {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(
    180deg,
    rgba(13, 31, 53, 0.52) 0%,
    rgba(21, 42, 69, 0.45) 38%,
    rgba(26, 10, 10, 0.58) 100%
  );
}

@keyframes battlefield-pan {
  0% {
    background-position:
      0% 50%,
      0 0,
      0 0,
      0 0,
      0 0,
      0 0;
  }
  100% {
    background-position:
      100% 50%,
      0 0,
      0 0,
      0 0,
      0 0,
      0 0;
  }
}

.war-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0.35;
}

.war-silhouette {
  position: absolute;
  bottom: 0;
  width: 120%;
  left: -10%;
  height: 45%;
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.85) 0%,
    rgba(40, 20, 10, 0.4) 45%,
    transparent 100%
  );
  filter: blur(1px);
}

.spark {
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #ffaa44;
  box-shadow: 0 0 12px #ff6600;
  animation: spark-rise 4s ease-in infinite;
}

@keyframes spark-rise {
  0% {
    opacity: 0;
    transform: translateY(0) scale(1);
  }
  15% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-100vh) scale(0.2);
  }
}

/* Full-screen cartoon layer (chess skit OR battle march) — blends with CSS battlefield below */
.home-hero-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  pointer-events: none;
  display: block;
  opacity: 0.56;
}

#screen-home.home-bg-mode--battle .home-hero-canvas {
  opacity: 0.48;
}

#screen-home.home-bg-mode--battle .war-layer {
  opacity: 0.52;
}

#screen-home.home-bg-mode--chess .war-layer {
  opacity: 0.28;
}

#screen-home.home-bg-mode--battle .home-battlefield {
  filter: saturate(1.14) contrast(1.05);
}

.home-fg {
  position: relative;
  z-index: 10;
  max-width: 560px;
  margin: 1.5rem;
  padding: 2.25rem 2.5rem;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.7);
  border: 2px solid rgba(232, 197, 71, 0.45);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.5),
    0 24px 60px rgba(0, 0, 0, 0.65),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
}

.home-fg h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(1.75rem, 4vw, 2.35rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--gold);
  text-shadow: 0 2px 16px rgba(232, 197, 71, 0.35);
}

.home-fg .subtitle {
  margin: 0 0 1.25rem;
  font-size: 0.95rem;
  opacity: 0.88;
  line-height: 1.5;
}

#home-tip {
  min-height: 5.5rem;
  margin: 0 0 1.5rem;
  padding: 1rem 1.1rem;
  font-size: 0.95rem;
  line-height: 1.55;
  color: #dce6f5;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 12px;
  border-left: 4px solid var(--river-teal);
}

#btn-start {
  display: block;
  width: 100%;
  padding: 1rem 1.5rem;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #0a1628;
  background: linear-gradient(180deg, #ffe566 0%, var(--gold) 45%, var(--gold-dim) 100%);
  border: none;
  border-radius: 14px;
  cursor: pointer;
  box-shadow:
    0 4px 0 #7a5f12,
    0 12px 32px rgba(232, 197, 71, 0.35);
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease;
}

#btn-start:hover {
  transform: translateY(-2px);
  box-shadow:
    0 6px 0 #7a5f12,
    0 18px 40px rgba(232, 197, 71, 0.45);
}

#btn-start:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #7a5f12;
}

/* ——— Game layout ——— */
#screen-game {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 3.75rem 0 1rem;
}

.game-top-bar {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 100;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.45rem;
  max-width: calc(100vw - 24px);
}

.btn-top-fixed {
  padding: 0.55rem 1rem;
  font-weight: 800;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 10px;
  border: 2px solid rgba(232, 197, 71, 0.55);
  background: rgba(10, 22, 40, 0.92);
  color: var(--gold);
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  transition: background 0.15s ease, transform 0.15s ease;
}

.btn-top-fixed:hover {
  background: rgba(232, 197, 71, 0.18);
  transform: translateY(-1px);
}

.btn-top-fixed.btn-home {
  border-color: rgba(148, 163, 184, 0.65);
  color: #e2e8f0;
}

.btn-top-fixed.btn-home:hover {
  background: rgba(148, 163, 184, 0.2);
}

.victory-banner {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  z-index: 55;
  padding: 1rem 2.5rem;
  font-size: clamp(1.1rem, 3vw, 1.65rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #422006;
  border-radius: 14px;
  border: 3px solid #b45309;
  background: linear-gradient(180deg, #fde68a 0%, #f59e0b 45%, #b45309 100%);
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.35),
    0 20px 50px rgba(245, 158, 11, 0.45);
  animation: victory-pop 0.55s ease-out;
}

.victory-banner.hidden {
  display: none;
}

@keyframes victory-pop {
  from {
    transform: translate(-50%, -50%) scale(0.6);
    opacity: 0;
  }
  to {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}

.game-layout {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-start;
  justify-content: flex-start;
  flex: 1 1 auto;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0 1rem;
  gap: 0;
  position: relative;
  z-index: 2;
  box-sizing: border-box;
  min-height: 0;
}

.board-panel {
  flex: 0 0 60%;
  width: 60%;
  max-width: 60%;
  box-sizing: border-box;
  padding-right: 0.75rem;
  perspective: 1000px;
}

.board-stage {
  transform-style: preserve-3d;
  transform: rotateX(15deg);
  filter: drop-shadow(0 28px 40px rgba(0, 0, 0, 0.55));
}

.board-surface {
  position: relative;
  width: 100%;
  max-width: min(100%, 520px);
  margin: 0 auto;
  aspect-ratio: 9 / 10;
  background: linear-gradient(165deg, var(--wood-light) 0%, var(--wood-mid) 35%, var(--wood-dark) 100%);
  border-radius: 10px;
  box-shadow:
    inset 0 0 0 3px rgba(0, 0, 0, 0.35),
    inset 0 2px 0 rgba(255, 255, 255, 0.12),
    inset 0 -8px 24px var(--shadow-ink),
    0 0 0 2px #1a0f08;
}

.board-surface::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 10px;
  pointer-events: none;
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.25);
}

.board-svg {
  position: absolute;
  inset: var(--board-pad);
  width: calc(100% - 2 * var(--board-pad));
  height: calc(100% - 2 * var(--board-pad));
  overflow: visible;
  z-index: 2;
  pointer-events: none;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.35));
}

.board-svg .grid-carve .grid-line {
  stroke: #0a0604;
  stroke-width: 3px;
  stroke-linecap: square;
  vector-effect: non-scaling-stroke;
  shape-rendering: crispEdges;
}

.board-svg .grid-main .grid-line {
  stroke: var(--grid-ink);
  stroke-width: 2px;
  stroke-linecap: square;
  vector-effect: non-scaling-stroke;
  shape-rendering: crispEdges;
  filter: drop-shadow(1px 1px 0 rgba(0, 0, 0, 0.35));
}

.board-svg .palace-line {
  stroke: var(--grid-ink);
}

.river-strip {
  position: absolute;
  left: var(--board-pad);
  right: var(--board-pad);
  top: calc(var(--board-pad) + (100% - 2 * var(--board-pad)) * 4 / 9);
  height: calc((100% - 2 * var(--board-pad)) / 9);
  border-radius: 4px;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
  opacity: 0.78;
  background: linear-gradient(90deg, var(--river-teal), var(--river-blue), var(--river-teal));
  background-size: 300% 100%;
  background-position: 0% 50%;
  animation: river-shift 12s linear infinite;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.35);
}

@keyframes river-shift {
  0% {
    background-position: 0% 50%;
  }
  100% {
    background-position: 200% 50%;
  }
}

.river-strip::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    105deg,
    transparent,
    transparent 10px,
    rgba(255, 255, 255, 0.08) 10px,
    rgba(255, 255, 255, 0.08) 12px
  );
  animation: shimmer 3s linear infinite;
}

@keyframes shimmer {
  from {
    transform: translateX(-20px);
  }
  to {
    transform: translateX(20px);
  }
}

.river-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  font-size: clamp(0.65rem, 2.2vw, 0.85rem);
  font-weight: 700;
  letter-spacing: 0.35em;
  color: rgba(255, 255, 255, 0.35);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.pieces-layer {
  position: absolute;
  inset: var(--board-pad);
  z-index: 4;
}

.piece {
  position: absolute;
  width: 11.5%;
  aspect-ratio: 1;
  left: var(--lx, 50%);
  top: var(--ly, 50%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: clamp(0.68rem, 2.6vw, 1rem);
  cursor: pointer;
  user-select: none;
  border-radius: 50%;
  transform: translate(-50%, -50%) translateZ(12px) rotateX(-6deg);
  transform-style: preserve-3d;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    filter 0.2s ease,
    opacity 0.2s ease;
  box-shadow:
    0 6px 0 rgba(0, 0, 0, 0.4),
    0 14px 20px rgba(0, 0, 0, 0.35),
    inset 0 2px 5px rgba(255, 255, 255, 0.28),
    inset 0 -4px 8px rgba(0, 0, 0, 0.28);
  paint-order: stroke fill;
  -webkit-text-stroke: 0.45px rgba(255, 255, 255, 0.95);
}

.piece.red {
  color: #fff7ed;
  border: 3px solid #ca8a04;
  background: radial-gradient(circle at 32% 28%, #fecaca 0%, var(--piece-red) 42%, #7f1d1d 100%);
  filter: drop-shadow(0 4px 3px rgba(0, 0, 0, 0.45));
}

.piece.black {
  color: #f8fafc;
  border: 3px solid #94a3b8;
  background: radial-gradient(circle at 32% 28%, #64748b 0%, var(--piece-black) 48%, #020617 100%);
  filter: drop-shadow(0 4px 3px rgba(0, 0, 0, 0.5));
}

.piece:hover:not(.ghost) {
  filter: brightness(1.08);
  transform: translate(-50%, -50%) translateZ(18px) rotateX(-4deg) scale(1.05);
}

.piece.selected {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  z-index: 5;
  transform: translate(-50%, -50%) translateZ(20px) rotateX(-4deg) scale(1.06);
}

.piece.thinking {
  animation: pulse-piece 0.8s ease-in-out infinite alternate;
}

@keyframes pulse-piece {
  from {
    filter: brightness(1);
  }
  to {
    filter: brightness(1.15);
  }
}

.piece.retreat {
  pointer-events: none;
  transition:
    transform 1.4s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 1.4s ease;
  opacity: 0;
}

.piece.retreat.retreat-left {
  transform: translate(-50%, -50%) translateX(-130vw) translateZ(0) scale(0.35) !important;
}

.piece.retreat.retreat-right {
  transform: translate(-50%, -50%) translateX(130vw) translateZ(0) scale(0.35) !important;
}

.ghost-dot {
  position: absolute;
  width: 22px;
  height: 22px;
  left: var(--lx, 0);
  top: var(--ly, 0);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(45, 212, 191, 0.55);
  box-shadow: 0 0 14px rgba(45, 212, 191, 0.85);
  z-index: 4;
  pointer-events: auto;
  cursor: pointer;
}

.hint-dot {
  position: absolute;
  width: 22px;
  height: 22px;
  left: var(--lx, 0);
  top: var(--ly, 0);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid rgba(232, 197, 71, 0.95);
  background: rgba(217, 4, 41, 0.15);
  z-index: 4;
  pointer-events: auto;
  cursor: pointer;
}

.defeat-overlay {
  position: absolute;
  left: 0;
  right: 0;
  height: 50%;
  z-index: 6;
  pointer-events: none;
  display: none;
  align-items: center;
  justify-content: center;
}

.defeat-overlay.visible {
  display: flex;
}

.defeat-overlay.player-side {
  bottom: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.06));
}

.defeat-overlay.ai-side {
  top: 0;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.06));
}

.defeat-overlay svg {
  width: 90%;
  height: 90%;
  opacity: 0.92;
}

.defeat-overlay .x-line {
  stroke: #d90429;
  stroke-width: 14;
  stroke-linecap: round;
  filter: drop-shadow(0 0 8px rgba(217, 4, 41, 0.8));
}

.sidebar {
  flex: 0 0 40%;
  width: 40%;
  max-width: 40%;
  min-width: 0;
  box-sizing: border-box;
  background: linear-gradient(180deg, rgba(18, 34, 56, 0.95) 0%, rgba(10, 22, 40, 0.98) 100%);
  border-radius: 16px;
  border: 1px solid rgba(232, 197, 71, 0.25);
  padding: 1.1rem 1.25rem;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.sidebar h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
  color: var(--gold);
  letter-spacing: 0.06em;
}

.score-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

.score-row strong {
  font-size: 1.35rem;
  color: var(--river-teal);
}

.status-pill {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: rgba(45, 212, 191, 0.15);
  border: 1px solid rgba(45, 212, 191, 0.35);
}

.status-pill.threat {
  background: rgba(217, 4, 41, 0.15);
  border-color: rgba(217, 4, 41, 0.45);
}

.capture-section {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.capture-section h3 {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.75;
}

.capture-pile {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  min-height: 2.5rem;
}

.trophy {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 800;
  box-shadow:
    0 3px 0 rgba(0, 0, 0, 0.35),
    inset 0 1px 2px rgba(255, 255, 255, 0.25);
  border: 1px solid rgba(0, 0, 0, 0.4);
  animation: pop-in 0.35s ease;
}

@keyframes pop-in {
  from {
    transform: scale(0);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.trophy.red {
  color: #fff7ed;
  border: 2px solid #ca8a04;
  -webkit-text-stroke: 0.35px rgba(255, 255, 255, 0.9);
  paint-order: stroke fill;
  background: radial-gradient(circle at 30% 25%, #fecaca, var(--piece-red));
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
}

.trophy.black {
  color: #f8fafc;
  border: 2px solid #94a3b8;
  -webkit-text-stroke: 0.35px rgba(255, 255, 255, 0.85);
  paint-order: stroke fill;
  background: radial-gradient(circle at 30% 25%, #64748b, var(--piece-black));
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.4));
}

.flying-capture {
  position: fixed;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 900;
  font-size: 0.95rem;
  pointer-events: none;
  transition:
    left 0.62s cubic-bezier(0.2, 0.85, 0.2, 1),
    top 0.62s cubic-bezier(0.2, 0.85, 0.2, 1),
    width 0.62s cubic-bezier(0.2, 0.85, 0.2, 1),
    height 0.62s cubic-bezier(0.2, 0.85, 0.2, 1),
    opacity 0.62s ease;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
  paint-order: stroke fill;
  -webkit-text-stroke: 0.4px rgba(255, 255, 255, 0.95);
}

.flying-capture.fly-token-black {
  color: #f8fafc;
  border: 3px solid #94a3b8;
  background: radial-gradient(circle at 30% 25%, #64748b, var(--piece-black));
}

.flying-capture.fly-token-red {
  color: #fff7ed;
  border: 3px solid #ca8a04;
  background: radial-gradient(circle at 30% 25%, #fecaca, var(--piece-red));
}

#fx-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  z-index: 60;
  padding: 0.65rem 1.25rem;
  border-radius: 10px;
  background: rgba(10, 22, 40, 0.95);
  border: 1px solid rgba(232, 197, 71, 0.35);
  font-size: 0.88rem;
  transition: transform 0.35s ease;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 900px) {
  .game-layout {
    flex-direction: column;
    align-items: center;
  }

  .board-panel,
  .sidebar {
    flex: 1 1 auto;
    width: 100%;
    max-width: 520px;
    padding-right: 0;
  }

  .board-stage {
    transform: rotateX(10deg);
  }
}
