/* Multi Chess UI — black, white and greys like the board and the pieces (dark by default, light available).
   The accent is the "ink" colour: near-black in the light theme, near-white in the dark theme. */

:root {
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, Menlo, monospace;

  /* light theme */
  --bg: #ececee;
  --bg-grad: radial-gradient(1200px 500px at 85% -120px, rgba(0, 0, 0, .05), transparent 70%);
  --surface: #ffffff;
  --surface-2: #f5f5f6;
  --surface-3: #e6e6e9;
  --border: #d5d5da;
  --border-strong: #b4b4bb;
  --text: #18181b;
  --muted: #5d5d66;
  --accent: #1f1f23;
  --accent-hover: #000000;
  --accent-2: #5d5d66;
  --accent-soft: #e4e4e7;
  --accent-text: #ffffff;
  --link: #1f1f23;
  --good: #1f8a4c;
  --good-soft: #def3e6;
  --danger: #c0352b;
  --danger-soft: #fbe2df;
  --warn: #8a5a00;
  --warn-soft: #fcf0d2;
  --info-soft: #ececef;
  --clock-bg: #e6e6e9;
  --clock-run: #1f1f23;
  --clock-run-text: #ffffff;
  --clock-low: #c0352b;
  --glow: rgba(0, 0, 0, .10);
  --shadow: 0 1px 2px rgba(20, 20, 25, .06), 0 6px 20px rgba(20, 20, 25, .07);
  --shadow-lg: 0 24px 60px rgba(10, 10, 15, .28);
  --radius: 12px;
  --radius-sm: 8px;
  --focus: 0 0 0 3px rgba(24, 24, 27, .30);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #111113;
  --bg-grad: radial-gradient(1200px 520px at 85% -140px, rgba(255, 255, 255, .06), transparent 70%);
  --surface: #1a1a1d;
  --surface-2: #212124;
  --surface-3: #2b2b2f;
  --border: #343438;
  --border-strong: #4c4c52;
  --text: #ececef;
  --muted: #a1a1aa;
  --accent: #e8e8eb;
  --accent-hover: #ffffff;
  --accent-2: #a1a1aa;
  --accent-soft: #2f2f34;
  --accent-text: #111113;
  --link: #e4e4e7;
  --good: #4cc27d;
  --good-soft: #17301f;
  --danger: #f06a5d;
  --danger-soft: #3d2220;
  --warn: #f0b74a;
  --warn-soft: #382d18;
  --info-soft: #222228;
  --clock-bg: #26262a;
  --clock-run: #ededf0;
  --clock-run-text: #111113;
  --clock-low: #f06a5d;
  --glow: rgba(255, 255, 255, .10);
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 8px 24px rgba(0, 0, 0, .28);
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, .55);
  --focus: 0 0 0 3px rgba(255, 255, 255, .38);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.55 var(--font-ui);
}
a { color: var(--link); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.012em; }
h1 { font-size: 2rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.mono { font-family: var(--font-mono); }
.accent { color: var(--accent); }
.mt { margin-top: 12px; }
.mt0 { margin-top: 0; }
.nowrap { white-space: nowrap; }
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }

svg.icon { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.2em; }

/* ------------------------------------------------------------------ top bar */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.12rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -.02em;
}
.brand:hover { color: var(--text) !important; }
.brand b { color: var(--accent); font-weight: 800; }
.brand img { border-radius: 8px; }
.topbar nav { display: flex; gap: 2px; margin-left: 14px; }
.topbar nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  font-weight: 600;
}
.topbar nav a:hover, .topbar nav a[aria-current="page"] { color: var(--text) !important; background: var(--surface-3); }
.topbar nav a[aria-current="page"] { box-shadow: inset 0 -2px 0 var(--accent); }
.topbar .spacer { flex: 1; }
.name-chip, .user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 230px;
  min-height: 36px;
  padding: 4px 12px 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
}
.name-chip span, .user-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name-chip:hover, .user-chip:hover { border-color: var(--accent); color: var(--text) !important; }
.name-chip .guest-tag { font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 1px 6px; border-radius: 4px; background: var(--surface-3); flex: none; }
.user-chip .avatar, .avatar {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-text);
  font-weight: 800;
  font-size: .8rem;
  flex: none;
}
.auth-links { display: flex; gap: 6px; align-items: center; }
.auth-links .btn { min-height: 36px; padding: 5px 14px; }

.menu { position: relative; }
.menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 210px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  z-index: 60;
}
.menu-list .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-list .who b { display: block; }
.menu-list a, .menu-list button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text);
  text-decoration: none;
  text-align: left;
  cursor: pointer;
  font-weight: 550;
}
.menu-list a:hover, .menu-list button:hover { background: var(--surface-3); color: var(--text) !important; }

/* ------------------------------------------------------------------ badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 750;
  letter-spacing: .02em;
  white-space: nowrap;
  vertical-align: middle;
}
.badge svg.icon { width: 12px; height: 12px; stroke-width: 2.6; }
.badge.member { background: var(--accent-soft); color: var(--accent); }
.badge.guest { background: var(--surface-3); color: var(--muted); }
.badge.free { background: var(--good-soft); color: var(--good); }
.badge.lock { background: var(--surface-3); color: var(--muted); }
.member-mark { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); color: var(--accent-text); flex: none; }
.member-mark svg.icon { width: 11px; height: 11px; stroke-width: 3.2; }

/* ------------------------------------------------------------------ buttons & forms */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 7px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .12s, border-color .12s, color .12s, transform .06s, box-shadow .12s;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); color: var(--text) !important; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 88%, #fff) 0%, var(--accent) 100%);
  border-color: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .18) inset, 0 4px 14px rgba(0, 0, 0, .22);
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-text) !important; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger) !important; }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-3); border-color: var(--border); }
.btn.icon { padding: 7px; min-width: 38px; }
.btn.big { min-height: 50px; font-size: 1.05rem; padding: 11px 22px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn.small { min-height: 30px; padding: 3px 10px; font-size: .84rem; }
.btn.toggled { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.btn:focus-visible, .seg label:focus-within, .name-chip:focus-visible, .user-chip:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, .mode-card:focus-visible, a:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > .label, label.label { font-weight: 650; font-size: .9rem; }
.field .hint { font-size: .82rem; color: var(--muted); }
.field .error { font-size: .84rem; color: var(--danger); font-weight: 600; }
input[type="text"], input[type="search"], input[type="email"], input[type="password"], select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  transition: border-color .12s, box-shadow .12s;
}
input[type="text"]:hover, input[type="email"]:hover, input[type="password"]:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input[aria-invalid="true"] { border-color: var(--danger); }
textarea { resize: vertical; font-family: var(--font-mono); font-size: .85rem; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); width: 18px; height: 18px; flex: none; }

/* segmented radio group */
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  font-weight: 600;
  user-select: none;
  transition: border-color .12s, background-color .12s;
}
.seg label:hover { border-color: var(--border-strong); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--text); box-shadow: inset 0 0 0 1px var(--accent); }
.seg label:has(input:disabled) { opacity: .45; cursor: not-allowed; }
.seg.colors label { padding: 6px; background: var(--sq-light); border-color: transparent; }
.seg.colors label:has(input:checked) { background: var(--sq-light); box-shadow: 0 0 0 3px var(--accent); }
.seg.colors .piece-img { width: 38px; height: 38px; }
.seg.stack label { flex-direction: column; align-items: flex-start; gap: 0; flex: 1 1 180px; }
.seg.stack label small { color: var(--muted); font-weight: 450; font-size: .8rem; line-height: 1.35; }
.random-king { position: relative; display: inline-block; width: 36px; height: 36px; vertical-align: middle; }
.random-king .piece-img { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
.random-king .piece-img.black { clip-path: polygon(50% 0, 100% 0, 100% 100%, 50% 100%); }
.random-king .piece-img.white { clip-path: polygon(0 0, 50% 0, 50% 100%, 0 100%); }
table.seeks .random-king { width: 22px; height: 22px; }

.check-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.check-row .label + .btn { margin-left: auto; }
.check-row.compact { padding: 0; border: 0; gap: 8px; font-size: .88rem; justify-content: flex-start; }
fieldset.field { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px 12px 8px; margin: 0 0 16px; min-width: 0; }
fieldset.field > legend { padding: 0 6px; margin-left: -6px; }
.volume-row { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.sound-groups { padding-left: 14px; border-left: 2px solid var(--border); margin: 4px 0 4px 2px; }
.sound-groups.off { opacity: .5; }
.check-row:last-child { border-bottom: 0; }
.check-row .label { font-weight: 600; }
.check-row .hint { display: block; font-size: .8rem; color: var(--muted); font-weight: 400; }

.level-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
.level-grid label { justify-content: center; padding: 8px 0; font-weight: 750; }
.level-info { display: flex; justify-content: space-between; gap: 10px; font-size: .84rem; color: var(--muted); }
.level-info b { color: var(--text); }
/* levels already beaten (record kept in this browser, see js/lib/ai-record.js) */
.level-grid .won-mark { position: absolute; top: 3px; right: 3px; width: 11px; height: 11px; color: var(--good); }
.level-label { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.level-label .beaten-count { display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; font-weight: 650; color: var(--good); }
.level-label .beaten-count .icon { width: 13px; height: 13px; }
.level-record { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); }
.level-record .icon { width: 14px; height: 14px; flex: none; }
.level-record b { color: var(--text); }
.level-record.won .icon, .level-record.won b { color: var(--good); }
.level-progress { display: flex; flex-wrap: wrap; gap: 4px; }
.level-progress span {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: .75rem;
  font-weight: 750;
}
.level-progress span.won { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 50%, transparent); color: var(--good); }
.level-progress span.current { box-shadow: 0 0 0 2px var(--accent); }
.notice.progress { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; padding: 8px 12px; }
.notice.progress .lbl, .ai-progress .lbl { font-size: .8rem; font-weight: 650; color: var(--muted); }
.ai-progress { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.platform-note { display: inline-flex; align-items: center; gap: 5px; font-size: .78rem; color: var(--muted); }
.platform-note .icon { width: 13px; height: 13px; flex: none; color: var(--good); }
.ai-levels p { margin: 0 0 10px; }

.explain { margin: -6px 0 16px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px dashed var(--border); font-size: .86rem; color: var(--muted); }
.explain b { color: var(--text); }

/* ------------------------------------------------------------------ dialogs */

dialog.modal {
  width: min(580px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
dialog.modal[open] { animation: pop .16s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.985); } }
dialog.modal.wide { width: min(780px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgba(5, 5, 8, .62); backdrop-filter: blur(3px); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; flex: 1; font-size: 1.16rem; }
.modal-body { padding: 18px 20px; overflow: auto; max-height: calc(100vh - 180px); }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 16px 16px; }
.modal-foot .btn.primary { min-width: 150px; }

.tc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 6px; }
.tc-grid label { justify-content: center; flex-direction: column; gap: 0; padding: 6px 4px; line-height: 1.2; }
.tc-grid label b { font-size: 1.05rem; }
.tc-grid label small { color: var(--muted); font-size: .72rem; font-weight: 500; }
.custom-tc { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 12px; padding: 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.custom-tc output { font-weight: 700; }

/* ------------------------------------------------------------------ toasts */

.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 200; pointer-events: none; width: min(440px, calc(100vw - 32px)); }
.toast { padding: 11px 16px; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); font-weight: 600; animation: toast-in .18s ease-out; text-align: center; }
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--good); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ------------------------------------------------------------------ home */

main { flex: 1; width: 100%; }
.home { max-width: 1200px; margin: 0 auto; padding: 30px 20px 48px; display: grid; gap: 34px; overflow-x: clip; } /* the glow behind the hero board must not cause sideways scrolling on phones */

.hero { display: grid; grid-template-columns: 1.15fr .85fr; gap: 36px; align-items: center; }
.hero h1 { font-size: clamp(2rem, 4.2vw, 3.1rem); line-height: 1.05; letter-spacing: -.03em; margin-bottom: 14px; }
.hero h1 span { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero .lead { color: var(--muted); font-size: 1.08rem; max-width: 600px; margin-bottom: 22px; }
.hero .cta { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.hero .trust { display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--muted); font-size: .88rem; }
.hero .trust span { display: inline-flex; align-items: center; gap: 6px; }
.hero .trust svg { color: var(--accent); }
.hero-board-wrap { position: relative; justify-self: center; width: min(400px, 100%); }
.hero-board-wrap::before { content: ""; position: absolute; inset: -18px; border-radius: 24px; background: radial-gradient(closest-side, var(--glow), transparent); filter: blur(10px); z-index: -1; }
.hero-board { width: 100%; aspect-ratio: 1; border-radius: 8px; overflow: hidden; box-shadow: var(--shadow-lg); }
.hero-caption { margin-top: 10px; text-align: center; font-size: .84rem; color: var(--muted); min-height: 1.4em; }

.resume { display: grid; gap: 10px; }
.resume-card { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 14px 18px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: linear-gradient(90deg, var(--accent-soft), var(--surface) 70%); box-shadow: inset 4px 0 0 var(--accent), var(--shadow); }
.resume-card .text { flex: 1; min-width: 200px; }
.resume-card .text b { display: block; }
.resume-card .mode-icon { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.resume-card .pulse-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 60%, transparent); animation: dot 1.6s infinite; flex: none; }
@keyframes dot { 70% { box-shadow: 0 0 0 10px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.section-head { display: flex; align-items: end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.section-head h2 { margin: 0; font-size: 1.45rem; }
.section-head p { margin: 4px 0 0; color: var(--muted); }

.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.mode-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, transform .15s, box-shadow .15s;
  color: var(--text);
}
.mode-card:hover { border-color: var(--accent); transform: translateY(-3px); box-shadow: var(--shadow), 0 10px 30px var(--glow); }
.mode-card .top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mode-card .mode-icon { width: 48px; height: 48px; border-radius: 13px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.mode-card .mode-icon svg { width: 26px; height: 26px; }
.mode-card h3 { margin: 4px 0 0; font-size: 1.22rem; }
.mode-card p { margin: 0; color: var(--muted); font-size: .93rem; }
.mode-card ul { margin: 2px 0 0; padding-left: 1.1em; color: var(--muted); font-size: .88rem; }
.mode-card li { margin: 2px 0; }
.mode-card .go { margin-top: auto; padding-top: 8px; color: var(--link); font-weight: 700; display: flex; align-items: center; gap: 6px; }
.mode-card.locked .go { color: var(--muted); }
.mode-card.locked .mode-icon { filter: grayscale(.7); opacity: .8; }

.lobby-grid { display: grid; grid-template-columns: minmax(290px, 390px) 1fr; gap: 20px; align-items: start; }
.panel { border: 1px solid var(--border); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.panel-head > svg { color: var(--accent); }
.panel-head h2 { margin: 0; font-size: 1.06rem; flex: 1; }
.panel-head.sub-head { border-top: 1px solid var(--border); background: var(--surface-2); }
.panel-head .badge { flex: none; }
.panel-body { padding: 16px 18px; }
.quick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.quick-grid button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color .12s, background-color .12s, transform .08s;
}
.quick-grid button:hover { border-color: var(--accent); background: var(--accent-soft); }
.quick-grid button:active { transform: scale(.98); }
.quick-grid button b { font-size: 1.25rem; font-weight: 700; }
.quick-grid button small { color: var(--muted); font-size: .78rem; }
.quick-grid button.pending { border-color: var(--accent); background: var(--accent-soft); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px var(--accent-soft); } }
.quick-foot { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.quick-foot .check-row { padding: 6px 0; border: 0; justify-content: flex-start; font-size: .88rem; }

.stats { display: flex; gap: 16px; font-size: .88rem; color: var(--muted); }
.stats b { color: var(--text); }
.stats .live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--good); margin-right: 6px; }

.my-open { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 18px; background: var(--accent-soft); border-bottom: 1px solid var(--border); font-size: .92rem; }
.my-open .row { display: flex; gap: 6px; }
.my-open .btn { min-height: 32px; padding: 4px 12px; }
table.seeks { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.seeks th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 9px 12px; border-bottom: 1px solid var(--border); }
table.seeks td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.seeks tr:last-child td { border-bottom: 0; }
table.seeks tbody tr { cursor: pointer; transition: background-color .1s; }
table.seeks tbody tr:hover td { background: var(--surface-2); }
table.seeks tr.mine td { background: var(--accent-soft); cursor: default; }
table.seeks tr.locked td { opacity: .6; }
table.seeks .who { font-weight: 650; max-width: 200px; }
table.seeks .who .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; max-width: 150px; vertical-align: middle; }
table.seeks .who .badge { margin-left: 4px; }
table.seeks .col-color .piece-img { display: inline-block; width: 22px; height: 22px; vertical-align: middle; }
table.seeks td:last-child { text-align: right; }
.empty { padding: 30px 18px; text-align: center; color: var(--muted); }
.empty svg { width: 34px; height: 34px; opacity: .5; display: block; margin: 0 auto 8px; }

.explainer { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 14px; }
.explainer .card { padding: 18px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.explainer .card h3 { display: flex; align-items: center; gap: 8px; font-size: 1rem; margin-bottom: 8px; }
.explainer .card h3 svg { color: var(--accent); }
.explainer .card p { font-size: .9rem; color: var(--muted); margin-bottom: .6em; }
.explainer .card p:last-child { margin-bottom: 0; }
.explainer .card .who { font-size: .82rem; }

table.access { width: 100%; border-collapse: collapse; font-size: .92rem; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
table.access th, table.access td { padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; }
table.access thead th { background: var(--surface-2); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
table.access tr:last-child td { border-bottom: 0; }
table.access td.yes { color: var(--good); font-weight: 700; }
table.access td.no { color: var(--muted); }

.features { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.feature { padding: 18px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.feature .ficon { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: var(--accent-soft); color: var(--accent); margin-bottom: 10px; }
.feature h3 { font-size: .98rem; margin-bottom: 4px; }
.feature p { margin: 0; font-size: .88rem; color: var(--muted); }

.about { display: grid; grid-template-columns: auto 1fr; gap: 22px; align-items: center; padding: 24px; border-radius: 18px; border: 1px solid var(--border); background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%); box-shadow: var(--shadow); position: relative; overflow: hidden; }
.about::after { content: ""; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px; border-radius: 50%; background: radial-gradient(closest-side, var(--glow), transparent); pointer-events: none; }
.about .portrait { width: 84px; height: 84px; border-radius: 22px; display: grid; place-items: center; background: linear-gradient(135deg, #2a2b31, #16171a); border: 1px solid var(--border-strong); font-size: 2.6rem; color: var(--accent); }
.about h2 { margin-bottom: 4px; font-size: 1.3rem; }
.about .role { color: var(--muted); margin-bottom: 10px; }
.about p { max-width: 760px; }
.about .links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.about .links a { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--surface-3); color: var(--text); text-decoration: none; font-weight: 600; font-size: .88rem; border: 1px solid var(--border); }
.about .links a:hover { border-color: var(--accent); color: var(--text) !important; }
.about .ai-note { display: flex; gap: 10px; align-items: flex-start; margin-top: 14px; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); font-size: .88rem; }
.about .ai-note svg { color: var(--accent); margin-top: 2px; }

footer.site-footer { padding: 20px; border-top: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: .86rem; }
footer.site-footer .inner { max-width: 1200px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; }
footer.site-footer nav { display: flex; gap: 16px; flex-wrap: wrap; }
footer.site-footer a { color: var(--muted); }
footer.site-footer a:hover { color: var(--text) !important; }
footer.site-footer .spacer { flex: 1; }

.lobby-teaser { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding: 20px 22px; }
.lobby-teaser .teaser-icon { width: 54px; height: 54px; border-radius: 15px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.lobby-teaser .teaser-icon svg { width: 28px; height: 28px; }
.lobby-teaser .teaser-text { flex: 1; min-width: 240px; }
.lobby-teaser h2 { margin-bottom: 2px; }
.lobby-teaser p { margin-bottom: 6px; }
.lobby-teaser .stats { flex-wrap: wrap; gap: 6px 16px; }

.lobby-page, .admin-page { max-width: 1200px; margin: 0 auto; padding: 26px 20px 48px; display: grid; gap: 18px; align-content: start; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0 0 4px; display: flex; align-items: center; gap: 10px; }
.page-head p { margin: 0; }
.page-head .row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.create-row { display: flex; gap: 8px; flex-wrap: wrap; }
.lobby-note { margin: 0; }
.panel-head h2 .count, .page-tabs .count { display: inline-block; min-width: 1.6em; margin-left: 4px; padding: 0 6px; border-radius: 999px; background: var(--surface-3); color: var(--muted); font-size: .76rem; font-weight: 750; text-align: center; vertical-align: 2px; }
.panel-head h2 .count:empty, .page-tabs .count:empty { display: none; }
.row-links { display: flex; gap: 8px; flex-wrap: wrap; }

/* administration */
.page-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.page-tabs [role="tab"][role="tab"] { flex: none; padding: 10px 18px 9px; font-size: .95rem; border-radius: 8px 8px 0 0; }
.admin-h { font-size: 1.05rem; margin: 6px 0 10px; color: var(--muted); }
.admin-stats { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-bottom: 8px; }
.admin-stats .v { font-size: 1.45rem; }
.admin-grid { grid-template-columns: 1fr 1fr; margin-top: 12px; }
table.kv { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.kv th { text-align: left; font-weight: 650; color: var(--muted); padding: 6px 12px 6px 0; width: 38%; }
table.kv td { padding: 6px 0; }
ul.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: .9rem; }
ul.checks li { display: flex; gap: 8px; align-items: flex-start; }
ul.checks li.ok svg { color: var(--good); }
ul.checks li.warn svg { color: var(--danger); }
ul.checks li.warn { font-weight: 650; }
.filter-bar { flex-wrap: wrap; gap: 10px; }
.filter-bar input[type="search"] { flex: 1 1 240px; width: auto; }
.filter-bar select { width: auto; flex: 0 1 200px; }
.filter-bar .seg label { padding: 5px 11px; font-size: .86rem; }
.table-wrap { overflow-x: auto; }
table.admin-table { font-size: .88rem; }
table.admin-table tbody tr { cursor: default; }
table.admin-table td { vertical-align: top; }
table.admin-table .stack { display: grid; gap: 4px; }
table.admin-table .pl { display: inline-flex; align-items: center; gap: 6px; max-width: 260px; }
table.admin-table .pl .nm { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.admin-table .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
table.admin-table .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: .45; margin-right: 6px; flex: none; }
table.admin-table .dot.on { background: var(--good); opacity: 1; }
table.admin-table tr.ended td { opacity: .7; }
table.admin-table tr.unverified td { color: var(--muted); }
table.admin-table .badge { margin-left: 6px; }
.piece-dot { width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--border-strong); flex: none; }
.piece-dot.white { background: #f4f4f5; }
.piece-dot.black { background: #18181b; }
.piece-dot.random { background: linear-gradient(90deg, #f4f4f5 50%, #18181b 50%); }
.actions-cell { white-space: nowrap; text-align: right; }
.actions-cell .btn + .btn { margin-left: 6px; }
.warn-text { color: var(--warn); font-weight: 650; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--border); }
.admin-gate { margin: 20px auto; text-align: center; }

/* ------------------------------------------------------------------ game page */

.game-page { --side-w: 350px; --gap: 16px; padding: 16px; }
.game {
  --board-size: min(calc(100vh - 110px) * var(--board-scale, 1), calc(100vw - var(--side-w) - var(--gap) * 3 - 28px), 900px);
  display: grid;
  grid-template-columns: auto var(--board-size) minmax(270px, var(--side-w));
  /* the panel never grows taller than the board; its content scrolls instead */
  height: var(--board-size);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "eval board top"
    "eval board panel"
    "eval board bottom";
  gap: 0;
  justify-content: center;
  align-items: stretch;
  max-width: 1440px;
  margin: 0 auto;
}
.eval-bar { grid-area: eval; width: 0; }
.board-area { grid-area: board; position: relative; width: var(--board-size); height: var(--board-size); }
.board-area .cg-wrap { box-shadow: 0 4px 24px rgba(0, 0, 0, .35); border-radius: var(--board-radius, 4px); }
.player.top { grid-area: top; margin-left: var(--gap); }
.player.bottom { grid-area: bottom; margin-left: var(--gap); }
.side-panel { grid-area: panel; min-height: 0; display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow-x: hidden; overflow-y: auto; margin: 8px 0 8px var(--gap); box-shadow: var(--shadow); }

.game.with-eval .eval-bar { width: 22px; margin-right: 10px; }
.eval-bar { position: relative; height: var(--board-size); border-radius: 5px; overflow: hidden; background: #3b3a38; }
.eval-bar .white-part { position: absolute; left: 0; right: 0; bottom: 0; height: 50%; background: #f2f2f2; transition: height .4s ease; }
.eval-bar .mid { position: absolute; left: 0; right: 0; top: 50%; height: 2px; margin-top: -1px; background: rgba(128, 128, 128, .9); z-index: 1; }
.eval-bar .label { position: absolute; left: 0; right: 0; text-align: center; font-size: 10px; font-weight: 700; z-index: 2; }
.eval-bar .label.bottom { bottom: 3px; color: #333; }
.eval-bar .label.top { top: 3px; color: #eee; }
.eval-bar.flipped { background: #f2f2f2; }
.eval-bar.flipped .white-part { background: #3b3a38; }
.eval-bar.flipped .label.bottom { color: #eee; }
.eval-bar.flipped .label.top { color: #333; }

.player { display: flex; align-items: stretch; gap: 10px; position: relative; }
.player .who { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 2px; padding: 6px 0; }
.player .name-line { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.04rem; min-width: 0; }
.player .name-line .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; opacity: .5; }
.player .dot.on { background: var(--good); opacity: 1; box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); }
.player .tag { font-size: .7rem; font-weight: 800; padding: 1px 6px; border-radius: 4px; background: var(--surface-3); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; flex: none; }
.player .tag.you { background: var(--accent-soft); color: var(--accent); }
.player .material { display: flex; align-items: center; gap: 0; min-height: 20px; font-size: .82rem; color: var(--muted); font-weight: 650; }
.player .material .piece-img { width: 18px; height: 18px; margin-right: -5px; }
.player .material .piece-img.gap { margin-left: 6px; }
.player .material .score { margin-left: 10px; }
.player .checks { display: inline-flex; gap: 3px; margin-left: 6px; }
.player .checks i { width: 9px; height: 9px; border-radius: 2px; background: var(--danger); display: inline-block; }

.emote-bubble {
  position: absolute;
  left: 0;
  z-index: 40;
  padding: 7px 12px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-weight: 700;
  font-size: .9rem;
  box-shadow: var(--shadow-lg);
  animation: bubble 3.2s ease forwards;
  pointer-events: none;
  white-space: nowrap;
}
.player.top .emote-bubble { top: calc(100% + 4px); }
.player.bottom .emote-bubble { bottom: calc(100% + 4px); }
@keyframes bubble { 0% { opacity: 0; transform: translateY(6px) scale(.9); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

.clock {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 132px;
  padding: 4px 14px;
  border-radius: var(--radius-sm);
  background: var(--clock-bg);
  font: 700 2rem/1 var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  color: var(--muted);
  border: 1px solid var(--border);
  transition: background-color .15s, color .15s;
}
.clock.running { background: var(--clock-run); color: var(--clock-run-text); border-color: var(--clock-run); box-shadow: 0 4px 16px rgba(0, 0, 0, .28); }
.clock.low { color: var(--clock-low); }
.clock.running.low { background: var(--clock-low); border-color: var(--clock-low); color: #fff; animation: lowpulse 1s infinite; }
@keyframes lowpulse { 50% { box-shadow: 0 0 0 5px rgba(240, 106, 93, .25); } }
.clock.flagged { background: var(--danger-soft); color: var(--danger); }
.clock .tenths { font-size: .6em; align-self: flex-end; margin-bottom: .12em; }
.clock.none { display: none; }

.panel-info { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: .88rem; }
.panel-info .variant { font-weight: 750; }
.panel-info .sep { color: var(--border-strong); }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; background: var(--surface-3); font-size: .77rem; font-weight: 700; color: var(--muted); }
.pill.live { background: var(--accent-soft); color: var(--accent); }
.pill svg.icon { width: 12px; height: 12px; }

.opening-line { display: flex; gap: 8px; align-items: baseline; padding: 7px 14px; border-bottom: 1px solid var(--border); font-size: .84rem; background: var(--surface-2); min-height: 34px; }
.opening-line .eco { font-family: var(--font-mono); font-weight: 700; color: var(--accent); font-size: .78rem; }
.opening-line .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.status-line { padding: 10px 14px; font-weight: 700; border-bottom: 1px solid var(--border); min-height: 46px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.status-line.result { background: var(--surface-2); flex-direction: column; align-items: flex-start; gap: 0; }
.status-line.result .score { font-size: 1.4rem; font-family: var(--font-mono); }
.status-line.result .why { font-size: .9rem; color: var(--muted); font-weight: 550; }
.status-line.result .explain-result { font-size: .82rem; color: var(--muted); font-weight: 450; margin-top: 4px; }
.status-line.turn-me { box-shadow: inset 4px 0 0 var(--accent); background: var(--accent-soft); }
.status-line.in-check { color: var(--danger); }
.status-line .sub { width: 100%; font-weight: 450; font-size: .82rem; color: var(--muted); }
.status-line .spinner { width: 16px; height: 16px; border-width: 2px; margin: 0; }

/* tabs of the side panel (moves, messages, review): the active one fills the free height and scrolls */
.panel-tabs { display: flex; gap: 2px; padding: 0 6px; border-bottom: 1px solid var(--border); background: var(--surface-2); flex: none; }
.panel-tabs [role="tab"], .page-tabs [role="tab"] {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 8px 8px;
  margin-bottom: -1px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font-weight: 700;
  font-size: .86rem;
  cursor: pointer;
  white-space: nowrap;
}
.panel-tabs [role="tab"]:hover, .page-tabs [role="tab"]:hover { color: var(--text); }
.panel-tabs [role="tab"][aria-selected="true"], .page-tabs [role="tab"][aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); background: var(--surface); }
.panel-tabs [role="tab"]:focus-visible, .page-tabs [role="tab"]:focus-visible { outline: none; box-shadow: var(--focus); }
.panel-tabs svg.icon { width: 15px; height: 15px; }
.tab-badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: .7rem; font-weight: 800; line-height: 1; }
.tab-pane { flex: 1 0 150px; min-height: 150px; display: flex; flex-direction: column; overflow: hidden; }
.tab-pane > .review { flex: 1 1 auto; overflow-y: auto; border-top: 0; }
.moves { flex: 1 1 auto; min-height: 0; overflow-y: auto; font-size: .93rem; }
.moves table { width: 100%; border-collapse: collapse; }
.moves td { padding: 3px 8px; }
.moves td.no { width: 44px; color: var(--muted); background: var(--surface-2); text-align: right; font-family: var(--font-mono); font-size: .82rem; padding-right: 10px; }
.moves td.mv { cursor: pointer; font-weight: 600; border-radius: 3px; white-space: nowrap; }
.moves td.mv:hover { background: var(--surface-3); }
.moves td.mv.active { background: var(--accent); color: var(--accent-text); font-weight: 750; }
.moves td.mv .glyph { margin-left: 3px; font-weight: 800; font-size: .85em; }
.moves .result-row td { text-align: center; padding: 10px; font-weight: 750; color: var(--muted); }
.moves .empty-moves { padding: 16px; color: var(--muted); text-align: center; font-size: .9rem; }

/* move quality (coach and game review) */
.q-best { color: #26a69a; }
.q-excellent { color: #43a047; }
.q-good { color: #7cb342; }
.q-book { color: #a1887f; }
.q-inaccuracy { color: #e0a800; }
.q-mistake { color: #f57c00; }
.q-blunder { color: #e53935; }

.nav-row { display: flex; gap: 4px; padding: 6px; border-top: 1px solid var(--border); background: var(--surface-2); }
.nav-row .btn { flex: 1; min-height: 34px; padding: 4px; }

.assist-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--border); align-items: center; }
.assist-row .lbl { font-size: .74rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-right: 2px; }
.chip-toggle { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); font-size: .82rem; font-weight: 650; cursor: pointer; color: var(--muted); }
.chip-toggle[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.chip-toggle svg.icon { width: 14px; height: 14px; }

.actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px; border-top: 1px solid var(--border); }
.actions .btn { flex: 1 1 auto; min-height: 36px; font-size: .88rem; padding: 6px 10px; }

/* chat between the two players */
.chat { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.chat-head { display: flex; align-items: flex-start; gap: 8px; padding: 8px 10px 6px; }
.chat-head #chat-tools { display: flex; gap: 4px; flex: none; }
.chat-head .btn { min-height: 28px; padding: 2px 9px; font-size: .78rem; }
.chat-notice { flex: 1; padding: 6px 9px; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-size: .76rem; line-height: 1.4; }
.chat-notice b { color: var(--text); }
.chat-log { flex: 1 1 auto; min-height: 60px; overflow-y: auto; padding: 4px 10px; display: flex; flex-direction: column; gap: 4px; font-size: .88rem; }
.chat-log .msg.quick { font-style: italic; }
.chat-log .msg { padding: 4px 10px; border-radius: 10px 10px 10px 3px; background: var(--surface-3); max-width: 88%; align-self: flex-start; overflow-wrap: anywhere; }
.chat-log .msg.me { align-self: flex-end; background: var(--accent-soft); border-radius: 10px 10px 3px 10px; }
.chat-log .msg b { display: block; font-size: .72rem; color: var(--muted); }
.chat-log .sys { align-self: center; color: var(--muted); font-size: .76rem; font-style: italic; text-align: center; }
.chat-form { display: flex; gap: 6px; padding: 8px 10px 4px; }
.chat-form input { min-height: 34px; padding: 5px 9px; }
.chat-form .btn { min-height: 34px; padding: 4px 12px; }
.chat .emote-row { border-top: 1px solid var(--border); }
.emote-row { display: flex; flex-wrap: wrap; gap: 5px; padding: 8px 10px; border-top: 1px solid var(--border); }
.emote-row button { padding: 4px 9px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); font-size: .8rem; font-weight: 650; cursor: pointer; }
.emote-row button:hover { border-color: var(--accent); }
.emote-row button:disabled { opacity: .45; cursor: default; }

.notice { margin: 0 10px 10px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--info-soft); font-size: .9rem; display: flex; flex-direction: column; gap: 8px; }
#notices .notice:first-child { margin-top: 10px; }
.notice.warn { background: var(--warn-soft); }
.notice.good { background: var(--good-soft); }
.notice.accent { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.notice .row { display: flex; gap: 6px; flex-wrap: wrap; }
.notice .row .btn { flex: 1; min-height: 32px; font-size: .85rem; padding: 4px 10px; }

.coach { margin: 10px 10px 0; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2); font-size: .88rem; display: flex; gap: 10px; align-items: flex-start; }
.coach .q { font-weight: 800; white-space: nowrap; }
.coach .txt { flex: 1; }
.coach .txt .btn { margin-top: 6px; }
.coach.thinking { color: var(--muted); }
.coach .spinner { width: 16px; height: 16px; border-width: 2px; margin: 2px 0 0; flex: none; }
.coach .q.accent { color: var(--accent); }

.engine-line { padding: 8px 14px; border-top: 1px solid var(--border); font-size: .85rem; background: var(--surface-2); }
.engine-line .ev { font-weight: 800; font-family: var(--font-mono); margin-right: 6px; }
.engine-line .pv { color: var(--muted); }
.engine-line .depth { float: right; color: var(--muted); font-size: .78rem; }

/* game review */
.review { border-top: 1px solid var(--border); padding: 10px 12px; display: grid; gap: 8px; background: var(--surface-2); }
.review .progress { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.review .progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .2s; }
.review-sides { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.review-side { padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); }
.review-side .nm { font-size: .78rem; color: var(--muted); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.review-side .acc { font-size: 1.5rem; font-weight: 800; font-family: var(--font-mono); line-height: 1.1; }
.review-side .acc small { font-size: .55em; color: var(--muted); font-family: var(--font-ui); font-weight: 650; }
.review-side .counts { display: flex; gap: 8px; font-size: .78rem; font-weight: 750; margin-top: 2px; }
.review-graph { width: 100%; height: 64px; display: block; cursor: pointer; border-radius: 6px; background: #3b3a38; }
.review-note { font-size: .86rem; }

/* overlay on the board (waiting / invite / accept) */
.board-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(8, 8, 10, .6);
  backdrop-filter: blur(2px);
  border-radius: var(--board-radius, 4px);
}
.overlay-card { width: min(450px, 100%); max-height: 100%; overflow: auto; padding: 24px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-lg); text-align: center; border: 1px solid var(--border); }
.overlay-card h2 { font-size: 1.3rem; }
.overlay-card .facts { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin: 0 0 16px; }
.overlay-card .btn-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.overlay-card .back { margin-top: 14px; }
.overlay-card .waiting { display: inline-flex; align-items: center; gap: 8px; }
.overlay-card .waiting .spinner { width: 14px; height: 14px; border-width: 2px; margin: 0; }
.invite-link { display: flex; gap: 6px; margin: 12px 0; }
.alert-setup { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 4px 0 10px; padding: 10px; border-radius: var(--radius-sm); background: var(--surface-2); }
.alert-setup .btn { min-height: 32px; }
.invite-link input { font-family: var(--font-mono); font-size: .85rem; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--accent); animation: spin .9s linear infinite; margin: 4px auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* settings preview */
.settings-layout { display: grid; grid-template-columns: 1fr 240px; gap: 22px; align-items: start; }
.settings-preview { position: sticky; top: 0; }
.settings-preview .mini-board { width: 240px; height: 240px; }
.theme-swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 6px; }
.theme-swatches label { flex-direction: column; padding: 5px; gap: 4px; font-size: .74rem; }
.theme-swatches .sw { width: 44px; height: 44px; border-radius: 4px; background-size: 100% 100%, 50% 50%; }
.piece-swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.piece-swatches label { flex-direction: column; font-size: .78rem; }
.piece-swatches .pcs { display: flex; padding: 3px 5px; border-radius: 6px; background: var(--sq-light); }
.piece-swatches .pcs span { width: 28px; height: 28px; }

/* ------------------------------------------------------------------ account & auth pages */

.auth-page { display: grid; place-items: start center; padding: 40px 16px 60px; }
.auth-card { width: min(460px, 100%); border: 1px solid var(--border); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.auth-card .tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--border); }
.auth-card .tabs a { padding: 14px; text-align: center; font-weight: 700; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; }
.auth-card .tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); background: var(--surface-2); }
.auth-card .tabs a:hover { color: var(--text) !important; }
.auth-card .body { padding: 24px; }
.auth-card h1 { font-size: 1.45rem; margin-bottom: 6px; }
.auth-card .intro { color: var(--muted); margin-bottom: 20px; }
.auth-card form .btn.primary { width: 100%; margin-top: 4px; }
.auth-card .alt { margin-top: 16px; font-size: .9rem; text-align: center; color: var(--muted); }
.auth-card .perks { margin: 0 0 18px; padding: 12px 14px 12px 32px; border-radius: 10px; background: var(--accent-soft); font-size: .88rem; }
.auth-card .perks li { margin: 2px 0; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 44px; }
.pw-wrap .reveal { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); min-height: 32px; min-width: 32px; padding: 4px; }
.pw-meter { height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.pw-meter i { display: block; height: 100%; width: 0; transition: width .2s, background-color .2s; }
.form-msg { padding: 10px 12px; border-radius: var(--radius-sm); font-size: .9rem; margin-bottom: 14px; }
.form-msg.error { background: var(--danger-soft); color: var(--danger); font-weight: 600; }
.form-msg.success { background: var(--good-soft); color: var(--good); font-weight: 600; }
.form-msg.info { background: var(--info-soft); }
.terms-row { display: flex; gap: 10px; align-items: flex-start; font-size: .88rem; line-height: 1.45; cursor: pointer; }
.terms-row input { margin-top: 2px; }
.hp { position: absolute !important; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.big-icon { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 18px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.big-icon svg.icon { width: 32px; height: 32px; }

.account-page { max-width: 1100px; margin: 0 auto; padding: 28px 20px 56px; display: grid; gap: 20px; }
.profile-head { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.profile-head .avatar { width: 64px; height: 64px; font-size: 1.8rem; border-radius: 18px; }
.profile-head h1 { margin: 0; font-size: 1.8rem; }
.profile-head .sub { color: var(--muted); }
.profile-head .spacer { flex: 1; }
.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.stat { padding: 14px 16px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.stat .v { font-size: 1.7rem; font-weight: 800; font-family: var(--font-mono); line-height: 1.1; }
.stat .k { font-size: .8rem; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.stat.win .v { color: var(--good); }
.stat.loss .v { color: var(--danger); }
.wdl-bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--surface-3); }
.wdl-bar i:nth-child(1) { background: var(--good); }
.wdl-bar i:nth-child(2) { background: var(--muted); }
.wdl-bar i:nth-child(3) { background: var(--danger); }
.account-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }
.account-grid .panel-body form { margin-bottom: 18px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.account-grid .panel-body form:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: 0; }
.account-grid h3 { font-size: .98rem; margin-bottom: 10px; }
table.history { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.history th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--border); }
table.history td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.history tbody tr { cursor: pointer; }
table.history tbody tr:hover td { background: var(--surface-2); }
.outcome { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; font-weight: 800; font-size: .8rem; }
.outcome.win { background: var(--good-soft); color: var(--good); }
.outcome.loss { background: var(--danger-soft); color: var(--danger); }
.outcome.draw { background: var(--surface-3); color: var(--muted); }
.stack-col { display: grid; gap: 20px; align-content: start; }
.settings-block { margin-bottom: 18px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.block-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.block-row:last-child { border-bottom: 0; }
.danger-zone .settings-block:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: 0; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }

/* ------------------------------------------------------------------ text & help pages */

.text-page { max-width: 860px; margin: 0 auto; padding: 32px 20px 56px; }
.text-page h2 { margin-top: 1.8em; }
.text-page h3 { margin-top: 1.4em; }
.text-page address { font-style: normal; }
.text-page ul, .text-page ol { padding-left: 1.3em; }
.text-page li { margin-bottom: .35em; }
.text-page .updated { color: var(--muted); font-size: .9rem; }
.text-page table { border-collapse: collapse; width: 100%; font-size: .92rem; margin-bottom: 1em; }
.text-page th, .text-page td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.text-page code { font-family: var(--font-mono); font-size: .88em; background: var(--surface-3); padding: 1px 5px; border-radius: 4px; }

.help-layout { max-width: 1180px; margin: 0 auto; padding: 30px 20px 60px; display: grid; grid-template-columns: 230px 1fr; gap: 34px; align-items: start; }
.help-toc { position: sticky; top: 76px; display: grid; gap: 2px; font-size: .92rem; }
.help-toc b { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 6px 10px; }
.help-toc a { padding: 6px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; font-weight: 600; }
.help-toc a:hover { background: var(--surface-3); color: var(--text) !important; }
.help-main { min-width: 0; }
.help-main > section { scroll-margin-top: 76px; margin-bottom: 40px; }
.help-main h1 { font-size: 2.2rem; }
.help-main h2 { font-size: 1.5rem; padding-bottom: 8px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.help-main p, .help-main li { color: var(--text); }
.help-main .lead { color: var(--muted); font-size: 1.06rem; }
.steps { counter-reset: step; display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.steps > div { counter-increment: step; padding: 16px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.steps > div::before { content: counter(step); display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-weight: 800; margin-bottom: 10px; }
.steps h3 { font-size: 1rem; margin-bottom: 4px; }
.steps p { margin: 0; font-size: .9rem; color: var(--muted) !important; }
.piece-guide { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.piece-guide > div { display: flex; gap: 14px; padding: 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.piece-guide .piece-img { width: 52px; height: 52px; flex: none; }
.piece-guide h3 { margin: 0 0 4px; font-size: 1rem; }
.piece-guide p { margin: 0; font-size: .9rem; color: var(--muted) !important; }
.piece-guide .val { font-size: .78rem; font-weight: 700; color: var(--accent); }
.info-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.info-grid > div { padding: 14px 16px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.info-grid h3 { font-size: 1rem; margin-bottom: 6px; }
.info-grid p { margin: 0; font-size: .9rem; color: var(--muted) !important; }
.help-main table { width: 100%; border-collapse: collapse; font-size: .92rem; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; margin-bottom: 1em; }
.help-main th, .help-main td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.help-main thead th { background: var(--surface-2); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.help-main tr:last-child td { border-bottom: 0; }
kbd { font-family: var(--font-mono); font-size: .82em; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--border-strong); border-bottom-width: 2px; background: var(--surface-2); }
details.faq { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); margin-bottom: 8px; }
details.faq summary { cursor: pointer; padding: 12px 16px; font-weight: 700; }
details.faq > div { padding: 0 16px 12px; color: var(--muted); }
details.faq[open] summary { color: var(--accent); }

/* ------------------------------------------------------------------ responsive */

@media (max-width: 1180px) {
  .modes { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 1080px) {
  .features { grid-template-columns: repeat(2, 1fr); }
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; }
  .hero-board-wrap { width: min(340px, 100%); }
  .modes { grid-template-columns: 1fr; }
  .lobby-grid { grid-template-columns: 1fr; }
  .settings-layout { grid-template-columns: 1fr; }
  .settings-preview { position: static; display: flex; justify-content: center; }
  .account-grid { grid-template-columns: 1fr; }
  .admin-grid { grid-template-columns: 1fr; }
  .help-layout { grid-template-columns: 1fr; }
  .help-toc { position: static; display: flex; flex-wrap: wrap; gap: 4px; }
  .help-toc b { width: 100%; }
  .steps { grid-template-columns: 1fr; }
  .piece-guide, .info-grid { grid-template-columns: 1fr; }

  .game-page { padding: 8px 0 20px; }
  .game {
    --board-size: min(100vw, calc(100vh - 150px) * var(--board-scale, 1) + 200px, 640px);
    height: auto;
    grid-template-columns: var(--board-size);
    grid-template-rows: none;
    grid-template-areas: "top" "board" "bottom" "panel";
  }
  .game.with-eval { grid-template-columns: var(--board-size); }
  .eval-bar { display: none; }
  .player { padding: 0 8px; margin-left: 0 !important; }
  .player.top { margin-bottom: 6px; }
  .player.bottom { margin-top: 6px; }
  .clock { font-size: 1.6rem; min-width: 106px; }
  .side-panel { margin: 10px 8px 0 !important; }
  .moves { max-height: 220px; }
  .tab-pane { flex: none; min-height: 0; }
  .chat-log { max-height: 220px; }
  .board-area .cg-wrap, .board-area cg-board { border-radius: 0; }
}

/* phones held sideways: board and panel side by side, the whole board visible without scrolling */
@media (max-width: 960px) and (min-width: 641px) and (max-height: 560px) and (orientation: landscape) {
  .game-page { --side-w: 300px; --gap: 10px; padding: 6px 10px; }
  .game {
    --board-size: min(calc(100vh - 72px), calc(100vw - var(--side-w) - 40px));
    height: var(--board-size);
    grid-template-columns: var(--board-size) minmax(220px, var(--side-w));
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "board top" "board panel" "board bottom";
  }
  .game.with-eval { grid-template-columns: var(--board-size) minmax(220px, var(--side-w)); }
  .eval-bar { display: none; }
  .player { padding: 0; margin-left: var(--gap) !important; }
  .player.top { margin-bottom: 0; }
  .player.bottom { margin-top: 0; }
  .clock { font-size: 1.3rem; min-width: 86px; }
  .side-panel { margin: 6px 0 6px var(--gap) !important; }
  .moves { max-height: none; }
  .tab-pane { flex: 1 0 110px; min-height: 110px; }
  .chat-log { max-height: none; }
}

@media (max-width: 640px) {
  .topbar { padding: 8px 12px 0; gap: 6px; flex-wrap: wrap; }
  .topbar nav { order: 10; width: calc(100% + 24px); margin: 4px -12px 0; padding: 0 8px; gap: 0; overflow-x: auto; border-top: 1px solid var(--border); }
  .topbar nav a { padding: 8px 10px; border-radius: 0; white-space: nowrap; }
  .topbar nav a[aria-current="page"] { background: none; }
  .brand span { display: none; }
  .name-chip, .user-chip { max-width: 132px; padding-right: 10px; gap: 6px; }
  .name-chip .guest-tag { display: none; } /* "Sign up" next to it already says it */
  .auth-links .btn.ghost { display: none; }
  .auth-links .btn { padding: 5px 11px; }
  .topbar .btn.icon { min-width: 34px; padding: 6px; }
  .home { padding: 20px 16px 36px; gap: 26px; }
  .lobby-page, .admin-page { padding: 18px 12px 32px; gap: 14px; }
  .create-row .btn { flex: 1 1 calc(50% - 8px); }
  .lobby-teaser .btn { width: 100%; }
  .page-tabs [role="tab"][role="tab"] { flex: 1; padding: 9px 8px 8px; font-size: .88rem; }
  h1 { font-size: 1.55rem; }
  .features, .explainer, .modes { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  table.seeks .col-variant, table.history .col-hide { display: none; }
  .quick-grid button b { font-size: 1.1rem; }
  .modal-body { padding: 14px 16px; }
  .about { grid-template-columns: 1fr; }
  .level-grid { grid-template-columns: repeat(4, 1fr); }
  .review-sides { grid-template-columns: 1fr; }
  /* information tables (help, legal pages, home): narrower cells so four columns fit a phone */
  .help-main table, .text-page table, table.access { font-size: .84rem; }
  .help-main th, .help-main td, .text-page th, .text-page td, table.access th, table.access td { padding: 7px 7px; overflow-wrap: anywhere; hyphens: auto; }
  .help-main thead th, table.access thead th { font-size: .68rem; letter-spacing: .02em; }
}

/* small phones: the speaker, theme and settings buttons do not fit next to "Sign up"; the colour scheme
   is also in the settings */
@media (max-width: 420px) {
  .topbar #btn-theme { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  /* `transition: none`, not a tiny duration: a duration alone would transition *every* property (the
     default transition-property is `all`), so sizes read right after a change (chessground measuring the
     board on resize) would still be the old ones and the pieces end up misplaced */
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
  .emote-bubble { animation: none !important; }
}
