:root {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --ink: #2b2723;
  --muted: #7c736a;
  --line: #d9d2c6;
  --mine: #2f6f4f;
  --mine-soft: #2f6f4f22;
  --theirs: #9a4a34;
  --accent: #1f6feb;
  --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;
    --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;
}

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

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

.home-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr;
  max-width: 560px;
  margin: 0 auto;
}

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

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;
}

.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 --------------------------------------------------------- */

.game {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
  align-items: start;
}

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

.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.idle {
  opacity: 0.45;
}

.seat.out {
  opacity: 0.3;
}

.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;
}

.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));
}

.hand.dead {
  opacity: 0.32;
  border-style: dashed;
}

.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;
}

.history {
  max-height: 260px;
  overflow-y: auto;
  font-size: 14px;
}

.history ol {
  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 ---------------------------------------------------------------- */

.chat-log {
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
  max-height: 180px;
  overflow-y: auto;
  font-size: 14px;
}

.chat-log:empty {
  margin: 0;
}

.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;
  flex-wrap: wrap;
  gap: 8px;
}

.actions button {
  flex: 1 1 auto;
  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;
}

/* 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;
}
