@font-face {
  font-family: 'Bricolage Grotesque';
  src: url('fonts/bricolage-grotesque.woff2?v=62220c02') format('woff2');
  font-weight: 200 800;
  font-display: swap;
}

:root {
  --table: #171c28;      /* the surface everything sits on */
  --rail: #212838;       /* lobby bar and games bar */
  --line: #343d53;
  --text: #ece7da;
  --muted: #9ba3b5;
  --buff: #e6dcbb;       /* light squares */
  --green: #3c7a5a;      /* dark squares, tournament-board green */
  --red: #c6382e;
  --ivory: #f4efe2;
  --out: #f08a24;        /* invite you sent */
  --in: #a368f0;         /* invite you received */
  --live: #3fbf6f;       /* game in progress */
  --face: 46px;
  --sb-frame: #14284a;   /* sea battle: the case, and the two peg colours */
  --sb-yellow: #f6d21e;
  --sb-red: #e03a2b;
  /* Room to leave at the screen edges for notches and system bars. Discord
     supplies its own values on phones; elsewhere the browser's are used. */
  --sait: var(--discord-safe-area-inset-top, env(safe-area-inset-top, 0px));
  --saib: var(--discord-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --sail: var(--discord-safe-area-inset-left, env(safe-area-inset-left, 0px));
  --sair: var(--discord-safe-area-inset-right, env(safe-area-inset-right, 0px));
  /* Space kept clear at the top of the screen. It is left in the background
     colour; nothing is drawn in it. */
  --top: var(--sait);
  color-scheme: dark;
}
/* In Discord's phone app, its own buttons (the app name and Leave) are drawn
   over the top of the activity, so everything starts below them. */
:root.mobile { --top: max(var(--sait), 44px); }

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

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--table);
  color: var(--text);
  font-family: 'Bricolage Grotesque', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.35;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

#app {
  height: 100dvh;
  padding: var(--top) var(--sair) var(--saib) var(--sail);
}

button { font: inherit; color: inherit; }
button:focus-visible { outline: 2px solid var(--buff); outline-offset: 2px; }

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- messages shown before the app is up ---------------------------------- */

.notice {
  height: 100%;
  max-width: 38ch;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  text-align: center;
  color: var(--muted);
  font-size: 16px;
}
.notice p { margin: 0; }

/* ---- buttons ---------------------------------------------------------------- */

.btn {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #2a3246;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover { background: #333c54; }
.btn.quiet { background: transparent; color: var(--muted); }
.btn.quiet:hover { color: var(--text); }
.btn.danger { background: #b3362c; border-color: transparent; color: #fff; }
.btn.primary { background: var(--buff); border-color: transparent; color: #1a2030; font-weight: 600; }
.btn.primary:hover { background: #f3ebcf; }

/* ---- right-click menu ------------------------------------------------------- */

.menu {
  position: fixed;
  z-index: 20;
  min-width: 150px;
  padding: 5px;
  display: grid;
  gap: 1px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #283044;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}
.menu-item {
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  background: none;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: #364060; outline: none; }

/* ---- panel (admins) ---------------------------------------------------------
   Everything stays within the left 90% of the screen; the strip on the right
   is left empty for the right-click menu. */

.panel {
  height: 100%;
  overflow-y: auto;
  padding: 18px 0 48px 16px;
}
.panel-body {
  width: min(620px, 90vw - 16px);
  display: grid;
  gap: 8px;
}
.panel h1 { margin: 0 0 6px; font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.panel-status { margin: 0; color: var(--muted); }

.cat {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--rail);
}
.cat > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  font-size: 16px;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}
.cat > summary::-webkit-details-marker { display: none; }
.cat > summary:focus-visible { outline: 2px solid var(--buff); outline-offset: -2px; }
.cat > summary svg { width: 16px; height: 16px; color: var(--muted); transition: transform 0.15s ease; }
.cat[open] > summary svg { transform: rotate(90deg); }
.cat-count { margin-left: auto; color: var(--muted); font-size: 13px; font-weight: 500; }
.cat-body { padding: 6px 14px 12px; border-top: 1px solid var(--line); }

/* An ID row and the box for typing a new one share their size and type, so
   a saved box can lose its border and look like any other row. */
.id-row { display: flex; align-items: center; gap: 6px; min-height: 38px; }
.id-text, .id-input {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 14.5px;
  font-variant-numeric: tabular-nums;
  -webkit-user-select: text;
  user-select: text;
}
.id-row.empty .id-text { color: var(--muted); }
.id-input { border-color: var(--line); background: #1a2030; outline: none; }
.id-input:focus { border-color: #5f6c90; }
.id-input::placeholder { color: #6f7890; }
.id-input.bad { animation: glow-bad 0.85s ease-out 1; }
.id-text.bad { animation: pulse-bad 0.85s ease-out 1; }
.id-input.ok { animation: glow-ok 0.85s ease-out 1 forwards; }
.id-row.settled .icon-btn { visibility: hidden; }

@keyframes glow-bad {
  0%, 35% { border-color: #ef5350; box-shadow: 0 0 0 4px rgba(239, 83, 80, 0.4); }
  100% { border-color: var(--line); box-shadow: 0 0 0 0 rgba(239, 83, 80, 0); }
}
@keyframes pulse-bad {
  0%, 35% { color: #ef5350; }
  100% { color: var(--text); }
}
@keyframes glow-ok {
  0%, 35% { border-color: var(--live); background: #1a2030; box-shadow: 0 0 0 4px rgba(63, 191, 111, 0.35); }
  100% { border-color: transparent; background: transparent; box-shadow: 0 0 0 0 rgba(63, 191, 111, 0); }
}

.icon-btn {
  flex: none;
  width: 30px;
  height: 30px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #2a3246;
  cursor: pointer;
}
.icon-btn:hover { background: #364060; }
.icon-btn svg { width: 14px; height: 14px; }
.icon-btn.yes { color: var(--live); }
.icon-btn.no { color: #ef8a84; }

.game-head, .game-row {
  display: grid;
  grid-template-columns: 40px 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
}
.game-head { min-height: 26px; color: var(--muted); font-size: 12px; }
.game-head span:nth-child(-n+2) { text-align: center; }
.game-row { min-height: 42px; }
.game-name { font-size: 15px; font-weight: 500; }
.row-actions { display: flex; gap: 6px; }

/* The On and Dev switches: grey when off, coloured when on. */
.toggle {
  width: 34px;
  height: 34px;
  padding: 0;
  justify-self: center;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: none;
  color: #5d667c;
  cursor: pointer;
}
.toggle:hover { background: rgba(255, 255, 255, 0.07); }
.toggle svg { width: 20px; height: 20px; }
.toggle.power.on { color: var(--live); }
.toggle.dev.on { color: #f2c94c; }

/* ---- landing page ----------------------------------------------------------- */

.landing {
  height: 100%;
  overflow-y: auto;
  padding: clamp(20px, 6vw, 64px);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: center;
}
.landing > * { width: 100%; max-width: 760px; margin-inline: auto; }
.landing h1 {
  margin-block: 0;
  font-size: clamp(44px, 11vw, 92px);
  font-weight: 750;
  line-height: 0.92;
  letter-spacing: -0.035em;
}
.whoami {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-block: 16px 30px;
  color: var(--muted);
}
.whoami .face { --face: 24px; box-shadow: none; }
.whoami .initials { font-size: 10px; }

.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: 14px;
}
.card {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--rail);
  text-align: left;
  cursor: pointer;
}
.card:hover { border-color: var(--buff); }
.card:hover .cb-mini, .card:hover .sb-mini, .card:hover .ch-mini { transform: rotate(0deg); }
.card-text { display: grid; gap: 2px; }
.card-name { font-size: 25px; font-weight: 700; letter-spacing: -0.01em; }
.card-tagline { color: var(--muted); font-size: 14px; }
.card-note { margin-top: 6px; color: var(--live); font-size: 13.5px; font-weight: 600; }
.card-pending { color: #c9a8fb; }
.card-tag { margin-top: 4px; color: #f2c94c; font-size: 12.5px; font-weight: 600; }
.shelf-empty { margin: 0; color: var(--muted); }
.card-note:not([hidden]) + .card-pending { margin-top: 0; }

.cb-mini {
  width: 92px;
  aspect-ratio: 1;
  display: grid;
  grid-template: repeat(4, 1fr) / repeat(4, 1fr);
  border-radius: 9px;
  overflow: hidden;
  container-type: size;
  transform: rotate(-6deg);
  transition: transform 0.2s ease;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}
.cb-mini > span { position: relative; }
.cb-mini .light { background: var(--buff); }
.cb-mini .dark { background: var(--green); }
.cb-mini .cb-piece { --sq: 25cqw; position: absolute; inset: 0; }

/* ---- game screen ------------------------------------------------------------
   Five pieces on a grid: the Games button, the Invites and Here now lanes,
   the stage with the board, and the Your games lane.

   Tall screens (the default): lobby across the top, your games along the
   bottom. Wide screens: see "wide screens" near the end of this file. */

.table {
  height: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "back  invites here"
    "stage stage   stage"
    "games games   games";
}
.back { grid-area: back; }
.lane-invites { grid-area: invites; }
.lane-here { grid-area: here; }
.stage { grid-area: stage; }
.lane-games { grid-area: games; }

.back, .lane {
  background: var(--rail);
  border: 0 solid var(--line);
}

.back {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 2px;
  padding: 0 12px;
  border-right-width: 1px;
  border-bottom-width: 1px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.back:hover { color: var(--text); }
.back svg { width: 20px; height: 20px; }

.lane {
  --pad: 7px;
  position: relative;
  min-width: 0;
  padding: var(--pad) 0 8px;
}
.lane-invites, .lane-here { border-bottom-width: 1px; }
.lane-here { border-left-width: 1px; }
.lane-games { border-top-width: 1px; }

/* Soft edges where a row of pictures scrolls out of its lane. */
.lane::before, .lane::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 1;
  width: 14px;
  pointer-events: none;
}
.lane::before { left: 0; background: linear-gradient(to right, var(--rail), transparent); }
.lane::after { right: 0; background: linear-gradient(to left, var(--rail), transparent); }
.lane h2 {
  margin: 0 14px 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}
.lane-empty {
  height: calc(var(--face) + 31px);
  margin: 0;
  padding: 0 14px;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
}

/* A row of profile pictures that scrolls sideways by drag or finger. */
.strip {
  display: flex;
  gap: 8px;
  padding: 7px 14px 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  cursor: grab;
}
.strip::-webkit-scrollbar { display: none; }
.strip:empty { display: none; }
.strip.dragging { cursor: grabbing; }
.strip.dragging .chip { pointer-events: none; }

.chip {
  --ring: transparent;
  position: relative;
  flex: 0 0 auto;
  width: calc(var(--face) + 14px);
  padding: 0 0 4px;
  display: grid;
  justify-items: center;
  gap: 6px;
  border: 0;
  border-radius: 12px;
  background: none;
  cursor: pointer;
}
.chip.out { --ring: var(--out); }
.chip.in { --ring: var(--in); }
.chip.live { --ring: var(--live); }
.chip.here:hover { --ring: color-mix(in srgb, var(--out) 55%, transparent); }

.face {
  position: relative;
  width: var(--face);
  height: var(--face);
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  background: var(--tint, #4e7fd1);
  /* The coloured border: a gap in the bar colour, then the ring. */
  box-shadow: 0 0 0 2px var(--rail), 0 0 0 5px var(--ring, transparent);
  transition: box-shadow 0.15s ease;
}
.face img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.initials { color: #fff; font-size: 16px; font-weight: 650; }

.chip-name {
  max-width: 100%;
  overflow: hidden;
  color: var(--muted);
  font-size: 11.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Corner mark: a tick on invites you can accept, a cross on ones you can
   take back, a dot on games waiting for your move. */
.badge {
  position: absolute;
  top: -5px;
  right: 0;
  width: 18px;
  height: 18px;
  display: none;
  place-items: center;
  border: 2px solid var(--rail);
  border-radius: 50%;
  background: var(--ring);
  color: #14161c;
}
.badge svg { width: 10px; height: 10px; stroke-width: 4; }
.chip.in .badge, .chip.out .badge { display: grid; }
.chip.live.turn .badge {
  display: block;
  width: 14px;
  height: 14px;
  top: -3px;
  right: 3px;
  background: var(--buff);
}

.chip.live.selected { background: rgba(255, 255, 255, 0.08); }
.chip.live.selected .face { box-shadow: 0 0 0 2px var(--rail), 0 0 0 6px var(--ring); }
.chip.live.selected .chip-name { color: var(--text); font-weight: 600; }
.chip.away .face img, .chip.away .initials { opacity: 0.4; }
.lane-games .strip { padding-top: 9px; }
.lane-games .chip { padding-top: 6px; }
.lane-games .badge { top: 1px; }
.lane-games .chip.live.turn .badge { top: 3px; }

/* ---- stage ------------------------------------------------------------------ */

.stage {
  position: relative;
  min-height: 0;
  padding: 14px 14px 8px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px;
}
.board-host {
  min-height: 0;
  display: grid;
  place-items: center;
  container-type: size;
}
.status {
  min-height: 38px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 12px;
}
.status-text { margin: 0; font-size: 15.5px; font-weight: 500; text-align: center; }
.status-actions { display: flex; gap: 8px; }
.status-actions:empty { display: none; }

.pill {
  position: absolute;
  top: 22px;
  left: 50%;
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(10, 12, 18, 0.85);
  font-size: 13px;
  transform: translateX(-50%);
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 28%;
  z-index: 10;
  margin: 0;
  padding: 9px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--table);
  font-size: 14px;
  font-weight: 500;
  transform: translateX(-50%);
}

/* ---- checkers --------------------------------------------------------------- */

.cb {
  position: relative;
  width: calc(min(100cqw, 100cqh) - 14px);
  aspect-ratio: 1;
  border-radius: 8px;
  box-shadow: 0 0 0 7px #2b3348, 0 16px 36px rgba(0, 0, 0, 0.4);
  container-type: size;
  transition: filter 0.2s ease;
}
.cb.idle { filter: saturate(0.6) brightness(0.72); }

.cb-grid {
  height: 100%;
  display: grid;
  grid-template: repeat(8, 1fr) / repeat(8, 1fr);
  overflow: hidden;
  border-radius: 8px;
}
.cb-sq { position: relative; margin: 0; padding: 0; border: 0; border-radius: 0; }
.cb-sq.light { background: var(--buff); }
.cb-sq.dark { background: var(--green); }
.cb-sq.dark.last { background: color-mix(in srgb, var(--green) 62%, #e9cf5a); }
.cb-sq:focus-visible { outline-offset: -3px; z-index: 1; }
.cb-sq.target { cursor: pointer; }
.cb.watching .cb-sq.target { cursor: default; }
.cb-sq.target::after {
  content: '';
  position: absolute;
  inset: 33%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
}

.cb-pieces { position: absolute; inset: 0; pointer-events: none; }
.cb-pieces .cb-piece {
  --sq: 12.5cqw;
  position: absolute;
  top: 0;
  left: 0;
  width: 12.5%;
  height: 12.5%;
  transition: transform 0.22s ease, opacity 0.25s ease;
}

/* A piece is a disc with a raised rim, drawn on ::before so the element
   itself can stay the size of its square. */
.cb-piece { display: grid; place-items: center; }
.cb-piece::before {
  content: '';
  position: absolute;
  inset: 11%;
  border-radius: 50%;
  transition: transform 0.15s ease;
}
.cb-piece.s0::before {
  background: radial-gradient(circle at 50% 35%, #e25b4e, var(--red) 65%, #a82a22);
  box-shadow:
    inset 0 0 0 calc(var(--sq) * 0.07) #a82a22,
    inset 0 0 0 calc(var(--sq) * 0.1) rgba(255, 255, 255, 0.22),
    0 calc(var(--sq) * 0.05) calc(var(--sq) * 0.08) rgba(0, 0, 0, 0.45);
}
.cb-piece.s1::before {
  background: radial-gradient(circle at 50% 35%, #fffdf7, var(--ivory) 65%, #d9d2bf);
  box-shadow:
    inset 0 0 0 calc(var(--sq) * 0.07) #cfc7b1,
    inset 0 0 0 calc(var(--sq) * 0.1) rgba(255, 255, 255, 0.7),
    0 calc(var(--sq) * 0.05) calc(var(--sq) * 0.08) rgba(0, 0, 0, 0.45);
}
.cb-piece svg { position: relative; width: 44%; stroke: none; }
.cb-piece.s0 svg { fill: #f8d977; }
.cb-piece.s1 svg { fill: #a77a1f; }

/* Pieces that can move this turn get a pale outline; the one picked up
   lifts and gets a solid one. */
.cb-piece.movable::after,
.cb-piece.selected::after {
  content: '';
  position: absolute;
  inset: 7%;
  border-radius: 50%;
  border: calc(var(--sq) * 0.035) solid rgba(255, 255, 255, 0.6);
}
.cb-piece.selected::before { transform: scale(1.07); }
.cb-piece.selected::after { inset: 4%; border-color: #ffe48a; border-width: calc(var(--sq) * 0.05); }
.cb-piece.gone { opacity: 0; }

/* ---- chess ---------------------------------------------------------------------
   The board, with a thin bar of moves on its right. Pieces are SVG: a
   silhouette (.sil) with the line work (.ink) over it. */

.ch { display: flex; gap: 8px; }
.ch-board {
  position: relative;
  flex: none;
  width: calc(min(100cqw - 96px, 100cqh) - 14px);
  aspect-ratio: 1;
  border-radius: 8px;
  box-shadow: 0 0 0 7px #2b3348, 0 16px 36px rgba(0, 0, 0, 0.4);
  container-type: size;
  touch-action: none;
  transition: filter 0.2s ease;
}
.ch-board.idle { filter: saturate(0.6) brightness(0.72); }
/* Looking back at an earlier position, not the game itself. */
.ch-board.past { filter: saturate(0.7) brightness(0.93); }

.ch-grid {
  height: 100%;
  display: grid;
  grid-template: repeat(8, 1fr) / repeat(8, 1fr);
  overflow: hidden;
  border-radius: 8px;
}
.ch-sq { position: relative; margin: 0; padding: 0; border: 0; border-radius: 0; cursor: default; }
.ch-sq.light { background-color: #ebecd0; color: #739552; }
.ch-sq.dark { background-color: #739552; color: #ebecd0; }
/* The move just made, and the piece in hand. */
.ch-sq.last.light, .ch-sq.sel.light { background-color: #f5f682; }
.ch-sq.last.dark, .ch-sq.sel.dark { background-color: #b9ca43; }
.ch-sq.check {
  background-image: radial-gradient(circle, rgba(235, 60, 45, 0.95) 0 30%, rgba(235, 60, 45, 0.5) 58%, transparent 76%);
}
/* Where the piece in hand can go: a dot on an empty square, a ring round a
   piece it would take. */
.ch-sq.dot::after {
  content: '';
  position: absolute;
  inset: 35%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.2);
}
.ch-sq.ring::after {
  content: '';
  position: absolute;
  inset: 3%;
  border: 1.1cqw solid rgba(0, 0, 0, 0.2);
  border-radius: 50%;
}
.ch-sq.over { box-shadow: inset 0 0 0 0.7cqw rgba(255, 255, 255, 0.85); }
.ch-sq:focus-visible { z-index: 1; outline: 2px solid #1a2030; outline-offset: -3px; }
.ch-board.mine .ch-sq.can { cursor: grab; }
.ch-board.mine .ch-sq.dot, .ch-board.mine .ch-sq.ring { cursor: pointer; }
.ch-rank, .ch-file { position: absolute; font-size: 2.7cqw; font-weight: 700; line-height: 1; pointer-events: none; }
.ch-rank { top: 5%; left: 6%; }
.ch-file { right: 7%; bottom: 5%; }

.ch-pieces { position: absolute; inset: 0; pointer-events: none; }
.ch-pieces .ch-piece {
  position: absolute;
  top: 0;
  left: 0;
  width: 12.5%;
  height: 12.5%;
  transition: transform 0.18s ease, opacity 0.2s ease;
}
.ch-piece svg { display: block; width: 100%; height: 100%; stroke: none; transition: transform 0.12s ease; }
/* Traced pieces (queen, knight): a silhouette with the line work over it. */
.ch-piece.w .sil { fill: #fff; }
.ch-piece.w .ink { fill: #3a3835; }
.ch-piece.b .sil { fill: #c9c6bd; }
.ch-piece.b .ink { fill: #454240; }
/* Drawn pieces (king, rook, bishop, pawn): outlined shapes, then lines. */
.ch-piece .body { stroke-width: 2.8; stroke-linejoin: round; }
.ch-piece.w .body { fill: #fff; stroke: #3a3835; }
.ch-piece.b .body { fill: #454240; stroke: #454240; }
.ch-piece .detail { fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.ch-piece.w .detail { stroke: #3a3835; }
.ch-piece.b .detail { stroke: #c9c6bd; }
/* A piece being dragged follows the pointer, lifted above the rest. */
.ch-pieces .ch-piece.drag { z-index: 5; transition: none; }
.ch-pieces .ch-piece.drag svg { transform: scale(1.2); filter: drop-shadow(0 4px 5px rgba(0, 0, 0, 0.35)); }
.ch-pieces .ch-piece.gone, .ch-pieces .ch-piece.taken { opacity: 0; }

/* Choosing what a pawn becomes: a column of four pieces on its file. */
.ch-promo {
  position: absolute;
  top: 0;
  z-index: 6;
  width: 12.5%;
  display: grid;
  overflow: hidden;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5);
}
.ch-promo .ch-piece { width: 100%; aspect-ratio: 1; padding: 0; border: 0; background: none; cursor: pointer; }
.ch-promo .ch-piece:hover, .ch-promo .ch-piece:focus-visible { background: #dfe6c8; outline: none; }
.ch-promo-cancel {
  height: 5.2cqw;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  background: #eceff1;
  color: #5c6470;
  cursor: pointer;
}
.ch-promo-cancel svg { width: 2.8cqw; height: 2.8cqw; }

/* The popup before play: two pawns to choose a colour, then Play. */
.ch-pick {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 7;
  width: min(88%, 290px);
  padding: 16px 14px 14px;
  display: grid;
  justify-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--rail);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.55);
  text-align: center;
  transform: translate(-50%, -50%);
}
.ch-pick-title { margin: 0; font-size: 15px; font-weight: 600; }
.ch-pawns { display: flex; gap: 14px; }
.ch-pawn {
  position: relative;
  width: 74px;
  height: 74px;
  padding: 5px;
  border: 2px solid transparent;
  border-radius: 12px;
  cursor: pointer;
}
.ch-pawn.w { background: #739552; }
.ch-pawn.b { background: #ebecd0; }
.ch-pawn.mine { border-color: var(--buff); box-shadow: 0 0 0 2px var(--buff); }
.ch-pawn .ch-piece { display: block; width: 100%; height: 100%; }
/* The pictures of whoever picked this colour sit on the pawn's foot. */
.ch-pawn-faces { position: absolute; right: 0; bottom: -10px; left: 0; display: flex; justify-content: center; gap: 3px; }
.ch-pawn-faces .face { --face: 22px; box-shadow: 0 0 0 2px var(--rail); }
.ch-pawn-faces .initials { font-size: 10px; }
.ch-pick-info { min-height: 2.7em; margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.35; }
.ch-pick .btn { min-width: 110px; padding: 8px 18px; font-size: 14.5px; }
.ch-pick .btn:disabled { background: #2a3246; color: var(--muted); cursor: default; }

/* Moves so far, between a "previous" arrow and a "next" arrow. No scrollbar:
   use the wheel, or drag with a finger. Pressing a row shows that position. */
.ch-history {
  flex: none;
  width: 88px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--rail);
}
/* About four fifths the height of a move row, the full width of the bar. */
.ch-nav {
  flex: none;
  height: 20px;
  padding: 0;
  border: 0;
  background: #2a3246;
  color: var(--text);
  font-size: 13px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
}
.ch-nav:hover:not(:disabled) { background: #364060; }
.ch-nav:disabled { color: #5d667c; cursor: default; }
.ch-nav:focus-visible, .ch-row:focus-visible { outline: 2px solid var(--buff); outline-offset: -2px; }
.ch-moves-box { position: relative; flex: 1; min-height: 0; }
.ch-moves {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}
.ch-moves::-webkit-scrollbar { display: none; }
.ch-row {
  width: 100%;
  padding: 3px 7px;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: none;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.ch-row:hover:not(:disabled) { background: rgba(255, 255, 255, 0.05); }
.ch-row:disabled { cursor: default; }
/* The move whose position is on the board. */
.ch-row.latest, .ch-row.latest:hover { background: rgba(255, 255, 255, 0.12); }
.ch-row .face { --face: 18px; flex: none; box-shadow: none; }
.ch-row .initials { font-size: 9px; }
.ch-san { white-space: nowrap; }

/* The picture on the home page card. */
.ch-mini {
  width: 92px;
  aspect-ratio: 1;
  display: grid;
  grid-template: repeat(4, 1fr) / repeat(4, 1fr);
  overflow: hidden;
  border-radius: 9px;
  transform: rotate(-6deg);
  transition: transform 0.2s ease;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}
.ch-mini .light { background: #ebecd0; }
.ch-mini .dark { background: #739552; }
.ch-mini .ch-piece { display: block; width: 100%; height: 100%; }

@media (max-width: 420px) {
  .ch-board { width: calc(min(100cqw - 82px, 100cqh) - 14px); }
  .ch-history { width: 74px; }
  .ch-row { gap: 5px; padding: 3px 5px; font-size: 12.5px; }
}

/* ---- sea battle ---------------------------------------------------------------
   Two square grids hinged like an open case. The one the camera is over lies
   flat to the screen; the other is tipped away and seen at an angle. --w is
   the side of a grid, set from the space available by the script. */

.sb {
  --w: 300px;
  --m: calc(var(--w) * 0.5);          /* height given to the grid seen at an angle */
  --lens: calc(var(--w) * 3);
  --tilt: 60deg;
  display: flex;
  align-items: center;
  gap: 8px;
  touch-action: none;
}
.sb.idle .sb-stage { filter: saturate(0.55) brightness(0.7); }

.sb-stage {
  position: relative;
  flex: none;
  width: var(--w);
  height: calc(var(--w) + var(--m));
}

/* The grips at the sides: drag (or press) to swing between the two grids. */
.sb-rail {
  flex: none;
  width: 22px;
  height: calc(var(--w) * 0.7);
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: repeating-linear-gradient(to bottom, #22395f 0 3px, #182b4b 3px 7px);
  color: #9fcbee;
  cursor: grab;
}
.sb-rail svg { width: 18px; height: 18px; transition: transform 0.3s ease; }
.sb[data-view="fleet"] .sb-rail svg { transform: rotate(180deg); }

.sb-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--w);
  height: var(--w);
  display: grid;
  grid-template: repeat(11, minmax(0, 1fr)) / repeat(11, minmax(0, 1fr));
  overflow: hidden;
  border: 3px solid var(--sb-frame);
  border-radius: 10px;
  background: var(--sb-frame);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.4);
  container-type: size;
  transition: transform 0.7s cubic-bezier(0.3, 0.1, 0.2, 1), filter 0.7s ease;
}
.sb-target { transform-origin: 50% 100%; }
.sb-fleet { transform-origin: 50% 0; }

/* Camera on the target: it stands upright, your fleet lies tipped below. */
.sb[data-view="target"] .sb-target {
  transform: translateY(0) perspective(var(--lens)) rotateX(0deg) scale(1);
}
.sb[data-view="target"] .sb-fleet {
  transform: translateY(var(--w)) perspective(var(--lens)) rotateX(var(--tilt)) scale(0.76);
  filter: brightness(0.9);
  pointer-events: none;
}
/* Camera over your fleet: it lies flat, the target leans away above it. */
.sb[data-view="fleet"] .sb-target {
  transform: translateY(calc(var(--m) - var(--w))) perspective(var(--lens)) rotateX(var(--tilt)) scale(1);
  filter: brightness(0.9);
  pointer-events: none;
}
.sb[data-view="fleet"] .sb-fleet {
  transform: translateY(var(--m)) perspective(var(--lens)) rotateX(0deg) scale(1);
}

/* The water: grid lines, and a peg hole in the middle of every square. */
.sb-sea {
  z-index: 0;
  background-color: #3493dc;
  background-image:
    radial-gradient(circle, #0c2b55 0 11%, rgba(225, 245, 255, 0.5) 12% 17%, transparent 18%),
    linear-gradient(to right, rgba(195, 236, 255, 0.6) 0 1px, transparent 1px),
    linear-gradient(to bottom, rgba(195, 236, 255, 0.6) 0 1px, transparent 1px);
  background-size: 10% 10%;
}
.sb-fleet .sb-sea { background-color: #2b82c9; }
.sb-label {
  display: grid;
  place-items: center;
  background: #1c8fe6;
  color: #fff;
  font-size: 4.6cqw;
  font-weight: 700;
  box-shadow: inset 0 0 0 0.5px rgba(195, 236, 255, 0.45);
}

.sb-cell {
  z-index: 1;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  cursor: default;
}
.sb-cell:focus-visible { z-index: 3; outline: 2px solid #fff; outline-offset: -2px; }
.sb.aiming .sb-target .sb-cell, .sb.arranging .sb-fleet .sb-cell { cursor: pointer; }
/* Where the ship in hand would go: green if it fits, red if not. */
.sb-cell.ok { z-index: 3; background: rgba(70, 225, 120, 0.55); }
.sb-cell.bad { z-index: 3; background: rgba(245, 70, 60, 0.55); }

.sb-ship {
  position: relative;
  z-index: 2;
  margin: 1cqw;
  background: linear-gradient(135deg, #d7dce2, #8d96a3);
  box-shadow: inset 0 0 0 0.4cqw rgba(55, 65, 82, 0.55), 0 0.5cqw 0.9cqw rgba(0, 0, 0, 0.35);
  pointer-events: none;
  transition: opacity 0.15s ease;
}
.sb-ship.v { border-radius: 50% 50% 1.6cqw 1.6cqw / 4.2cqw 4.2cqw 1.6cqw 1.6cqw; }
.sb-ship.h { border-radius: 1.6cqw 4.2cqw 4.2cqw 1.6cqw / 1.6cqw 50% 50% 1.6cqw; }
.sb-deck { position: absolute; border-radius: 1cqw; background: linear-gradient(135deg, #7f8996, #626c79); }
.sb-ship.v .sb-deck { inset: 32% 28% 20% 28%; }
.sb-ship.h .sb-deck { inset: 28% 32% 28% 20%; }
.sb-ship.held { opacity: 0.45; }
.sb-ship.sunk { background: linear-gradient(135deg, #cf9d94, #84504a); }
/* A sunk enemy ship: a see-through outline behind its red pegs. */
.sb-ship.ghost {
  background: rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 0 0 0.55cqw rgba(255, 255, 255, 0.9);
}
.sb-ship.ghost .sb-deck { display: none; }
/* Enemy ships that were still afloat, shown once the game is over. */
.sb-ship.ghost.survivor {
  background: rgba(255, 255, 255, 0.07);
  box-shadow: inset 0 0 0 0.4cqw rgba(255, 255, 255, 0.45);
}

/* Pegs, seen end-on. "aim" is a peg held over the hole, not yet pushed in:
   bigger, lifted, with a longer shadow. */
.sb-peg {
  position: relative;
  z-index: 4;
  place-self: center;
  width: 54%;
  aspect-ratio: 1;
  border-radius: 50%;
  background-color: var(--sb-yellow);
  background-image: radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.8), transparent 46%);
  box-shadow: 0 0.3cqw 0.5cqw rgba(0, 0, 0, 0.5), inset 0 -0.5cqw 0.6cqw rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: scale(0.5);
  pointer-events: none;
  transition: transform 0.16s ease, opacity 0.1s ease, background-color 0.25s ease, box-shadow 0.16s ease;
}
.sb-peg.in { opacity: 1; transform: scale(1); }
.sb-peg.aim {
  opacity: 0.95;
  transform: translateY(-18%) scale(1.34);
  box-shadow: 0 1.7cqw 1.4cqw rgba(0, 0, 0, 0.4), inset 0 -0.5cqw 0.6cqw rgba(0, 0, 0, 0.25);
}
.sb-peg.hit { background-color: var(--sb-red); }
/* The most recent shot. */
.sb-peg.last::after {
  content: '';
  position: absolute;
  inset: -30%;
  border: 0.5cqw solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
}

/* Turn and put-back buttons on the ship in hand. */
.sb-tools { z-index: 5; display: flex; align-items: center; justify-content: space-around; pointer-events: none; }
.sb-tools.v { flex-direction: column; }
.sb-tool {
  width: 8cqw;
  height: 8cqw;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--sb-frame);
  box-shadow: 0 0.4cqw 1cqw rgba(0, 0, 0, 0.45);
  cursor: pointer;
  pointer-events: auto;
}
.sb-tool svg { width: 62%; height: 62%; transition: transform 0.2s ease; }
.sb-tool.sideways svg { transform: rotate(90deg); }

/* The picture on the home page card. */
.sb-mini {
  width: 92px;
  aspect-ratio: 1;
  display: grid;
  grid-template: repeat(4, 1fr) / repeat(4, 1fr);
  overflow: hidden;
  border: 4px solid var(--sb-frame);
  border-radius: 9px;
  background: var(--sb-frame);
  container-type: size;
  transform: rotate(-6deg);
  transition: transform 0.2s ease;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}
.sb-mini > span {
  display: grid;
  background:
    radial-gradient(circle, #0c2b55 0 12%, rgba(225, 245, 255, 0.5) 13% 19%, transparent 20%),
    #3493dc;
  box-shadow: inset 0 0 0 0.5px rgba(195, 236, 255, 0.6);
}
.sb-mini .sb-peg { width: 58%; }

/* ---- short screens (phones held sideways, small pop-out windows) ---------- */

@media (max-height: 540px) {
  :root { --face: 34px; }
  .lane h2, .chip-name { display: none; }
  .lane { --pad: 2px; padding-bottom: 6px; }
  .lane-empty { height: calc(var(--face) + 11px); font-size: 12.5px; }
  .chip { gap: 0; }
  .initials { font-size: 13px; }
  .back span { display: none; }
  .stage { padding: 10px 10px 4px; gap: 4px; }
  .status { min-height: 30px; }
  .status-text { font-size: 14px; }
  .btn { padding: 4px 12px; }
}

@media (max-width: 420px) {
  .lane h2, .lane-empty { margin-inline: 10px; padding-inline: 0; }
  .lane-empty { margin: 0 10px; font-size: 12.5px; }
  .strip { padding-inline: 10px; gap: 4px; }
  .back { padding-inline: 8px; }
}

/* ---- wide screens ------------------------------------------------------------
   The board is limited by height here, so the lobby moves down to share one
   bar with your games: Games button, Your games, Invites, Here now. */

@media (min-aspect-ratio: 11/10) and (min-width: 520px) {
  .table {
    grid-template-columns: auto repeat(3, minmax(0, 1fr));
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas:
      "stage stage stage   stage"
      "back  games invites here";
  }
  .back, .lane-invites, .lane-here { border-bottom-width: 0; }
  .back, .lane { border-top-width: 1px; }
  .lane-invites { border-left-width: 1px; }
  /* Discord's phone buttons sit in the top corners, clear of the centred
     board, so only the notch needs room here. */
  :root.mobile { --top: var(--sait); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
