/* Look and layout modelled on lichess.org's dark theme. */
:root {
  --bg: #161512;
  --panel: #262421;
  --panel-hi: #302e2c;
  --line: #3d3b39;
  --text: #bababa;
  --strong: #e6e6e6;
  --dim: #8a8784;
  --brand: #d64f00;
  --link: #3692e7;
  --green: #629924;
  --bad: #cc3333;
  --sq-light: #f0d9b5;
  --sq-dark: #b58863;
  --red: #d8392b;
  --blue: #2f73d9;
  --bg-top: #2e2a24;
  --button-top: #3c3934;
  --button-bottom: #33312e;
  --card-sq: #3a3835;
  --cell: min(112px, (100vh - 96px) / 5, (100vw - 640px) / 5);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #edebe9;
  --bg-top: #ffffff;
  --panel: #ffffff;
  --panel-hi: #f3f1ef;
  --line: #d9d6d2;
  --text: #4d4d4d;
  --strong: #1f1f1f;
  --dim: #7b7875;
  --button-top: #f7f6f5;
  --button-bottom: #eceae8;
  --card-sq: #dddad6;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg) linear-gradient(to bottom, var(--bg-top), var(--bg) 116px) no-repeat;
  color: var(--text);
  font: 14px/1.45 "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--link); text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
h2, h3 { margin: 0; font-weight: 400; color: var(--strong); }

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

#top {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 16px;
  /* The same width on every page, so the bar never shifts between them. */
  max-width: 1400px;
  margin: 0 auto;
}
.brand { font-size: 26px; font-weight: 300; color: var(--text); letter-spacing: 0.01em; }
.brand:hover { color: var(--brand); }
#top nav { display: flex; gap: 20px; }
#top nav a { color: var(--text); text-transform: uppercase; font-size: 13px; letter-spacing: 0.04em; }
#top nav a:hover { color: var(--strong); }
#top nav a.donate { color: var(--brand); }
#top nav a.donate:hover { filter: brightness(1.25); }

/* ---------- shared bits ---------- */

.box {
  background: var(--panel);
  border-radius: 3px;
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 1px 5px rgba(0, 0, 0, 0.12);
}

.button {
  background: var(--link);
  color: #fff;
  border: 0;
  border-radius: 3px;
  padding: 8px 14px;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.button:hover { filter: brightness(1.12); }
.button.flat { background: none; color: var(--text); }
.button.flat:hover { background: var(--panel-hi); color: var(--strong); filter: none; }
.button.flat.armed { background: var(--bad); color: #fff; }
.button.good { background: var(--green); }
.button.bad { background: var(--bad); }
.button:disabled { opacity: 0.4; cursor: default; pointer-events: none; }
a.button { display: inline-block; }

.error { color: #e0655c; min-height: 1.4em; margin: 6px 0; }

/* ---------- lobby ---------- */
/* Three columns like the lichess home page: tournaments, pairing and buttons on
   top; a live game, the rules and the leaderboard below. */

#lobby {
  max-width: 1400px;
  margin: 16px auto 40px;
  padding: 0 16px;
  display: grid;
  grid-template-columns: minmax(230px, 1fr) minmax(0, 2fr) minmax(230px, 1fr);
  grid-template-areas: "side app table" "tv feed leaders" ". footer .";
  gap: 16px;
  align-items: start;
}
#lobby-side { grid-area: side; margin-top: 30px; }
#lobby-app { grid-area: app; min-width: 0; }
#lobby-table { grid-area: table; align-self: stretch; display: flex; flex-direction: column; }
#lobby-tv { grid-area: tv; }
#lobby-feed { grid-area: feed; align-self: stretch; }
#leaderboard { grid-area: leaders; }
#lobby-footer { grid-area: footer; }

.about-side { margin: 14px 4px 0; color: var(--dim); font-size: 13px; }

/* Tabs above the pairing tiles */
.tabs { display: flex; height: 30px; margin-bottom: 8px; }
.tabs button {
  flex: 1;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 0 8px 4px;
  color: var(--text);
}
.tabs button:hover { color: var(--strong); border-bottom-color: var(--line); }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

/* Quick pairing tiles */
#pools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.pool {
  position: relative;
  background: color-mix(in srgb, var(--panel-hi) 82%, transparent);
  border: 0;
  border-radius: 3px;
  aspect-ratio: 17 / 10;
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text);
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 1px 5px rgba(0, 0, 0, 0.12);
  transition: background 0.15s, color 0.15s;
}
.pool .tc { font-size: clamp(22px, 3vw, 38px); font-weight: 300; letter-spacing: 0.06em; line-height: 1.25; }
.pool .perf, .pool.custom { font-size: clamp(15px, 1.9vw, 24px); font-weight: 300; }
.pool:hover { background: color-mix(in srgb, var(--brand) 30%, var(--panel-hi)); color: #fff; }
.pool.seeking { background: var(--brand); color: #fff; }
.pool.seeking .perf { visibility: hidden; }
.pool.seeking::after {
  content: "Waiting… click to cancel";
  position: absolute;
  bottom: 14%;
  left: 0;
  right: 0;
  font-size: 12.5px;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.45; } }

/* The live list lies over the quick pairing grid and scrolls inside it, so both tabs are the same size. */
#lobby-panels { position: relative; }
#pools.behind { visibility: hidden; }
#live { position: absolute; inset: 0; background: var(--panel); border-radius: 3px; overflow: auto; }
#live thead th { position: sticky; top: 0; }
#live table { width: 100%; border-collapse: collapse; }
#live th {
  text-align: left;
  font-weight: 400;
  color: var(--dim);
  padding: 6px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-hi);
}
#live td { padding: 9px 16px; border-bottom: 1px solid var(--line); }
#live tbody tr { cursor: pointer; }
#live tbody tr:hover { background: color-mix(in srgb, var(--brand) 22%, var(--panel)); color: #fff; }
#live td.code { font-weight: 600; color: var(--strong); }
#live td.watch { text-align: right; }
#live td.watch a { text-transform: uppercase; font-size: 12px; font-weight: 600; }
#live-empty { padding: 28px 16px; margin: 0; color: var(--dim); text-align: center; }
.turn-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.turn-dot.red { background: var(--red); }
.turn-dot.blue { background: var(--blue); }

/* Start buttons and the counters under them */
#lobby-start { display: flex; flex-direction: column; gap: 10px; margin: auto 0; padding-top: 30px; }
.big-button {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 14px 18px;
  background: linear-gradient(to bottom, var(--button-top), var(--button-bottom));
  color: var(--strong);
  border: 0;
  border-radius: 3px;
  font-size: 16px;
  font-weight: 600;
  text-align: left;
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 1px 5px rgba(0, 0, 0, 0.12);
}
.big-button svg { width: 30px; height: 30px; flex: none; fill: currentColor; opacity: 0.55; }
.big-button:hover { background: var(--brand); color: #fff; }
.big-button:hover svg { opacity: 1; }
#lobby-error:empty { display: none; }
#lobby-counters { display: flex; flex-direction: column; padding-top: 12px; }
#lobby-counters strong { color: var(--strong); }

/* A live game on a small board */
.mini-game { display: flex; flex-direction: column; color: var(--text); }
.mini-player { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 3px 2px; min-height: 27px; }
.mini-player .who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-player .name { color: var(--strong); }
.mini-player .rating { color: var(--dim); font-size: 12px; margin-left: 6px; }
.mini-clock { font-variant-numeric: tabular-nums; }
.mini-clock.running { color: var(--brand); }
.mini-board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  aspect-ratio: 1;
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 1px 5px rgba(0, 0, 0, 0.12);
}
/* Without this a square holding a piece grows taller than an empty one. */
.mini-board .cell { min-width: 0; min-height: 0; overflow: hidden; }
.mini-board .cell::before { border-width: 2px; }
:root[data-pieces="tiles"] .mini-board .piece.far { transform: rotate(180deg); }

.howto { padding: 16px 20px; }
.howto h2 { font-size: 18px; color: var(--brand); }
.howto ul { padding-left: 18px; margin: 10px 0 0; }
.howto li { margin: 8px 0; }
.howto strong { color: var(--strong); }

#leaderboard { display: flex; flex-direction: column; }
#leaderboard .caption { text-align: right; padding: 3px 2px; min-height: 27px; }
#leaders { margin: 0; padding: 8px 16px 8px 38px; }
#leaders li { padding: 4px 0; }
#leaders li a { color: var(--strong); }
#leaders li a:hover { color: var(--brand); }
#leaders li span { float: right; color: var(--dim); }

#lobby-footer { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; padding: 8px 0; font-size: 12.5px; font-weight: 600; }
#lobby-footer a, #version { color: var(--dim); }
#version { font-weight: 400; }
#lobby-footer a:hover { color: var(--strong); }

/* Open tournaments */
.tours-head { display: flex; justify-content: space-between; padding: 8px 12px; background: var(--panel-hi); color: var(--strong); font-weight: 600; }
.tours-head a { color: var(--dim); font-weight: 400; }
.tours-head a:hover { color: var(--link); }
#lobby-tours { overflow: hidden; }
#lobby-tours table { width: 100%; border-collapse: collapse; }
/* Each tournament takes two lines in the narrow column: name and players, then when it starts or ends. */
#lobby-tours tbody { display: block; }
#lobby-tours tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px 10px; padding: 8px 12px; border-top: 1px solid var(--line); cursor: pointer; }
#lobby-tours tr:hover { background: var(--panel-hi); }
#lobby-tours td { padding: 0; white-space: nowrap; }
#lobby-tours td.name { overflow: hidden; text-overflow: ellipsis; }
#lobby-tours td.players { color: var(--dim); font-size: 12.5px; }
#lobby-tours td.progress { grid-column: 1 / -1; }
#lobby-tours .bar { position: relative; display: block; background: var(--bg); border-radius: 9px; overflow: hidden; font-size: 12.5px; }
#lobby-tours .bar i { position: absolute; inset: 0 auto 0 0; background: color-mix(in srgb, var(--link) 45%, transparent); }
#lobby-tours .bar span { position: relative; display: block; padding: 0 10px; }
#lobby-tours-empty { margin: 0; padding: 12px; color: var(--dim); }

/* ---------- game layout ---------- */

#game {
  margin: 8px auto 24px;
  padding: 0 16px;
  display: grid;
  justify-content: center;
  grid-template-columns: 240px calc(var(--cell) * 5) var(--moves-width, 320px);
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  grid-template-areas:
    "side board opp-hand"
    "side board opp-bar"
    "side board moves"
    "side board my-bar"
    "side board my-hand";
  column-gap: 16px;
}
#side { grid-area: side; display: flex; flex-direction: column; gap: 16px; }
#board { grid-area: board; }
#opp-hand { grid-area: opp-hand; margin-bottom: 8px; }
#opp-label { grid-area: opp-bar; border-radius: 3px 3px 0 0; }
#moves-box { grid-area: moves; }
#my-label { grid-area: my-bar; border-radius: 0 0 3px 3px; }
#my-hand { grid-area: my-hand; margin-top: 8px; }

/* ---------- side column ---------- */

#info { padding: 14px 16px; }
.info-title { color: var(--strong); font-size: 15px; margin-bottom: 8px; }
#info-players div { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
#info-players .me { color: var(--dim); }
.info-meta { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); color: var(--dim); display: flex; justify-content: space-between; }
#room-code { letter-spacing: 0.08em; }

#spare-box { padding: 12px 16px; display: flex; align-items: center; gap: 14px; }
#spare-box h3 { font-size: 14px; color: var(--text); }
#spare-label { margin: 4px 0 0; color: var(--dim); font-size: 12.5px; }

/* ---------- board ---------- */

#board {
  position: relative;
  display: grid;
  /* A fixed size, so the layout can never squeeze the board and clip a column. */
  width: calc(var(--cell) * 5);
  height: calc(var(--cell) * 5);
  grid-template-columns: repeat(5, var(--cell));
  grid-template-rows: repeat(5, var(--cell));
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 1px 5px rgba(0, 0, 0, 0.12);
  align-self: start;
  user-select: none;
}

.cell {
  position: relative;
  border: 0;
  padding: 0;
  border-radius: 0;
  background-color: var(--sq-light);
  display: grid;
  place-items: center;
  cursor: default;
}
.cell.dark { background-color: var(--sq-dark); }
.cell.last { background-image: linear-gradient(rgba(155, 199, 0, 0.41), rgba(155, 199, 0, 0.41)); }
.cell.selected { background-image: linear-gradient(rgba(20, 85, 30, 0.5), rgba(20, 85, 30, 0.5)); }
.cell.mine { cursor: pointer; }
.cell.target { cursor: pointer; background-image: radial-gradient(rgba(20, 85, 30, 0.5) 19%, rgba(0, 0, 0, 0) 20%); }
.cell.target.capture { background-image: radial-gradient(transparent 0%, transparent 79%, rgba(20, 85, 30, 0.3) 80%); }
.cell.target:hover { background-image: linear-gradient(rgba(20, 85, 30, 0.3), rgba(20, 85, 30, 0.3)); }

/* Temple squares carry a ring in their owner's colour. */
.cell.temple-red::before,
.cell.temple-blue::before {
  content: "";
  position: absolute;
  inset: 7%;
  border-radius: 50%;
  border: 3px solid;
  opacity: 0.55;
  pointer-events: none;
}
.cell.temple-red::before { border-color: var(--red); }
.cell.temple-blue::before { border-color: var(--blue); }

/* Drag the bottom right corner to resize the board; double-click to reset. */
#board-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 22px;
  height: 22px;
  cursor: nwse-resize;
  touch-action: none;
  opacity: 0.35;
  background: linear-gradient(135deg, transparent 50%, #1b1b1b 50%, #1b1b1b 60%, transparent 60%, transparent 72%, #1b1b1b 72%, #1b1b1b 82%, transparent 82%);
}
#board-resize:hover, #board-resize.dragging { opacity: 0.8; }

.coord { position: absolute; font-size: 11px; font-weight: 700; line-height: 1; color: var(--sq-dark); pointer-events: none; }
.cell.dark .coord { color: var(--sq-light); }
.coord.file { left: 4px; bottom: 3px; }
.coord.rank { right: 4px; top: 3px; }

.piece {
  position: relative;
  width: 68%;
  height: 68%;
  stroke: #1b1b1b;
  stroke-width: 1.6;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.4));
  pointer-events: none;
}
.piece.master { width: 84%; height: 84%; }
.piece.red { fill: var(--red); }
.piece.blue { fill: var(--blue); }

/* ---------- right column ---------- */

.hand { display: flex; gap: 8px; justify-content: space-between; }

.card {
  flex: 1;
  background: var(--panel);
  border: 0;
  border-radius: 3px;
  padding: 10px 8px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  color: var(--text);
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.14), 0 1px 5px rgba(0, 0, 0, 0.12);
}
button.card:hover { background: var(--panel-hi); }
.card.selected { background: var(--panel-hi); box-shadow: 0 0 0 2px var(--green); }
.card.dim { opacity: 0.6; }
#spare .card { box-shadow: none; padding: 0; background: none; }

.card-grid { display: grid; grid-template-columns: repeat(5, var(--card-cell, 15px)); grid-template-rows: repeat(5, var(--card-cell, 15px)); gap: 2px; }
.card-grid i { background: var(--card-sq); border-radius: 1px; }
.card-grid i.c { background: var(--strong); }
.card.red .card-grid i.m { background: var(--red); }
.card.blue .card-grid i.m { background: var(--blue); }
.card.neutral .card-grid i.m { background: var(--dim); }
.card-name { font-size: 13px; color: var(--strong); display: flex; align-items: center; gap: 6px; }
.stamp { width: 7px; height: 7px; border-radius: 50%; }
.stamp.red { background: var(--red); }
.stamp.blue { background: var(--blue); }

.player {
  background: var(--panel);
  height: 40px;
  padding: 0 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  color: var(--strong);
  overflow: hidden;
}
.player .note { color: var(--dim); font-size: 12.5px; }
.player .clock {
  margin-left: auto;
  align-self: stretch;
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: transparent;
}
.player.turn .clock { background: #384722; color: #fff; }
.player.timed .clock {
  color: var(--text);
  background: var(--panel-hi);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  min-width: 84px;
  justify-content: center;
}
.player.timed.turn .clock { background: #384722; color: #fff; }
.player.timed.turn .clock.low { background: #7a2020; }

.dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--dim); flex: none; }
.dot.on { background: var(--green); border-color: var(--green); }
.swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.swatch.red { background: var(--red); }
.swatch.blue { background: var(--blue); }

#moves-box {
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 150px;
}

#share { padding: 12px; border-bottom: 1px solid var(--line); }
#share p { margin: 0 0 8px; }
.share-row { display: flex; gap: 6px; }
.share-row input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  color: var(--strong);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 7px 8px;
  font: inherit;
}

/* The list is absolutely positioned so a long game scrolls instead of stretching the layout. */
#moves-scroll { position: relative; flex: 1; min-height: 100px; }
#moves {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: 30px 1fr 1fr;
  align-content: start;
}
#moves .n { background: var(--panel-hi); color: var(--dim); text-align: center; padding: 4px 0; border-right: 1px solid var(--line); }
#moves .mv { cursor: pointer; padding: 4px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 6px; }
#moves .mv b { font-weight: 400; color: var(--dim); font-size: 12px; margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
#moves .mv i { font-style: normal; color: var(--dim); font-size: 12px; font-variant-numeric: tabular-nums; flex: none; min-width: 26px; text-align: right; }
#moves .mv i:empty { display: none; }
#replay #move-times { flex: 0 0 44px; font-size: 15px; padding: 0; border-left: 1px solid var(--line); opacity: 0.45; }
#replay #move-times[aria-pressed="true"] { opacity: 1; color: var(--strong); }
#moves .mv:hover { background: var(--panel-hi); }
#moves .mv.current { background: #293a49; color: #fff; }

#status { padding: 8px 12px; text-align: center; color: var(--text); border-top: 1px solid var(--line); min-height: 36px; }
#status.win { color: var(--strong); font-style: italic; }
#status.warn { color: #e0655c; }
#status .result { display: block; font-style: normal; font-weight: 700; font-size: 15px; }

#controls { display: flex; justify-content: center; gap: 8px; padding: 0 8px 8px; }
#controls:not(:has(.button:not([hidden]))) { display: none; }

/* ---------- replay, offers, chat ---------- */

#replay { display: flex; border-bottom: 1px solid var(--line); }
#replay button { flex: 1; background: none; border: 0; padding: 2px 0 5px; color: var(--text); font-size: 20px; line-height: 1.2; }
#replay button:hover { background: var(--panel-hi); color: var(--strong); }
#replay button:disabled { opacity: 0.3; pointer-events: none; }

#offer {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  background: #293a49;
  color: #fff;
}
#offer-text { flex-basis: 100%; text-align: center; }

#chat { flex: 1; display: flex; flex-direction: column; min-height: 190px; }
#chat h3 { font-size: 14px; color: var(--text); padding: 10px 16px; border-bottom: 1px solid var(--line); }
#chat-scroll { position: relative; flex: 1; }
#chat-list { position: absolute; inset: 0; overflow-y: auto; margin: 0; padding: 6px 12px; list-style: none; }
#chat-list li { padding: 2px 0; overflow-wrap: anywhere; }
#chat-list li b { font-weight: 600; margin-right: 6px; }
#chat-list li b.red { color: var(--red); }
#chat-list li b.blue { color: var(--blue); }
#chat-list li.system { color: var(--dim); font-style: italic; }
#chat-input {
  width: 100%;
  background: none;
  border: 0;
  border-top: 1px solid var(--line);
  padding: 9px 12px;
  color: var(--strong);
  font: inherit;
}
#chat-input:focus { outline: none; background: var(--panel-hi); }

/* ---------- narrow screens ---------- */

@media (max-width: 980px) {
  :root { --cell: max(40px, min(96px, (100vw - 16px) / 5, (100dvh - 318px) / 5)); }
  #top { padding: 0 8px; height: 44px; gap: 14px; }
  .brand { font-size: 22px; }
  #lobby { grid-template-columns: minmax(0, 1fr); grid-template-areas: "app" "table" "side" "tv" "leaders" "feed" "footer"; }
  #lobby-side, #lobby-start { margin-top: 0; padding-top: 0; }
  #lobby-tv, #leaderboard { width: min(100%, 420px); margin: 0 auto; }
  /* A game fits one phone screen: the opponent's cards and the spare, the
     board between the two clocks, then your cards. Moves and chat are below. */
  #game {
    margin-top: 0;
    padding: 0 8px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: calc(var(--cell) * 5 + 16px);
    grid-template-rows: none;
    grid-template-areas:
      "opp-hand opp-hand spare"
      "opp-bar opp-bar opp-bar"
      "board board board"
      "my-bar my-bar my-bar"
      "my-hand my-hand my-hand"
      "moves moves moves"
      "chat chat chat"
      "info info info";
    column-gap: 6px;
    row-gap: 0;
  }
  #board-resize { display: none; }
  .hand { gap: 6px; }
  .card { padding: 6px 4px 4px; gap: 4px; }
  .card-name { font-size: 12px; }
  #opp-hand, #spare-box { --card-cell: 10px; margin: 0 0 6px; }
  #my-hand { --card-cell: 12px; margin-top: 6px; }
  .player { height: 32px; font-size: 14px; }
  .player.timed .clock { font-size: 18px; min-width: 70px; }
  #opp-label, #my-label { border-radius: 0; }
  #moves-box { margin-top: 8px; border-radius: 3px; border: 0; }
  #moves-scroll { min-height: 120px; }
  #chat { min-height: 240px; }
  #pools { gap: 6px; }
  .pool .tc { font-size: 24px; }
  .pool .perf, .pool.custom { font-size: 15px; }
  .pool.seeking::after { content: "Waiting… tap to cancel"; }
  /* Let the side column's boxes take their own places in the single column. */
  #side { display: contents; }
  /* The spare sits beside the opponent's cards, outlined to set it apart. */
  #spare-box { grid-area: spare; padding: 0; gap: 0; justify-content: center; background: none; box-shadow: none; outline: 1px dashed var(--line); outline-offset: -1px; }
  #spare-box > div:last-child { display: none; }
  #spare .card { padding: 6px 4px 4px; }
  #spare .card-name::after { content: "· spare"; color: var(--dim); }
  #chat { grid-area: chat; margin-top: 8px; }
  #info { grid-area: info; margin-top: 8px; }
}

/* A phone on its side: the board on the left, cards and clocks stacked on the right. */
@media (max-width: 980px) and (orientation: landscape) and (max-height: 560px) {
  :root { --cell: max(40px, min(96px, (100dvh - 54px) / 5, (100vw - 290px) / 5)); }
  #game {
    width: auto;
    grid-template-columns: calc(var(--cell) * 5) minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "board opp-hand opp-hand"
      "board opp-bar opp-bar"
      "board spare spare"
      "board my-bar my-bar"
      "board my-hand my-hand"
      "moves moves moves"
      "chat chat chat"
      "info info info";
    column-gap: 8px;
  }
  #opp-hand, #my-hand { --card-cell: 9px; margin: 0; }
  .hand .card { flex-direction: row; justify-content: center; gap: 10px; }
  #spare-box { --card-cell: 9px; margin: 4px 0; align-self: center; }
  #spare .card { flex-direction: row; gap: 10px; }
}

/* The analysis board has no room, presence or live controls. */
#game.analysis .info-meta,
#game.analysis .player .dot,
#game.analysis #controls { display: none; }
/* Reading the moves is the point of the analysis board, so the list gets more room there. */
#game.analysis #moves-scroll { min-height: 260px; }
/* Wider too, for the move times; maxCell() in the client allows for it. */
#game.analysis { --moves-width: 370px; }

/* ---------- accounts ---------- */

/* ---------- menu (top right) ---------- */

#menu { margin-left: auto; position: relative; display: flex; align-items: center; gap: 16px; }
#menu-button { background: none; border: 0; padding: 6px 0 6px 6px; display: flex; align-items: center; gap: 8px; color: var(--strong); }
#menu-button svg { width: 26px; height: 26px; fill: none; stroke: var(--dim); stroke-width: 1.5; }
#menu-button:hover svg, #menu-button[aria-expanded="true"] svg { stroke: var(--brand); }
#menu-button:hover #menu-name { color: var(--brand); }
#menu-rating { font-style: normal; color: var(--dim); }
#menu-rating:empty, #menu-name:empty { display: none; }
#menu-panel {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 20;
  width: 230px;
  background: var(--panel-hi);
  border-radius: 3px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  padding: 6px 0;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 14px;
  background: none;
  border: 0;
  text-align: left;
  color: var(--text);
  font-size: 14px;
}
.menu-item:hover { background: var(--green); color: #fff; }
.menu-item .glyph { width: 14px; text-align: center; color: var(--dim); }
.menu-item:hover .glyph { color: #fff; }
.menu-item.sub::after { content: "›"; margin-left: auto; color: var(--green); font-size: 20px; line-height: 0.8; }
.menu-item.sub:hover::after { color: #fff; }
.menu-item.back { color: var(--strong); border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-item.back::before { content: "‹"; color: var(--green); font-size: 20px; line-height: 0.8; }
.menu-item.back:hover::before { color: #fff; }
.menu-item.choice.selected::after { content: "✓"; margin-left: auto; color: var(--green); }
.menu-item.choice.selected:hover::after { color: #fff; }
.menu-item .swatch2 { width: 22px; height: 22px; border-radius: 2px; flex: none; }
.menu-item svg.piece { width: 24px; height: 24px; flex: none; filter: none; }
#menu-account { border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-bottom: 6px; }
#menu-ping { display: flex; align-items: flex-end; justify-content: space-between; border-top: 1px solid var(--line); margin-top: 6px; padding: 10px 14px 6px; color: var(--dim); font-size: 12.5px; line-height: 1.35; }
#menu-ping b { color: var(--text); font-weight: 400; font-size: 14px; }
#signal { display: flex; align-items: flex-end; gap: 2px; height: 22px; }
#signal i { width: 6px; background: var(--line); }
#signal i:nth-child(1) { height: 25%; }
#signal i:nth-child(2) { height: 50%; }
#signal i:nth-child(3) { height: 75%; }
#signal i:nth-child(4) { height: 100%; }
#signal i.on { background: var(--green); }
.menu-form { padding: 6px 14px 8px; display: flex; flex-direction: column; gap: 12px; }
.menu-form label { display: flex; flex-direction: column; gap: 5px; color: var(--dim); font-size: 13px; }
.menu-form select { background: var(--bg); color: var(--strong); border: 1px solid var(--line); border-radius: 3px; padding: 7px 8px; font: inherit; }
/* Pieces shaped like tiles point at the opponent. */
:root[data-pieces="tiles"] #board .piece.far { transform: rotate(180deg); }
.link { background: none; border: 0; padding: 0; color: var(--link); text-transform: uppercase; font-size: 13px; letter-spacing: 0.04em; }
.link:hover { color: var(--strong); }


dialog {
  background: var(--panel);
  color: var(--text);
  border: 0;
  border-radius: 6px;
  padding: 0;
  width: min(440px, calc(100vw - 24px));
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.45), 0 10px 10px rgba(0, 0, 0, 0.4);
}
#friend-dialog { width: min(640px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog form { padding: 22px 24px; display: flex; flex-direction: column; gap: 14px; }
dialog h2 { font-size: 22px; text-align: center; }
dialog label { display: flex; flex-direction: column; gap: 5px; color: var(--dim); }
dialog label.inline { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
dialog input:not([type="radio"]):not([type="range"]),
dialog select {
  background: var(--bg);
  color: var(--strong);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 9px 10px;
  font: inherit;
}
dialog input:focus, dialog select:focus { outline: 1px solid var(--link); }
dialog fieldset { border: 1px solid var(--line); border-radius: 3px; display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; margin: 0; }
dialog legend { color: var(--dim); padding: 0 6px; }
dialog .error { margin: 0; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
#auth-form .dialog-actions { justify-content: center; }
.button.google { background: #fff; color: #1f1f1f; text-align: center; padding: 11px; text-transform: none; font-size: 14px; }
.or { text-align: center; color: var(--dim); font-size: 12.5px; }

.option-row { display: flex; gap: 4px; }
.option-row .button { padding: 5px 8px; white-space: nowrap; }
#option-volume { accent-color: var(--green); }

#card-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
#card-picker .card { background: var(--panel-hi); padding: 8px 4px 6px; }
#card-picker .card:hover { background: var(--line); }
#card-picker .card.selected { box-shadow: 0 0 0 2px var(--green); background: color-mix(in srgb, var(--green) 25%, var(--panel)); }
#card-picker .card-grid { grid-template-columns: repeat(5, 11px); grid-template-rows: repeat(5, 11px); }
#card-picker .card.selected .card-grid i.m { background: var(--strong); }

.identity { display: inline-flex; align-items: baseline; gap: 6px; min-width: 0; }
.identity .rating, .identity .diff { flex: none; }
.identity .name { color: inherit; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.identity a.name:hover { color: var(--link); }
.identity .rating { color: var(--dim); font-size: 13px; }
.diff.up, td.outcome.win { color: #7eb82f; }
.diff.down, td.outcome.loss { color: #e0655c; }
.diff.flat, td.outcome.draw { color: var(--dim); }
.identity .diff { font-size: 13px; font-weight: 600; }

/* ---------- profile ---------- */

#profile { max-width: 900px; margin: 24px auto; padding: 0 16px; display: flex; flex-direction: column; gap: 16px; }
#profile-head { padding: 22px 24px; }
#profile-name { margin: 0; font-weight: 300; font-size: 34px; color: var(--strong); }
#profile-rating { font-size: 20px; color: var(--brand); margin-top: 2px; }
#profile-stats { margin: 8px 0 0; color: var(--dim); }
#profile-games { padding-bottom: 8px; overflow-x: auto; }
#profile-games h2 { padding: 14px 16px; font-size: 18px; }
#profile-games table { width: 100%; border-collapse: collapse; }
#profile-games th { text-align: left; font-weight: 400; color: var(--dim); padding: 6px 16px; border-bottom: 1px solid var(--line); background: var(--panel-hi); }
#profile-games td { padding: 9px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
#profile-games tbody tr { cursor: pointer; }
#profile-games tbody tr:hover { background: color-mix(in srgb, var(--brand) 22%, var(--panel)); color: #fff; }
td.outcome { font-weight: 600; }
td.diff { font-weight: 600; }
#profile-empty { padding: 28px 16px; margin: 0; color: var(--dim); text-align: center; }

/* ---------- donate ---------- */

/* ---------- creating an account ---------- */

#signup { max-width: 460px; margin: 24px auto; padding: 0 16px; }
#signup-box { padding: 26px 30px 24px; font-size: 15px; }
#signup-box h1 { margin: 0 0 10px; font-weight: 300; font-size: 30px; color: var(--strong); }
#signup-box form { display: flex; flex-direction: column; gap: 14px; }
#signup-box label { display: flex; flex-direction: column; gap: 5px; color: var(--dim); }
#signup-box input {
  background: var(--bg);
  color: var(--strong);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 10px;
  font: inherit;
}
#signup-box input:focus { outline: 1px solid var(--link); }
#signup-box small { font-size: 12px; }
#signup-box .error { margin: 0; }
#signup-box form .button.good { padding: 12px; font-size: 15px; }
#signup-box > div .button { display: inline-block; margin-top: 6px; }
#signup-box > div .note { margin: 12px 0 4px; }
.auth-switch { margin: 0; text-align: center; color: var(--dim); font-size: 13.5px; }
.auth-switch .link, #auth-resend { text-transform: none; font-size: inherit; letter-spacing: 0; }
#auth-resend { align-self: flex-start; }
.auth-forgot { align-self: flex-start; font-size: 13.5px; }

#donate { max-width: 720px; margin: 24px auto; padding: 0 16px; }
#donate-box { padding: 26px 30px 22px; font-size: 15px; }
#donate-box h1 { margin: 0 0 12px; font-weight: 300; font-size: 34px; color: var(--strong); }
#donate-box h2 { margin-top: 26px; font-size: 18px; }
#donate-box ul { padding-left: 20px; }
#donate-box li { margin: 6px 0; }
#donate-link { margin-top: 8px; padding: 14px 28px; font-size: 16px; }
#donate-closed { margin-top: 8px; font-size: 14px; }

/* ---------- tournaments ---------- */

#tournaments, #tournament { max-width: 900px; margin: 24px auto; padding: 0 16px; display: flex; flex-direction: column; gap: 16px; }
.note { margin: 0; color: var(--dim); font-size: 13px; }
.table-box { padding-bottom: 8px; overflow-x: auto; }
.table-box h2 { padding: 14px 16px; font-size: 18px; }
.table-box .note { padding: 0 16px 12px; }
.table-box .note:empty { display: none; }
.box-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px; }
.box-head h1, #tournament-name { margin: 0; font-weight: 300; font-size: 30px; color: var(--strong); }
.table-box table { width: 100%; border-collapse: collapse; }
.table-box th { text-align: left; font-weight: 400; color: var(--dim); padding: 6px 16px; border-bottom: 1px solid var(--line); background: var(--panel-hi); }
.table-box td { padding: 9px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table-box td.strong { font-weight: 600; color: var(--strong); }
.table-box td a { color: inherit; }
.table-box td a:hover { color: var(--link); }
.table-box .empty { padding: 28px 16px; margin: 0; color: var(--dim); text-align: center; }
#tournaments-list tr, #profile-tournament-list tr { cursor: pointer; }
#tournaments-list tr:hover, #profile-tournament-list tr:hover { background: color-mix(in srgb, var(--brand) 22%, var(--panel)); color: #fff; }
td.status.running { color: #7eb82f; font-weight: 600; }
td.status.finished { color: var(--dim); }

#tournament-head { padding: 22px 24px; }
#tournament-meta { margin: 4px 0 0; color: var(--dim); }
#tournament-clock { font-size: 22px; color: var(--brand); margin-top: 10px; font-variant-numeric: tabular-nums; }
#tournament-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 14px; min-height: 34px; }
#tournament-delete { margin-left: auto; }
#tournament-note.waiting { animation: pulse 1.4s ease-in-out infinite; }
#tournament-standings tr.me { background: color-mix(in srgb, var(--link) 14%, var(--panel)); }
#tournament-standings tr.withdrawn { opacity: 0.5; }
#tournament-standings td.score, #profile-tournament-list td.score { font-weight: 700; color: var(--strong); font-size: 15px; }
#tournament-standings td.rank { color: var(--dim); width: 1%; }
#tournament-standings .rating { color: var(--dim); font-size: 13px; margin-left: 6px; }
#tournament-standings td.watch { text-align: right; }
#tournament-standings td.watch a { color: var(--link); text-transform: uppercase; font-size: 12px; font-weight: 600; }

@media (max-width: 560px) {
  #tournament-standings th:nth-child(4), #tournament-standings td:nth-child(4) { display: none; }
  #tournaments th:nth-child(3), #tournaments td:nth-child(3) { display: none; }
  .table-box th, .table-box td { padding-left: 10px; padding-right: 10px; }
  #card-picker { grid-template-columns: repeat(3, 1fr); }
  #live th:nth-child(4), #live td:nth-child(4), #live th:nth-child(5), #live td:nth-child(5) { display: none; }
  /* The bar must fit a phone with Tournaments showing: the logo already leads home, Donate is in the lobby footer and the name is in the menu. */
  #top { gap: 12px; }
  #top nav { gap: 14px; }
  #top nav a:first-child, #top nav a.donate { display: none; }
  #top nav a, #signin { white-space: nowrap; }
  #menu-rating, #menu-name { display: none; }
}
