/* Layout: header bar; lobby in two columns (one on phones);
   game = player / board / player stacked, side column beside it (below it on phones) */
:root {
  --bg: #eef0ea;
  --surface: #f8f9f5;
  --ink: #1f241d;
  --muted: #5d6658;
  --line: #d3d8cc;
  --frame: #7a4b22;
  --sq-a: #d9a96e;
  --sq-b: #b67c43;
  --grid: #6e4521;
  --brass: #c9952e;
  --path: #ffd76a;
  --hint: rgba(255, 236, 170, .95);
  --danger: #b4432f;
  --ok: #3f8a4f;
  --victim: #e5533b;
  --piece-w: #f4efe3;
  --piece-w-edge: #c9bea6;
  --piece-b: #262220;
  --piece-b-edge: #0c0a09;
  --f-display: "Alexandria", "Segoe UI", system-ui, sans-serif;
  --f-body: "IBM Plex Sans", "IBM Plex Sans Arabic", "Segoe UI", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161714; --surface: #1f201c; --ink: #ecebe4; --muted: #a3a395; --line: #34352f;
    --frame: #5a3517; --sq-a: #c08d55; --sq-b: #94602f; --grid: #4f3117; --brass: #e0ad45;
    --danger: #e0735e; --ok: #74c084; color-scheme: dark;
  }
}
:root[lang="ar"] { --f-body: "IBM Plex Sans Arabic", "IBM Plex Sans", "Segoe UI", Tahoma, sans-serif; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 var(--f-body); padding-bottom: env(safe-area-inset-bottom, 0px); }
button, input, select { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
h2 { margin: 0; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 10; }
.brand { font-family: var(--f-display); font-weight: 700; font-size: 24px; color: var(--ink); text-decoration: none; letter-spacing: -.01em; }
.me { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 auto; }
.me input { border: 0; border-bottom: 1px dashed var(--line); background: transparent; padding: 4px 0; width: 11ch; min-width: 0; font-weight: 600; }
.me input:focus { outline: none; border-bottom-color: var(--brass); }
.idchip { font: 500 13px var(--f-mono); border: 1px solid var(--line); background: var(--bg); border-radius: 99px; padding: 4px 10px; cursor: pointer; white-space: nowrap; }
.idchip b { letter-spacing: .08em; }
.top-end { display: flex; align-items: center; gap: 10px; margin-inline-start: auto; }
.conn { font-size: 13px; color: var(--muted); }
.conn.bad { color: var(--danger); }
.dot-on { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); display: inline-block; flex: none; }

.wrap { max-width: 1100px; margin: 0 auto; padding-inline: 16px; padding-block: 20px 48px; }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px; display: grid; gap: 12px; min-width: 0; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; display: flex; gap: 6px; align-items: center; }
:root[lang="ar"] .label { text-transform: none; letter-spacing: 0; font-size: 14px; }
.label .count { color: var(--ink); }
.sub { font-size: 13px; color: var(--muted); font-weight: 600; margin-top: 4px; }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.empty { color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.field { display: grid; gap: 4px; flex: 1 1 140px; }
.grow-input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg); border-radius: 6px; padding: 10px 12px; font-family: var(--f-mono); text-transform: uppercase; font-size: 16px; }
select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px; font-size: 16px; width: 100%; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { font-weight: 600; font-size: 14px; padding: 10px 16px; min-height: 42px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, .idchip:focus-visible, .cell:focus-visible, select:focus-visible, .grow-input:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

/* ---------- lobby ---------- */
.lobby { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.col { display: grid; gap: 16px; min-width: 0; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); min-width: 0; flex-wrap: wrap; }
.list.compact li { padding: 6px 10px; font-size: 13px; }
.list .grow { flex: 1 1 8em; min-width: 0; overflow-wrap: anywhere; }
.list .meta { font-size: 12px; color: var(--muted); font-family: var(--f-mono); white-space: nowrap; }
.pres { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.pres.on { background: var(--ok); }
.tc { font: 500 12px var(--f-mono); padding: 2px 7px; border-radius: 99px; border: 1px solid var(--line); white-space: nowrap; }
.res-w { color: var(--ok); font-weight: 600; }
.res-l { color: var(--danger); font-weight: 600; }
.record { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; font-variant-numeric: tabular-nums; }
.record div { display: grid; gap: 2px; padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.record b { font-family: var(--f-display); font-size: 24px; }
.record span { font-size: 12px; color: var(--muted); }

/* ---------- game ---------- */
.game { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.board-col { display: grid; gap: 8px; max-width: 640px; width: 100%; }
.side { display: grid; gap: 16px; min-width: 0; }

.board-frame { background: var(--frame); border-radius: 10px; padding: 22px; box-shadow: 0 10px 30px rgba(0,0,0,.2); position: relative; }
.board-wrap { position: relative; aspect-ratio: 1; width: 100%; border: 3px solid var(--grid); touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.board { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); }
.cell { position: relative; border: 0; box-shadow: inset 0 0 0 1px var(--grid); background: var(--sq-a); display: grid; place-items: center; padding: 0; cursor: default; min-width: 0; }
.cell.alt { background: var(--sq-b); }
.cell.movable { cursor: pointer; }
.cell.last { box-shadow: inset 0 0 0 1px var(--grid), inset 0 0 0 100px rgba(255,255,255,.14); }
.cell.selected { box-shadow: inset 0 0 0 1px var(--grid), inset 0 0 0 4px var(--path); }
.cell.dest { cursor: pointer; }
.cell.dest::after { content: ""; position: absolute; width: 28%; aspect-ratio: 1; border-radius: 50%; background: var(--hint); box-shadow: 0 0 0 2px rgba(0,0,0,.18); }
.cell.dest.cap::after { width: 44%; background: rgba(255, 215, 106, .25); border: 3px solid var(--hint); box-shadow: 0 0 10px rgba(255, 215, 106, .8); animation: glow 1.2s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 2px rgba(255, 215, 106, .3); } }
.cell.victim .piece { box-shadow: 0 0 0 3px var(--victim), 0 3px 0 rgba(0,0,0,.3); }
.cell.eaten .piece { opacity: .3; filter: grayscale(1); }
.piece { width: 76%; aspect-ratio: 1; border-radius: 50%; position: relative; transition: transform .12s ease; }
.piece.w { background: radial-gradient(circle at 35% 30%, #fff, var(--piece-w) 55%); border: 2px solid var(--piece-w-edge); box-shadow: 0 3px 0 var(--piece-w-edge); }
.piece.b { background: radial-gradient(circle at 35% 30%, #4a433e, var(--piece-b) 60%); border: 2px solid var(--piece-b-edge); box-shadow: 0 3px 0 var(--piece-b-edge); }
.piece.k::after { content: ""; position: absolute; inset: 22%; border-radius: 50%; border: 3px solid var(--brass); }
@media (hover: hover) { .cell.movable:hover .piece { transform: translateY(-2px); } }
.cell.must .piece { outline: 3px solid var(--path); outline-offset: 2px; }
svg.paths { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.fly { position: absolute; width: 12.5%; height: 12.5%; display: grid; place-items: center; pointer-events: none; z-index: 3; transition: left var(--dur, 260ms) ease-in-out, top var(--dur, 260ms) ease-in-out; }
.fly .piece { transform: scale(1.08); box-shadow: 0 8px 14px rgba(0,0,0,.35); }
.coords { position: absolute; font-family: var(--f-mono); font-size: 11px; color: #f1dcc0; pointer-events: none; }
.files { left: 25px; right: 25px; bottom: 3px; display: grid; grid-template-columns: repeat(8, 1fr); text-align: center; }
.ranks { top: 25px; bottom: 25px; left: 7px; display: grid; grid-template-rows: repeat(8, 1fr); align-items: center; }
.over { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(20, 14, 8, .55); z-index: 4; padding: 16px; }
.over-card { background: var(--surface); color: var(--ink); border-radius: 10px; padding: 20px 22px; display: grid; gap: 10px; text-align: center; max-width: 320px; box-shadow: 0 12px 30px rgba(0,0,0,.35); }
.over-card h2 { font-family: var(--f-display); font-size: 24px; text-wrap: balance; }
.over-card p { margin: 0; color: var(--muted); }

/* players + clocks */
.prow { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
.prow.on { border-color: var(--brass); box-shadow: inset 0 -3px 0 var(--brass); }
.prow .pname { font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
.prow .pname small { font-weight: 400; color: var(--muted); }
.prow .pname .away { color: var(--danger); font-weight: 500; font-size: 13px; }
.dot { width: 18px; height: 18px; border-radius: 50%; flex: none; }
.dot.w { background: var(--piece-w); border: 2px solid var(--piece-w-edge); }
.dot.b { background: var(--piece-b); border: 2px solid var(--piece-b-edge); }
.clock { font: 500 22px var(--f-mono); font-variant-numeric: tabular-nums; padding: 2px 8px; border-radius: 5px; }
.prow.on .clock { background: var(--ink); color: var(--bg); }
.clock.low { color: var(--danger); }
.prow.on .clock.low { background: var(--danger); color: #fff; }
.status { font-family: var(--f-display); font-size: 20px; font-weight: 500; }
.notice { font-size: 14px; color: var(--danger); font-weight: 500; }
.notice:empty { display: none; }
.offer { display: grid; gap: 8px; padding: 10px; border: 1px solid var(--brass); border-radius: 6px; }

/* step-by-step capture */
.steps { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--brass); border-radius: 8px; background: color-mix(in srgb, var(--brass) 10%, var(--surface)); }
.step-dots { display: flex; gap: 6px; flex-wrap: wrap; }
.step-dots span { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font: 600 12px var(--f-body); border: 2px solid var(--victim); color: var(--victim); }
.step-dots span.done { background: var(--victim); color: #fff; }

ol.moves { margin: 0; padding: 0; list-style: none; font-family: var(--f-mono); font-size: 13px; max-height: 220px; overflow-y: auto; display: grid; grid-template-columns: 2.4em 1fr 1fr; row-gap: 3px; font-variant-numeric: tabular-nums; }
ol.moves li { display: contents; }
ol.moves .n { color: var(--muted); }
ol.moves span { overflow-wrap: anywhere; }

/* toasts */
.toasts { position: fixed; inset-inline-end: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 8px; z-index: 50; max-width: min(360px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: var(--bg); border-radius: 8px; padding: 12px 14px; box-shadow: 0 10px 24px rgba(0,0,0,.25); display: grid; gap: 8px; font-size: 14px; }
.toast.err { background: var(--danger); color: #fff; }
.toast .btns .btn { background: transparent; color: inherit; border-color: currentColor; }
.toast .btn.primary { background: var(--brass); color: #1f1a10; border-color: var(--brass); }

/* ---------- tablets ---------- */
@media (max-width: 880px) {
  .game { grid-template-columns: minmax(0, 1fr); }
  .board-col { margin: 0 auto; }
}
@media (max-width: 760px) {
  .lobby { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- phones ---------- */
@media (max-width: 520px) {
  .wrap { padding-inline: 10px; padding-block: 10px 32px; }
  .top { padding-inline: 10px; gap: 6px 10px; }
  .brand { font-size: 20px; }
  .me { order: 3; flex-basis: 100%; }
  .me input { flex: 1; width: auto; }
  .panel { padding: 14px; }
  .board-frame { padding: 14px; border-radius: 8px; }
  .files { left: 17px; right: 17px; bottom: 0; font-size: 9px; }
  .ranks { top: 17px; bottom: 17px; left: 3px; font-size: 9px; }
  .piece { width: 80%; }
  .piece.k::after { border-width: 2px; }
  .clock { font-size: 19px; }
  .prow { padding: 6px 10px; }
  .status { font-size: 18px; }
  .side .btns .btn { flex: 1 1 auto; }
  .toasts { inset-inline: 10px; max-width: none; }
}
@media (prefers-reduced-motion: reduce) { .piece, .fly { transition: none; } .cell.dest.cap::after { animation: none; } }
