/* Chess styling — page chrome reuses the site theme variables (line_escape.css);
   the board squares use their own selectable palette (body[data-chess-board]). */

.ch-wrap { max-width: 560px; margin: 0 auto; padding: calc(14px + env(safe-area-inset-top)) 12px calc(24px + env(safe-area-inset-bottom)); color: var(--text); }
.hidden { display: none !important; }

.ch-topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.ch-topbar a.back { color: var(--accent); text-decoration: none; font-size: 13px; font-weight: 600; background: var(--btn); border: 1px solid var(--line2); border-radius: 8px; padding: 6px 12px; }
.ch-topbar a.back:active { transform: translateY(1px); }
.ch-title { font-size: 20px; font-weight: 700; letter-spacing: 0.3px; }

/* cards / setup / online / lobby */
.ch-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.ch-h2 { font-size: 18px; font-weight: 700; margin: 0 0 12px; color: var(--text); }
.ch-field { margin-bottom: 14px; }
.ch-field > label { display: block; font-size: 12px; color: var(--muted2); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.ch-seg { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.ch-seg button { background: var(--btn); color: var(--muted); border: 1px solid var(--line2); border-radius: 8px; padding: 8px 14px; font-size: 14px; font-weight: 600; cursor: pointer; }
.ch-seg button.active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
#ch-theme { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line2); border-radius: 8px; padding: 9px 10px; font-size: 14px; }
.ch-setup-actions { display: flex; gap: 8px; margin-top: 6px; }
.ch-btn { background: var(--btn); color: var(--text); border: 1px solid var(--line2); border-radius: 10px; padding: 10px 14px; font-size: 14px; font-weight: 600; cursor: pointer; }
.ch-btn:active { transform: translateY(1px); }
.ch-btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); flex: 1; }
.ch-btn.ghost { color: var(--muted); }
.ch-btn.block { display: block; width: 100%; }
.ch-or { text-align: center; color: var(--muted2); font-size: 13px; margin: 10px 0; }
.ch-join-row { display: flex; gap: 8px; }
.ch-join-row input { flex: 1; background: var(--bg); color: var(--text); border: 1px solid var(--line2); border-radius: 8px; padding: 10px; font-size:var(--fld-fs,15px); text-transform: uppercase; letter-spacing: 2px; }
.ch-note { color: var(--muted2); font-size: 13px; margin: 12px 0; min-height: 18px; }
.ch-roomcode { font-size: 34px; font-weight: 800; letter-spacing: 6px; text-align: center; color: var(--accent); margin: 6px 0 10px; }
.ch-lobby-players { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.co-player { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--line2); border-radius: 8px; padding: 8px 10px; font-size: 14px; }

/* status */
.ch-status { display: none !important; }
.ch-turn { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 14px; }
.ch-swatch { width: 15px; height: 15px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.35); display: inline-block; }
.ch-swatch.w { background: #f7f5ef; }
.ch-swatch.b { background: #2a2a2e; }
.ch-thinking { display: none; align-items: center; gap: 8px; color: var(--accent); font-size: 13px; font-weight: 600; }
.ch-thinking.on { display: flex; }
.ch-spin { width: 14px; height: 14px; border: 2px solid var(--line2); border-top-color: var(--accent); border-radius: 50%; animation: ch-spin 0.7s linear infinite; }
@keyframes ch-spin { to { transform: rotate(360deg); } }

/* clocks */
.ch-clocks { display: none; gap: 10px; margin-bottom: 10px; }
.ch-clocks.on { display: grid; grid-template-columns: 1fr 1fr; }
.ch-clock { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; text-align: center; }
.ch-clock .lbl { font-size: 11px; color: var(--muted2); text-transform: uppercase; letter-spacing: 0.6px; }
.ch-clock .time { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ch-clock.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255,207,92,0.25); }
.ch-clock.low .time { color: #ff6b6b; }

/* board */
.ch-board-frame { position: relative; width: 100%; aspect-ratio: 1/1; border-radius: 14px; padding: 14px; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0,0,0,0.28); }
.ch-board { position: relative; width: 100%; height: 100%; border-radius: 8px; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25); touch-action: none; }
.ch-squares { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8,1fr); grid-template-rows: repeat(8,1fr); }
.ch-sq { position: relative; }
.ch-sq.light { background: var(--ch-light); }
.ch-sq.dark { background: var(--ch-dark); }
.ch-coord { position: absolute; font-size: 10px; font-weight: 700; opacity: 0.55; pointer-events: none; }
.ch-coord.file { right: 3px; bottom: 1px; }
.ch-coord.rank { left: 3px; top: 1px; }
.ch-sq.light .ch-coord { color: var(--ch-dark); }
.ch-sq.dark .ch-coord { color: var(--ch-light); }
.ch-sq.last { box-shadow: inset 0 0 0 100px rgba(255,215,90,0.30); }
.ch-sq.sel { box-shadow: inset 0 0 0 100px rgba(255,215,90,0.55); }
.ch-sq.check { box-shadow: inset 0 0 0 100px rgba(233,69,69,0.85), inset 0 0 22px 6px rgba(233,69,69,0.6); }
.ch-marker { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.ch-sq.move .ch-marker::after { content: ""; width: 30%; height: 30%; border-radius: 50%; background: rgba(30,40,30,0.32); }
.ch-sq.capture .ch-marker::after { content: ""; width: 86%; height: 86%; border-radius: 50%; border: 5px solid rgba(30,40,30,0.32); box-sizing: border-box; }

/* pieces */
.ch-pieces { position: absolute; inset: 0; pointer-events: none; }
.ch-piece { position: absolute; top: 0; left: 0; width: 12.5%; height: 12.5%; display: flex; align-items: center; justify-content: center; line-height: 1; cursor: grab; will-change: transform, filter; transition: transform 0.28s cubic-bezier(.22,.9,.29,1), filter 0.28s ease; z-index: 2; user-select: none; }
.ch-pieces.no-anim .ch-piece { transition: none !important; }
.ch-piece.moving { z-index: 14; filter: drop-shadow(0 8px 6px rgba(0,0,0,0.42)); }
.ch-piece.dragging { transition: none; z-index: 30; cursor: grabbing; filter: drop-shadow(0 13px 10px rgba(0,0,0,0.5)); }
.ch-piece.dragging .glyph { transform: scale(1.14); }
.ch-piece.captured-out { z-index: 1; pointer-events: none; }
.ch-piece.captured-out .glyph { transition: transform 0.22s ease, opacity 0.22s ease; transform: scale(0.25) rotate(14deg); opacity: 0; }
.ch-piece .glyph { font-size: 0.82em; line-height: 1; transition: transform 0.12s ease; }
.ch-piece.landed .glyph { animation: ch-land 0.24s cubic-bezier(.3,.7,.4,1); }
@keyframes ch-land { 0% { transform: scale(1.09); } 55% { transform: scale(0.965); } 100% { transform: scale(1); } }
.ch-piece.white .glyph { color: #f7f5ef; text-shadow: 0 1px 0 #b9b6ac, 0 2px 3px rgba(0,0,0,0.35); -webkit-text-stroke: 1.3px #3a3a3f; }
.ch-piece.black .glyph { color: #2a2a2e; text-shadow: 0 1px 2px rgba(0,0,0,0.45); -webkit-text-stroke: 1.1px #000; }

/* sidebar */
.ch-side { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
@media (max-width: 460px) { .ch-side { grid-template-columns: 1fr; } }
.ch-side-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.ch-side-h { font-size: 12px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted2); margin-bottom: 8px; }
.ch-cap-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.ch-cap-line:last-child { margin-bottom: 0; }
.ch-cap-line .who { font-size: 12px; color: var(--muted2); min-width: 40px; }
.ch-captured { display: flex; align-items: center; gap: 1px; flex-wrap: wrap; min-height: 24px; font-size: 20px; line-height: 1; color: #2a2a2e; }
.ch-captured .cap { text-shadow: 0 1px 1px rgba(0,0,0,0.3); }
.ch-adv { font-size: 12px; font-weight: 700; color: var(--good); }
.adv { font-size: 12px; font-weight: 700; color: var(--good); }
.ch-moves { max-height: 220px; overflow-y: auto; font-variant-numeric: tabular-nums; }
.ch-moves table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ch-moves td { padding: 3px 6px; }
.ch-moves td.num { color: var(--muted2); width: 32px; }
.ch-moves tr:nth-child(odd) { background: rgba(127,127,127,0.06); }
.ch-empty { color: var(--muted2); font-size: 13px; padding: 6px 2px; }

/* controls */
.ch-controls { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.ch-controls .ch-btn { flex: 1; min-width: 62px; text-align: center; }

/* overlays / modals */
.ch-overlay { position: fixed; inset: 0; background: rgba(6,9,16,0.68); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 18px; }
.ch-overlay.hidden { display: none; }
.ch-modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: 100%; max-width: 420px; box-shadow: 0 10px 30px rgba(0,0,0,0.45); animation: ch-pop 0.18s ease; }
@keyframes ch-pop { from { transform: scale(0.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.ch-modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.ch-modal-title { font-size: 18px; font-weight: 700; }
.ch-modal-close { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.ch-modal-body { color: var(--text); }
.ch-promo-card { max-width: 340px; text-align: center; }
.ch-promo { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.ch-promo button { width: 62px; height: 62px; font-size: 42px; line-height: 1; display: flex; align-items: center; justify-content: center; background: var(--btn); border: 1px solid var(--line2); border-radius: 12px; cursor: pointer; }
.ch-promo button:active { transform: translateY(1px); }
.ch-promo button .glyph { -webkit-text-stroke: 1.2px #3a3a3f; }
.ch-promo.white button { color: #f7f5ef; }
.ch-promo.black button { color: #2a2a2e; }
.ch-over-card { text-align: center; max-width: 340px; }
.ch-over-icon { font-size: 44px; margin-bottom: 4px; }
.ch-over-title { font-size: 22px; font-weight: 700; }
.ch-over-sub { color: var(--muted2); margin: 4px 0 16px; }

/* leaderboard table */
.ch-lb { width: 100%; border-collapse: collapse; font-size: 14px; }
.ch-lb th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted2); padding: 4px 6px; }
.ch-lb td { padding: 5px 6px; border-top: 1px solid var(--line); }
.ch-lb tr.me { background: rgba(255,207,92,0.14); }
.ch-lb .flag { vertical-align: -1px; }
.ch-me-line { margin-top: 10px; font-size: 13px; color: var(--muted2); }
.ch-note-guest { margin-top: 14px; text-align: center; color: var(--muted2); font-size: 13px; }

/* board palettes */
body { --ch-light: #eef2e6; --ch-dark: #7c9a76; }
body[data-chess-board="sage"] { --ch-light: #eef2e6; --ch-dark: #7c9a76; }
body[data-chess-board="slate"] { --ch-light: #dfe6ef; --ch-dark: #5b6b82; }
body[data-chess-board="walnut"] { --ch-light: #f0d9b5; --ch-dark: #b58863; }
body[data-chess-board="ocean"] { --ch-light: #d7e7ef; --ch-dark: #4a7f9c; }
body[data-chess-board="rose"] { --ch-light: #f3e0e4; --ch-dark: #b06d84; }
body[data-chess-board="emerald"] { --ch-light: #e9efe2; --ch-dark: #4b8063; }
body[data-chess-board="mono"] { --ch-light: #e9e9e9; --ch-dark: #7d7d7d; }

/* ===== v63: computer Elo stepper ===== */
.ch-elo { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ch-elo-btn { min-width: 42px; font-size: 18px; padding: 6px 12px; line-height: 1; }
.ch-elo-val { font-size: 22px; font-weight: 800; min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; color: var(--text); }
.ch-elo-tag { color: var(--muted2); font-size: 13px; }

/* ===== v64: time-control select ===== */
#ch-tc { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line2); border-radius: 8px; padding: 9px 10px; font-size: 14px; }

/* ===== v66: piece styles + vector set ===== */
#ch-piece-style { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line2); border-radius: 8px; padding: 9px 10px; font-size: 14px; }
.ch-piece.svg .ch-svgp { width: 88%; height: 88%; display: block; }
.ch-piece.svg .ch-svgp path { fill: currentColor; stroke: var(--pc-stroke); stroke-width: 1.3; stroke-linejoin: round; }
.ch-piece.svg.white { color: #f7f5ef; --pc-stroke: #33343a; }
.ch-piece.svg.black { color: #2a2a2e; --pc-stroke: #000; }
.ch-piece.ps-minimal .glyph { text-shadow: none; -webkit-text-stroke-width: 0.5px; }

/* ===== v67: green (chess.com) board + image piece sets ===== */
body[data-chess-board="green"] { --ch-light: #eeeed2; --ch-dark: #769656; }
.ch-piece.img { }
.ch-piece.img .ch-img { width: 100%; height: 100%; display: block; pointer-events: none; -webkit-user-drag: none; user-select: none; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.28)); }
.ch-piece.landed .ch-img { animation: ch-land 0.24s cubic-bezier(.3,.7,.4,1); }

/* ===== v68: wood board themes ===== */
body[data-chess-board="wood"] { --ch-light: #e8c48c; --ch-dark: #a5693c; }
body[data-chess-board="maple"] { --ch-light: #f2dcae; --ch-dark: #c48f56; }

/* ===== v70: robust board checkerboard (fallback so the board is never blank) ===== */
.ch-board {
  background-color: var(--ch-light, #eeeed2);
  background-image:
    linear-gradient(45deg, var(--ch-dark, #769656) 25%, transparent 25%, transparent 75%, var(--ch-dark, #769656) 75%),
    linear-gradient(45deg, var(--ch-dark, #769656) 25%, transparent 25%, transparent 75%, var(--ch-dark, #769656) 75%);
  background-size: 25% 25%;
  background-position: 0 0, 12.5% 12.5%;
}
