:root {
  --bg: #f7f1e7;
  --bg-soft: #fbf7f0;
  --card: #fffaf2;
  --line: #7a4d1b;
  --board: #d4ab67;
  --board-edge: #bc8b49;
  --text: #2f261d;
  --muted: #6d6254;
  --red: #b12d2d;
  --black: #1f2730;
  --gold: #e8c36a;
  --legal: #4fa377;
  --danger: #cc4b4b;
  --shadow: 0 14px 34px rgba(67, 48, 26, 0.12);
  --radius: 26px;
  --cell: 78px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', Arial, sans-serif;
  background: linear-gradient(180deg, #fcf8f1 0%, #f4ebdd 100%);
  color: var(--text);
}
button, select { font: inherit; }
.site-header { background: #fffdf8; border-bottom: 1px solid #ecdfca; position: sticky; top: 0; z-index: 20; }
.header-inner, .footer-inner, .page-shell { max-width: 1400px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 16px; padding-bottom: 16px; flex-wrap: wrap; }
.brand-wrap { display: flex; flex-direction: column; gap: 4px; }
.brand { text-decoration: none; color: var(--text); font-size: 1.5rem; font-weight: 800; }
.tagline { color: var(--muted); font-weight: 700; letter-spacing: 0.14em; font-size: 0.8rem; }
.site-nav, .footer-links { display: flex; gap: 14px; flex-wrap: wrap; }
.site-nav a, .footer-links a, .breadcrumb-bar a { text-decoration: none; color: var(--text); font-weight: 600; font-size: 0.95rem; }
.site-nav a:hover, .footer-links a:hover, .breadcrumb-bar a:hover, .brand:hover { opacity: 0.78; }
.page-shell { padding-top: 18px; padding-bottom: 46px; }
.breadcrumb-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: 0.92rem; margin-bottom: 16px; }
.hero-card, .game-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.hero-card { padding: 24px; margin-bottom: 22px; text-align: center; }
.eyebrow { margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.8rem; font-weight: 800; }
.hero-card h1 { margin: 0; font-size: clamp(2rem, 4vw, 3.1rem); line-height: 1.08; }
.hero-copy { margin: 12px auto 0; max-width: 820px; color: var(--muted); line-height: 1.6; }
/* Main game area: board gets most of the width, side panel stays narrow. */
.game-layout {
  --side-panel-eye-level-offset: 66px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(240px, 20vw, 292px);
  gap: 16px;
  align-items: start;
}
.game-card { padding: 18px; }
.board-card { min-width: 0; }

/* Align the Game Settings title with the top edge of the wooden board.
   This makes the right panel feel visually connected to the board instead
   of starting too high beside the turn/status area. */
.side-panel {
  width: 100%;
  max-width: 292px;
  justify-self: end;
  padding: 16px;
  margin-top: var(--side-panel-eye-level-offset);
}
.game-toolbar { display: flex; justify-content: space-between; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar-label, .mini-label, .field-label { font-size: 0.82rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.toolbar-value { font-size: 1.7rem; font-weight: 800; }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.action-button { appearance: none; border: 0; border-radius: 999px; padding: 10px 15px; font-weight: 800; background: var(--text); color: #fff; cursor: pointer; transition: transform 0.15s ease, opacity 0.15s ease; }
.action-button.secondary { background: #efe1c4; color: var(--text); }
.action-button:hover { transform: translateY(-1px); }
.action-button:disabled { opacity: 0.48; cursor: not-allowed; transform: none; }
.status-banner { background: #f8f1e4; color: #5e523f; border-radius: 14px; padding: 8px 10px; font-weight: 800; min-height: 34px; display: flex; align-items: center; line-height: 1.35; }
.status-banner.check { background: #fff3d8; color: #7b4b00; }
.status-banner.finished { background: #ffe5df; color: #8b2b19; }
.side-status-wrap { margin-top: 8px; }
.side-status { margin-top: 5px; border: 1px solid #eadcc3; background: #fffdf8; }
.side-status.check { border-color: #ecc46d; background: #fff3d8; }
.side-status.finished { border-color: #efb4a6; background: #ffe5df; }
.board-scroll { overflow-x: auto; padding: 8px 0 10px; display: flex; justify-content: center; }
.xiangqi-board {
  box-sizing: content-box;
  position: relative;
  width: calc(var(--cell) * 8 + 54px);
  height: calc(var(--cell) * 9 + 136px);
  min-width: calc(var(--cell) * 8 + 54px);
  margin: 0 auto;
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,0.28), transparent 28%),
    linear-gradient(135deg, #e5bd78 0%, #c9944d 48%, #a96f32 100%);
  border: 8px solid #8f5c2a;
  border-radius: 30px;
  box-shadow:
    inset 0 5px 0 rgba(255,255,255,0.24),
    inset 0 -9px 0 rgba(86, 49, 18, 0.22),
    0 22px 42px rgba(67, 48, 26, 0.24);
  transition: width 0.18s ease, height 0.18s ease;
}
.xiangqi-board::before {
  content: '';
  position: absolute;
  inset: 10px;
  border-radius: 22px;
  border: 1px solid rgba(255,255,255,0.28);
  pointer-events: none;
}
.board-surface { position: absolute; left: 24px; top: 24px; width: calc(var(--cell) * 8); height: calc(var(--cell) * 9 + 72px); }
.h-line, .v-line, .diag-line { position: absolute; background: var(--line); z-index: 1; }
.h-line { height: 2px; width: calc(var(--cell) * 8); }
.v-line { width: 2px; }
.diag-line { height: 2px; transform-origin: left center; }
.river-label { position: absolute; left: 0; width: calc(var(--cell) * 8); text-align: center; font-size: 1.05rem; letter-spacing: 0.34em; line-height: 1; font-weight: 800; color: rgba(82, 50, 19, 0.9); z-index: 2; pointer-events: none; transform: translateY(-50%); }
.intersection, .legal-dot, .capture-ring, .piece, .last-move-mark { position: absolute; transform: translate(-50%, -50%); }
.intersection { width: 18px; height: 18px; border-radius: 50%; background: transparent; border: 0; padding: 0; z-index: 2; cursor: pointer; }
.intersection::after { content: ''; position: absolute; inset: 4px; border-radius: 50%; background: rgba(122,77,27,0.75); opacity: 0.72; }
.legal-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--legal); border: 3px solid rgba(255,255,255,0.95); z-index: 4; cursor: pointer; box-shadow: 0 2px 7px rgba(0,0,0,0.16); }
.capture-ring { width: 56px; height: 56px; border-radius: 50%; border: 4px solid rgba(79, 163, 119, 0.95); z-index: 3; pointer-events: none; }
.last-move-mark { width: 62px; height: 62px; border-radius: 50%; background: rgba(255,255,255,0.20); border: 2px dashed rgba(255,255,255,0.75); z-index: 2; pointer-events: none; }
.piece { width: 54px; height: 54px; border-radius: 50%; border: 2px solid #7a5327; background: radial-gradient(circle at 32% 25%, #fffdf5 0%, #f4e2bb 56%, #d8b271 100%); box-shadow: inset 0 3px 0 rgba(255,255,255,0.68), inset 0 -5px 0 rgba(114,78,32,0.18), 0 7px 12px rgba(0,0,0,0.22); display: flex; align-items: center; justify-content: center; font-size: 1.85rem; font-weight: 900; z-index: 5; cursor: pointer; user-select: none; text-shadow: 0 1px 0 rgba(255,255,255,0.7); transition: transform 0.14s ease, box-shadow 0.14s ease; }
.piece.red { color: var(--red); }
.piece.black { color: var(--black); }
.piece.selected { outline: 4px solid rgba(232,195,106,0.95); transform: translate(-50%, -50%) scale(1.05); }
.piece.hint { animation: pulseHint 0.9s ease-in-out 3; }
@keyframes pulseHint { 0%,100% { box-shadow: 0 4px 8px rgba(0,0,0,0.18); } 50% { box-shadow: 0 0 0 10px rgba(79,163,119,0.22), 0 4px 8px rgba(0,0,0,0.18); } }
.side-panel section + section { margin-top: 14px; padding-top: 14px; border-top: 1px solid #eadcc3; }
.side-panel h2 { margin: 0 0 9px; font-size: 1.05rem; }
.side-panel p, .side-panel li { color: var(--muted); line-height: 1.6; }
.side-panel ul { margin: 0; padding-left: 18px; }
.settings-panel { display: grid; gap: 8px; }
.select-input { width: 100%; border: 1px solid #e5d4b7; background: #fffdf8; border-radius: 12px; padding: 8px 10px; color: var(--text); font-weight: 700; }
.toggle-row { display: flex; align-items: center; gap: 9px; color: var(--muted); font-weight: 700; margin-top: 4px; }
.capture-grid { display: grid; gap: 10px; }
.captured-row { min-height: 38px; background: #fffdf8; border: 1px solid #eadcc3; border-radius: 16px; padding: 8px 10px; color: var(--muted); line-height: 1.8; }
.captured-piece { display: inline-flex; width: 28px; height: 28px; border-radius: 50%; align-items: center; justify-content: center; margin: 2px; background: #f3dfb8; border: 1px solid #a47436; font-weight: 800; }
.captured-piece.red { color: var(--red); }
.captured-piece.black { color: var(--black); }
.section-heading-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.text-button { border: 0; background: transparent; color: var(--muted); font-weight: 800; cursor: pointer; }
.text-button:hover { color: var(--text); }
.move-log { margin: 0; padding: 10px 10px 10px 32px; max-height: 190px; overflow-y: auto; background: #fffdf8; border: 1px solid #eadcc3; border-radius: 16px; color: var(--muted); }
.move-log li { margin-bottom: 6px; line-height: 1.45; }
.move-log li:last-child { color: var(--text); font-weight: 800; }
.move-log::-webkit-scrollbar { width: 8px; }
.move-log::-webkit-scrollbar-thumb { background: #dac59d; border-radius: 99px; }
details summary { cursor: pointer; font-weight: 800; }
.site-footer { border-top: 1px solid #ecdfca; background: #fffdf8; }
.footer-inner { padding-top: 18px; padding-bottom: 18px; display: flex; justify-content: space-between; gap: 18px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: 0.95rem; }
.footer-brand { color: var(--text); font-weight: 800; margin-bottom: 4px; }
.footer-tagline { color: var(--muted); }
@media (max-width: 980px) {
  .game-layout { grid-template-columns: 1fr; }
  .side-panel { max-width: none; justify-self: stretch; margin-top: 0; }
  .side-panel { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .side-panel section + section { margin-top: 0; padding-top: 0; border-top: 0; }
}
@media (max-width: 760px) {
  .side-panel { display: block; }
  .side-panel section + section { margin-top: 14px; padding-top: 14px; border-top: 1px solid #eadcc3; }
}
@media (max-width: 640px) {
  :root { --cell: 46px; }
  .header-inner { justify-content: center; text-align: center; }
  .brand-wrap, .footer-brand-block { width: 100%; text-align: center; }
  .site-nav, .footer-links, .breadcrumb-bar { justify-content: center; }
  .page-shell { padding-top: 16px; padding-bottom: 28px; }
  .hero-card, .game-card { border-radius: 20px; padding: 14px; }
  .toolbar-value { font-size: 1.35rem; }
  .river-label { font-size: 0.8rem; letter-spacing: 0.22em; }
  .piece { width: 38px; height: 38px; font-size: 1.25rem; }
  .capture-ring { width: 42px; height: 42px; border-width: 3px; }
  .last-move-mark { width: 46px; height: 46px; }
  .legal-dot { width: 12px; height: 12px; border-width: 2px; }
  .footer-inner { justify-content: center; text-align: center; }
}
