/* Tessera Live -- shared board and controllers.
   Palette and type match the pass-and-play games so the two modes read as one
   product. Fonts fall back to system faces; no CDN. */

:root {
  --paper: #f4efe6;
  --paper-deep: #ebe3d4;
  --ink: #1a2238;
  --ink-soft: #3d4a6b;
  --ink-faint: #8590a8;
  --rule: #d6cdb9;
  --gold: #b08428;
  --gold-deep: #8a651a;
  --crimson: #8b2942;
  --shadow: rgba(26, 34, 56, 0.08);
  --shadow-strong: rgba(26, 34, 56, 0.18);

  --p-0: #6b4a7a; /* aubergine */
  --p-1: #2c5f6f; /* deep teal  */
  --p-2: #a64b2a; /* terracotta */
  --p-3: #4f6b3a; /* moss       */
  --p-4: #8b3a4f; /* wine       */
  --p-5: #c08a2e; /* ochre      */

  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #161b29;
    --paper-deep: #1f2737;
    --ink: #f1ece1;
    --ink-soft: #b9b6ad;
    --ink-faint: #6f7891;
    --rule: #2c3447;
    --shadow: rgba(0, 0, 0, 0.35);
    --shadow-strong: rgba(0, 0, 0, 0.55);
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.wrap {
  max-width: 62rem;
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2.5rem);
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; }
h1 { font-size: clamp(2rem, 5vw, 3rem); letter-spacing: 0.01em; }
h2 { font-size: clamp(1.4rem, 3vw, 2rem); }

.smallcaps {
  font-variant-caps: all-small-caps;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
  font-size: 0.85rem;
}

.card {
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  padding: clamp(1rem, 3vw, 1.75rem);
  box-shadow: 0 1px 3px var(--shadow);
}

.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }

button, .btn {
  font: inherit;
  font-weight: 600;
  padding: 0.7rem 1.25rem;
  border-radius: 0.35rem;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  min-height: 2.75rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button:hover, .btn:hover { border-color: var(--gold); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--gold);
  border-color: var(--gold-deep);
  color: #1a1408;
}
.btn-primary:hover { background: var(--gold-deep); color: var(--paper); }

input[type="text"] {
  font: inherit;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--rule);
  border-radius: 0.35rem;
  background: var(--paper);
  color: var(--ink);
  min-height: 2.75rem;
  width: 100%;
}

.code-display {
  font-family: var(--serif);
  font-size: clamp(2.5rem, 9vw, 5rem);
  font-weight: 700;
  letter-spacing: 0.22em;
  text-align: center;
  color: var(--gold-deep);
}
@media (prefers-color-scheme: dark) { .code-display { color: var(--gold); } }

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-size: 1.5rem;
  text-align: center;
}

.join-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: clamp(1rem, 4vw, 2.5rem);
  align-items: center;
}
@media (max-width: 40rem) { .join-grid { grid-template-columns: 1fr; } }

.qr { width: clamp(9rem, 26vw, 15rem); height: auto; background: #fff; padding: 0.6rem; border-radius: 0.4rem; }

.seat-list { list-style: none; display: grid; gap: 0.5rem; }
.seat {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--rule);
  border-radius: 0.35rem;
  background: var(--paper);
}
.seat-swatch { width: 1.1rem; height: 1.1rem; border-radius: 0.2rem; flex: none; }
.seat-name { font-weight: 600; }
.seat-status { margin-left: auto; font-size: 0.85rem; color: var(--ink-faint); }
.seat.disconnected { opacity: 0.55; }
.seat.is-you { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }

.empty { color: var(--ink-faint); font-style: italic; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 0.7rem 1.1rem;
  border-radius: 0.35rem;
  box-shadow: 0 4px 14px var(--shadow-strong);
  max-width: min(30rem, calc(100vw - 2rem));
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
  z-index: 50;
}
.toast.show { opacity: 1; }

.conn {
  position: fixed;
  top: 0.6rem;
  right: 0.6rem;
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  color: var(--ink-faint);
}
.conn.online { color: var(--p-3); }
.conn.offline { color: var(--crimson); }

/* --- the shared board ------------------------------------------------ */

.board {
  display: grid;
  grid-template-columns: repeat(var(--n, 12), 1fr);
  grid-template-rows: repeat(var(--n, 12), 1fr);
  gap: 2px;
  background: var(--rule);
  border: 2px solid var(--rule);
  border-radius: 0.35rem;
  aspect-ratio: 1;
  width: 100%;
  touch-action: manipulation;
}

.cell {
  background: var(--paper);
  border-radius: 1px;
  position: relative;
}
.cell.filled { border-radius: 2px; }
.cell.pending { outline: 2px solid var(--gold); outline-offset: -2px; }

/* Placement preview on the controller's mini board. */
.cell.preview-valid { background: var(--gold); opacity: 0.75; }
.cell.preview-invalid { background: var(--crimson); opacity: 0.55; }

/* `margin: 0 auto` centres the frame, but auto inline margins also switch a
   grid item from stretch to fit-content sizing -- and a grid of empty cells has
   no intrinsic width, so on the play screen (where the frame is a grid item)
   the board collapsed to the width of its own gaps. An explicit width keeps it
   stretched; the auto margins then only centre the max-width-capped box. */
.board-frame { width: 100%; max-width: min(78vh, 100%); margin: 0 auto; }

/* --- the draft pool --------------------------------------------------- */

.pool {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(3.25rem, 1fr));
  gap: 0.5rem;
}

.piece-card {
  font: inherit;
  border: 1px solid var(--rule);
  border-radius: 0.35rem;
  background: var(--paper);
  padding: 0.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 3.25rem;
  cursor: pointer;
  touch-action: manipulation;
}
.piece-card.taken, .piece-card:disabled { opacity: 0.3; cursor: default; }
/* The board's pool is display-only; do not imply it is pressable. */
.piece-card:disabled:hover { border-color: var(--rule); }
.piece-card.selected { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }

.mini { display: grid; gap: 1px; }
.mini-cell { width: 100%; aspect-ratio: 1; border-radius: 1px; }
.mini-cell.on { background: var(--ink-soft); }
.mini-cell.off { background: transparent; }

/* --- turn and scoreboard ---------------------------------------------- */

.scoreboard { display: grid; gap: 0.4rem; }
.score-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.6rem;
  border-radius: 0.3rem;
  border: 1px solid transparent;
}
.score-row.active { border-color: var(--gold); background: var(--paper); }
.score-row .pts { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.score-row .left { color: var(--ink-faint); font-size: 0.85rem; }

.turn-banner {
  padding: 0.75rem 1rem;
  border-radius: 0.35rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  font-weight: 600;
}
.turn-banner.yours { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }

.objective { border-left: 3px solid var(--gold); padding-left: 0.85rem; }
.objective h3 { font-size: 1.25rem; }
.objective p { color: var(--ink-soft); }

.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.actions button { flex: 1 1 auto; }

/* --- forms -------------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field label { font-weight: 600; font-size: 0.9rem; }

select, textarea {
  font: inherit;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--rule);
  border-radius: 0.35rem;
  background: var(--paper);
  color: var(--ink);
  width: 100%;
  min-height: 2.75rem;
}
textarea { resize: vertical; }

input:focus-visible, select:focus-visible, textarea:focus-visible,
button:focus-visible, a:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.field-error { color: var(--crimson); font-size: 0.85rem; }
.form-error {
  color: var(--crimson);
  border: 1px solid var(--crimson);
  border-radius: 0.35rem;
  padding: 0.7rem 0.85rem;
  background: color-mix(in srgb, var(--crimson) 8%, transparent);
}

/* Hidden from people, filled by form-spraying bots. Positioned off-screen
   rather than display:none, which some bots skip. */
.honeypot {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* --- legal documents ---------------------------------------------------- */

.legal-content {
  max-width: 44rem;
  margin-top: 1.5rem;
}
.legal-content h2 {
  font-size: 1.3rem;
  margin: 2rem 0 0.6rem;
}
.legal-content h3 {
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 700;
  margin: 1.25rem 0 0.4rem;
}
.legal-content p, .legal-content ul { color: var(--ink-soft); }
.legal-content p + p { margin-top: 0.75rem; }
.legal-content ul { margin: 0.6rem 0 0.6rem 1.25rem; }
.legal-content li { margin-bottom: 0.3rem; }

/* --- footer ------------------------------------------------------------- */

footer {
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  color: var(--ink-faint);
  font-size: 0.85rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  justify-content: space-between;
}
footer nav { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; }

a { color: var(--gold-deep); }
@media (prefers-color-scheme: dark) { a { color: var(--gold); } }
