:root {
  --bg: #9cc7ee;
  --panel: rgba(24, 26, 30, 0.88);
  --text: #f1f1ea;
  --muted: #b5b8b0;
  --ow: #6fbf3f;
  --ne: #e0503b;
  --accent: #f2c21b;
  --btn: #3b3f46;
  --btn-hover: #4d525b;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
html, body { height: 100vh; height: 100dvh; } /* dvh: mobile browser bars do not cut content off */
body { touch-action: manipulation; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
#bar-top, #bar-bottom, #mbar, #sheet-close { display: none; }

#panel {
  position: fixed; top: 12px; right: 12px; bottom: 12px; width: 300px;
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px 16px; border-radius: 10px; background: var(--panel);
  overflow-y: auto; font-size: 14px;
  transition: transform 0.25s ease;
}
#panel.hidden { transform: translateX(calc(100% + 24px)); }
#panel h1 { margin: 0; font-size: 20px; letter-spacing: 0.5px; }
#panel h2 { margin: 0 0 4px; font-size: 13px; text-transform: uppercase; color: var(--muted); letter-spacing: 1px; }
.sub { margin: 2px 0 0; color: var(--muted); }
.ow { color: var(--ow); font-weight: 600; }
.ne { color: var(--ne); font-weight: 600; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0; }
.error { color: #ff8a7a; min-height: 1em; }

#turn { display: flex; align-items: center; gap: 8px; font-size: 17px; font-weight: 600; }
#turn .dot { width: 14px; height: 14px; border-radius: 3px; background: var(--muted); flex: none; }
#turn.w .dot { background: var(--ow); }
#turn.b .dot { background: var(--ne); }
#substatus { color: var(--muted); margin-top: 4px; min-height: 1.2em; }
#substatus.check { color: #ff8a7a; font-weight: 600; }

#players > div { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
#players .name { flex: 1; }
.clock {
  font-family: Consolas, "Cascadia Mono", monospace; font-size: 18px; font-weight: 600;
  padding: 2px 8px; border-radius: 5px; background: #15171a; color: var(--muted); min-width: 78px; text-align: right;
}
.clock.active { background: #f2f2e8; color: #111; }
.clock.low { color: #fff; background: #b3261e; }
.clock.low.active { animation: low-blink 1s steps(2) infinite; }
@keyframes low-blink { 50% { background: #e0503b; } }
.clock.paused { outline: 2px dashed var(--accent); }
select, input[type=number] {
  font: inherit; color: var(--text); background: #111; border: 1px solid #555; border-radius: 6px; padding: 5px 6px;
}
select { width: 100%; }
input[type=number] { width: 70px; }
#tc-custom { display: flex; gap: 10px; margin-top: 6px; }
#tc-custom label { display: flex; align-items: center; gap: 4px; }
#moves li.result { list-style: none; margin-left: -28px; color: var(--accent); font-weight: 600; }
.online { color: #8fe08a; }
.offline { color: var(--muted); }

.row { display: flex; gap: 6px; margin-top: 4px; }
input[readonly] {
  flex: 1; min-width: 0; padding: 6px 8px; border-radius: 6px; border: 1px solid #555;
  background: #111; color: var(--text); font-size: 12px;
}

.captured { font-size: 13px; }
.captured span { display: inline-block; margin-right: 6px; }
.label { display: inline-block; width: 92px; font-size: 12px; }
#captured-box > div { margin: 3px 0; }

#moves-box { flex: 1; min-height: 80px; display: flex; flex-direction: column; }
#moves {
  margin: 0; padding: 0 0 0 28px; overflow-y: auto; flex: 1;
  font-family: Consolas, "Cascadia Mono", monospace; font-size: 13px;
  columns: 1;
}
#moves li { padding: 1px 0; }
#moves li span { display: inline-block; width: 70px; }

button {
  font: inherit; color: var(--text); background: var(--btn); border: 0; border-radius: 6px;
  padding: 7px 12px; cursor: pointer;
}
button:hover { background: var(--btn-hover); }
button.big { display: block; width: 100%; padding: 12px; font-size: 16px; font-weight: 600; background: #4f7f2f; margin: 8px 0; }
button.big:hover { background: #5d9437; }
button.link { background: none; color: var(--muted); text-decoration: underline; }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; width: 100%; }


#banner {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  padding: 12px 22px; border-radius: 10px; background: var(--panel);
  font-size: 20px; font-weight: 700; text-align: center; max-width: calc(100vw - 32px);
  border: 2px solid var(--accent);
}
#banner small { display: block; font-size: 13px; font-weight: 400; color: var(--muted); margin-top: 4px; }
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  padding: 8px 16px; border-radius: 8px; background: #6b2a22; font-size: 14px;
  max-width: calc(100vw - 32px);
}

dialog {
  border: 0; border-radius: 12px; padding: 20px 24px; background: #23262b; color: var(--text);
  width: min(380px, calc(100vw - 32px)); max-height: calc(100dvh - 24px); overflow-y: auto;
  overscroll-behavior: contain;
}
dialog::backdrop { background: rgba(10, 20, 30, 0.5); }
dialog h2 { margin-top: 0; }
fieldset { border: 1px solid #444; border-radius: 8px; margin: 12px 0 0; padding: 8px 12px; }
fieldset label { display: block; padding: 3px 0; }
#promo-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
#promo-choices button { padding: 12px 8px; }
#promo-choices button small { display: block; color: var(--muted); font-size: 12px; }

/* --- Compact layouts (main.js sets body[data-layout]) ------------------------ */
.pbar {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; min-height: 48px;
  background: #23262b; border-left: 4px solid transparent; font-size: 15px;
}
.pbar.to-move { border-left-color: var(--accent); background: #2d3137; }
.pbar .pname { font-weight: 700; white-space: nowrap; }
.pbar .psub { font-size: 12px; }
.pbar .padv { flex: 1; color: var(--muted); font-size: 13px; }
.pbar .clock { font-size: 22px; min-width: 92px; padding: 4px 10px; }
#mbar { background: #1d2024; padding: 6px 8px; }
#m-status { font-weight: 600; font-size: 15px; padding: 2px 4px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#m-status.in-check { color: #ff8a7a; }
.m-buttons { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.m-buttons button { min-height: 44px; min-width: 44px; padding: 8px 12px; font-size: 15px; }
.games-link.compact { margin: 0 0 0 auto; min-height: 44px; padding: 0 6px; }
.games-link.compact .badge-text { display: none; }

body[data-layout="portrait"], body[data-layout="landscape"] { display: grid; }
body[data-layout="portrait"] #stage, body[data-layout="landscape"] #stage { position: relative; inset: auto; min-height: 0; min-width: 0; overflow: hidden; }
body[data-layout="portrait"] #bar-top, body[data-layout="landscape"] #bar-top,
body[data-layout="portrait"] #bar-bottom, body[data-layout="landscape"] #bar-bottom,
body[data-layout="portrait"] #mbar, body[data-layout="landscape"] #mbar { display: flex; }
body[data-layout="portrait"] #stage canvas, body[data-layout="landscape"] #stage canvas { position: absolute; left: 0; top: 0; }
body[data-layout="portrait"] #mbar, body[data-layout="landscape"] #mbar { flex-direction: column; }
/* The panel's own turn line and player rows are in the bars now. */
body[data-layout="portrait"] #status-box, body[data-layout="landscape"] #status-box,
body[data-layout="portrait"] #players-box, body[data-layout="landscape"] #players-box,
body[data-layout="landscape"] #actions { display: none; }
body[data-layout="portrait"] .m-buttons .m-new { display: none; } /* New game lives in the sheet */

/* Portrait: opponent bar, board (as big as possible), your bar, buttons. Panel = sheet. */
body[data-layout="portrait"] {
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
body[data-layout="portrait"] #mbar { padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
body[data-layout="portrait"] #panel {
  top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 75dvh; border-radius: 14px 14px 0 0;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); font-size: 15px; z-index: 10;
  background: rgba(24, 26, 30, 0.97); transform: translateY(105%); overscroll-behavior: contain;
}
body[data-layout="portrait"].sheet-open #panel { transform: none; box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.4); }
body[data-layout="portrait"] #sheet-close { display: block; float: right; min-width: 44px; min-height: 44px; }
body[data-layout="portrait"] #moves-box { min-height: 120px; }

/* Landscape phones: board on the left, compact column on the right. */
body[data-layout="landscape"] {
  grid-template-columns: minmax(0, 1fr) minmax(250px, 36vw);
  grid-template-rows: auto auto auto minmax(0, 1fr);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
body[data-layout="landscape"] #stage { grid-column: 1; grid-row: 1 / -1; }
body[data-layout="landscape"] #bar-top { grid-column: 2; grid-row: 1; }
body[data-layout="landscape"] #bar-bottom { grid-column: 2; grid-row: 2; }
body[data-layout="landscape"] #mbar { grid-column: 2; grid-row: 3; }
body[data-layout="landscape"] #btn-menu { display: none; }
body[data-layout="landscape"] #panel {
  position: static; grid-column: 2; grid-row: 4; width: auto; border-radius: 0; padding: 8px 12px;
  gap: 8px; font-size: 13px; min-height: 0; overscroll-behavior: contain;
}
body[data-layout="landscape"] #panel header { display: none; }
body[data-layout="landscape"] .pbar { min-height: 40px; padding: 4px 8px; }
body[data-layout="landscape"] .pbar .clock { font-size: 18px; min-width: 76px; }
body[data-layout="landscape"] .m-buttons button { min-height: 40px; min-width: 40px; padding: 6px 10px; }
body[data-layout="landscape"] #m-status { font-size: 14px; padding-bottom: 4px; }
body[data-layout="landscape"] #banner { left: 37%; font-size: 15px; top: 8px; }

body[data-layout="portrait"] #banner { top: calc(60px + env(safe-area-inset-top)); font-size: 16px; width: max-content; }
body[data-layout="portrait"] #toast, body[data-layout="landscape"] #toast { bottom: auto; top: 45%; z-index: 20; }

/* Touch screens: 44 px targets, larger text in forms. */
@media (pointer: coarse) {
  button, a.button, a.big-link, select, input[type=number] { min-height: 44px; }
  input[readonly] { min-height: 44px; font-size: 14px; }
  fieldset label { padding: 8px 0; }
  input[type=radio], input[type=checkbox] { width: 20px; height: 20px; }
  #promo-choices button { min-height: 64px; font-size: 17px; }
  .check { min-height: 44px; }
  details summary { padding: 10px 0; }
}

/* --- "My games" page and badges ---------------------------------------- */
body.page { overflow: auto; height: auto; min-height: 100%; background: #1d2024; overscroll-behavior: auto; }
#games-page {
  max-width: 820px; margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
}
.games-head { flex-wrap: wrap; }
.gc-title, .gc-info { overflow-wrap: anywhere; }
@media (max-width: 480px) {
  .gc-actions > * { flex: 1 1 auto; }
  .games-head h1 { font-size: 26px; }
}
.games-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.games-head h1 { margin: 0; }
a.button, a.big-link {
  display: inline-flex; align-items: center; justify-content: center; color: var(--text); background: var(--btn); border-radius: 6px;
  padding: 7px 12px; text-decoration: none; font-size: 14px;
}
a.button:hover { background: var(--btn-hover); }
a.big-link { background: #4f7f2f; font-weight: 600; padding: 10px 16px; }
a.button.primary { background: #4f7f2f; font-weight: 600; }
button.danger { background: #5a2a26; }
button.danger:hover { background: #75352f; }
#game-list { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.game-card {
  background: var(--panel); border-radius: 10px; padding: 12px 14px; border-left: 5px solid #555;
  display: flex; flex-direction: column; gap: 8px;
}
.game-card.your-move { border-left-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.game-card.finished { opacity: 0.75; }
.gc-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.gc-title { font-size: 16px; font-weight: 600; }
.gc-mode { color: var(--muted); font-weight: 400; }
.pill { padding: 3px 10px; border-radius: 999px; background: #3b3f46; font-size: 13px; white-space: nowrap; }
.pill.yours { background: var(--accent); color: #111; font-weight: 700; }
.pill.wait { background: #2f4a63; }
.pill.done { background: #444; }
.pill.gone { background: #6b2a22; }
.gc-info { color: var(--muted); font-size: 13px; }
.gc-clocks { display: flex; gap: 18px; flex-wrap: wrap; }
.gc-clock { display: flex; align-items: center; gap: 8px; }
.gc-clock .clock { font-size: 16px; min-width: 70px; }
.gc-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { color: var(--muted); }
.games-link { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-size: 14px; }
.games-link:hover { text-decoration: underline; }
.badge {
  display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 999px; background: var(--accent);
  color: #111; font-weight: 700; font-size: 12px; text-align: center;
}
.badge-text { color: var(--accent); font-size: 13px; }
.games-link { margin-top: 6px; flex-wrap: wrap; }
.gl-name { white-space: nowrap; }
.badge-text:empty { display: none; }
.badge-text { flex-basis: 100%; }
.gc-actions button, .gc-actions a.button { font-size: 14px; }

/* --- Names and passwords ---------------------------------------------------- */
.game-title {
  font-weight: 600; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%; margin-top: 4px;
}
#m-title { font-size: 13px; padding: 0 4px; margin: 0; }
#m-title:empty { display: none; }
label.field { display: block; margin: 8px 0; font-size: 14px; }
label.field input, .names-form input {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px; font: inherit; color: var(--text);
  background: #111; border: 1px solid #555; border-radius: 6px; min-width: 0;
}
.opt { color: var(--muted); font-size: 12px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.two label.field { margin-top: 0; }
.names-form { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.names-form label { font-size: 13px; color: var(--muted); }
.lock-hint { color: var(--accent); }
#moves-head { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pbar .pname { overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; }
.pbar .psub, .pbar .clock { flex: none; }
.pbar .padv { min-width: 0; }
#players .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.lock { margin-left: 4px; }
@media (pointer: coarse) { label.field input, .names-form input { min-height: 44px; font-size: 16px; } }
.gc-name { overflow-wrap: anywhere; }
.gc-sides { font-size: 14px; overflow-wrap: anywhere; }
.plain-link { display: block; margin-top: 10px; color: var(--muted); font-size: 14px; }

/* --- Statistics page ------------------------------------------------------------ */
#games-page h2 { font-size: 18px; margin: 26px 0 8px; }
.st-range { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.st-range select { font: inherit; color: var(--text); background: var(--btn); border: 0; border-radius: 6px; padding: 7px 10px; }
.st-totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-top: 14px; }
.st-card { background: var(--panel); border-radius: 10px; padding: 12px 14px; }
.st-value { font-size: 22px; font-weight: 700; color: var(--accent); }
.st-label { color: var(--muted); font-size: 13px; margin-top: 2px; }
.st-days {
  display: flex; align-items: flex-end; gap: 2px; height: 120px; background: var(--panel); border-radius: 10px;
  padding: 10px;
}
.st-day { flex: 1 1 0; height: 100%; display: flex; align-items: flex-end; min-width: 0; }
.st-day { border-bottom: 1px solid #3b3f46; }
.st-bar { width: 100%; background: var(--ow); border-radius: 2px 2px 0 0; }
.st-visits .st-bar { background: var(--accent); }
.st-scroll { overflow-x: auto; background: var(--panel); border-radius: 10px; }
.st-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.st-table th, .st-table td { padding: 8px 10px; text-align: left; white-space: nowrap; }
.st-table th { color: var(--muted); font-weight: 600; border-bottom: 1px solid #3b3f46; }
.st-table tbody tr + tr td { border-top: 1px solid #2b2e33; }
.st-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.st-id, .st-aka { color: var(--muted); font-size: 12px; }
.st-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ow); }
label.field select { display: block; width: 100%; margin-top: 4px; }

/* --- Start screen: step 1 (choose a mode), step 2 (that mode's settings) ------------ */
dialog.start-dlg { width: min(960px, calc(100vw - 24px)); padding: 0; }
.start-form { display: flex; flex-direction: column; gap: 16px; padding: 22px 26px 16px; }
.start-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.start-head h2 { margin: 0; font-size: 26px; }
.start-sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.start-head .games-link { margin: 4px 0 0; }
.start-step { display: flex; flex-direction: column; gap: 16px; }
.start-step[hidden] { display: none !important; }

.mode-choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.mode-choice {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 170px; padding: 18px 12px; border-radius: 12px; background: #2d3137;
  border: 2px solid #3b4048; text-align: center; transition: border-color 0.15s, transform 0.15s, background 0.15s;
}
.mode-choice:hover, .mode-choice:focus-visible { border-color: var(--accent); background: #343941; transform: translateY(-2px); outline: none; }
.mode-choice.last-used { border-color: #4f7f2f; }
.mc-icon { font-size: 40px; line-height: 1; }
.mc-title { font-size: 18px; font-weight: 700; }
.mc-desc { color: var(--muted); font-size: 14px; }

.start-continue {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px;
  border-radius: 10px; background: #1d2024; border: 1px solid #333840;
}
.start-label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 1px; margin-right: 4px; }
button.secondary, a.button.secondary { background: #3b3f46; font-size: 14px; }

.step2-head { display: flex; align-items: center; gap: 12px; }
.step2-head h3 { margin: 0; font-size: 20px; }
.step2-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; align-items: start; }
.mode-card, .start-group {
  background: #2a2e34; border-radius: 10px; padding: 12px 16px 14px; border: 1px solid #353a42;
}
.mode-card h4, .start-group h4 { margin: 0 0 4px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.mode-card .hint { margin-top: 8px; }
.mode-card select, .start-group select { min-width: 0; }
.side-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; }
.side-pick > span { width: 100%; }
.side-pick label { display: inline-flex; align-items: center; gap: 6px; padding: 4px 0; }
.start-dlg[data-mode="computer"] .mode-card:not([data-mode="computer"]),
.start-dlg[data-mode="local"] .mode-card:not([data-mode="local"]),
.start-dlg[data-mode="online"] .mode-card:not([data-mode="online"]),
.start-dlg[data-mode="computer"] .step2-actions button:not([data-mode="computer"]),
.start-dlg[data-mode="local"] .step2-actions button:not([data-mode="local"]),
.start-dlg[data-mode="online"] .step2-actions button:not([data-mode="online"]) { display: none; }
.step2-actions { display: flex; justify-content: flex-end; }
.step2-actions .big { width: auto; min-width: 220px; margin: 0; }
.start-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.start-foot .plain-link { margin: 0; font-size: 13px; }
#start-error:empty { display: none; }
.version { color: var(--muted); font-size: 12px; opacity: 0.8; font-variant-numeric: tabular-nums; }
.page-foot { display: flex; justify-content: flex-end; margin-top: 16px; }

/* Narrow screens: the choices and the settings stack. */
@media (max-width: 720px) {
  .start-form { padding: 16px 16px 12px; gap: 12px; }
  .start-head h2 { font-size: 22px; }
  .mode-choices { grid-template-columns: 1fr; gap: 10px; }
  .mode-choice { min-height: 0; flex-direction: row; justify-content: flex-start; text-align: left; padding: 12px 14px; gap: 4px 14px; flex-wrap: wrap; }
  .mode-choice .mc-icon { font-size: 30px; grid-row: span 2; }
  .mode-choice { display: grid; grid-template-columns: auto 1fr; align-items: center; }
  .mc-title { font-size: 17px; }
  .step2-grid { grid-template-columns: 1fr; }
  .step2-actions .big { width: 100%; }
}
/* Short landscape phones: compact choices in a row, settings side by side. */
@media (max-height: 500px) and (min-width: 721px) {
  .start-form { padding: 12px 18px 10px; gap: 10px; }
  .start-sub { display: none; }
  .mode-choice { min-height: 110px; padding: 10px; }
  .mc-icon { font-size: 28px; }
}

/* --- Chat ------------------------------------------------------------------------- */
#chat-box summary { cursor: pointer; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.chat-list {
  display: flex; flex-direction: column; gap: 6px; max-height: 220px; min-height: 60px; overflow-y: auto;
  margin: 8px 0 6px; padding: 6px; background: #1b1d21; border-radius: 8px; overscroll-behavior: contain;
}
.chat-msg { max-width: 85%; padding: 5px 9px; border-radius: 10px; background: #33373e; align-self: flex-start; }
.chat-msg.mine { align-self: flex-end; background: #2f4f22; }
.chat-msg.theirs.ne-msg { border-left: 3px solid var(--ne); }
.chat-msg.theirs.ow-msg { border-left: 3px solid var(--ow); }
.chat-meta { font-size: 11px; color: var(--muted); }
.chat-text { font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-empty { margin: 4px; }
.chat-quick { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.chat-quick button { padding: 4px 10px; font-size: 13px; border-radius: 999px; }
.chat-form { display: flex; gap: 6px; }
.chat-form input {
  flex: 1; min-width: 0; padding: 7px 9px; font: inherit; color: var(--text); background: #111;
  border: 1px solid #555; border-radius: 6px;
}
#chat-error:empty { display: none; }
#btn-chat { position: relative; }
#btn-chat .badge { position: absolute; top: -4px; right: -4px; }
body[data-layout="portrait"] .chat-list { max-height: 35dvh; }
body[data-layout="landscape"] .chat-list { max-height: 30dvh; }
@media (pointer: coarse) { .chat-form input { min-height: 44px; font-size: 16px; } .chat-quick button { min-height: 44px; } }
.start-head h2:focus { outline: none; }

/* --- In-game panel (redesign): header, players, status, tabs, action bar ------------ */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#panel { gap: 10px; padding: 12px 14px; }
.pn-head { border-bottom: 1px solid #353a42; padding-bottom: 8px; }
.pn-title-row { display: flex; align-items: flex-start; gap: 8px; }
.pn-title { flex: 1; min-width: 0; }
.pn-head .game-title { margin: 0; font-size: 17px; color: var(--text); }
.pn-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.tag { font-size: 12px; color: var(--muted); background: #353a42; border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.pn-head .games-link { margin: 2px 0 0; font-size: 13px; color: var(--muted); white-space: nowrap; flex-wrap: nowrap; }
.pn-head .games-link .badge-text { display: none; }
.pn-head #sheet-close { display: none; }

.pn-players #players { display: flex; flex-direction: column; gap: 4px; }
.prow {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; background: #23262b;
  border-left: 3px solid transparent; min-height: 40px;
}
.prow.to-move { border-left-color: var(--accent); background: #2d3137; }
.pside { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.ow-bg { background: var(--ow); }
.ne-bg { background: var(--ne); }
.prow .pname, .pbar .pname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; }
.prow .psub { font-size: 12px; flex: none; }
.prow .psub.online::before, .pbar .psub.online::before { content: '● '; color: #8fe08a; }
.prow .padv { flex: 1; min-width: 0; color: var(--muted); font-size: 12px; }
.prow .clock { flex: none; font-size: 16px; min-width: 70px; }
.pspect { font-size: 12px; color: var(--muted); padding-left: 4px; }

.pn-status { padding: 2px 2px 0; }
.pn-status #turn { font-size: 16px; }
.pn-status #turn-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pn-status #substatus { margin-top: 2px; font-size: 13px; min-height: 0; }
.pn-status #substatus:empty { display: none; }

.pn-tabs { display: flex; gap: 2px; border-bottom: 1px solid #353a42; }
.pn-tabs [role="tab"] {
  flex: 1; background: none; border-radius: 6px 6px 0 0; padding: 8px 6px; color: var(--muted); font-weight: 600;
  border-bottom: 2px solid transparent; display: inline-flex; justify-content: center; align-items: center; gap: 6px;
}
.pn-tabs [role="tab"][aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); background: #2a2e34; }
.pn-tabs [role="tab"]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.pn-pane { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.pn-pane[hidden] { display: none !important; }
#pane-moves #moves-box { flex: 1; min-height: 60px; }
.pn-captured { font-size: 13px; display: flex; flex-direction: column; gap: 2px; }
.pn-captured .label { width: 104px; font-size: 12px; }
#pane-chat #chat-box { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#pane-chat .chat-list { flex: 1; max-height: none; min-height: 120px; }
.pn-group h3 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.pn-group:not(:last-child) { border-bottom: 1px solid #353a42; padding-bottom: 10px; } /* #info-box is last and always shown */
.pn-info { margin: 0 0 6px; padding-left: 18px; font-size: 13px; color: var(--muted); }
.pn-info li { margin: 2px 0; }
.pn-info li:empty { display: none; }
.check.small { font-size: 12px; }

.pn-actions { display: flex; gap: 6px; border-top: 1px solid #353a42; padding-top: 10px; align-items: flex-start; }
.pn-actions-main { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.pn-actions-main > button { padding: 7px 11px; font-size: 14px; }
.pn-actions button.primary { background: #4f7f2f; font-weight: 600; }
.more-wrap { position: relative; margin-left: auto; }
#btn-more { font-size: 18px; line-height: 1; padding: 6px 12px; }
.more-menu {
  position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 20; min-width: 220px;
  display: flex; flex-direction: column; padding: 6px; border-radius: 10px; background: #2d3137;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45); border: 1px solid #3b4048;
}
.more-menu[hidden] { display: none; }
.more-menu > button, .more-menu > a, .more-menu > label {
  display: flex; align-items: center; gap: 8px; text-align: left; background: none; padding: 9px 10px; border-radius: 6px;
  color: var(--text); text-decoration: none; font-size: 14px; width: 100%;
}
.more-menu > button:hover, .more-menu > a:hover, .more-menu > label:hover { background: #3b4048; }

/* Compact layouts: the bars and button row above/below the board carry players, status and actions. */
body[data-layout="portrait"] .pn-head .games-link, body[data-layout="landscape"] .pn-head .games-link { display: none; }
body[data-layout="portrait"] .pn-head #sheet-close { display: block; float: none; min-width: 44px; min-height: 44px; }
body[data-layout="portrait"] #panel { padding-top: 10px; }
body[data-layout="portrait"] .pn-pane { max-height: none; }
/* landscape: the title is in the compact bar, so the panel header stays hidden */
@media (pointer: coarse) { .pn-tabs [role="tab"] { min-height: 44px; } .more-menu > * { min-height: 44px; } }
body[data-layout="portrait"] #panel { background: #1b1d21; }
.start-foot { justify-content: flex-end; }
/* Phone sheet: Undo, Hint, Flip… are already in the button row under the board; the sheet only adds New game and ⋯. */
body[data-layout="portrait"] .pn-actions-main > button:not(#btn-new) { display: none; }
body[data-layout="portrait"] #actions { justify-content: space-between; }
/* Phones have ⟲ in the button row. */
body[data-layout="portrait"] #menu-reset-view, body[data-layout="landscape"] #menu-reset-view { display: none; }

/* Full screen: a round button in the top-right corner of the 3D view (over the sky). On
   desktop the panel floats over the right of the view, so the button sits left of it. */
#btn-fs {
  position: absolute; z-index: 5; top: 12px; right: 336px; width: 40px; height: 40px; padding: 0;
  display: flex; align-items: center; justify-content: center; border-radius: 50%;
  background: rgba(20, 22, 26, 0.5); color: #fff; border: 1px solid rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(2px); touch-action: manipulation;
}
#btn-fs:hover { background: rgba(20, 22, 26, 0.72); }
#btn-fs:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#btn-fs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
#btn-fs .fs-exit, #btn-fs[aria-pressed="true"] .fs-enter { display: none; }
#btn-fs[aria-pressed="true"] .fs-exit { display: block; }
#btn-fs[hidden] { display: none !important; }
body[data-layout="portrait"] #btn-fs, body[data-layout="landscape"] #btn-fs { top: 8px; right: 8px; width: 44px; height: 44px; }
@media (pointer: coarse) { #btn-fs { width: 44px; height: 44px; } }
/* Keep the result banner clear of the button. */
body[data-layout="portrait"] #banner { max-width: calc(100vw - 120px); }
body[data-layout="landscape"] #banner { max-width: 40vw; }

/* --- "Allow notifications?" card ---------------------------------------------------- */
.nt-ask {
  display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-radius: 10px;
  background: #2b3324; border: 1px solid #4f7f2f; font-size: 13px;
}
.nt-ask[hidden] { display: none !important; }
.nt-ask-text { margin: 0; line-height: 1.35; }
.nt-ask-icon { font-size: 15px; }
.nt-ask-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.nt-ask-buttons button { padding: 6px 12px; font-size: 13px; }
.nt-ask-buttons button.primary { background: #4f7f2f; font-weight: 600; }
.nt-ask-buttons button.primary:hover { background: #5d9437; }
#mbar .nt-ask { margin: 0 0 6px; padding: 8px 10px; }
#mbar .nt-ask-text { font-size: 13px; }
#games-page .nt-ask { margin: 12px 0 0; font-size: 14px; }
@media (pointer: coarse) { .nt-ask-buttons button { min-height: 44px; } }

/* --- Notification settings ------------------------------------------------------------ */
.nt-settings { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.nt-settings p { margin: 0; }
.nt-state { color: var(--muted); }
.nt-state .nt-on { color: #8fe08a; }
.nt-state .nt-blocked { color: #ff8a7a; }
.nt-settings fieldset { border: 0; margin: 2px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nt-settings legend { color: var(--muted); font-size: 12px; padding: 0; margin-bottom: 2px; }
.nt-settings .check { color: var(--text); }
.nt-settings .check.small { color: var(--muted); }
.nt-settings .nt-test { align-self: flex-start; font-size: 13px; padding: 5px 10px; }
.nt-switch { font-weight: 600; }
#games-page .nt-box { background: var(--panel); border-radius: 10px; padding: 10px 14px; margin: 12px 0; }
#games-page .nt-box summary { cursor: pointer; font-weight: 600; }
#games-page .nt-box[open] summary { margin-bottom: 8px; }
