:root {
  color-scheme: light;
  --bg: #edf2f7;
  --bg-accent: #f7fafc;
  --surface: rgba(255,255,255,.92);
  --surface-strong: #ffffff;
  --surface-alt: #f6f8fb;
  --surface-soft: #eef3f8;
  --text: #1a2430;
  --muted: #677789;
  --border: #d8e1ea;
  --primary: #4f8b3a;
  --primary-strong: #3b6e2a;
  --primary-soft: rgba(79, 139, 58, .14);
  --board-light: #eeecd3;
  --board-dark: #779954;
  --selected: #f3c95e;
  --legal: rgba(57, 107, 45, .45);
  --last: rgba(243, 201, 94, .45);
  --danger: #d85a5f;
  --shadow: 0 24px 50px rgba(17, 24, 39, .12);
  --shadow-soft: 0 12px 28px rgba(17, 24, 39, .08);
  --radius: 24px;
  --piece-white-fill: #f9fafb;
  --piece-white-stroke: #727b85;
  --piece-white-eye: #5c6470;
  --piece-black-fill: #4a4f56;
  --piece-black-stroke: #252a30;
  --piece-black-eye: #f4f7fa;
}
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1720;
  --bg-accent: #16202b;
  --surface: rgba(19, 28, 37, .92);
  --surface-strong: #15212b;
  --surface-alt: #1a2a36;
  --surface-soft: #172530;
  --text: #edf4f8;
  --muted: #9ab0bd;
  --border: #2b3c49;
  --primary: #7ac95f;
  --primary-strong: #9ee280;
  --primary-soft: rgba(122, 201, 95, .16);
  --board-light: #d8d6bb;
  --board-dark: #678a49;
  --selected: #f2c65c;
  --legal: rgba(139, 221, 103, .42);
  --last: rgba(242, 198, 92, .32);
  --danger: #ff7b82;
  --shadow: 0 26px 60px rgba(0,0,0,.38);
  --shadow-soft: 0 14px 30px rgba(0,0,0,.28);
  --piece-white-fill: #fbfcfe;
  --piece-white-stroke: #8b96a3;
  --piece-white-eye: #6e7781;
  --piece-black-fill: #454a51;
  --piece-black-stroke: #11161b;
  --piece-black-eye: #f5f7fb;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, var(--bg-accent) 0, transparent 32%),
    linear-gradient(180deg, color-mix(in srgb, var(--surface-strong) 30%, var(--bg)) 0, var(--bg) 100%);
}
button, select, input { font: inherit; }
button, select { cursor: pointer; }
a { color: inherit; }
.site-header {
  min-height: 78px;
  padding: 14px clamp(16px, 4vw, 42px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(18px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 86%, transparent);
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: linear-gradient(180deg, var(--primary), var(--primary-strong));
  color: #fff;
  font-size: 28px;
  box-shadow: 0 10px 22px color-mix(in srgb, var(--primary) 36%, transparent);
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 18px; letter-spacing: -.02em; }
.brand small { color: var(--muted); font-size: 12px; margin-top: 2px; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.icon-button, .theme-toggle {
  min-height: 42px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-strong) 86%, transparent);
  color: var(--text);
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--shadow-soft);
}
.icon-button { width: 42px; padding: 0; }
.theme-toggle { padding: 0 13px; }
.app-shell {
  width: min(1200px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 44px;
}
.hero-copy {
  max-width: 760px;
  margin: 0 auto 26px;
  text-align: center;
}
.eyebrow, .status-kicker {
  color: var(--primary);
  font-size: 11px;
  letter-spacing: .16em;
  font-weight: 800;
}
.hero-copy h1 {
  margin: 10px 0 12px;
  font-size: clamp(30px, 4.4vw, 50px);
  line-height: 1.04;
  letter-spacing: -.045em;
}
.hero-copy p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: clamp(15px, 1.75vw, 18px);
  line-height: 1.6;
}
.ad-slot {
  min-height: 92px;
  border: 1px dashed color-mix(in srgb, var(--border) 78%, var(--primary) 22%);
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: var(--muted);
  margin: 0 0 22px;
  background: color-mix(in srgb, var(--surface-strong) 84%, transparent);
}
.hidden { display: none !important; }
.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 700px) minmax(320px, 380px);
  justify-content: center;
  align-items: start;
  gap: 22px;
}
.board-panel, .control-panel, .feature-grid article {
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--border) 90%, transparent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.board-panel {
  min-width: 0;
  padding: 16px;
}
.player-strip {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 3px 4px 12px;
}
.player-strip:last-child { padding: 12px 4px 3px; }
.player-strip strong, .player-strip span { display: block; }
.player-strip span { color: var(--muted); font-size: 12px; margin-top: 2px; }
.avatar {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-size: 24px;
}
.bot-avatar { background: var(--surface-soft); color: var(--text); }
.turn-dot {
  margin-left: auto !important;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--border) 80%, transparent);
}
.turn-dot.active {
  background: var(--primary);
  box-shadow: 0 0 0 5px var(--primary-soft);
}
.board-wrap {
  position: relative;
  width: min(100%, 620px);
  margin: 0 auto;
  padding: 10px;
  border-radius: 20px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface-alt) 92%, transparent), color-mix(in srgb, var(--surface-soft) 72%, transparent));
  border: 1px solid color-mix(in srgb, var(--border) 84%, transparent);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.45);
}
.chessboard {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid rgba(0,0,0,.08);
  box-shadow: 0 18px 36px rgba(0,0,0,.14);
  user-select: none;
  touch-action: manipulation;
  background: var(--board-dark);
}
.square {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  padding: 0;
  line-height: 1;
  transition: background-color .14s ease, box-shadow .18s ease;
  -webkit-tap-highlight-color: transparent;
}
.square.light { background: var(--board-light); }
.square.dark { background: var(--board-dark); }
.square:focus { outline: none; }
.square:focus-visible {
  box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 6px var(--primary);
  z-index: 4;
}
.square.can-select:hover:not(.selected) {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--primary) 52%, transparent);
}
.piece-shell {
  width: 88%;
  height: 88%;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.piece-shell.white {
  --piece-fill: var(--piece-white-fill);
  --piece-stroke: var(--piece-white-stroke);
  --piece-eye: var(--piece-white-eye);
}
.piece-shell.black {
  --piece-fill: var(--piece-black-fill);
  --piece-stroke: var(--piece-black-stroke);
  --piece-eye: var(--piece-black-eye);
}
.piece-svg {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 1px 0 rgba(255,255,255,.16)) drop-shadow(0 6px 8px rgba(0,0,0,.18));
  transition: transform .16s ease, filter .16s ease;
}
.square.selected .piece-svg,
.square.can-select:hover .piece-svg {
  transform: translateY(-2px) scale(1.03);
}
.square.selected {
  box-shadow: inset 0 0 0 4px var(--selected), inset 0 0 0 1px rgba(255,255,255,.22);
}
.square.last-move {
  background-image: linear-gradient(var(--last), var(--last));
}
.square.last-move .piece-svg {
  animation: piece-land .22s ease;
}
.square.legal::after {
  content: "";
  position: absolute;
  width: 22%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--legal);
  z-index: 1;
}
.square.capture::after {
  width: 82%;
  background: transparent;
  border: 4px solid var(--legal);
}
.square.check {
  box-shadow: inset 0 0 0 5px var(--danger), inset 0 0 0 1px rgba(255,255,255,.18);
}
.coordinate {
  position: absolute;
  z-index: 3;
  font-size: 10px;
  font-weight: 800;
  opacity: .76;
  pointer-events: none;
}
.coordinate.file { right: 5px; bottom: 3px; }
.coordinate.rank { left: 5px; top: 3px; }
.thinking-badge {
  position: absolute;
  z-index: 6;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 15px;
  border-radius: 999px;
  background: rgba(17, 24, 39, .88);
  color: #fff;
  font-size: 13px;
  box-shadow: 0 14px 30px rgba(0,0,0,.28);
}
.control-panel {
  padding: 18px;
  display: grid;
  gap: 16px;
}
.status-card {
  padding: 18px;
  border-radius: 18px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--primary-soft) 100%, transparent), color-mix(in srgb, var(--surface-strong) 86%, transparent));
  border: 1px solid color-mix(in srgb, var(--primary) 26%, var(--border));
}
.status-card strong, .status-card span { display: block; }
.status-card strong {
  margin: 6px 0;
  font-size: 24px;
  letter-spacing: -.03em;
}
.status-card span:last-child {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
label {
  display: grid;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}
select, input {
  width: 100%;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-alt) 92%, transparent);
  color: var(--text);
  border-radius: 14px;
  padding: 12px 13px;
  outline: none;
}
select:focus, input:focus {
  border-color: color-mix(in srgb, var(--primary) 50%, var(--border));
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.primary-actions {
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr;
  gap: 10px;
}
.button {
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface-alt) 92%, transparent);
  color: var(--text);
  padding: 10px 14px;
  font-weight: 760;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
}
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.button.primary {
  background: linear-gradient(180deg, var(--primary), var(--primary-strong));
  border-color: color-mix(in srgb, var(--primary-strong) 85%, transparent);
  color: #fff;
}
.moves-card {
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  background: color-mix(in srgb, var(--surface-strong) 88%, transparent);
}
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.section-heading button {
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}
.move-list {
  margin: 0;
  padding: 14px 14px 14px 38px;
  max-height: 230px;
  overflow: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 20px;
  font-variant-numeric: tabular-nums;
}
.move-list li { padding: 6px 4px; color: var(--text); }
.empty-state {
  grid-column: 1 / -1;
  color: var(--muted) !important;
  list-style: none;
  text-align: center;
  padding: 22px !important;
}
.small-actions { display: grid; gap: 12px; }
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  color: var(--text);
  font-weight: 650;
}
.switch-row input { width: 44px; height: 23px; accent-color: var(--primary); }
.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-top: 26px;
}
.feature-grid article {
  padding: 22px;
  box-shadow: var(--shadow-soft);
}
.feature-grid article > span { font-size: 25px; }
.feature-grid h2 { margin: 12px 0 8px; font-size: 17px; }
.feature-grid p { margin: 0; color: var(--muted); line-height: 1.58; font-size: 14px; }
footer {
  padding: 22px clamp(16px, 4vw, 42px);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  border-top: 1px solid color-mix(in srgb, var(--border) 86%, transparent);
  font-size: 13px;
}
dialog {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  width: calc(100% - 30px);
  max-width: 560px;
}
dialog::backdrop {
  background: rgba(4, 10, 14, .66);
  backdrop-filter: blur(4px);
}
.settings-modal {
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 22px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
}
.modal-heading { display: flex; justify-content: space-between; align-items: flex-start; }
.modal-heading h2 { margin: 5px 0 0; font-size: 25px; }
.notice {
  margin: 0;
  padding: 13px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.boxed { border: 1px solid var(--border); padding: 13px; border-radius: 14px; }
.boxed span { display: grid; gap: 4px; }
.boxed small { color: var(--muted); font-weight: 500; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 130%);
  background: rgba(17, 24, 39, .96);
  color: #fff;
  padding: 11px 16px;
  border-radius: 14px;
  transition: transform .25s ease;
  z-index: 50;
  box-shadow: var(--shadow);
}
.toast.show { transform: translate(-50%, 0); }
@keyframes piece-land {
  0% { transform: translateY(-6px) scale(1.06); }
  100% { transform: translateY(0) scale(1); }
}
@media (max-width: 980px) {
  .game-layout { grid-template-columns: 1fr; }
  .board-wrap { width: min(100%, 680px); }
  .control-panel { grid-template-columns: 1fr 1fr; }
  .status-card, .moves-card, .small-actions { grid-column: 1 / -1; }
}
@media (max-width: 680px) {
  .site-header { min-height: 68px; padding: 10px 14px; }
  .brand small, .theme-label { display: none; }
  .app-shell { width: min(100% - 18px, 1200px); padding: 22px 0 34px; }
  .hero-copy { margin-bottom: 18px; }
  .hero-copy h1 { font-size: 32px; }
  .hero-copy p:last-child { font-size: 15px; }
  .board-panel { padding: 12px; border-radius: 18px; }
  .board-wrap { padding: 8px; }
  .control-panel { grid-template-columns: 1fr; padding: 14px; }
  .status-card, .moves-card, .small-actions { grid-column: auto; }
  .setup-grid { grid-template-columns: 1fr 1fr; }
  .primary-actions { grid-template-columns: 1fr 1fr; }
  .primary-actions .primary { grid-column: 1 / -1; }
  .feature-grid { grid-template-columns: 1fr; }
  .coordinate { font-size: 8px; }
  footer { flex-direction: column; text-align: center; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
.square.selected .piece-svg{filter:drop-shadow(0 2px 0 rgba(255,255,255,.2)) drop-shadow(0 10px 14px rgba(0,0,0,.24));}
.piece-shell.white .piece-svg{filter:drop-shadow(0 1px 0 rgba(255,255,255,.22)) drop-shadow(0 7px 10px rgba(0,0,0,.16));}
.piece-shell.black .piece-svg{filter:drop-shadow(0 1px 0 rgba(255,255,255,.06)) drop-shadow(0 8px 12px rgba(0,0,0,.28));}
.player-details { min-width:0; flex:1; }
.material-row {
  min-height:22px;
  margin-top:5px;
  display:flex;
  align-items:center;
  gap:7px;
  overflow:hidden;
}
.captured-pieces {
  min-width:0;
  display:flex;
  align-items:center;
  gap:0;
  overflow:hidden;
}
.captured-piece {
  width:18px;
  height:20px;
  display:inline-grid;
  place-items:center;
  margin-right:-3px;
  flex:0 0 auto;
}
.captured-piece .piece-shell {
  width:19px;
  height:19px;
}
.captured-piece .piece-svg {
  width:19px;
  height:19px;
  filter:drop-shadow(0 1px 1px rgba(0,0,0,.18));
}
.material-score {
  flex:0 0 auto;
  color:var(--muted)!important;
  font-size:10px!important;
  font-weight:800;
  letter-spacing:.02em;
}
.advantage-badge {
  flex:0 0 auto;
  padding:2px 6px;
  border-radius:999px;
  color:var(--primary-strong)!important;
  background:var(--primary-soft);
  font-size:10px!important;
  font-weight:900;
  margin:0!important;
}
.material-empty {
  color:var(--muted)!important;
  font-size:10px!important;
  opacity:.8;
}
@media (max-width:680px) {
  .captured-piece { width:16px; height:18px; }
  .captured-piece .piece-shell,
  .captured-piece .piece-svg { width:17px; height:17px; }
  .material-row { gap:5px; }
}
