/* Colour tokens. look.js sets data-theme (light or dark) and data-palette on
   <html>. The palette blocks hold only the players' colours and what follows
   from them, and also work on any element, so a preview swatch can show
   another palette (<span class="dot seat1" data-palette="cb">). */
:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --grid: #d9d4c7;
  --legal: #b9b2a1;
  --border: #e3dfd4;
  --danger: #b42318;
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15171c;
  --panel: #1d2027;
  --text: #e8e6e3;
  --muted: #9aa0a8;
  --grid: #2b2f38;
  --legal: #4a505c;
  --border: #2b2f38;
  --danger: #ff8a80;
}

/* Players' colours. --accent is the main button, --link the second colour in
   text; --tile is the Trax tile; --piece-edge outlines pieces that need it;
   --stripe marks the second player's pieces when data-marks is on. */
:root, [data-palette="classic"] {
  --p1: #e0584b; --p2: #2f8f9d; --win: #f2b705;
  --accent: #e0584b; --on-accent: #fff; --link: #2f8f9d; --chip2: #dcf0f2;
  --tile: #23262d; --piece-edge: transparent; --stripe: rgba(0, 0, 0, 0.38);
}
[data-theme="dark"], [data-theme="dark"] [data-palette="classic"] {
  --p1: #ff6f61; --p2: #45b8c8; --win: #ffd23f;
  --accent: #ff6f61; --link: #45b8c8; --chip2: #1c3337;
}
/* Blue and orange (Okabe and Ito): apart for every common kind of colour blindness. */
[data-palette="cb"] {
  --p1: #0072b2; --p2: #e69f00; --win: #cc79a7;
  --accent: #0072b2; --on-accent: #fff; --link: #0072b2; --chip2: #dcebf6;
  --tile: #23262d; --piece-edge: transparent; --stripe: rgba(0, 0, 0, 0.38);
}
[data-theme="dark"][data-palette="cb"], [data-theme="dark"] [data-palette="cb"] {
  --p1: #56b4e9; --p2: #e69f00; --win: #e58fc0;
  --accent: #56b4e9; --on-accent: #0b1a26; --link: #7cc6ef; --chip2: #17303f;
}
/* Black and white, like Go stones: no colour at all, outlined so both show. */
[data-palette="mono"] {
  --p1: #1f2328; --p2: #ffffff; --win: #e0a800;
  --accent: #1f2328; --on-accent: #fff; --link: #1f2328; --chip2: #e7e5df;
  --tile: #8b9099; --piece-edge: #1f2328; --stripe: rgba(0, 0, 0, 0.45);
}
[data-theme="dark"][data-palette="mono"], [data-theme="dark"] [data-palette="mono"] {
  --p1: #0b0c0e; --p2: #f4f4f4; --win: #ffd23f;
  --accent: #f4f4f4; --on-accent: #15171c; --link: #f4f4f4; --chip2: #2b2f38;
  --tile: #6b717c; --piece-edge: #aab0b8;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  accent-color: var(--accent);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; }

header.site {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top, 0px));
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
header.site .brand { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: 0.02em; text-decoration: none; }
header.site .who { margin-left: auto; color: var(--muted); }

button, .button {
  font: inherit;
  display: inline-block;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  line-height: 1.4;
}
button:hover, .button:hover { border-color: var(--muted); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); padding: 10px 20px; font-weight: 600; }

.page { max-width: 44rem; margin: 0 auto; padding: 24px 16px 48px; }
.page h1 { font-size: 32px; margin: 8px 0; }
.page h2 { font-size: 20px; margin: 28px 0 10px; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }

/* A player's colour in text. With marks on, the second player's is striped like their pieces. */
.dot {
  display: inline-block; width: 0.8em; height: 0.8em; margin-right: 0.4em; border-radius: 50%; vertical-align: -0.05em;
  box-shadow: inset 0 0 0 1.5px var(--piece-edge);
}
.dot.seat1 { background-color: var(--p1); }
.dot.seat2 { background-color: var(--p2); }
[data-marks] .dot.seat2, .dot.seat2.marked {
  background-image: repeating-linear-gradient(135deg, var(--stripe) 0 1.5px, transparent 1.5px 4px);
}

/* Shared bits */
.badge {
  display: inline-block; min-width: 1.5em; margin-left: 6px; padding: 0 6px; border-radius: 999px;
  background: var(--accent); color: var(--on-accent); font-size: 12px; font-weight: 700; line-height: 1.5em; text-align: center; vertical-align: 1px;
}
.bot {
  display: inline-block; margin-left: 6px; padding: 0 4px; border: 1px solid var(--muted); border-radius: 4px;
  color: var(--muted); font-size: 10px; font-weight: 700; line-height: 1.4; vertical-align: 2px;
}
.pill { flex: 0 0 auto; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill.you { background: var(--accent); color: var(--on-accent); }
.pill.wait { background: var(--chip2); color: var(--link); }
.pill.done { color: var(--muted); font-weight: 400; padding-right: 0; }
button.wide { display: block; width: 100%; padding: 14px 20px; font-size: 16px; margin-top: 16px; }

/* Lobby */
/* The new-game sheet */
.new-game fieldset { border: 0; margin: 0 0 18px; padding: 0; min-width: 0; }
.new-game legend { padding: 0; margin-bottom: 8px; font-weight: 600; }
.new-game .summary { margin: 8px 0 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(6rem, 1fr)); gap: 8px; }
/* Game cards hold a name and a few words, so they need more room than the others: two across on a phone. */
.cards.games-pick { grid-template-columns: repeat(auto-fill, minmax(9.25rem, 1fr)); }
.cards.two { grid-template-columns: 1fr 1fr; margin-bottom: 10px; }
.cards.three { grid-template-columns: repeat(3, 1fr); }
.card {
  position: relative; display: flex; flex-direction: column; justify-content: center; gap: 2px; min-height: 52px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); cursor: pointer;
}
.card input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.card .t { font-weight: 600; }
.card .s { color: var(--muted); font-size: 13px; line-height: 1.3; }
.card:has(input:checked) { border-color: var(--link); box-shadow: 0 0 0 1px var(--link); background: var(--panel); }
.card:has(input:focus-visible) { outline: 2px solid var(--link); outline-offset: 2px; }
.new-game details { margin: 0 0 4px; }
.new-game summary { cursor: pointer; padding: 6px 0; font-weight: 600; }
.new-game details[open] summary { margin-bottom: 8px; }
.new-game details[open] .muted { display: none; }
.new-game button.wide { margin-top: 8px; }
@media (max-width: 420px) {
  .cards.three { grid-template-columns: 1fr; }
  .cards.three .card { flex-direction: row; justify-content: space-between; align-items: center; }
}
.option-select { display: flex; align-items: center; gap: 8px; margin: 6px 0 14px; }
.option-select select {
  font: inherit; font-size: 16px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel); color: var(--text);
}
.choices { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 14px; }
.choices label {
  display: flex; align-items: center; gap: 6px; min-height: 44px;
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; background: var(--bg);
}
.choices label:has(input:checked) { border-color: var(--link); box-shadow: 0 0 0 1px var(--link); }
.panel h2 { margin-top: 0; }
.panel > p:first-child { margin-top: 0; }
.panel > p:last-child { margin-bottom: 0; }
.panel.hot { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.games { list-style: none; margin: 0; padding: 0; }
.games li { border-top: 1px solid var(--border); }
.games li:first-child { border-top: 0; }
.games li.empty { padding: 10px 4px; }
.games a { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 4px; text-decoration: none; border-radius: 8px; }
.games a:hover { background: var(--bg); }
.games .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.games .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.games .s { color: var(--muted); font-size: 13px; }
#show-all { margin-top: 8px; }
.tables .row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 4px; }
.tables .row button, .tables .row .button { flex: 0 0 auto; }
.tables .t { white-space: normal; }

.lobby-grid { max-width: 64rem; }
@media (min-width: 760px) {
  .lobby-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 0 24px; align-items: start; }
  .lobby-grid > [data-pane="play"] { grid-row: span 3; }
  .lobby-grid > .pane > :first-child:not([hidden]) { margin-top: 28px; }
  .lobby-grid > .pane > .panel:first-child { margin-top: 28px; }
  .tabbar { display: none !important; }
  .phone-only, #active li.yours, #active-block.only-yours { display: none; }
  #active li.yours + li:not(.yours) { border-top: 0; }
}

/* The look picker in Me */
.look .pair { display: inline-flex; margin-right: 2px; }
.look .pair .dot { margin-right: -0.15em; width: 1em; height: 1em; }
.look .pair .dot.seat2 { margin-right: 0.45em; }
.look label.check { display: flex; align-items: center; gap: 10px; min-height: 44px; margin-top: 4px; cursor: pointer; }
.look label.check input { width: 20px; height: 20px; }
.look .muted.small { margin: 0 0 10px; }
.panel.look > :last-child { margin-bottom: 0; }

/* Phone: one section at a time, chosen from the bottom tab bar. */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex;
  background: var(--panel); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar a {
  flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 56px; color: var(--muted); font-size: 12px; text-decoration: none;
}
.tabbar a[aria-current] { color: var(--link); font-weight: 700; }
.tabbar .ico { font-size: 18px; line-height: 1.2; }
.tabbar .badge { position: absolute; top: 4px; left: 52%; margin: 0; }
@media (max-width: 759px) {
  body.lobby .page { padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
  body.lobby header .who { display: none; }
  .wide-only { display: none; }
  body[data-tab="play"] .pane:not([data-pane="play"]),
  body[data-tab="games"] .pane:not([data-pane="games"]),
  body[data-tab="chat"] .pane:not([data-pane="chat"]),
  body[data-tab="me"] .pane:not([data-pane="me"]) { display: none; }
  /* The Chat tab is all chat: the list fills the screen above the box and the tab bar. */
  body[data-tab="chat"] .lobby-chat .chat-scroll { min-height: 10rem; height: calc(100dvh - 290px - env(safe-area-inset-bottom, 0px)); }
  .pane > :first-child:not([hidden]), .pane > [hidden]:first-child + * { margin-top: 0; }
  .pane > div:first-child > h2:first-child { margin-top: 0; }
  .pane > .panel.hot:first-child + button.wide { margin-top: 16px; }
}

/* Lobby chat */
.pane h2 .policy { float: right; margin-top: 6px; font-weight: 400; color: var(--link); text-decoration: none; }
.lobby-chat { padding: 0; overflow: hidden; }
.lobby-chat .chat-scroll { height: 18rem; overflow-y: auto; padding: 10px 14px; }
.lobby-chat .chat-foot { padding: 8px 12px 10px; }
.chat .msg.system a { font-weight: 600; color: var(--link); }

/* Room */
body.room { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
body.room #status { flex: 1; min-width: 12em; }
body.room .clock {
  font-variant-numeric: tabular-nums; white-space: nowrap; padding: 2px 10px; border-radius: 999px;
  border: 1px solid var(--border); font-weight: 600;
}
body.room .clock.theirs { color: var(--muted); font-weight: 400; }
body.room .clock.warn { color: var(--danger); border-color: var(--danger); }
body.room .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
body.room main {
  position: relative; flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto;
}
body.room .stage { position: relative; min-height: 0; grid-row: 2; }

/* Seats: a strip above the board on a phone, the top of the rail on a wide screen */
body.room .seats {
  grid-row: 1; display: flex; gap: 6px; padding: 6px 8px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.seat { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 5px 10px; border-radius: 10px; border: 1px solid transparent; }
.seat.turn { border-color: var(--link); background: var(--bg); }
.seat.open .seat-name { color: var(--muted); }
.seat-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat-line { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.seat-line strong { color: var(--text); font-weight: 600; }
.you {
  display: inline-block; margin-left: 6px; padding: 0 5px; border-radius: 4px; background: var(--chip2); color: var(--link);
  font-size: 10px; font-weight: 700; line-height: 1.5; vertical-align: 2px;
}

/* The rail. On a phone it is a drawer: the peek line sits under the board, and
   opening it covers the lower part of the board, never all of it. */
body.room { --peek-height: 52px; }
body.room .rail {
  grid-row: 3; display: flex; flex-direction: column; min-height: 0; z-index: 3;
  background: var(--panel); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom, 0px);
}
.rail .peek {
  box-sizing: border-box; min-height: var(--peek-height);
  display: flex; flex-direction: column; align-items: stretch; gap: 4px; width: 100%; padding: 6px 16px 10px;
  border: 0; border-radius: 0; background: none; text-align: left; font-size: 14px; color: var(--text); cursor: pointer;
}
.rail .peek #peek-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail .grip { align-self: center; width: 36px; height: 4px; border-radius: 2px; background: var(--border); }
.rail .rail-tabs, .rail .rail-body { display: none; }
body.room .rail.open {
  /* An absolutely placed grid item measures against its grid area, so it spans them all. */
  position: absolute; grid-row: 1 / -1; left: 0; right: 0; bottom: 0; height: 36%;
  border-radius: 14px 14px 0 0; box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
}
.rail.open .rail-tabs { display: flex; }
/* The board keeps its size while the drawer is open, so nothing jumps under it. */
body.room main:has(.rail.open) { grid-template-rows: auto minmax(0, 1fr) var(--peek-height); }
.rail.open .rail-body { display: block; }
.rail-tabs { gap: 4px; padding: 0 12px; border-bottom: 1px solid var(--border); }
.rail-tabs button {
  flex: 1; border: 0; border-radius: 0; background: none; padding: 10px 6px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.rail-tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--link); }
.rail-body { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 16px 16px; }
.rail-body h3 { font-size: 16px; margin: 6px 0 8px; }
.rail-body p { margin: 8px 0; }
.moves { list-style: none; margin: 0; padding: 0; font-variant-numeric: tabular-nums; }
.moves li { display: flex; align-items: baseline; gap: 4px; padding: 3px 0; border-top: 1px solid var(--border); font-size: 14px; }
.moves li:first-child { border-top: 0; }
.moves .n { min-width: 2.5em; color: var(--muted); }
.moves .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.moves .mv { font-weight: 600; }

/* Chat, in the rail's Chat tab. The box to type in stays under the messages. */
.chat { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.chat .msg { position: relative; display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 6px; font-size: 14px; line-height: 1.4; padding-right: 28px; }
.chat .msg .who { font-weight: 600; }
.chat .msg.mine .who { color: var(--link); }
.chat .msg.robot .text { font-style: italic; }
.chat .msg .text { overflow-wrap: anywhere; white-space: pre-wrap; }
.chat .msg time { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chat .msg.system { justify-content: center; padding: 0; font-size: 12px; color: var(--muted); }
.chat .msg .more {
  position: absolute; right: 0; top: -2px; border: 0; background: none; padding: 0 6px; min-height: 0;
  color: var(--muted); font-size: 16px; line-height: 1.4; opacity: 0.6;
}
.chat .msg:hover .more, .chat .msg .more:focus-visible { opacity: 1; }
.rail .chat-foot { display: none; }
.rail.open .chat-foot:not([hidden]) { display: block; }
.chat-foot { border-top: 1px solid var(--border); padding: 8px 12px 10px; }
.chat-foot .phrases { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.chat-foot .phrases button { flex: none; padding: 4px 10px; min-height: 30px; border-radius: 999px; font-size: 13px; }
.chat-foot .compose { display: flex; gap: 6px; }
.chat-foot .compose input {
  flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 16px; /* 16px stops phones zooming in */
}
.chat-foot .flag { padding: 0 10px; color: var(--muted); }
.chat-foot .chat-gate { margin: 0; font-size: 14px; color: var(--muted); }
.chat-foot .chat-error { margin: 6px 0 0; font-size: 13px; }
button.link { border: 0; background: none; padding: 0; min-height: 0; color: var(--link); font: inherit; font-weight: 600; cursor: pointer; }
.rail-tabs .badge { margin-left: 4px; font-size: 11px; }
dialog.chat-sheet .choices { display: flex; flex-direction: column; gap: 8px; }
dialog.chat-sheet .choices button { min-height: 48px; text-align: left; padding: 0 14px; font-weight: 600; }
dialog.chat-sheet .choices button.danger { color: var(--danger); }
dialog.chat-sheet .quoted { margin: 0 0 12px; padding: 8px 12px; border-left: 3px solid var(--border); color: var(--muted); overflow-wrap: anywhere; }
dialog.chat-sheet .hint { margin: 12px 0 0; }

@media (min-width: 900px) {
  body.room main, body.room main:has(.rail.open) { grid-template-columns: minmax(0, 1fr) 20rem; grid-template-rows: auto auto minmax(0, 1fr); }
  body.room .stage { grid-column: 1; grid-row: 1 / -1; }
  body.room .seats {
    grid-column: 2; grid-row: 1; flex-direction: column; gap: 4px; padding: 10px;
    border-bottom: 1px solid var(--border); border-left: 1px solid var(--border);
  }
  body.room .rail, body.room .rail.open {
    grid-column: 2; grid-row: 3; position: static; height: auto; border-top: 0; border-left: 1px solid var(--border);
    border-radius: 0; box-shadow: none;
  }
  .rail .peek { display: none; }
  .rail .rail-tabs { display: flex; }
  .rail .rail-body { display: block; }
  .rail .chat-foot:not([hidden]) { display: block; }
}
body.room canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
body.room canvas.dragging { cursor: grabbing; }
body.room .message {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; text-align: center;
}

/* Trax: the tray of tiles that fit the chosen square */
body.room .trax-tray {
  position: absolute; left: 50%; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 2;
  width: min(30rem, calc(100% - 24px)); padding: 10px 12px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--border); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
}
body.room .trax-tray[hidden] { display: none; }
.trax-info { font-size: 14px; color: var(--muted); margin: 0 2px 8px; min-height: 19px; }
.trax-info .good { color: var(--link); font-weight: 650; }
.trax-info .bad { color: var(--danger); font-weight: 650; }
.trax-row { display: flex; align-items: center; gap: 8px; }
.trax-opts { display: flex; gap: 8px; flex: 1; min-width: 0; overflow-x: auto; }
.trax-opt { flex: none; width: 58px; height: 58px; padding: 3px; border-radius: 10px; border: 3px solid transparent; background: none; }
.trax-opt.on { border-color: var(--win); }
body.room .trax-opt canvas { width: 100%; height: 100%; border-radius: 4px; cursor: pointer; }
.trax-cancel { flex: none; width: 44px; height: 48px; font-size: 24px; line-height: 1; padding: 0; }
.trax-place { flex: none; height: 48px; padding: 0 20px; }

/* Friend games: the invite card floats over the board until someone joins */
body.room .invite {
  /* Over the board on a phone: an absolutely placed grid item sits in its own grid area. */
  grid-row: 2; z-index: 2;
  position: absolute; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  width: min(26rem, calc(100% - 24px)); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
}
.invite-head { display: flex; align-items: center; justify-content: space-between; }
.invite-head h2 { margin: 0; font-size: 18px; }
.invite .close { border: 0; background: none; font-size: 26px; line-height: 1; padding: 4px 8px; color: var(--muted); }
.invite p { margin: 8px 0; }
.invite .seat-wait { margin-top: 10px; padding-top: 2px; border-top: 1px solid var(--border); }
.invite .seat-wait p:first-child { font-variant-numeric: tabular-nums; margin-bottom: 4px; }
.invite .small-buttons { margin-top: 4px; }
.invite .small-buttons button { padding: 4px 10px; font-size: 14px; }
/* On a wide screen the card sits to the side, leaving the middle of the board free. */
@media (min-width: 900px) {
  /* In the rail on a wide screen, between the seats and the moves. */
  body.room .invite {
    grid-column: 2; grid-row: 2; position: static; transform: none; width: auto; z-index: auto;
    border: 0; border-left: 1px solid var(--border); border-bottom: 1px solid var(--border); border-radius: 0; box-shadow: none;
  }
}
.copyrow { display: flex; gap: 8px; margin: 8px 0; }
.copyrow input {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg); color: var(--text);
}
.small { font-size: 13px; }
body.room .tab-guest {
  position: absolute; left: 12px; top: 12px; padding: 4px 10px; border-radius: 999px; font-size: 13px;
  background: var(--chip2); color: var(--link);
}

/* Join page */
.join .panel { max-width: 30rem; }
.join h1 { font-size: 26px; line-height: 1.25; margin: 0 0 8px; }
.join .buttons { margin-top: 16px; }

/* Buttons in a row, links that look like links, a quiet destructive action */
.buttons { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
button.link { border: 0; background: none; padding: 0 0 0 8px; color: var(--link); font-weight: 600; }
button.danger { border-color: transparent; background: none; color: var(--danger); padding-left: 0; }
.panel.nudge { margin-top: 16px; border-color: var(--link); }
.panel + .panel { margin-top: 12px; }

/* Sign-in sheet: a bottom sheet on phones, a centred dialog on wider screens */
dialog.sheet {
  width: min(26rem, 100vw); max-width: 100vw; max-height: 92dvh; overflow-y: auto;
  margin: auto auto 0; padding: 8px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  border: 0; border-radius: 16px 16px 0 0; background: var(--panel); color: var(--text);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25);
}
dialog.sheet::backdrop { background: rgba(20, 22, 26, 0.45); }
@media (min-width: 560px) {
  dialog.sheet { margin: auto; border-radius: 16px; padding-bottom: 20px; }
  dialog.sheet .grab { display: none; }
}
dialog.sheet .grab { width: 36px; height: 4px; border-radius: 4px; background: var(--border); margin: 0 auto 8px; }
dialog.sheet .sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
dialog.sheet h2 { margin: 4px 0; font-size: 20px; }
dialog.sheet .close { border: 0; background: none; font-size: 26px; line-height: 1; padding: 4px 8px; color: var(--muted); }
dialog.sheet form { display: flex; flex-direction: column; gap: 12px; }
dialog.sheet label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 14px; }
dialog.sheet label.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 400; min-height: 44px; }
dialog.sheet label.check input { width: 22px; height: 22px; }
dialog.sheet input:not([type=checkbox]) {
  font: inherit; font-size: 16px; /* 16px stops iPhone zooming in */
  padding: 10px 12px; min-height: 46px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text);
}
dialog.sheet input:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }
dialog.sheet .hint { font-weight: 400; font-size: 13px; color: var(--muted); }
dialog.sheet .hint.error { color: var(--danger); }
dialog.sheet .error { margin: 0; }
dialog.sheet button.wide { margin-top: 4px; }
dialog.sheet .social { display: block; width: 100%; min-height: 48px; margin-bottom: 8px; font-weight: 600; background: var(--panel); }
dialog.sheet .or { display: flex; align-items: center; gap: 10px; margin: 8px 0 12px; color: var(--muted); font-size: 13px; }
dialog.sheet .or::before, dialog.sheet .or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
dialog.sheet .links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin: 14px 0 0; font-size: 14px; }
dialog.sheet .links a { color: var(--link); font-weight: 600; text-decoration: none; padding: 6px 0; }

/* Home page */
.home .hero { padding: 16px 0 8px; }
.home .hero h1 { font-size: clamp(28px, 6vw, 40px); line-height: 1.15; margin: 0 0 12px; letter-spacing: -0.01em; }
.home .lead { font-size: 18px; margin: 0 0 20px; }
.home .hero .buttons button { padding: 12px 22px; font-size: 16px; }
.features { list-style: none; padding: 0; margin: 32px 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); }
.features li { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border-left: 3px solid var(--accent); background: var(--panel); border-radius: 0 10px 10px 0; }
.features li:nth-child(2) { border-left-color: var(--link); }
.features li:nth-child(3) { border-left-color: var(--muted); }
.features span { color: var(--muted); font-size: 15px; }
.catalog { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
.game-card h3 { margin: 0 0 6px; font-size: 20px; }
.game-card p { margin: 0 0 8px; }
.game-card details summary { cursor: pointer; color: var(--link); font-weight: 600; padding: 6px 0; }
.game-card details p:last-child { margin-bottom: 0; }

/* Chat policy and review pages */
.prose ul { padding-left: 1.2em; }
.prose li { margin: 6px 0; }
body.admin .filters { display: flex; gap: 6px; margin: 12px 0; }
body.admin .filters button[aria-selected="true"], body.admin .filters button[aria-checked="true"] { border-color: var(--link); color: var(--link); }
body.admin .lobby-switch { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 12px; }
body.admin .lobby-switch .filters { margin: 0; }
.reports { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.report { padding: 12px 16px; }
.report.open { border-left: 4px solid var(--accent); }
.report-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.report blockquote { margin: 8px 0; padding: 8px 12px; background: var(--bg); border-radius: 8px; overflow-wrap: anywhere; white-space: pre-wrap; }
.report .reasons { display: flex; flex-wrap: wrap; gap: 6px; }
.report .buttons { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0 0; }
.report .buttons button { padding: 4px 10px; font-size: 14px; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--chip2, var(--bg)); font-size: 12px; font-weight: 600; }
.chip.warn { background: var(--danger); color: #fff; }

/* "Your move" toasts: top centre, clear of the phone tab bar and the room drawer */
.toasts {
  position: fixed; z-index: 50; left: 50%; transform: translateX(-50%); top: calc(10px + env(safe-area-inset-top, 0px));
  display: flex; flex-direction: column; gap: 8px; width: min(28rem, calc(100vw - 24px)); pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 10px 8px 10px 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  animation: toast-in 0.2s ease-out;
}
.toast > span { flex: 1; min-width: 0; font-size: 14px; }
.toast .button { flex: none; padding: 6px 14px; }
.toast .close { flex: none; border: 0; background: none; min-height: 0; padding: 4px 8px; font-size: 22px; line-height: 1; color: var(--muted); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }
.push-offer button { flex: none; padding: 6px 12px; }

/* The review page: the board, and beside it (below it on a phone) the graph, the move and the move list. */
body.review { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
body.review #status { flex: 1; min-width: 12em; font-weight: 600; }
body.review .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
body.review main { flex: 1; min-height: 0; display: grid; grid-template-rows: minmax(0, 45fr) minmax(0, 55fr); }
body.review .stage { position: relative; min-height: 0; }
body.review canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
body.review .message { padding: 24px 16px; }
/* The players, graph, step buttons and the move's details stay put; the rest scrolls under them. */
body.review .side { min-height: 0; display: flex; flex-direction: column; background: var(--panel); border-top: 1px solid var(--border); }
body.review .side-top { padding: 10px 16px 0; }
body.review .side-scroll { position: relative; flex: 1; min-height: 0; overflow-y: auto; padding: 0 16px calc(16px + env(safe-area-inset-bottom, 0px)); }
body.review .side-top > *, body.review .side-scroll > * { margin: 0 0 10px; }
@media (min-width: 900px) {
  body.review main { grid-template-columns: minmax(0, 1fr) 22rem; grid-template-rows: minmax(0, 1fr); }
  body.review .side { border-top: 0; border-left: 1px solid var(--border); }
}
.review .players { font-weight: 600; }
.review .working progress { width: 100%; }
.review .graph { display: block; width: 100%; height: 64px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.review .graph .half { fill: var(--p1); opacity: 0.06; }
.review .graph .mid { stroke: var(--grid); stroke-dasharray: 3 3; }
.review .graph .line { fill: none; stroke: var(--text); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.review .graph .now { stroke: var(--muted); vector-effect: non-scaling-stroke; }
.review .graph .mark { stroke: var(--panel); stroke-width: 1; vector-effect: non-scaling-stroke; }
.review .nav { display: flex; align-items: center; gap: 6px; }
.review .nav .where { flex: 1; text-align: center; font-variant-numeric: tabular-nums; }
.review .detail p { margin: 0 0 6px; }
.review .play-here label { display: block; margin-bottom: 6px; color: var(--muted); }
.review .play-here select { font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.review .moves li { cursor: pointer; }
.review .moves li.current { background: var(--bg); font-weight: 600; }
.tag { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; color: #fff; background: var(--muted); }
.tag.winning, .graph .mark.winning { background: #2e8540; fill: #2e8540; }
.tag.losing, .graph .mark.losing { background: var(--danger); fill: var(--danger); }
.tag.missed-win, .graph .mark.missed-win { background: #b26b00; fill: #b26b00; }
.tag.blunder, .graph .mark.blunder { background: #c2410c; fill: #c2410c; }
.tag.mistake, .graph .mark.mistake { background: #8a6d00; fill: #8a6d00; }
