/* ════════════════════════════════════════════════
   Super Engine — B&W UI, high-contrast board
   ════════════════════════════════════════════════ */
:root {
  /* UI chrome (black & white) */
  --bg: #0b0b0b;
  --bg2: #141414;
  --bg3: #1d1d1d;
  --bg4: #2a2a2a;
  --border: #2c2c2c;
  --text: #f2f2f2;
  --text2: #a0a0a0;
  --text3: #626262;
  --accent: #ffffff;
  --accent-ink: #000;
  --ok: #3ddc84;
  --err: #ff5252;
  --info: #4fc3f7;

  /* Board — mid tone so BOTH colors pop */
  --frame: #23272e;
  --grid-line: #5c6573;
  --cell-bg: #363c46;
  --cell-hover: #414856;
  --lbl-color: #8b95a5;

  /* Stones */
  --ring-b: rgba(255,255,255,.28);
  --ring-w: rgba(0,0,0,.55);
  --x-color: #ff5a5a;
  --o-color: #4fb3ff;

  /* Highlights */
  --last-bg: #c79a1e;
  --last-dot: #ff3b30;
  --win-bg: #2e8b57;
  --win-line: #39ff88;
  --preview: #4fc3f7;

  /* Chessboard squares */
  --csq-l: #838d9e;
  --csq-d: #3b424f;

  --cell: 36px;
  --gw: 2px;
  --lbl: 18px;
  --radius: 8px;
  --mono: 'Cascadia Mono', 'Consolas', 'SF Mono', monospace;
}

/* ═════════ THEMES ═════════ */
[data-theme="light"] {
  --bg: #f4f4f4; --bg2: #ffffff; --bg3: #ececec; --bg4: #dcdcdc;
  --border: #d6d6d6; --text: #111; --text2: #555; --text3: #999;
  --accent: #111; --accent-ink: #fff;
  --frame: #d5dae1; --grid-line: #9aa3b0; --cell-bg: #e9ecf0; --cell-hover: #dde2e8;
  --lbl-color: #6b7482;
  --ring-b: rgba(0,0,0,.6); --ring-w: rgba(0,0,0,.65);
  --x-color: #e53935; --o-color: #1565c0;
  --last-bg: #ffd54f; --win-bg: #a5d6a7; --win-line: #00a152;
  --csq-l: #f0f2f5; --csq-d: #8b9bb0;
}
[data-theme="blue"] {
  --frame: #142338; --grid-line: #3f6597; --cell-bg: #24406a; --cell-hover: #2c4d7e;
  --lbl-color: #7fa3d1;
  --last-bg: #d4a017;
  --csq-l: #9bb8dc; --csq-d: #2f5384;
}
[data-theme="green"] {
  --frame: #15281b; --grid-line: #4f8a62; --cell-bg: #2f5a3c; --cell-hover: #386a47;
  --lbl-color: #84b893;
  --last-bg: #d4a017;
  --csq-l: #a8c9b0; --csq-d: #366645;
}
[data-theme="wood"] {
  --frame: #a8822f; --grid-line: #7a5a17; --cell-bg: #dcb35c; --cell-hover: #e6c272;
  --lbl-color: #4a3608;
  --ring-b: rgba(0,0,0,.6); --ring-w: rgba(0,0,0,.6);
  --last-bg: #ff9f43; --win-bg: #7bc67b;
  --csq-l: #f0d9b5; --csq-d: #b58863;
}
[data-theme="caro"] {
  --bg: #f4f4f4; --bg2: #ffffff; --bg3: #ececec; --bg4: #dcdcdc;
  --border: #d6d6d6; --text: #111; --text2: #555; --text3: #999;
  --accent: #111; --accent-ink: #fff;
  --frame: #ffffff; --grid-line: #9dbbe6; --cell-bg: #ffffff; --cell-hover: #eef4ff;
  --lbl-color: #5b7fb5;
  --ring-b: rgba(0,0,0,.6); --ring-w: rgba(0,0,0,.7);
  --x-color: #e53935; --o-color: #1565c0;
  --last-bg: #fff176; --win-bg: #c8e6c9; --win-line: #00a152;
  --csq-l: #ffffff; --csq-d: #9dbbe6;
}

/* ═════════ BASE ═════════ */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  height: 100%; overflow: hidden;
  font-family: -apple-system, 'Segoe UI', 'Inter', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; }
[hidden] { display: none !important; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }

.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }

/* Header */
.header {
  height: 46px; flex-shrink: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 14px; background: var(--bg2); border-bottom: 1px solid var(--border);
}
.header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { font-weight: 800; font-size: 1rem; letter-spacing: -.3px; color: var(--text); white-space: nowrap; }
.game-switch {
  display: inline-flex; padding: 2px; background: var(--bg3);
  border: 1px solid var(--border); border-radius: 10px; gap: 2px;
}
.gs-btn {
  padding: 4px 10px; border: none; border-radius: 8px; cursor: pointer;
  background: transparent; color: var(--text2); font-size: .76rem; font-weight: 700;
  transition: background .15s, color .15s; white-space: nowrap;
}
.gs-btn:hover { color: var(--text); }
.gs-btn.on { background: var(--accent); color: var(--accent-ink); }
.header-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.engine-tag {
  font: 600 .66rem var(--mono); color: var(--text2);
  padding: 3px 8px; border: 1px solid var(--border); border-radius: 20px;
}
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--err); transition: background .3s; }
.conn-dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }

.main { flex: 1; display: flex; overflow: hidden; position: relative; min-height: 0; }

/* ═════════ PANELS ═════════ */
.panel {
  width: 272px; flex-shrink: 0; overflow-y: auto; padding: 14px;
  background: var(--bg2); border-right: 1px solid var(--border); z-index: 50;
}
.panel-right { border-right: none; border-left: 1px solid var(--border); }
.sheet-handle { display: none; }
.sec { margin-bottom: 18px; }
.sec-title {
  font-size: .66rem; font-weight: 800; letter-spacing: .8px; text-transform: uppercase;
  color: var(--text3); margin-bottom: 10px;
}
.field { margin-bottom: 10px; flex: 1; min-width: 0; }
.field > label { display: block; font-size: .74rem; color: var(--text2); margin-bottom: 4px; }
.field-row { display: flex; gap: 8px; }
.sel {
  width: 100%; padding: 8px 10px; appearance: none; -webkit-appearance: none;
  background: var(--bg3) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: .82rem; font-family: inherit; cursor: pointer; outline: none;
}
.sel:focus { border-color: var(--text2); }

.tog-row { display: flex; align-items: center; justify-content: space-between; padding: 5px 0; font-size: .8rem; color: var(--text2); }
.tog { position: relative; width: 38px; height: 22px; cursor: pointer; flex-shrink: 0; }
.tog input { display: none; }
.tog-track { display: block; width: 100%; height: 100%; background: var(--bg4); border-radius: 11px; transition: background .2s; position: relative; }
.tog-dot { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; background: var(--text3); border-radius: 50%; transition: all .2s; }
.tog input:checked + .tog-track { background: var(--accent); }
.tog input:checked + .tog-track .tog-dot { transform: translateX(16px); background: var(--accent-ink); }

.theme-row { display: flex; gap: 8px; flex-wrap: wrap; }
.theme-swatch {
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer; padding: 3px;
  background: transparent; border: 2px solid var(--border); transition: transform .15s, border-color .15s;
}
.theme-swatch i { display: block; width: 100%; height: 100%; border-radius: 50%; }
.theme-swatch:hover { transform: scale(1.08); }
.theme-swatch.on { border-color: var(--accent); }

.side-btns { display: flex; gap: 6px; }
.side-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 6px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text2); font-size: .78rem; cursor: pointer;
}
.side-btn.on { border-color: var(--accent); color: var(--text); font-weight: 700; box-shadow: inset 0 0 0 1px var(--accent); }

/* Stone dots (icons) */
.dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.dot.bk { background: radial-gradient(circle at 35% 30%, #666, #000 70%); box-shadow: 0 0 0 1.5px rgba(255,255,255,.35); }
.dot.wh { background: radial-gradient(circle at 35% 30%, #fff, #cfcfcf 75%); box-shadow: 0 0 0 1.5px rgba(0,0,0,.5); }
[data-piece="xo"] .dot.bk { background: var(--x-color); box-shadow: none; }
[data-piece="xo"] .dot.wh { background: var(--o-color); box-shadow: none; }

/* Buttons */
.btn {
  display: block; width: 100%; padding: 9px 12px; margin-bottom: 6px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: .84rem; font-weight: 600; cursor: pointer; transition: filter .15s, background .15s;
}
.btn-go { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 800; }
.btn-go:hover { filter: brightness(.9); }
.btn-def { background: var(--bg3); color: var(--text); }
.btn-def:hover { background: var(--bg4); }
.btn-hint { background: transparent; color: var(--info); border-color: var(--info); }
.btn-bvb { background: var(--bg3); color: var(--ok); border-color: var(--ok); }
.btn-bvb.running { color: #ffb74d; border-color: #ffb74d; }
.btn-bvb:hover { background: var(--bg4); }
.dot-xs { width: 10px; height: 10px; vertical-align: middle; margin-right: 3px; }
.bvb-box { margin-top: 2px; padding: 8px; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); }
.bvb-box .sel { background-color: var(--bg2); }
.preset-row { display: flex; flex-wrap: wrap; gap: 4px; }
.preset-chip {
  flex: 1 1 auto; padding: 5px 7px; border-radius: 6px; font: 700 .68rem var(--mono);
  background: var(--bg2); color: var(--text2); border: 1px solid var(--border);
  cursor: pointer; transition: border-color .15s, color .15s, background .15s; white-space: nowrap;
}
.preset-chip:hover { color: var(--text); border-color: var(--text2); }
.preset-chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-row { display: flex; gap: 6px; }
.btn-row .btn { flex: 1; }
.btn-sm { padding: 6px 8px; font-size: .74rem; margin: 0; }
.btn-icon {
  flex: 1; height: 30px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg3); color: var(--text2); font-size: .8rem; cursor: pointer;
}
.btn-icon:hover { background: var(--bg4); color: var(--text); }

/* Engine stats */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 6px; }
.stat { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; background: var(--bg3); border-radius: 6px; }
.stat-k { font-size: .62rem; color: var(--text3); font-weight: 800; text-transform: uppercase; }
.stat-v { font: 600 .76rem var(--mono); color: var(--text); }
.log-box { max-height: 110px; overflow-y: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; }
.log-text { font: .6rem/1.45 var(--mono); color: var(--text3); white-space: pre-wrap; word-break: break-all; }

/* ═════════ CENTER STAGE ═════════ */
.board-area {
  flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center;
  padding: 12px; overflow: hidden;
}
.stage { display: flex; flex-direction: column; align-items: stretch; gap: 8px; max-width: 100%; }

/* ─── Match bar ─── */
.matchbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 14px;
  min-width: 0;
}
.pcard {
  display: flex; align-items: center; gap: 9px; flex: 0 1 auto; min-width: 0;
  padding: 7px 10px; border-radius: 10px; border: 1.5px solid transparent;
  transition: border-color .2s, background .2s, box-shadow .2s;
}
.pcard.right { text-align: right; }
.pcard.active { background: var(--bg3); border-color: var(--accent); box-shadow: 0 0 14px rgba(255,255,255,.08); }
[data-theme="light"] .pcard.active, [data-theme="caro"] .pcard.active { box-shadow: 0 2px 10px rgba(0,0,0,.08); }
.pstone { width: 22px; height: 22px; }
.pinfo { min-width: 0; }
.pname { font-weight: 800; font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.psub { font: 600 .72rem var(--mono); color: var(--text2); white-space: nowrap; }
.psep { margin: 0 5px; color: var(--text3); }
.pthink { display: none; gap: 3px; }
.pcard.thinking .pthink { display: inline-flex; }
.pthink i { width: 5px; height: 5px; border-radius: 50%; background: var(--text); animation: dots 1s infinite ease-in-out; }
.pthink i:nth-child(2) { animation-delay: .15s; }
.pthink i:nth-child(3) { animation-delay: .3s; }

.mcenter { flex: 1; min-width: 70px; text-align: center; }
.mmeta { font: 700 .64rem var(--mono); color: var(--text3); letter-spacing: .3px; margin-bottom: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wdl {
  display: flex; height: 12px; border-radius: 6px; overflow: hidden;
  border: 1px solid #666; background: #777;
}
.wdl-seg { height: 100%; transition: width .6s cubic-bezier(.2,.8,.2,1); }
.wdl-b { background: linear-gradient(#2a2a2a, #000); }
.wdl-d { background: repeating-linear-gradient(45deg, #8a8a8a 0 4px, #6f6f6f 4px 8px); }
.wdl-w { background: linear-gradient(#fff, #d6d6d6); }
[data-piece="xo"] .wdl-b { background: var(--x-color); }
[data-piece="xo"] .wdl-w { background: var(--o-color); }
[data-game="chess"] .wdl-b { background: linear-gradient(#fff, #dcdcdc); }
[data-game="chess"] .wdl-w { background: linear-gradient(#2a2a2a, #000); }
.wdl-nums { display: flex; justify-content: space-between; margin-top: 4px; font: 700 .68rem var(--mono); color: var(--text2); }

.mcomment {
  text-align: center; font-size: .84rem; color: var(--text2);
  min-height: 1.35em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 0 6px;
}
.mcomment b { color: var(--text); }
.mcomment.hot { color: #ffb74d; }
.mcomment.good { color: var(--ok); }
.mcomment.bad { color: var(--err); }
.mcomment.flash { animation: flash .5s ease; }

/* ─── Board ─── */
.board-wrap { position: relative; overflow: hidden; border-radius: 12px; touch-action: none; align-self: center; max-width: 100%; }
.board {
  display: grid;
  grid-template-columns: var(--lbl) auto var(--lbl);
  grid-template-rows: var(--lbl) auto var(--lbl);
  background: var(--frame); padding: 6px; border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  transform-origin: center center;
}
.no-coords .board { --lbl: 0px; }
.no-coords .lbl { display: none; }
.lbls-h { display: grid; grid-auto-flow: column; grid-auto-columns: var(--cell); gap: var(--gw); padding: 0 var(--gw); }
.lbls-v { display: grid; grid-auto-rows: var(--cell); gap: var(--gw); padding: var(--gw) 0; }
.lbl { display: flex; align-items: center; justify-content: center; font: 700 .62rem var(--mono); color: var(--lbl-color); user-select: none; }

.grid {
  position: relative; display: grid;
  grid-template-columns: repeat(var(--n), var(--cell)); grid-auto-rows: var(--cell);
  gap: var(--gw); padding: var(--gw);
  background: var(--grid-line); border-radius: 3px;
}
.cell {
  position: relative; display: flex; align-items: center; justify-content: center;
  background: var(--cell-bg); cursor: pointer; transition: background .12s;
}

/* Stones */
.cell.b::after, .cell.w::after {
  content: ''; position: absolute; width: 84%; height: 84%; border-radius: 50%; z-index: 2;
  animation: pop .18s ease-out;
}
.cell.b::after {
  background: radial-gradient(circle at 34% 28%, #6a6a6a 0, #262626 38%, #000 80%);
  box-shadow: 0 0 0 1.5px var(--ring-b), 0 3px 5px rgba(0,0,0,.55);
}
.cell.w::after {
  background: radial-gradient(circle at 34% 28%, #fff 0, #f4f4f4 40%, #c8c8c8 100%);
  box-shadow: 0 0 0 1.5px var(--ring-w), 0 3px 5px rgba(0,0,0,.45);
}
/* X / O style */
[data-piece="xo"] .cell.b::after, [data-piece="xo"] .cell.w::after {
  width: 100%; height: 100%; border-radius: 0; background: none; box-shadow: none;
  display: flex; align-items: center; justify-content: center;
  font: 900 calc(var(--cell) * .74)/1 'Arial Black', Arial, sans-serif;
}
[data-piece="xo"] .cell.b::after { content: 'X'; color: var(--x-color); }
[data-piece="xo"] .cell.w::after { content: 'O'; color: var(--o-color); }

/* Ghost stone on hover (desktop) */
@media (hover: hover) {
  .grid:not(.locked) .cell:not(.b):not(.w):hover { background: var(--cell-hover); }
  .grid.turn-b:not(.locked) .cell:not(.b):not(.w):hover::after,
  .grid.turn-w:not(.locked) .cell:not(.b):not(.w):hover::after {
    content: ''; position: absolute; width: 84%; height: 84%; border-radius: 50%; opacity: .4;
  }
  .grid.turn-b:not(.locked) .cell:not(.b):not(.w):hover::after { background: #000; }
  .grid.turn-w:not(.locked) .cell:not(.b):not(.w):hover::after { background: #fff; }
  [data-piece="xo"] .grid.turn-b:not(.locked) .cell:not(.b):not(.w):hover::after { content: 'X'; background: none; color: var(--x-color); font: 900 calc(var(--cell)*.74)/1 'Arial Black',Arial; display:flex; align-items:center; justify-content:center; }
  [data-piece="xo"] .grid.turn-w:not(.locked) .cell:not(.b):not(.w):hover::after { content: 'O'; background: none; color: var(--o-color); font: 900 calc(var(--cell)*.74)/1 'Arial Black',Arial; display:flex; align-items:center; justify-content:center; }
}
.grid.locked .cell { cursor: default; }

/* Move numbers */
.mnum { position: absolute; z-index: 3; font: 800 calc(var(--cell) * .34) var(--mono); pointer-events: none; }
.cell.b .mnum { color: #fff; }
.cell.w .mnum { color: #111; }
[data-piece="xo"] .mnum { top: 1px; right: 2px; font-size: calc(var(--cell) * .24); color: var(--text3) !important; }

/* Last move: colored cell + red center dot */
.cell.last { background: var(--last-bg) !important; }
.cell.last::before {
  content: ''; position: absolute; z-index: 3; width: 26%; height: 26%; border-radius: 50%;
  background: var(--last-dot); box-shadow: 0 0 0 2px rgba(255,255,255,.85);
}
.nums-on .cell.last::before, [data-piece="xo"] .cell.last::before { display: none; }

/* Win */
.cell.win { background: var(--win-bg) !important; }
.winsvg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 6; overflow: visible; }
.winsvg line { stroke: var(--win-line); stroke-linecap: round; filter: drop-shadow(0 0 4px var(--win-line)); stroke-dasharray: 2000; stroke-dashoffset: 2000; animation: draw .6s ease-out forwards; }

/* Preview (tap-to-confirm) */
.cell.preview { background: var(--cell-hover) !important; box-shadow: inset 0 0 0 2px var(--preview); }
.cell.preview::before {
  content: ''; position: absolute; width: 70%; height: 70%; border-radius: 50%; z-index: 3;
  border: 2px dashed var(--preview); animation: spin 3s linear infinite;
}

/* Suggestion */
.cell.suggest { background: rgba(79,195,247,.28) !important; box-shadow: inset 0 0 0 2px var(--info); }
.cell.suggest::before { content: '★'; position: absolute; z-index: 3; font-size: calc(var(--cell)*.55); color: var(--info); animation: bounce .9s ease-in-out infinite; }

/* ─── Chessboard ─── */
.cgrid {
  position: relative; display: grid;
  grid-template-columns: repeat(8, var(--cell)); grid-auto-rows: var(--cell);
  border: 2px solid var(--grid-line); border-radius: 3px; overflow: hidden;
}
.csq {
  position: relative; display: flex; align-items: center; justify-content: center;
  cursor: pointer; user-select: none; transition: filter .1s;
}
.csq.l { background: var(--csq-l); }
.csq.d { background: var(--csq-d); }
.csq.last::before {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background: rgba(255, 213, 79, .45);
}
.csq.sel::before {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background: rgba(79, 195, 247, .42); box-shadow: inset 0 0 0 2.5px var(--info);
}
.csq.check {
  background: radial-gradient(circle, rgba(255,40,40,.92) 0, rgba(220,20,20,.65) 55%, rgba(160,0,0,.35) 100%) !important;
}
.csq.legal::after {
  content: ''; position: absolute; width: 28%; height: 28%; border-radius: 50%;
  background: rgba(0, 0, 0, .32); z-index: 4; pointer-events: none;
}
.csq.d.legal::after { background: rgba(255, 255, 255, .36); }
.csq.cap::after {
  content: ''; position: absolute; width: 88%; height: 88%; border-radius: 50%;
  background: transparent !important; border: 4px solid rgba(0, 0, 0, .36); z-index: 4; pointer-events: none;
}
.csq.d.cap::after { border-color: rgba(255, 255, 255, .42); }
.csq.sug-from { box-shadow: inset 0 0 0 3px var(--info); }
.csq.sug-to { box-shadow: inset 0 0 0 3px var(--ok); }
.cgrid.locked .csq { cursor: default; }
@media (hover: hover) {
  .cgrid:not(.locked) .csq:hover { filter: brightness(1.07); }
}
.cpiece {
  width: 88%; height: 88%; position: relative; z-index: 2; pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.35));
}
.carrow {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 5;
}

/* Promotion overlay */
.promo-overlay {
  position: absolute; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.62); backdrop-filter: blur(2px);
}
.promo-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px; text-align: center; box-shadow: 0 12px 32px rgba(0,0,0,.5);
}
.promo-title { font-size: .84rem; font-weight: 800; margin-bottom: 10px; color: var(--text); }
.promo-opts { display: flex; gap: 8px; }
.promo-btn {
  width: 60px; height: 60px; border-radius: 10px; cursor: pointer;
  background: var(--csq-l); border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  transition: transform .12s, border-color .12s;
}
.promo-btn:hover { transform: scale(1.08); border-color: var(--info); }
.promo-btn .cpiece { width: 46px; height: 46px; }

/* Welcome Game Picker Modal */
.game-modal {
  position: fixed; inset: 0; z-index: 500;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(0, 0, 0, .78); backdrop-filter: blur(6px);
}
.game-modal-card {
  width: 100%; max-width: 560px; padding: 22px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,.65);
}
.game-modal-title { font-size: 1.25rem; font-weight: 800; text-align: center; margin-bottom: 6px; }
.game-modal-sub { font-size: .8rem; color: var(--text2); text-align: center; margin-bottom: 16px; }
.game-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.game-card {
  display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: 8px;
  padding: 16px; border-radius: 14px; cursor: pointer;
  background: var(--bg3); border: 1.5px solid var(--border); color: var(--text);
  transition: transform .15s, border-color .15s, background .15s;
}
.game-card:hover { transform: translateY(-2px); border-color: var(--accent); background: var(--bg4); }
.gc-icon { font-size: 2rem; line-height: 1; }
.gc-name { font-size: 1.05rem; font-weight: 800; margin-bottom: 2px; }
.gc-eng { font: 700 .7rem var(--mono); color: var(--info); margin-bottom: 6px; }
.gc-desc { font-size: .74rem; line-height: 1.45; color: var(--text2); }
.game-modal-foot { margin-top: 14px; text-align: center; font: 600 .72rem var(--mono); color: var(--text3); }
.game-modal-foot b { color: var(--text2); }

/* Footer */
.app-footer {
  height: 24px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg2); border-top: 1px solid var(--border);
  font: 600 .7rem var(--mono); color: var(--text3); letter-spacing: .3px;
}
.app-footer b { color: var(--text2); }

/* ═════════ ANIMATIONS ═════════ */
@keyframes pop { 0% { transform: scale(.2); opacity: 0; } 70% { transform: scale(1.08); } 100% { transform: scale(1); opacity: 1; } }
@keyframes dots { 0%, 80%, 100% { opacity: .2; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
@keyframes flash { 0% { opacity: .2; transform: translateY(3px); } 100% { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes bounce { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.2); } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }

/* ═════════ HISTORY ═════════ */
.hist-nav { display: flex; gap: 4px; margin-bottom: 8px; }
.hist-box { max-height: calc(100vh - 360px); overflow-y: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
.hist-list { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; padding: 4px; }
.mv { display: flex; align-items: center; gap: 6px; padding: 5px 7px; border-radius: 5px; cursor: pointer; font-size: .78rem; }
.mv:hover { background: var(--bg3); }
.mv.cur { background: var(--bg4); }
.mv.view { outline: 1.5px solid var(--info); background: rgba(79,195,247,.12); }
.mv-n { font: .66rem var(--mono); color: var(--text3); min-width: 20px; }
.mv .dot { width: 11px; height: 11px; }
.mv-c { font: 700 .78rem var(--mono); }
.ta { width: 100%; padding: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); resize: vertical; outline: none; font: .74rem var(--mono); margin-bottom: 6px; }
.ta:focus { border-color: var(--text2); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 80px); opacity: 0;
  padding: 9px 18px; background: var(--accent); color: var(--accent-ink);
  border-radius: 10px; font-size: .84rem; font-weight: 700;
  transition: all .25s ease; z-index: 1000; pointer-events: none; box-shadow: 0 6px 20px rgba(0,0,0,.35);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ═════════ MOBILE ═════════ */
.mob-bar { display: none; }
.scrim { display: none; }

@media (max-width: 900px) {
  :root { --lbl: 14px; }
  .header { height: 42px; padding: 0 10px; }
  .logo { display: none; }
  .engine-tag { font-size: .58rem; padding: 2px 6px; max-width: 135px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .game-cards { grid-template-columns: 1fr; }
  .desk-only { display: none; }
  .board-area { padding: 6px 4px; align-items: flex-start; }
  .stage { gap: 6px; width: 100%; }
  .matchbar { gap: 6px; padding: 5px 6px; border-radius: 12px; }
  .pcard { padding: 5px 6px; gap: 6px; }
  .pstone { width: 18px; height: 18px; }
  .pname { font-size: .76rem; max-width: 84px; }
  .psub { font-size: .66rem; }
  .mcomment { font-size: .78rem; }
  .board { padding: 4px; border-radius: 10px; }
  .lbl { font-size: .5rem; }

  .panel {
    position: fixed; left: 0; right: 0; bottom: calc(78px + env(safe-area-inset-bottom)); top: auto;
    width: auto; max-height: 68vh; border: none; border-top: 1px solid var(--border);
    border-radius: 18px 18px 0 0; z-index: 95; display: none;
    box-shadow: 0 -10px 30px rgba(0,0,0,.4);
    animation: slideUp .22s ease;
  }
  .app-footer { height: 22px; font-size: .64rem; }
  .panel.open { display: block; }
  .sheet-handle { display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--bg4); margin: -4px auto 12px; }
  .hist-box { max-height: 34vh; }
  .hist-list { grid-template-columns: 1fr 1fr 1fr; }
  .scrim.show { display: block; position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.35); }

  .mob-bar {
    display: flex; flex-shrink: 0; z-index: 100;
    height: calc(56px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg2); border-top: 1px solid var(--border);
  }
  .mob-btn {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    border: none; background: none; color: var(--text2); font-size: .64rem; font-weight: 600; cursor: pointer;
  }
  .mob-btn .ico { font-size: 1.15rem; line-height: 1; color: var(--text); }
  .mob-btn.on, .mob-btn.on .ico { color: var(--info); }
  .mob-btn:active { background: var(--bg3); }
  .toast { bottom: 76px; }
}
@media (max-width: 420px) {
  .psep, .pm { display: none; }
  .mmeta { font-size: .58rem; }
  .pname { max-width: 64px; }
}
