:root {
  --bg: #141210;
  --bg-elevated: #1e1b19;
  --bg-card: #241f1c;
  --line: #3b322b;
  --text: #f3ede4;
  --text-dim: #c3b8a8;
  --accent: #e8b34b;
  --accent-strong: #f5c158;
  --board-bg: #f2e3c0;
  --board-line: #2e2416;
  --shadow: 0 20px 50px rgba(0,0,0,0.45);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background:
    radial-gradient(1200px 600px at 20% -10%, #2c2416 0%, transparent 55%),
    radial-gradient(900px 500px at 85% -20%, #332414 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  min-height: 100%;
}

#app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 20px 40px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  font-family: Georgia, 'Iowan Old Style', 'Palatino Linotype', serif;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
}
.brand-mark { width: 34px; height: 34px; color: var(--accent); flex: none; }
.header-nav { display: flex; gap: 8px; }

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--text);
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 0.92rem;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
  font-weight: 600;
}
.btn:hover { border-color: var(--accent); color: var(--accent-strong); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(180deg, #f2be55 0%, #dfa12e 100%);
  border-color: #c98a1f;
  color: #2b1d05;
  box-shadow: 0 6px 18px rgba(238, 181, 59, 0.28);
}
.btn-primary:hover { filter: brightness(1.07); color: #241a04; }
.btn-large { font-size: 1.05rem; padding: 13px 32px; }
.btn-ghost { background: transparent; }
.hidden { display: none !important; }

/* Landing */
.screen { width: 100%; }
.landing-card {
  max-width: 640px;
  margin: 26px auto 0;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 34px 34px 30px;
  text-align: center;
}
.landing-title {
  font-family: Georgia, 'Iowan Old Style', serif;
  font-size: 2.3rem;
  margin: 0 0 6px;
  letter-spacing: 0.01em;
}
.landing-sub { color: var(--text-dim); margin: 0 0 24px; line-height: 1.5; }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.mode-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
  text-align: left;
  background: linear-gradient(180deg, #2b2622 0%, #221d1a 100%);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 16px 16px;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.mode-card:hover { border-color: var(--accent); }
.mode-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 10px 26px rgba(232,179,75,0.16);
}
.mode-card-icon { font-size: 1.5rem; }
.mode-card-title { font-weight: 700; font-size: 1.05rem; }
.mode-card-desc { font-size: 0.82rem; color: var(--text-dim); line-height: 1.4; }

.cpu-setup {
  border-top: 1px solid var(--line);
  padding-top: 18px;
  margin-bottom: 18px;
  text-align: left;
}
.cpu-setup h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-dim);
  margin: 14px 0 8px;
}
.cpu-setup h2:first-child { margin-top: 0; }
.difficulty-row, .color-row { display: flex; gap: 8px; }
.diff-btn, .color-btn {
  flex: 1;
  padding: 10px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 0.92rem;
  transition: all 0.13s ease;
}
.diff-btn.selected, .color-btn.selected {
  border-color: var(--accent);
  background: rgba(232,179,75,0.14);
  color: var(--accent-strong);
}
.diff-btn:hover, .color-btn:hover { border-color: var(--accent); }
.color-btn { display: flex; align-items: center; justify-content: center; gap: 8px; }
.cpu-setup-note { font-size: 0.8rem; color: var(--text-dim); margin: 12px 2px 0; }
.landing-hint { font-size: 0.82rem; color: var(--text-dim); margin: 14px 0 0; }

.piece-dot {
  display: inline-block;
  width: 14px; height: 14px; border-radius: 50%;
  vertical-align: middle;
}
.piece-dot.black { background: radial-gradient(circle at 35% 32%, #5c574f 0%, #2a2723 55%, #100e0c 100%); box-shadow: 0 1px 2px rgba(0,0,0,0.6); }
.piece-dot.white { background: radial-gradient(circle at 35% 32%, #fffdf7 0%, #e8dcc2 55%, #c9b588 100%); box-shadow: inset 0 0 0 1px #b09f7c, 0 1px 2px rgba(0,0,0,0.35); }

/* Game layout */
.game-topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.turn-banner {
  display: flex; align-items: center; gap: 10px;
  font-family: Georgia, serif; font-size: 1.15rem; font-weight: 700;
}
.turn-banner .piece-dot { width: 22px; height: 22px; }
.phase-pill {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-dim); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px;
}
.phase-pill.flying { color: var(--accent-strong); border-color: var(--accent); }

.game-layout {
  display: grid;
  grid-template-columns: 220px 1fr 240px;
  gap: 16px;
  align-items: start;
}
@media (max-width: 1080px) {
  .game-layout { grid-template-columns: 1fr; }
  .side-panel { display: contents; }
  .side-panel .side-card { grid-column: 1; }
}
.side-card {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 14px;
}
.side-card h3 {
  margin: 0 0 10px; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim);
}
.men-count-row { display: flex; align-items: center; gap: 10px; padding: 3px 0; font-size: 1.15rem; font-weight: 700; }
.hand-list { display: flex; gap: 5px; flex-wrap: wrap; min-height: 16px; margin-bottom: 6px; }
.hand-list:empty { display: none; }
.hand-list .piece-dot { width: 12px; height: 12px; }

.history {
  list-style: none; padding: 0; margin: 0;
  max-height: 430px; overflow-y: auto;
  font-size: 0.85rem; color: var(--text-dim);
}
.history li {
  padding: 6px 0; border-bottom: 1px dashed var(--line); line-height: 1.45;
}
.history li:last-child { border-bottom: none; }
.history .h-move { color: var(--text); font-weight: 600; }
.history .h-cap { color: #e0604a; }
.history .h-winner { color: var(--accent-strong); font-weight: 700; }

/* Board */
.board-wrap { display: flex; flex-direction: column; align-items: center; }
.board {
  position: relative;
  width: min(88vw, 600px);
  aspect-ratio: 1 / 1;
  background: var(--board-bg);
  border-radius: 18px;
  box-shadow: 0 0 0 6px #43331f, 0 0 0 8px #20201b, var(--shadow);
  user-select: none;
  touch-action: manipulation;
}
.board svg { display: block; width: 100%; height: 100%; }
.board .point-hit { cursor: pointer; }
.board .point-hit:hover circle.ring { opacity: 1; }
.board .legal-dot { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}
.piece { transition: transform 0.16s ease; }
.piece.fly { transition: transform 0.4s cubic-bezier(.3,1.4,.5,1); }

.board-overlay {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20, 17, 14, 0.72);
  border-radius: 18px;
  z-index: 5;
}
.board-overlay .overlay-card {
  background: #231f1c;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 30px;
  text-align: center;
  color: var(--text);
  box-shadow: var(--shadow);
  max-width: 320px;
}
.overlay-card h2 { font-family: Georgia, serif; font-size: 1.7rem; margin: 0 0 8px; }
.overlay-card p { margin: 0 0 18px; color: var(--text-dim); line-height: 1.5; }
.overlay-card .overlay-actions { display: flex; gap: 10px; justify-content: center; }
.overlay-card .overlay-note { font-size: 0.85rem; }

/* Stats */
.stats-card {
  max-width: 860px; margin: 0 auto;
  background: var(--bg-elevated); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 26px 28px; box-shadow: var(--shadow);
}
.stats-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.stats-head h2 { margin: 0; font-family: Georgia, serif; font-size: 1.6rem; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-tile { background: var(--bg-card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; text-align: center; }
.stat-tile .stat-num { font-size: 1.9rem; font-weight: 800; color: var(--accent-strong); line-height: 1.2; }
.stat-tile .stat-label { font-size: 0.72rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.07em; margin-top: 4px; }
.diff-table { width: 100%; border-collapse: collapse; margin: 6px 0 18px; font-size: 0.92rem; }
.diff-table th, .diff-table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
.diff-table th { color: var(--text-dim); text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.06em; }
.rate-bar { height: 8px; border-radius: 4px; background: #332b24; overflow: hidden; display: inline-block; width: 100%; vertical-align: middle; }
.rate-bar > span { display: block; height: 100%; background: linear-gradient(90deg, #e8b34b, #f5c158); }
.recent-list { max-height: 260px; overflow-y: auto; }
.recent-list .recent-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 0.85rem; color: var(--text-dim); }
.recent-list .recent-row:last-child { border-bottom: none; }

/* Help */
.help-body { line-height: 1.65; color: var(--text-dim); max-width: 760px; }
.help-body h3 { color: var(--text); margin-top: 22px; font-family: Georgia, serif; }
.help-body strong { color: var(--text); }
.help-note { font-size: 0.82rem; border-top: 1px solid var(--line); padding-top: 14px; }

/* Footer */
.app-footer {
  margin-top: auto; padding: 20px 0 4px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  color: #5f574d; font-size: 0.75rem; border-top: 1px solid var(--line);
}

/* Game-over toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #2d2620; color: var(--text); border: 1px solid var(--accent);
  padding: 10px 18px; border-radius: 10px; font-size: 0.9rem; z-index: 50;
  box-shadow: var(--shadow); opacity: 0; transition: opacity 0.2s ease; pointer-events: none;
}
.toast.show { opacity: 1; }

/* Piece animation keyframes */
@keyframes piece-pop {
  0% { transform: scale(0.3); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes piece-fly {
  0% { transform: translate(var(--dx, 0px), var(--dy, 0px)) scale(1.5); opacity: 0.7; }
  60% { transform: translate(0, 0) scale(1.05); opacity: 1; }
  100% { transform: translate(0, 0) scale(1); opacity: 1; }
}
