:root {
  --bg: #121a10;
  --bg-elevated: #1e2a18;
  --bg-panel: #182214;
  --border: #3a4e30;
  --text: #e8f0d8;
  --text-muted: #8fa078;
  --accent: #6a9a3a;
  --accent-hover: #82b84e;
  --danger: #e85d5d;
  --warn: #e0b84a;
  --success: #6dbf8a;
  --glow: rgba(106, 154, 58, 0.35);
  --felt: #3d6b3a;
  --felt-dark: #2a4a28;
  --paper: #d4c4a0;
  --paper-dark: #b8a47a;
  --ink: #2c2418;
  --river: #3a6e8a;
  --river-deep: #2a5570;
  --den: #5c3a28;
  --trap: #8a5a2a;
  --piece-cream: #f5ebd6;
  --piece-red: #c41e3a;
  --piece-blue: #1a3a6e;
  --select: rgba(120, 200, 90, 0.5);
  --last: rgba(240, 190, 70, 0.45);
  --radius: 14px;
  --font: "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei",
    "Source Han Sans TC", system-ui, sans-serif;
  --board-w: min(92vw, 420px, 72vh);
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background:
    radial-gradient(ellipse at 25% 0%, #2a3a20 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, #1a2814 0%, transparent 45%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  display: flex;
  justify-content: center;
  padding: 16px 12px 24px;
}

.app {
  width: min(1100px, 100%);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.header {
  text-align: center;
}

.title {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
  letter-spacing: 0.18em;
  color: #d8e8b8;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

.subtitle {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.88rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.layout {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(260px, var(--board-w)) minmax(160px, 220px);
  gap: 16px;
  align-items: start;
  justify-content: center;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
  min-height: 0;
}

.player-card {
  background: var(--bg-elevated);
  border-radius: 12px;
  padding: 12px;
  border: 1px solid var(--border);
}

.player-card.you {
  border-color: rgba(196, 30, 58, 0.55);
}

.player-card.opponent {
  border-color: rgba(80, 120, 180, 0.45);
}

.player-card.active-turn {
  box-shadow: 0 0 0 2px var(--accent);
}

.player-name {
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.captured {
  min-height: 1.8rem;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.captured-piece {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--piece-cream);
  border: 2px solid;
  line-height: 1;
}

.captured-piece.red {
  color: var(--piece-red);
  border-color: var(--piece-red);
}

.captured-piece.blue {
  color: var(--piece-blue);
  border-color: var(--piece-blue);
}

.stat-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.stat-value {
  font-size: 1.05rem;
  font-weight: 600;
}

.stat-value.warn {
  color: var(--warn);
}

.stat-value.win {
  color: var(--success);
}

.stat-value.lose {
  color: var(--danger);
}

.select {
  appearance: none;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: #243020;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, var(--accent-hover), var(--accent));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 18px var(--glow);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
  background: linear-gradient(180deg, var(--accent-hover), var(--accent));
}

.btn-danger {
  border-color: rgba(232, 93, 93, 0.45);
  color: #ffb0b0;
}

.legend,
.tips {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.legend-text {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text);
}

.legend-text.muted {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.tips-list {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.55;
}

.board-section {
  position: relative;
  width: var(--board-w);
  max-width: 100%;
  justify-self: center;
}

.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 7 / 9;
  border-radius: 16px;
  padding: 12px;
  background: linear-gradient(145deg, #2a3e22 0%, #152018 100%);
  border: 1px solid #4a6a40;
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.board {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  box-shadow: 0 0 0 2px #3a5230;
  background: #3d6b3a;
}

.thinking-badge {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: rgba(18, 26, 16, 0.9);
  color: var(--warn);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 5;
  pointer-events: none;
}

.thinking-badge.hidden {
  display: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 14, 6, 0.72);
  backdrop-filter: blur(4px);
  border-radius: 16px;
  z-index: 20;
  padding: 16px;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px 20px;
  text-align: center;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

.overlay-card h2 {
  margin: 0 0 8px;
  font-size: 1.35rem;
  color: #d8e8b8;
}

.overlay-card p {
  margin: 0 0 16px;
  color: var(--text-muted);
  line-height: 1.5;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.help {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.help p {
  margin: 0;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .panel-side {
    width: min(var(--board-w), 100%);
    max-width: 420px;
  }

  .board-section {
    order: -1;
  }

  .actions {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .actions .btn {
    flex: 1 1 40%;
  }
}

@media (max-width: 420px) {
  body {
    padding: 10px 8px 18px;
  }

  .board-wrap {
    padding: 8px;
  }
}
