:root {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --ink: #2b2723;
  --muted: #7c736a;
  --line: #d9d2c6;
  --mine: #2f6f4f;
  --mine-soft: #2f6f4f22;
  --theirs: #9a4a34;
  --accent: #1f6feb;
  --gold: #a9761b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 6px 20px rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1816;
    --panel: #242120;
    --ink: #ece6dd;
    --muted: #9a9086;
    --line: #3a3532;
    --mine: #6fbf92;
    --mine-soft: #6fbf9222;
    --theirs: #e08a6c;
    --accent: #5b9dff;
    --gold: #e2b458;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
}

.masthead {
  padding: 22px 20px 6px;
  text-align: center;
}

.masthead h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0.02em;
}

.masthead p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-style: italic;
}

.wrap {
  max-width: 1000px;
  margin: 0 auto;
  padding: 16px 20px 48px;
}

/* The game page carries a column either side of the table, so it gets more
   room than the home page. */
.wrap.wide {
  max-width: 1320px;
}

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

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 22px;
}

/* The lobby takes the width, with the form and the rules beside it - the
   waiting games are what the page is for. */
.home-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1fr) 380px;
  grid-template-areas:
    "lobby form"
    "lobby rules";
  align-content: start;
  margin: 0 auto;
}

.home-grid > .lobby {
  grid-area: lobby;
}

.home-grid > .create {
  grid-area: form;
}

.home-grid > .rules {
  grid-area: rules;
}

@media (max-width: 900px) {
  .home-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "form"
      "lobby"
      "rules";
    max-width: 560px;
  }
}

/* --- the lobby ----------------------------------------------------------- */

.lobby-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.lobby-head h2 {
  margin: 0;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.lobby-count {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.offers {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.offers th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  padding: 0 8px 6px;
  border-bottom: 1px solid var(--line);
}

.offers tbody:empty {
  display: none;
}

.offers td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
}

/* A row is a link: the whole thing is the target, as at a table you sit at. */
.offers tbody tr {
  cursor: pointer;
}

.offers tbody tr:hover td,
.offers tbody tr:focus-visible td {
  background: var(--mine-soft);
}

.offers tbody tr:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.offers .tabular {
  font-variant-numeric: tabular-nums;
}

.offers .muted {
  color: var(--muted);
}

.lobby-empty {
  color: var(--muted);
  font-size: 14px;
  font-style: italic;
  padding: 6px 8px;
}

fieldset {
  border: none;
  margin: 0 0 18px;
  padding: 0;
}

/* A question this mode does not ask. It holds its place - the form is the same
   height whichever mode is chosen, so nothing jumps when you switch - and
   `visibility` rather than opacity, so nothing in it can be clicked or tabbed
   into while it is blank. */
fieldset.vacant {
  visibility: hidden;
}

legend,
.label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  padding: 0;
  margin-bottom: 8px;
}

.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.choice {
  flex: 1 1 auto;
  border: 1px solid var(--line);
  background: transparent;
  color: inherit;
  border-radius: 9px;
  padding: 9px 14px;
  font: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.choice:hover {
  border-color: var(--accent);
}

.choice[aria-pressed="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  font-weight: 600;
}

input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  color: inherit;
  font: inherit;
}

.primary {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 10px;
  background: var(--ink);
  color: var(--panel);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.primary:hover {
  opacity: 0.9;
}

.primary:disabled {
  opacity: 0.5;
  cursor: default;
}

/* The three ways to start. Same game, different guest list, so they are three
   buttons rather than a question with an answer to pick first. */
.starts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.starts button {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.starts small {
  font-weight: 400;
  font-size: 12px;
  opacity: 0.75;
}

.starts .secondary {
  border: 1px solid var(--line);
  background: transparent;
  color: inherit;
}

.starts .secondary:hover {
  border-color: var(--accent);
}

.starts button:disabled {
  opacity: 0.5;
  cursor: default;
}

.rules {
  color: var(--muted);
  font-size: 14px;
}

.rules h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  margin: 0 0 8px;
}

.rules ul {
  margin: 0;
  padding-left: 18px;
}

.rules li {
  margin-bottom: 5px;
}

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

/* Chat on the left at a fixed width, the table in the middle taking what is
   left, the game's own panels on the right. Placement is by area, so the
   columns can be rearranged for a narrow window without moving the markup. */
.game {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 300px;
  grid-template-areas: "chat board side";
  gap: 20px;
  align-items: start;
}

/* No room for three: the chat goes under the table, still full height. */
@media (max-width: 1140px) {
  .game {
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-areas:
      "board side"
      "chat chat";
  }
}

@media (max-width: 820px) {
  .game {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "board"
      "side"
      "chat";
  }
}

.game > .chat {
  grid-area: chat;
}

.game > .board {
  grid-area: board;
}

.game > .side {
  grid-area: side;
}

.board {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 18px;
}

/* The table everyone sits around. Seats are placed on an ellipse by script,
   with the viewer always at the bottom. */
.table {
  position: relative;
  width: 100%;
  height: 560px;
}

.table::before {
  content: "";
  position: absolute;
  inset: 8% 4%;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: color-mix(in srgb, var(--ink) 3%, transparent);
}

.seats {
  position: absolute;
  inset: 0;
}

.seat {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border: 2px solid transparent;
  border-radius: 16px;
  transition: opacity 0.2s, border-color 0.2s, background 0.2s;
}

/* Whose turn it is, said with the board rather than with words. */
.seat.active {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

.seat.out {
  opacity: 0.3;
}

/* Won it. The same treatment as the seat to move, in the other colour, so the
   end of a game reads the way the middle of one did. */
.seat.won {
  border-color: color-mix(in srgb, var(--gold) 60%, transparent);
  background: color-mix(in srgb, var(--gold) 10%, transparent);
}

/* A winner who did not live to see it - an outlaw whose side took it anyway -
   is still worth being able to see. */
.seat.out.won {
  opacity: 0.75;
}

.seat-head {
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: 200px;
  font-size: 14px;
}

.seat-head b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-head .tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.dot.on {
  background: #48b06a;
}

/* A role the viewer is allowed to know: their own, the sheriff's all game, and
   everybody's once it is over. */
.role {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
  color: var(--muted);
}

.role.sheriff {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 50%, var(--line));
}

.role.deputy {
  color: var(--mine);
  border-color: color-mix(in srgb, var(--mine) 50%, var(--line));
}

.role.outlaw {
  color: var(--theirs);
  border-color: color-mix(in srgb, var(--theirs) 50%, var(--line));
}

.role.renegade {
  color: var(--ink);
  border-color: var(--ink);
}

.clock {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 13px;
}

.clock.running {
  border-color: var(--accent);
  color: var(--accent);
}

.clock.low {
  border-color: var(--theirs);
  color: var(--theirs);
}

.hands {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.hand {
  border: 2px solid var(--line);
  border-radius: 16px;
  background: transparent;
  color: var(--theirs);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0;
  font: inherit;
  cursor: default;
}

.hand.mine {
  color: var(--mine);
  border-color: color-mix(in srgb, var(--mine) 45%, var(--line));
}

/* Nothing in it - drawn as an outline whether or not it can come back. */
.hand.empty {
  border-style: dashed;
}

/* And out of the game for good: no partner to split, so it stays empty. */
.hand.dead {
  opacity: 0.32;
}

.hand .count {
  position: absolute;
  right: 7px;
  bottom: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.hand.pickable {
  cursor: pointer;
}

.hand.pickable:hover {
  border-color: var(--accent);
}

.hand.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

.hand.target {
  border-color: var(--accent);
  border-style: dashed;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  cursor: pointer;
}

.hand.last {
  background: color-mix(in srgb, var(--accent) 7%, transparent);
}

.middle {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(340px, 80%);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.status {
  font-weight: 600;
}

.status.dim {
  color: var(--muted);
  font-weight: 400;
  font-style: italic;
}

/* Six seats will not fit on an ellipse on a phone, so the table unrolls into
   a plain column with the viewer last. */
.table.stacked {
  height: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.table.stacked::before {
  display: none;
}

.table.stacked .seats {
  position: static;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.table.stacked .seat {
  position: static;
  transform: none;
}

.table.stacked .middle {
  position: static;
  transform: none;
  width: auto;
  order: 99;
}

/* --- throwing ------------------------------------------------------------ */

.throw {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.steppers {
  display: flex;
  gap: 22px;
}

.stepper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.stepper .hand {
  color: var(--mine);
  border-color: color-mix(in srgb, var(--mine) 45%, var(--line));
}

.pm {
  display: flex;
  gap: 8px;
}

.pm button {
  width: 34px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.pm button:hover:not(:disabled) {
  border-color: var(--accent);
}

.pm button:disabled {
  opacity: 0.35;
  cursor: default;
}

.hint {
  color: var(--muted);
  font-size: 14px;
  min-height: 21px;
  text-align: center;
}

/* The two waits with a deadline on them: the lobby filling itself, and the
   opening being thrown for you. */
.countdown {
  /* Inline-block so the pill is as wide as its own text, centred by the
     middle's own text-align rather than stretched across it. */
  display: inline-block;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  font-size: 15px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 12px;
  margin-bottom: 6px;
}

.countdown.low {
  border-color: var(--theirs);
  color: var(--theirs);
}

/* --- sidebar ------------------------------------------------------------- */

.side {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px;
}

/* A fixed box, like the chat: the panel does not grow as the game does, and the
   heading stays put while the list under it scrolls. */
.history {
  display: flex;
  flex-direction: column;
  height: 260px;
  font-size: 14px;
}

.history .label {
  flex: none;
}

.history ol {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  padding-left: 0;
  /* Only moves are numbered - the openings are the position play started from,
     not a move - so the number is a counter rather than the list's marker. */
  list-style: none;
  counter-reset: move;
}

.history li.move .line::before {
  counter-increment: move;
  content: counter(move) ".";
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* A hairline where the openings end and play begins. */
.history li.opening + li.move {
  border-top: 1px solid var(--line);
  padding-top: 4px;
  margin-top: 4px;
}

.history li {
  margin-bottom: 3px;
  color: var(--ink);
}

/* Names, words and drawn hands on one line, wrapping in a narrow panel. The
   row is a span inside the item rather than the item itself, since a list item
   laid out as a flex box loses its number. */
.history li .line {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  vertical-align: top;
}

.history li .word {
  color: var(--muted);
}

/* The same colours as the board: your hands green, everyone else's rust. */
.history .glyph {
  flex: none;
  color: var(--theirs);
}

.history .glyph.mine {
  color: var(--mine);
}

.history .glyph.dead {
  opacity: 0.38;
}

.history li:not(:last-child) {
  opacity: 0.72;
}

/* --- chat ---------------------------------------------------------------- */

/* The same height as the table beside it, whatever is in it: the box for saying
   something stays where you last saw it rather than walking down the page as
   the conversation grows. */
.chat {
  display: flex;
  flex-direction: column;
  height: 596px;
}

@media (max-width: 1140px) {
  .chat {
    height: 320px;
  }
}

.chat-log {
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
  /* The log takes all the room left over, so lines fill from the top and the
     scrollbar appears only once they reach the bottom. */
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  font-size: 14px;
}

/* The two things pinned under it keep their own size. */
.chat-say,
.chat .hint {
  flex: none;
}

.chat-log li {
  margin-bottom: 4px;
  /* A long line wraps under its own name rather than pushing the panel wide. */
  overflow-wrap: anywhere;
}

.chat-log b {
  color: var(--muted);
  font-weight: 600;
  margin-right: 6px;
}

.chat-log b.mine {
  color: var(--mine);
}

.chat-say {
  display: flex;
  gap: 6px;
}

.chat-say input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: inherit;
  font: inherit;
}

.chat-say input:focus {
  outline: none;
  border-color: var(--accent);
}

.chat-say button {
  padding: 8px 12px;
  border: 1px solid var(--accent);
  border-radius: 9px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.actions {
  display: flex;
  /* One line, always: the row is a fixed set of slots, not a paragraph. */
  flex-wrap: nowrap;
  gap: 8px;
}

.actions button {
  /* A zero basis makes every button in the row exactly the same width, so a
     label that changes - or a button that replaces another - never moves the
     row about. */
  flex: 1 1 0;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.actions button:hover {
  border-color: var(--accent);
}

.actions button.go {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* Already offered. Shown as a pressed button rather than by relabelling it,
   which would change the button's width for no reason. */
.actions button.offered {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}

/* Somebody is waiting on this button. A slow pulse says so without taking up a
   line of text - and holds still for anyone who would rather it did not move. */
@keyframes waiting-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

.actions button.waiting {
  animation: waiting-pulse 1.8s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .actions button.waiting {
    animation: none;
    background: color-mix(in srgb, var(--accent) 16%, transparent);
  }
}

.invite {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.invite input {
  font-size: 13px;
}

.result {
  text-align: center;
}

.result h2 {
  margin: 0 0 4px;
  font-size: 19px;
}

.result p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.watchers {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--panel);
  padding: 10px 16px;
  border-radius: 9px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.toast.show {
  opacity: 1;
}
