/* Zain — used for all right-to-left languages (Kurdish, Arabic).
   Arabic-script and Latin glyphs come from separate files, split by unicode-range. */
@font-face {
  font-family: 'Zain';
  src: url('../fonts/zain/zain-arabic-400.woff2') format('woff2'), url('../fonts/zain/zain-arabic-400.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: 'Zain';
  src: url('../fonts/zain/zain-arabic-700.woff2') format('woff2'), url('../fonts/zain/zain-arabic-700.ttf') format('truetype');
  font-weight: 500 900;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: 'Zain';
  src: url('../fonts/zain/zain-latin-400.woff2') format('woff2'), url('../fonts/zain/zain-latin-400.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Zain';
  src: url('../fonts/zain/zain-latin-700.woff2') format('woff2'), url('../fonts/zain/zain-latin-700.ttf') format('truetype');
  font-weight: 500 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #15171c;
  --panel: #1d2027;
  --card: #252932;
  --line: #343a46;
  --text: #ece7de;
  --muted: #9aa0ab;
  --accent: #d9a54a;
  --accent-ink: #1a1408;
  --danger: #e25555;
  --green: #4ade80;
  --radius: 12px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

html[dir='rtl'] {
  --font: 'Zain', 'Inter', system-ui, sans-serif;
}
/* Zain is compact, so right-to-left text runs a little larger */
html[dir='rtl'] body { font-size: 17px; }

* { box-sizing: border-box; }

/* Thin, soft scrollbars in the accent color */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(217, 165, 74, 0.28) transparent;
}
*:hover { scrollbar-color: rgba(217, 165, 74, 0.55) transparent; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(217, 165, 74, 0.28); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(217, 165, 74, 0.6); }
::-webkit-scrollbar-corner { background: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

/* ---------- board area: player bars + 3D stage ---------- */
.board-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.stage {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* chess.com-style player bars with clocks */
.player-bar .pinfo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  height: 100%;
}
.player-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 12px;
  background: var(--panel);
  font-size: 14px;
  flex-shrink: 0;
}
.player-bar .chip { width: 22px; height: 22px; border-radius: 6px; }
.player-bar .pname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; min-width: 0; }
.player-bar .pcap {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  font-family: 'Noto Sans Symbols 2', 'Segoe UI Symbol', 'DejaVu Sans', sans-serif;
  font-size: 17px;
  letter-spacing: -3px;
  color: var(--muted);
  direction: ltr;
  text-align: start;
}
html[dir='rtl'] .player-bar .pcap { text-align: end; }
.player-bar .padv { color: var(--green); font-weight: 700; font-size: 13px; }
.player-bar .pturn {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: transparent;
}
.player-bar.active .pturn { background: var(--green); box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.18); }
.player-bar.active .pname { color: #fff; }
.player-bar.timed .pturn { display: none; }   /* the running clock shows whose turn it is */

.pclock {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  min-width: 96px;
  padding: 0 10px;
  margin-inline-start: auto;
  border-radius: 6px;
  background: #1a1c21;
  color: #8e939c;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  justify-content: flex-end;
  flex-shrink: 0;
  transition: background 0.2s, color 0.2s;
}
.pclock svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  visibility: hidden;
}
.pclock.running { background: #f2f0ea; color: #1b1a17; }
.pclock.running svg { visibility: visible; animation: tickSpin 2s steps(8) infinite; transform-origin: 50% 54%; }
.pclock.low { color: #e25555; }
.pclock.running.low { background: #f6d9d6; color: #b3261e; }
@keyframes tickSpin { to { transform: rotate(360deg); } }
.player-bar .padv { margin-inline-end: 4px; }

/* ---------- turn / status pill in the top bar (2D mode) ---------- */
.bar-status {
  display: none;
  align-items: center;
  gap: 7px;
  min-width: 0;
  max-width: 40%;
  height: 28px;
  padding: 0 11px;
  margin-inline-end: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 1;
}
.bar-status .bs-text { overflow: hidden; text-overflow: ellipsis; }
.bar-status .bs-dot { width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; border: 1px solid #6b6f78; }
.bar-status.w .bs-dot { background: #f3e7d0; }
.bar-status.b .bs-dot { background: #2a2320; }
.bar-status.over .bs-dot { background: var(--accent); border-color: var(--accent); }
.bar-status.thinking { color: var(--accent); }
body.flat-mode .bar-status { display: inline-flex; }
body.flat-mode .banner { display: none; }       /* the board fills the area, so the status moves to the bar */

/* ---------- move controls bar under the board (desktop / tablet) ---------- */
.board-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 54px;
  padding: 0 12px;
  flex-shrink: 0;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.bc-nav { display: flex; gap: 3px; padding: 4px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.bc-nav button {
  width: 40px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.bc-nav button:hover:not(:disabled) { background: var(--card); }
.bc-nav button:disabled { opacity: 0.3; cursor: default; }
.bc-nav svg { width: 20px; height: 20px; }
.bc-nav .bc-play { width: 48px; background: var(--accent); color: var(--accent-ink); }
.bc-nav .bc-play:hover:not(:disabled) { background: #e6b560; }
.bc-play .i-pause, .bc-play.playing .i-play { display: none; }
.bc-play.playing .i-pause { display: block; }
html[dir='rtl'] .bc-nav svg { transform: scaleX(-1); }
.bc-sep { width: 1px; height: 26px; background: var(--line); }
.bc-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.bc-pill svg { width: 18px; height: 18px; }
.bc-pill:hover:not(:disabled) { border-color: var(--accent); }
.bc-pill.on { border-color: var(--accent); color: var(--accent); }
.bc-pill.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.bc-pill.danger { color: #f08a8a; }
.bc-pill:disabled { opacity: 0.35; cursor: default; border-color: var(--line); }
.bc-pill.primary:hover { background: #e6b560; }
/* Buttons that live in the bottom bar are not repeated in the sidebar.
   (They stay in the page, hidden, because the bar mirrors their enabled state.) */
#btnNew, #btnUndo, #btnResign, #btnFlat { display: none !important; }
@media (min-width: 600px) {
  .moves .move-nav { display: none; }         /* first / prev / next / last are in the bar */
  #btnFlip, #btnView { display: none; }       /* flip board and reset view are in the bar too */
}

/* the bar adapts to the width of the board area (not the window) */
.board-area { container-type: inline-size; }
@container (max-width: 780px) {
  .bc-pill span { display: none; }            /* icon-only pills; the title shows the name */
  .bc-pill { padding: 0 11px; }
  .board-controls { gap: 8px; }
}
@container (max-width: 520px) {
  .bc-nav button { width: 32px; }
  .bc-nav .bc-play { width: 40px; }
  .bc-pill { padding: 0 9px; height: 34px; }
  .board-controls { gap: 6px; padding: 0 6px; }
}
@media (max-width: 599px) {
  .board-controls { display: none; }          /* phones use the bottom nav instead */
}

/* ---------- vertical material bar (desktop) ---------- */
.eval-bar {
  display: none;
  position: relative;
  width: 16px;
  flex-shrink: 0;
  background: #2a2320;
  border-inline-end: 1px solid var(--line);   /* flush with the screen edge, line towards the board */
  overflow: hidden;
}
.eval-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  background: #f1e4cc;
  transition: height 0.45s ease;
}
.eval-bar.flipped .eval-fill { bottom: auto; top: 0; }
.eval-bar::after {            /* centre (equal material) mark */
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: rgba(217, 165, 74, 0.6);
}
.eval-label {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  font-family: 'Inter', sans-serif;
  font-size: 9px;
  font-weight: 800;
  z-index: 1;
}
.eval-label.w { color: #2a2320; }
.eval-label.b { color: #f1e4cc; }
@media (min-width: 861px) {
  .eval-bar { display: block; }
}
.stage canvas { display: block; }

.banner {
  position: absolute;
  top: 16px;
  inset-inline-start: 50%;
  transform: translateX(-50%);
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(20, 22, 27, 0.72);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 2;
}
html[dir='rtl'] .banner { transform: translateX(50%); }
.banner.thinking { color: var(--accent); }


.error {
  margin: 40px auto;
  max-width: 420px;
  text-align: center;
  color: var(--danger);
  padding: 0 16px;
}

/* ---------- side panel ---------- */
.panel {
  width: 420px;
  flex-shrink: 0;
  background: var(--panel);
  border-inline-start: 1px solid var(--line);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

/* Language dropdown: part of the top bar above the board */
.lang {
  position: relative;
  z-index: 8;          /* above the board, phone sheet (6) and toolbar (7); below modals (10) */
  flex-shrink: 0;
  padding-inline-end: 10px;
  margin-inline-end: 4px;
  border-inline-end: 1px solid var(--line);
  height: 28px;
  display: flex;
  align-items: center;
}
.lang-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.lang-btn:hover, .lang-btn[aria-expanded='true'] { border-color: var(--accent); }
.lang-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.lang-btn .globe { color: var(--accent); }
.lang-btn .chev { width: 15px; height: 15px; color: var(--muted); transition: transform 0.2s; }
.lang-btn[aria-expanded='true'] .chev { transform: rotate(180deg); }

.lang-menu {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-start: 0;
  min-width: 170px;
  margin: 0;
  padding: 5px;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
  animation: langIn 0.14s ease-out;
}
@keyframes langIn { from { opacity: 0; transform: translateY(-4px); } }
.lang-menu button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  cursor: pointer;
  font-size: 15px;
  color: var(--text);
  text-align: start;
}
.lang-menu button:hover, .lang-menu button:focus-visible { background: var(--card); outline: none; }
.lang-menu button[aria-selected='true'] { color: var(--accent); font-weight: 700; }
.lang-menu .code { font-size: 11px; color: var(--muted); letter-spacing: 0.05em; font-family: 'Inter', sans-serif; }
.lang-menu button[aria-selected='true']::after { content: '✓'; margin-inline-start: auto; }
.lang-menu button[aria-selected='true'] .code { display: none; }
/* Each language name in its own script's font */
.lang [lang='ckb'], .lang [lang='ar'] { font-family: 'Zain', 'Inter', sans-serif; font-size: 16px; }
.lang [lang='en'] { font-family: 'Inter', system-ui, sans-serif; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.card h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 8px;
  font-weight: 600;
}
html[dir='rtl'] .card h2 { text-transform: none; letter-spacing: 0; font-size: 13px; }

.status-card {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  min-height: 48px;
}
.turn-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid var(--line);
}
.turn-dot.w { background: #f3e7d0; }
.turn-dot.b { background: #2a2320; border-color: #6b6f78; }
.turn-dot.over { background: var(--accent); }

.settings { display: flex; flex-direction: column; gap: 10px; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.label { color: var(--muted); font-size: 13px; }

.seg {
  display: flex;
  background: var(--bg);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
}
.seg button {
  border: 0;
  background: none;
  padding: 6px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.seg button[aria-pressed='true'] { background: var(--card); color: var(--text); box-shadow: 0 0 0 1px var(--line); }

.chip {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid #6b6f78;
  flex-shrink: 0;
}
.chip.w { background: #f3e7d0; }
.chip.b { background: #2a2320; }

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover:not(:disabled) { border-color: #4a5160; background: #2c313b; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #e6b560; border-color: #e6b560; }
.btn.danger { color: #f08a8a; }
.btn:focus-visible, .seg button:focus-visible, .lang-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.cap-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
}
.cap {
  font-size: 19px;
  line-height: 1;
  font-family: 'Segoe UI Symbol', 'DejaVu Sans', sans-serif;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  direction: ltr;
  white-space: nowrap;
}
html[dir='rtl'] .cap { justify-content: flex-end; }
/* one stack per piece type: same pieces overlap, a small gap between types */
.cg { letter-spacing: -0.42em; padding-right: 0.42em; }
.player-bar .pcap { display: flex; gap: 3px; letter-spacing: 0 !important; }
.adv { color: var(--green); font-size: 13px; font-weight: 700; }
.adv, .padv { direction: ltr; unicode-bidi: isolate; }
.pts { color: var(--muted); font-size: 12px; white-space: nowrap; min-width: 44px; text-align: end; }

/* material balance: white share of the bar grows with White's lead */
.balance {
  height: 8px;
  border-radius: 999px;
  background: #2a2320;
  border: 1px solid var(--line);
  overflow: hidden;
  margin: 10px 0 6px;
}
.balance-fill {
  height: 100%;
  width: 50%;
  background: #f1e4cc;
  transition: width 0.35s ease;
}
.lead { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.lead.w, .lead.b { color: var(--text); }

.btn.wide, .check.wide { grid-column: 1 / -1; }

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  cursor: pointer;
  font-size: 14px;
  user-select: none;
}
.check input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.check:has(input:checked) { border-color: var(--accent); }

.moves { display: flex; flex-direction: column; }
.move-list {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  height: 240px;
  font-size: 14px;
}
.move-list li {
  display: grid;
  grid-template-columns: 40px 1fr 1fr;
  padding: 3px 4px;
  border-radius: 6px;
}
.move-list li:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }
.move-list .n { color: var(--muted); }
.move-list .san {
  font-family: 'Segoe UI Symbol', 'Inter', 'DejaVu Sans', sans-serif;
  unicode-bidi: isolate;
  text-align: start;
}
html[dir='rtl'] .move-list .san { text-align: end; }
.move-list .san[dir] { cursor: pointer; border-radius: 4px; padding: 0 4px; }
.move-list .san:hover:not(:empty) { background: rgba(255, 255, 255, 0.06); }
.move-list .san.current { background: rgba(217, 165, 74, 0.2); color: var(--accent); font-weight: 600; }

/* history navigation */
.move-nav {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 8px;
}
.move-nav button {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 8px;
  height: 34px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text);
}
.move-nav button:hover:not(:disabled) { border-color: var(--accent); }
.move-nav button:disabled { opacity: 0.3; cursor: default; }
.move-nav svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
html[dir='rtl'] .move-nav svg { transform: scaleX(-1); }
.move-nav.reviewing button[data-nav='last'] { border-color: var(--accent); color: var(--accent); }


/* ---------- new game dialog ---------- */
.dialog.new-game { width: min(600px, 100%); }
/* New game dialog: every choice is its own button instead of one shared segmented track */
.new-game .seg { background: none; padding: 0; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.new-game .seg.time-grid { gap: 6px; }
.new-game .seg button {
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  color: var(--muted);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.new-game .seg button:hover { border-color: #4a5160; color: var(--text); }
.new-game .seg button[aria-pressed='true'] {
  background: rgba(217, 165, 74, 0.14);
  border-color: var(--accent);
  color: var(--text);
  box-shadow: none;
  font-weight: 600;
}
.ng-rows { display: flex; flex-direction: column; gap: 12px; margin: 16px 0 20px; text-align: start; }
.ng-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ng-row .seg { flex-shrink: 0; }
.seg.time-grid {
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 3px;
}
.seg.time-grid button { justify-content: center; }
.chip.r { background: linear-gradient(90deg, #f3e7d0 50%, #2a2320 50%); }
html[dir='rtl'] .chip.r { background: linear-gradient(270deg, #f3e7d0 50%, #2a2320 50%); }
@media (max-width: 460px) {
  .ng-row { flex-direction: column; align-items: stretch; gap: 6px; }
  .ng-row .seg button { flex: 1; justify-content: center; }
  .new-game .seg.time-grid, .new-game #coachGrid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .new-game .seg button { padding: 7px 8px; }
}

/* ---------- rating badges ---------- */
.pbadge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.pbadge svg { width: 16px; height: 16px; flex-shrink: 0; }
.tier-bronze svg, .obadge.tier-bronze { color: #c98a55; fill: #c98a55; }
.tier-silver svg, .obadge.tier-silver { color: #c3ccd6; fill: #c3ccd6; }
.tier-gold svg, .obadge.tier-gold { color: #e9bb3f; fill: #e9bb3f; }
.tier-diamond svg, .obadge.tier-diamond { color: #6fd3f5; fill: #6fd3f5; }
.pdelta { font-size: 12px; font-weight: 800; }
.pdelta.up { color: var(--green); }
.pdelta.down { color: #ef6b6b; }

/* ---------- inputs (New game dialog) ---------- */
.text-input {
  width: 200px;
  max-width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
.text-input:focus { outline: none; border-color: var(--accent); }
.code-input { font-family: 'Inter', monospace; letter-spacing: 0.25em; text-transform: uppercase; font-weight: 700; text-align: center; }

/* ---------- custom time ---------- */
.custom-time { display: flex; align-items: center; gap: 8px; }
.custom-time label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.custom-time input {
  width: 62px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
}
.custom-time input:focus { outline: none; border-color: var(--accent); }
.custom-time .plus { color: var(--muted); font-weight: 700; }

/* ---------- game over card ---------- */
.dialog.over {
  position: relative;
  width: min(410px, 100%);
  background: var(--panel);
  border-color: var(--line);
  padding: 22px 18px 18px;
}
.over-x {
  color: var(--muted) !important;
  position: absolute;
  top: 12px;
  inset-inline-end: 12px;
  width: 30px;
  height: 30px;
  border: 0;
  background: none;
  color: #8b8987;
  cursor: pointer;
  border-radius: 6px;
  display: grid;
  place-items: center;
}
.over-x:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.over-x svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.dialog .over-title { margin: 0; font-size: 30px; font-weight: 800; color: var(--text); letter-spacing: -0.01em; }
.dialog .over-title.win { color: var(--accent); }
.dialog .over-title.loss { color: var(--text); }
.over-sub { margin: 4px 0 18px !important; font-size: 14px; font-weight: 700; color: var(--muted) !important; }

.over-ratings { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.orate { display: flex; align-items: center; gap: 10px; justify-content: center; text-align: start; }
.obadge { width: 40px; height: 40px; display: grid; place-items: center; flex-shrink: 0; }
.obadge svg { width: 40px; height: 40px; }
.oline { display: flex; align-items: flex-start; gap: 3px; }
.oval { font-size: 26px; font-weight: 800; color: var(--text); line-height: 1; font-variant-numeric: tabular-nums; }
.odelta { font-size: 13px; font-weight: 800; color: var(--muted); }
.odelta.up { color: var(--green); }
.odelta.down { color: #ef6b6b; }
.owho { display: block; margin-top: 4px; font-size: 12px; color: var(--muted); max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.coach { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 14px; }
.coach-avatar { width: 58px; height: 58px; flex-shrink: 0; }
.coach-avatar svg { width: 100%; height: 100%; }
.coach-bubble {
  position: relative;
  flex: 1;
  margin: 0 !important;
  padding: 12px 14px;
  background: #fff;
  color: #312e2b !important;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.45;
  text-align: start;
}
.coach-bubble::before {
  content: '';
  position: absolute;
  bottom: 12px;
  inset-inline-start: -8px;
  border: 8px solid transparent;
  border-inline-end-color: #fff;
  border-inline-start: 0;
}

.over-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.ostat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 6px 8px;
  display: grid;
  grid-template-columns: auto auto;
  justify-content: center;
  align-items: center;
  gap: 2px 7px;
}
.ostat .oico {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 900;
  color: #fff;
}
.ostat b { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ostat small { grid-column: 1 / -1; font-size: 13px; font-weight: 700; }
.ostat.good .oico { background: var(--accent); color: var(--accent-ink); }
.ostat.good b, .ostat.good small { color: var(--accent); }
.ostat.warn .oico { background: #ef6b6b; }
.ostat.warn b, .ostat.warn small { color: #ef6b6b; }

.over-review {
  width: 100%;
  height: 56px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  box-shadow: 0 5px 0 #9c7431;
  color: var(--accent-ink);
  font-size: 20px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  margin-bottom: 16px;
  transition: filter 0.15s, transform 0.08s;
}
.over-review svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; }
.over-review:hover { filter: brightness(1.07); }
.over-review:active { transform: translateY(3px); box-shadow: 0 2px 0 #9c7431; }
.over-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.over-actions button {
  height: 48px;
  border: 0;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--line) !important;
  box-shadow: 0 4px 0 #14161a;
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}
.over-actions button:hover { background: #2c313b; border-color: var(--accent) !important; }
.over-actions button:active { transform: translateY(2px); box-shadow: 0 2px 0 #14161a; }

/* ---------- online dialog ---------- */
.dialog.online { width: min(380px, 100%); }
.invite { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 14px 0 6px; }
.invite small { color: var(--muted); font-size: 13px; }
.invite-code {
  font-family: 'Inter', monospace;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 0.2em;
  padding: 8px 16px 8px 24px;
  border: 1px dashed var(--accent);
  border-radius: 12px;
  color: var(--accent);
  user-select: all;
}
.online-status { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 12px 0 18px !important; }
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 30;
  max-width: min(420px, calc(100% - 32px));
  padding: 10px 16px;
  border-radius: 10px;
  background: #f2f0ea;
  color: #1b1a17;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  text-align: center;
}
.toast.show { animation: toastIn 0.25s ease-out; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ---------- game review ---------- */
.review { display: flex; flex-direction: column; gap: 10px; }
.rv-head { display: flex; align-items: center; justify-content: space-between; }
.rv-head h2 { margin: 0; }
.rv-progress { font-size: 12px; color: var(--accent); font-weight: 600; }
.rv-bar { height: 4px; border-radius: 999px; background: var(--bg); overflow: hidden; }
.rv-bar-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }
.rv-acc { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.acc { border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.acc.w { background: #f1e4cc; color: #2a2320; }
.acc.b { background: #1a1614; color: #f1e4cc; border: 1px solid var(--line); }
.acc small { font-size: 11px; font-weight: 600; opacity: 0.75; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc b { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.acc span { font-size: 11px; opacity: 0.7; }
.rv-graph { width: 100%; height: 80px; border-radius: 8px; cursor: pointer; display: block; }
.rv-graph .g-bg { fill: #2a2320; }
.rv-graph .g-white { fill: #f1e4cc; }
.rv-graph .g-mid { stroke: rgba(217, 165, 74, 0.5); stroke-width: 0.6; }
.rv-graph .g-cur { stroke: var(--accent); stroke-width: 1.4; }
.rv-graph .gm.cls-inaccuracy { fill: #f7c631; }
.rv-graph .gm.cls-brilliant { fill: #26c2a3; }
.rv-graph .gm.cls-mistake { fill: #ffa459; }
.rv-graph .gm.cls-blunder { fill: #fa412d; }
.rv-note {
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  font-family: 'Segoe UI Symbol', var(--font);
}
.rv-note.cls-best, .rv-note.cls-excellent { color: #81b64c; }
.rv-note.cls-brilliant { color: #26c2a3; }
/* "what if" test moves during review */
.rv-note.what-if, .wk-whatif {
  color: #e8f1ff !important;
  background: rgba(125, 211, 252, 0.14);
  border: 1px dashed rgba(125, 211, 252, 0.7);
  border-radius: 8px;
  padding: 8px 10px;
  font-weight: 600;
}

/* review move by move */
.walk-wrap { display: flex; flex-direction: column; }
.rv-walk-btn { width: 100%; }
.rv-walk {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.wk-bar { display: flex; align-items: center; gap: 6px; }
.wk-pos { flex: 1; text-align: center; font-size: 13px; font-weight: 700; color: var(--text); }
.wk-nav {
  width: 38px;
  height: 34px;
  display: grid;
  place-items: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
}
.wk-nav:hover:not(:disabled) { border-color: var(--accent); }
.wk-nav:disabled { opacity: 0.3; cursor: default; }
.wk-nav svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
html[dir='rtl'] #rvWalkPrev svg, html[dir='rtl'] #rvWalkNext svg { transform: scaleX(-1); }
.wk-close { width: 34px; color: var(--muted); }
.wk-body {
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
  font-family: 'Segoe UI Symbol', var(--font);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.wk-body p { margin: 0; }
.wk-body ul { margin: 0; padding-inline-start: 18px; color: var(--muted); }
.wk-head { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.wk-head .cls-ico { width: 22px; height: 22px; font-size: 11px; flex-shrink: 0; }
.wk-cls { font-weight: 800; margin-inline-start: auto; }
.wk-head.cls-brilliant { color: #26c2a3; }
.wk-head.cls-best, .wk-head.cls-excellent { color: #81b64c; }
.wk-head.cls-good { color: #95b776; }
.wk-head.cls-inaccuracy { color: #f7c631; }
.wk-head.cls-mistake { color: #ffa459; }
.wk-head.cls-blunder { color: #fa412d; }
.wk-san { color: var(--text); }
.wk-who { color: var(--muted); font-size: 12px; }
.wk-why, .wk-lead { color: var(--text); }
.wk-label { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding-top: 4px; }
html[dir='rtl'] .wk-label { text-transform: none; letter-spacing: 0; font-size: 12px; }
.wk-eval { color: var(--muted); font-variant-numeric: tabular-nums; }
.wk-better { color: #81b64c; font-weight: 700; }
.wk-punish { color: #ffa459; }
.wk-body .ex_capture, .wk-body .ex_promo, .wk-body .ex_mate, .wk-body .ex_fork { color: #81b64c; }
.wk-body .ex_hang, .wk-body .ex_leaves { color: #ffa459; }
.rv-note.cls-good { color: #95b776; }
.rv-note.cls-inaccuracy { color: #f7c631; }
.rv-note.cls-mistake { color: #ffa459; }
.rv-note.cls-blunder { color: #fa412d; }
.rv-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.rv-table td { padding: 4px 2px; }
.rv-table .rv-w, .rv-table .rv-b { width: 44px; text-align: center; font-weight: 800; font-variant-numeric: tabular-nums; }
.rv-table .rv-name { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); }
.cls-ico {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  font-size: 10px;
  font-weight: 900;
  color: #fff;
  font-family: 'Inter', sans-serif;
}
.cls-brilliant .cls-ico { background: #26c2a3; } .cls-brilliant .cls-ico::before { content: '!!'; }
.cls-best .cls-ico { background: #81b64c; } .cls-best .cls-ico::before { content: '★'; }
.cls-excellent .cls-ico { background: #96bc4b; } .cls-excellent .cls-ico::before { content: '!'; }
.cls-good .cls-ico { background: #95b776; } .cls-good .cls-ico::before { content: '✓'; }
.cls-inaccuracy .cls-ico { background: #f7c631; } .cls-inaccuracy .cls-ico::before { content: '?!'; }
.cls-mistake .cls-ico { background: #ffa459; } .cls-mistake .cls-ico::before { content: '?'; }
.cls-blunder .cls-ico { background: #fa412d; } .cls-blunder .cls-ico::before { content: '??'; }
.rv-table .cls-best .rv-w, .rv-table .cls-best .rv-b { color: #81b64c; }
.rv-table .cls-inaccuracy .rv-w, .rv-table .cls-inaccuracy .rv-b { color: #f7c631; }
.rv-table .cls-mistake .rv-w, .rv-table .cls-mistake .rv-b { color: #ffa459; }
.rv-table .cls-blunder .rv-w, .rv-table .cls-blunder .rv-b { color: #fa412d; }

/* move list: classification symbol after each analysed move */
.move-list .san[data-cls]::after { margin-inline-start: 3px; font-size: 11px; font-weight: 900; }
.move-list .san[data-cls='best']::after { content: '★'; color: #81b64c; }
.move-list .san[data-cls='brilliant']::after { content: '!!'; color: #26c2a3; }
.move-list .san[data-cls='inaccuracy']::after { content: '?!'; color: #f7c631; }
.move-list .san[data-cls='mistake']::after { content: '?'; color: #ffa459; }
.move-list .san[data-cls='blunder']::after { content: '??'; color: #fa412d; }

/* ---------- phone toolbar ---------- */
.toolbar { display: none; }
.toolbar button {
  flex: 1;
  border: 0;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 2px;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  min-width: 0;
}
.toolbar button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.toolbar svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.toolbar button:active { color: var(--text); }
.toolbar button.on { color: var(--accent); }
.toolbar button:disabled { opacity: 0.35; }
.toolbar button[data-act='resign'] { color: #f08a8a; }

/* ---------- modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 12, 0.6);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  z-index: 10;
  padding: 16px;
}
.dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  width: min(400px, 100%);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.dialog h3 { margin: 0 0 6px; font-size: 20px; }
.dialog p { margin: 0 0 16px; color: var(--muted); }
.over-text { font-size: 17px; color: var(--text) !important; font-weight: 600; }
.dialog-actions { display: flex; gap: 10px; justify-content: center; }
.dialog-actions .btn { min-width: 120px; }

.promo-choices {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.promo {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 10px 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.promo:hover { border-color: var(--accent); }
.promo .glyph { font-size: 38px; line-height: 1.1; font-family: 'Segoe UI Symbol', 'DejaVu Sans', sans-serif; }
.promo .name { font-size: 12px; color: var(--muted); }

/* ---------- responsive ---------- */


/* Touch devices: no hover, no right-click; bigger tap targets */
@media (hover: none) {
  .btn, .check { min-height: 44px; }
  .seg button { min-height: 36px; }
}

/* ---------- coach + move explanations ---------- */
.explain-col {
  width: 330px;
  flex-shrink: 0;
  background: var(--panel);
  border-inline-start: 1px solid var(--line);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}
.explain-col .explain-card { flex: 1; min-height: 220px; display: flex; flex-direction: column; }
.explain-col .ex-list { flex: 1; max-height: none; min-height: 0; }

.ng-note { margin: -4px 0 0; font-size: 12px; line-height: 1.45; color: var(--muted); }
#coachGrid { grid-template-columns: repeat(4, auto); }

.coach-card { display: flex; flex-direction: column; gap: 10px; border-color: rgba(217, 165, 74, 0.45); }
.cc-head { display: flex; align-items: center; gap: 10px; }
.cc-avatar { width: 40px; height: 40px; flex-shrink: 0; }
.cc-avatar svg { width: 100%; height: 100%; display: block; }
.cc-title h2 { margin: 0; color: var(--accent); }
.cc-title small { font-size: 12px; color: var(--muted); }
.cc-bubble {
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
  font-family: 'Segoe UI Symbol', var(--font);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cc-bubble p { margin: 0; }
.cc-bubble ul { margin: 0; padding-inline-start: 18px; color: var(--muted); }
.cc-bubble li + li { margin-top: 2px; }
.cc-lead { color: var(--text); }
.cc-grade { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.cc-grade .cls-ico { flex-shrink: 0; }
.cc-grade.cls-best, .cc-grade.cls-excellent { color: #81b64c; }
.cc-grade.cls-brilliant { color: #26c2a3; }
.cc-grade.cls-good { color: #95b776; }
.cc-grade.cls-inaccuracy { color: #f7c631; }
.cc-grade.cls-mistake { color: #ffa459; }
.cc-grade.cls-blunder { color: #fa412d; }
.cc-better { color: #81b64c; font-weight: 700; }
.cc-why { color: var(--muted); }
.cc-opp { color: var(--text); font-weight: 600; padding-top: 6px; border-top: 1px solid var(--line); }
.cc-tip { color: var(--accent); }
.cc-actions { display: flex; gap: 8px; }
.cc-actions .btn { flex: 1; }

.explain-card { display: flex; flex-direction: column; gap: 6px; }
.explain-card h2 { margin-bottom: 2px; }
.ex-label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
html[dir='rtl'] .ex-label { text-transform: none; letter-spacing: 0; font-size: 12px; }
.ex-empty { margin: 0; font-size: 13px; color: var(--muted); }
.ex-list { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.ex-item {
  width: 100%;
  text-align: start;
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 12.5px;
  font-family: 'Segoe UI Symbol', var(--font);
}
.ex-item:hover { border-color: var(--line); }
.ex-item.current { border-color: var(--accent); }
.ex-last .ex-item { border-color: rgba(217, 165, 74, 0.45); font-size: 13.5px; padding: 10px 12px; }
.ex-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ex-n { color: var(--muted); font-variant-numeric: tabular-nums; }
.ex-glyph { font-size: 18px; line-height: 1; }
.ex-last .ex-glyph { font-size: 22px; }
.ex-sq { font-weight: 700; color: var(--accent); }
.ex-san { color: var(--muted); margin-inline-start: auto; }
.ex-cls .cls-ico { width: 18px; height: 18px; font-size: 10px; }
.ex-lines { margin: 4px 0 0; padding-inline-start: 18px; color: var(--muted); line-height: 1.45; }
.ex-lines .ex_capture, .ex-lines .ex_promo, .ex-lines .ex_mate, .ex-lines .ex_fork { color: #81b64c; font-weight: 600; }
.ex-lines .ex_check, .ex-lines .ex_attack { color: var(--accent); font-weight: 600; }
.ex-lines .ex_hang, .ex-lines .ex_leaves, .ex-lines .ex_earlyQueen, .ex-lines .ex_kingCastle { color: #ffa459; }

/* Small laptops / landscape tablets: narrower sidebar */
@media (max-width: 1100px) {
  .panel { width: 380px; padding: 14px; }
  .cap { font-size: 17px; }
  h1 { font-size: 20px; }
}

/* Tablets and phones: board on top with player bars, controls below */
@media (max-width: 860px) {
  .app { flex-direction: column; height: auto; min-height: 100dvh; }
  .board-area { flex: none; }
  /* the language switch sits over the top-left of the first bar */
  .stage { flex: none; height: min(60dvh, 100vw); min-height: 280px; }
  .panel {
    width: 100%;
    border-inline-start: 0;
    border-top: 1px solid var(--line);
    padding: 14px 16px calc(24px + env(safe-area-inset-bottom));
    overflow: visible;
  }
  .status-card, .captured { display: none; }   /* the player bars show turn + material */
  .move-list { height: 180px; }
  .banner { font-size: 13px; top: 8px; padding: 5px 14px; max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis; }
  .hint { font-size: 11px; bottom: 6px; }
}

/* Portrait tablets: two-column control panel */
@media (min-width: 600px) and (max-width: 860px) {
  .panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      'head head'
      'walk walk'
      'review review'
      'moves settings'
      'moves actions';
    align-items: start;
    gap: 12px 16px;
  }
  .panel .head { grid-area: head; }
  .panel .walk-wrap { grid-area: walk; }
  .panel .review { grid-area: review; }
  .panel .moves { grid-area: moves; }
  .panel .settings { grid-area: settings; }
  .panel .actions { grid-area: actions; }
  .panel .coach-card, .panel .explain-card { grid-column: 1 / -1; }
  .move-list { height: 220px; }
}

/* Phones: full-screen game — top bar · board · bottom bar · bottom nav.
   Everything else lives in a slide-up sheet opened from the nav's "More" button. */
.sheet-backdrop { display: none; }
/* Phones after the game: replay bar (first · prev · play · next · last) above the bottom toolbar */
.replay-bar { display: none; }
@media (max-width: 599px) {
  body.replay-on .replay-bar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(58px + env(safe-area-inset-bottom));
    z-index: 7;
    height: 52px;
    padding: 6px 12px;
    gap: 8px;
    background: var(--panel);
    border-top: 1px solid var(--line);
  }
  .replay-bar button {
    flex: 1;
    display: grid;
    place-items: center;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    cursor: pointer;
  }
  .replay-bar button:disabled { opacity: 0.3; cursor: default; }
  .replay-bar button:active:not(:disabled) { transform: translateY(1px); }
  .replay-bar svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
  html[dir='rtl'] .replay-bar button:not(.rp-play) svg { transform: scaleX(-1); }
  .replay-bar .rp-play { flex: 1.4; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
  .rp-play .i-pause, .rp-play.playing .i-play { display: none; }
  .rp-play.playing .i-pause { display: block; }
  /* make room for the bar: the board and the sheet move up by its height */
  body.replay-on .app { height: calc(100dvh - 58px - 52px - env(safe-area-inset-bottom)); }
  body.replay-on .stage { height: min(100vw, calc(100dvh - 58px - 52px - 88px - env(safe-area-inset-bottom))); }
  body.replay-on .panel { bottom: calc(58px + 52px + env(safe-area-inset-bottom)); }
}

@media (max-width: 599px) {
  .app {
    height: calc(100dvh - 58px - env(safe-area-inset-bottom));
    min-height: 0;
    overflow: hidden;
  }
  /* player bars pinned to the top and bottom; the square, full-width board is centred between them */
  .board-area { flex: 1; min-height: 0; }
  .stage { flex: none; margin: auto 0; height: min(100vw, calc(100dvh - 58px - 88px - env(safe-area-inset-bottom))); min-height: 0; }
  #langCurrent { display: none; }           /* compact on phones: globe + arrow only */
  .lang-btn { padding: 0 8px; gap: 4px; }
  .banner { top: 8px; }
  .pclock { height: 32px; min-width: 84px; font-size: 18px; }
  body.flat-mode .bar-status { display: none; }   /* phones: no turn/status pill in the top bar */
  .lang-btn .chev { display: none; }
  .lang { padding-inline-end: 6px; margin-inline-end: 2px; }
  .player-bar { gap: 6px; padding: 0 8px; }
  .player-bar .pinfo { gap: 6px; }
  .player-bar .pcap { font-size: 15px; }

  /* the sidebar becomes a bottom sheet above the nav */
  .panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(58px + env(safe-area-inset-bottom));
    z-index: 6;
    max-height: 72dvh;
    overflow-y: auto;
    padding: 8px 12px 16px;
    border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    background: var(--panel);
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.5);
    transform: translateY(calc(100% + 80px));
    visibility: hidden;
    transition: transform 0.28s ease, visibility 0s linear 0.28s;
  }
  .panel::before {                           /* drag handle */
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    margin: 0 auto 6px;
    border-radius: 999px;
    background: var(--line);
    flex-shrink: 0;
  }
  body.sheet-open .panel {
    transform: none;
    visibility: visible;
    transition: transform 0.28s ease;
  }
  .sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 5;
    background: rgba(8, 9, 12, 0.5);
  }
  .head { display: none; }
  .move-list { height: 170px; }
  /* these live in the bottom nav on phones */
  #btnNew, #btnUndo, #btnResign, #btnFlip, #btnFlat { display: none; }
  #btnView { grid-column: 1 / -1; }
  .btn { padding: 10px 8px; font-size: 13px; }
  .card { padding: 10px 12px; }

  .toolbar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 7;
    height: calc(58px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--panel);
    border-top: 1px solid var(--line);
  }
  .dialog { padding: 18px 14px; }
  .dialog .over-title { font-size: 26px; }
  .oval { font-size: 22px; }
  .obadge, .obadge svg { width: 32px; height: 32px; }
  .text-input { width: 100%; }
  .promo .glyph { font-size: 32px; }
}
@media (max-width: 400px) {
  .row { flex-direction: column; align-items: stretch; }
  .seg button { flex: 1; justify-content: center; }
}

/* Phones in landscape: board (with bars) beside the controls */
@media (max-height: 540px) and (orientation: landscape) {
  .app { flex-direction: row; height: 100dvh; min-height: 0; padding-bottom: 0; }
  .board-area { flex: 1; min-height: 0; }
  .player-bar { height: 36px; }
  .stage { flex: 1; height: auto; min-height: 0; }
  .panel {
    display: flex;
    width: 290px;
    border-top: 0;
    border-inline-start: 1px solid var(--line);
    overflow-y: auto;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }
  .sub, .hint { display: none; }
  .move-list { height: 120px; }
}
