:root {
  color-scheme: dark;
  --page: #111714;
  --surface: #1a211d;
  --surface-raised: #202923;
  --surface-hover: #28332c;
  --line: #2b352e;
  --text: #edf2eb;
  --muted: #89968c;
  --green: #9dc575;
  --green-strong: #b1d88a;
  --green-deep: #506b3f;
  --board-light: #e6e3d8;
  --board-dark: #78946b;
  --board-last: #b4c97b;
  --board-selected: #c1d47d;
  --danger: #e07e71;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(ellipse at 12% 0%, rgb(91 123 71 / 10%), transparent 42%),
    var(--page);
  color: var(--text);
}

button, select { font: inherit; }
button { color: inherit; }
button:focus-visible, select:focus-visible, a:focus-visible, input:focus-visible + .toggle-ui {
  outline: 2px solid var(--green-strong);
  outline-offset: 3px;
}

.app-shell { width: min(1320px, 100% - 64px); margin: 0 auto; }
.topbar { height: 76px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgb(255 255 255 / 5%); }
.brand { display: inline-flex; gap: 10px; align-items: center; color: var(--text); text-decoration: none; font: 800 16px Manrope, sans-serif; letter-spacing: 1.8px; }
.brand-mark { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 11px; background: #28352a; color: var(--green-strong); font-size: 22px; }
.brand-period { color: var(--green); }
.topbar-center, .engine-badge { display: flex; align-items: center; gap: 9px; color: #a4afa6; font-size: 10px; font-weight: 700; letter-spacing: 1.3px; }
.live-dot, .engine-dot, .turn-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: var(--green); box-shadow: 0 0 11px rgb(157 197 117 / 55%); }
.engine-badge { padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: rgb(26 33 29 / 74%); font-size: 10px; letter-spacing: .3px; text-transform: uppercase; }
.engine-dot { width: 6px; height: 6px; }
.engine-badge.is-loading .engine-dot { background: #d7ae5e; animation: pulse 1.1s infinite; }
.engine-badge.is-error .engine-dot { background: var(--danger); box-shadow: none; }
.mobile-settings { display: none !important; }

.main-layout { display: grid; grid-template-columns: minmax(0, 1fr) 370px; gap: 46px; align-items: start; padding: 34px 0 50px; }
.game-column { width: 100%; max-width: 766px; justify-self: center; }
.game-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 0 0 22px; }
.eyebrow { margin: 0 0 7px; color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: 1.65px; }
h1, h2, p { margin-top: 0; }
h1, h2 { font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif; }
h1 { margin-bottom: 0; font-size: clamp(22px, 2.5vw, 29px); font-weight: 700; letter-spacing: -.8px; }
h2 { margin-bottom: 0; font-size: 15px; font-weight: 700; letter-spacing: -.2px; }
.button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; padding: 0 15px; border: 1px solid transparent; border-radius: 9px; cursor: pointer; font-size: 12px; font-weight: 700; transition: background .18s, border-color .18s, transform .18s, box-shadow .18s; }
.button:hover { transform: translateY(-1px); }
.button-primary { background: var(--green); color: #172014; box-shadow: 0 5px 16px rgb(118 156 82 / 15%); }
.button-primary:hover { background: var(--green-strong); box-shadow: 0 7px 20px rgb(118 156 82 / 24%); }
.button-secondary { border-color: #506b3f; background: #28352a; color: #c8dfae; }
.button-secondary:hover { background: #32432f; }
.button:disabled, .text-button:disabled { opacity: .48; cursor: not-allowed; transform: none; }

.board-wrap { width: min(100%, 742px); margin: 0 auto; }
.player-strip { height: 58px; display: flex; align-items: center; gap: 11px; }
.opponent-strip { margin-bottom: 10px; }
.human-strip { margin-top: 10px; }
.avatar { width: 35px; height: 35px; display: grid; flex: 0 0 auto; place-items: center; border: 1px solid var(--line); border-radius: 10px; font-size: 21px; }
.engine-avatar { background: #273328; color: #c3d7ae; }
.human-avatar { background: #30362c; color: #e4d8b7; font: 700 14px "Segoe UI", sans-serif; }
.player-copy { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.player-copy strong { font-size: 12px; font-weight: 700; }
.player-copy > span { color: var(--muted); font-size: 10px; }
.bot-tag, .you-tag { margin-left: 4px; padding: 3px 5px; border-radius: 4px; background: #29382c; color: var(--green); font-size: 7px; font-weight: 700; letter-spacing: .8px; vertical-align: 1px; }
.you-tag { background: #34372d; color: #cbbf8b; }
.material-score { min-width: 24px; color: var(--green-strong); font-size: 10px; }
.clock { min-width: 79px; margin-left: auto; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; background: #1b221e; color: #d4ddd3; font: 700 15px "Segoe UI", sans-serif; text-align: center; font-variant-numeric: tabular-nums; }
.clock.is-active { border-color: #607c4e; background: #28352a; color: #e3f0d7; box-shadow: 0 0 14px rgb(157 197 117 / 7%); }
.clock.is-low { border-color: #8d554d; color: #f0a195; animation: pulse 1s infinite; }

.board-frame { width: 100%; padding: 0; overflow: hidden; border: 1px solid rgb(235 241 229 / 12%); border-radius: 8px; background: #303c31; box-shadow: 0 22px 65px rgb(0 0 0 / 28%), 0 3px 12px rgb(0 0 0 / 18%); }
.chessboard { display: grid; width: 100%; aspect-ratio: 1; grid-template: repeat(8, 1fr) / repeat(8, 1fr); touch-action: manipulation; user-select: none; }
.square { position: relative; display: grid; min-width: 0; min-height: 0; padding: 0; place-items: center; border: 0; border-radius: 0; cursor: pointer; transition: filter .12s, background-color .12s; }
.square.light { background: var(--board-light); }
.square.dark { background: var(--board-dark); }
.square:hover { filter: brightness(1.09); }
.square.last-move.light { background: #c7d398; }
.square.last-move.dark { background: #a3b86e; }
.square.selected { background: var(--board-selected) !important; }
.square.in-check { background: #cf766a !important; }
.piece { z-index: 1; display: block; font-family: "DejaVu Sans", "Segoe UI Symbol", serif; font-size: clamp(28px, 6.15vw, 62px); line-height: 1; cursor: grab; transition: transform .13s ease; }
.piece.white-piece { color: #fffdf1; text-shadow: 0 2px 2px rgb(0 0 0 / 50%), 0 0 1px #34372f; }
.piece.black-piece { color: #262c27; text-shadow: 0 1px 1px rgb(255 255 255 / 38%); }
.piece:active { cursor: grabbing; }
.piece.piece-arrived { animation: piece-arrive .18s ease-out; }
.square.drag-over { box-shadow: inset 0 0 0 4px rgb(239 246 207 / 78%); }
.square.legal-target::after { position: absolute; width: 22%; height: 22%; border-radius: 50%; background: rgb(31 47 28 / 36%); content: ""; }
.square.legal-capture::after { position: absolute; inset: 3px; border: 5px solid rgb(34 48 30 / 36%); border-radius: 50%; content: ""; }
.square.last-move.legal-target::after, .square.last-move.legal-capture::after { opacity: .75; }
.coordinate { position: absolute; z-index: 2; left: 4px; top: 2px; color: #394536; font: 700 clamp(8px, 1.25vw, 11px) "Segoe UI", sans-serif; line-height: 1; pointer-events: none; }
.square.dark .coordinate { color: #edf1dc; }
.file-coordinate { inset: auto 4px 3px auto; }
.board-footer { display: flex; align-items: center; justify-content: space-between; margin: 13px 0 0; }
.turn-indicator { display: flex; align-items: center; gap: 8px; color: #b6c0b5; font-size: 11px; }
.turn-dot { width: 6px; height: 6px; }
.turn-dot.is-thinking { background: #d7ae5e; box-shadow: 0 0 10px rgb(215 174 94 / 50%); }
.board-actions { display: flex; align-items: center; gap: 12px; }
.text-button { display: inline-flex; align-items: center; gap: 5px; padding: 5px; border: 0; background: transparent; color: #9da89e; cursor: pointer; font-size: 17px; transition: color .18s; }
.text-button span { font-size: 10px; }
.text-button:hover { color: var(--green-strong); }

.sidebar { display: flex; flex-direction: column; gap: 13px; }
.panel { padding: 17px; border: 1px solid var(--line); border-radius: 12px; background: linear-gradient(140deg, rgb(31 39 33 / 97%), rgb(25 32 28 / 98%)); box-shadow: 0 8px 26px rgb(0 0 0 / 9%); }
.panel-heading, .section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-heading .eyebrow, .section-title .eyebrow { margin-bottom: 5px; }
.status-icon, .settings-glyph, .analysis-glyph { color: #82966d; font-size: 20px; }
.status-message { margin: 11px 0 0; color: #9ca89d; font-size: 11px; line-height: 1.55; }
.thinking-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: #cad9bc; font-size: 10px; }
.thinking-row[hidden] { display: none; }
.thinking-spinner { width: 13px; height: 13px; border: 2px solid #53634b; border-top-color: var(--green-strong); border-radius: 50%; animation: spin .75s linear infinite; }
.moves-panel { padding-bottom: 12px; }
.move-count { color: #7d8a7f; font-size: 8px; font-weight: 700; letter-spacing: 1px; }
.move-list { display: grid; max-height: 177px; grid-template-columns: 35px 1fr 1fr; align-content: start; margin: 13px -4px 0; overflow: auto; scrollbar-color: #465348 transparent; scrollbar-width: thin; }
.move-row { display: contents; }
.move-number, .move-cell { min-height: 30px; display: flex; align-items: center; padding: 0 8px; border-radius: 5px; font-size: 11px; }
.move-number { color: #77847a; font-size: 9px; }
.move-cell { color: #cbd4ca; font-variant-numeric: tabular-nums; }
.move-cell.latest { background: #303c31; color: #d9e9c8; font-weight: 700; }
.empty-moves { grid-column: 1 / -1; margin: 3px 0 8px; color: #7f8b80; font-size: 10px; }
.move-tools { display: flex; justify-content: flex-end; gap: 15px; margin-top: 7px; padding-top: 8px; border-top: 1px solid rgb(255 255 255 / 5%); }
.move-tools .text-button { font-size: 14px; }
.field-label { display: block; margin: 12px 0 6px; color: #aeb8af; font-size: 10px; font-weight: 600; }
.select-control { width: 100%; height: 37px; padding: 0 10px; border: 1px solid #354138; border-radius: 7px; background: #181f1b; color: #e0e7dc; cursor: pointer; font-size: 11px; }
.select-control:hover { border-color: #53644f; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.field-pair .field-label { margin-top: 11px; }
.toggle-list { margin-top: 12px; }
.toggle-row { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 42px; border-top: 1px solid rgb(255 255 255 / 5%); cursor: pointer; }
.toggle-row > span:first-child { display: flex; flex-direction: column; gap: 2px; }
.toggle-row strong { color: #cbd4ca; font-size: 10px; font-weight: 600; }
.toggle-row small { color: #7d8980; font-size: 9px; }
.toggle-row input { position: absolute; right: 0; width: 36px; height: 21px; opacity: 0; }
.toggle-ui { position: relative; width: 34px; height: 19px; flex: 0 0 auto; border: 1px solid #435047; border-radius: 20px; background: #303933; transition: background .18s, border-color .18s; }
.toggle-ui::after { position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%; background: #89958a; content: ""; transition: transform .18s, background .18s; }
.toggle-row input:checked + .toggle-ui { border-color: #77995d; background: #526d43; }
.toggle-row input:checked + .toggle-ui::after { transform: translateX(15px); background: #e5efd9; }
.toggle-row input:focus-visible + .toggle-ui { outline: 2px solid var(--green-strong); outline-offset: 3px; }
.start-game-button { width: 100%; margin-top: 13px; }
.analysis-copy { min-height: 30px; margin: 11px 0; color: #9ca89d; font-size: 10px; line-height: 1.6; }
.button-analysis { width: 100%; border-color: #354138; background: #202923; color: #c8d3c6; }
.button-analysis:hover { border-color: #688054; background: #28352a; color: var(--green-strong); }
.footer-note { margin: 1px 3px 0; color: #68756b; font-size: 9px; text-align: center; letter-spacing: .3px; }
.toast { position: fixed; z-index: 10; right: 24px; bottom: 24px; max-width: min(360px, calc(100vw - 32px)); padding: 11px 15px; transform: translateY(14px); border: 1px solid #465348; border-radius: 9px; background: #263129; color: #dce8d5; font-size: 11px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.visible { transform: translateY(0); opacity: 1; }
.game-over-overlay[hidden] { display: none; }
.game-over-overlay { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 20px; background: rgb(7 10 8 / 78%); backdrop-filter: blur(7px); animation: overlay-in .18s ease-out; }
.game-over-card { width: min(420px, 100%); padding: 30px; border: 1px solid #465849; border-radius: 17px; background: linear-gradient(145deg, #242e27, #19201b); box-shadow: 0 24px 80px rgb(0 0 0 / 48%); text-align: center; animation: card-in .22s ease-out; }
.game-over-piece { display: grid; width: 58px; height: 58px; place-items: center; margin: 0 auto 17px; border: 1px solid #52684d; border-radius: 17px; background: #2d3b2e; color: var(--green-strong); font: 40px "Segoe UI Symbol", serif; }
.game-over-card .eyebrow { margin-bottom: 8px; }
.game-over-card h2 { font-size: 24px; }
.game-over-message { margin: 11px 0 21px; color: #aab6ab; font-size: 13px; line-height: 1.55; }
.game-over-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes card-in { from { transform: translateY(8px) scale(.98); opacity: .7; } to { transform: translateY(0) scale(1); opacity: 1; } }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .5; } }
@keyframes piece-arrive { from { transform: scale(.78); opacity: .65; } to { transform: scale(1); opacity: 1; } }

@media (min-width: 1200px) {
  .main-layout { grid-template-columns: minmax(0, 766px) 370px; gap: 46px; }
}

@media (max-width: 1000px) {
  .app-shell { width: min(100% - 40px, 820px); }
  .main-layout { grid-template-columns: minmax(0, 1fr) 330px; gap: 24px; }
  .game-column { min-width: 0; }
  .board-wrap { width: 100%; }
  .panel { padding: 14px; }
  .main-layout { padding-top: 27px; }
}

@media (max-width: 760px) {
  .app-shell { width: min(100% - 32px, 560px); }
  .topbar { height: 64px; }
  .topbar-center { display: none; }
  .engine-badge { margin-left: auto; padding: 8px 10px; font-size: 9px; }
  .main-layout { display: flex; flex-direction: column; gap: 24px; padding-top: 23px; }
  .game-column, .sidebar { width: 100%; max-width: none; }
  .game-heading { align-items: center; margin-bottom: 13px; }
  .game-heading .eyebrow { font-size: 8px; }
  h1 { max-width: 265px; font-size: clamp(20px, 5vw, 26px); line-height: 1.2; }
  .new-game-top { min-height: 37px; padding: 0 11px; font-size: 10px; white-space: nowrap; }
  .board-wrap { width: min(100%, 540px); }
  .player-strip { height: 48px; }
  .opponent-strip { margin-bottom: 7px; }
  .human-strip { margin-top: 7px; }
  .avatar { width: 31px; height: 31px; }
  .clock { min-width: 68px; padding: 6px 7px; font-size: 13px; }
  .piece { font-size: clamp(30px, 10.1vw, 56px); }
  .sidebar { gap: 11px; }
  .panel { padding: 16px; }
  .move-list { max-height: 210px; }
  .game-over-card { padding: 25px 20px; }
  .game-over-actions { flex-direction: column; }
  .game-over-actions .button { width: 100%; }
}

@media (max-width: 390px) {
  .app-shell { width: calc(100% - 22px); }
  .brand { gap: 7px; font-size: 14px; }
  .brand-mark { width: 30px; height: 30px; }
  .engine-badge { font-size: 8px; }
  .new-game-top { gap: 5px; padding: 0 9px; }
  .player-copy strong { font-size: 11px; }
  .clock { min-width: 62px; font-size: 12px; }
  .piece { font-size: 9.8vw; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
