/* ---------------------------------------------------------------- tokens */
/*
 * The wedding's palette after dark: a warm espresso ground with cream text,
 * kept dark on purpose for a projector in a dim room and for older eyes at a
 * distance. The hues are lifted straight from the wedding site — terracotta is
 * the action colour on the buttons, gold is the one elegant highlight (the
 * timer, the join code, the winner), with sage and a burgundy-rose filling out
 * the answer set.
 *
 * Answer colours are paired with a shape glyph everywhere they appear, so
 * guests who cannot separate the sage from the terracotta still have a reliable
 * handle on which button is which.
 */

:root {
  --ink: #201a12;        /* deep espresso ground */
  --base: #2d2417;       /* cards and inputs */
  --raised: #3a3021;     /* raised surfaces */
  --edge: #574734;       /* warm borders */
  --lamp: #c9a24c;       /* gold — the highlight: timer, join code, scores */
  --terracotta: #c15a2f; /* the action colour, as on the wedding site's buttons */
  --alert: #d5593a;      /* urgency — the closing timer and error text */
  --text: #f4efe4;       /* wedding cream */
  --muted: #c6b59b;      /* warm tan for secondary text */

  --opt-0: #c9a24c;      /* gold */
  --opt-1: #8f9d6f;      /* sage */
  --opt-2: #d67e52;      /* terracotta */
  --opt-3: #c17784;      /* dusty rose, from the burgundy */

  /* The wedding's own typefaces: Cormorant Garamond for display, EB Garamond
     for body. Both are serifs — the whole invitation is set this way. */
  --display: 'Cormorant Garamond', 'Hoefler Text', Georgia, 'Times New Roman', serif;
  --body: 'EB Garamond', Georgia, 'Times New Roman', serif;

  --gap: clamp(0.75rem, 2vw, 1.5rem);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--text);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  /* Phones get poked repeatedly and quickly. Nothing here should select,
     zoom, or bounce under a hurried thumb. */
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, .numeral {
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: 0;
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

:focus-visible {
  outline: 3px solid var(--lamp);
  outline-offset: 3px;
}

.hidden { display: none !important; }

/* ----------------------------------------------------------- scaffolding */

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: var(--gap);
  /* Keep the answer grid clear of the iOS home bar and notch. */
  padding-bottom: max(var(--gap), env(safe-area-inset-bottom));
  min-height: 0;
}

.screen--center {
  justify-content: center;
  align-items: center;
  text-align: center;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  width: 100%;
  max-width: 24rem;
}

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.875rem;
  flex: none;
}

.topbar strong {
  color: var(--text);
  font-weight: 600;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  text-align: left;
}

.field > span {
  color: var(--muted);
  font-size: 0.875rem;
}

.field input,
.field textarea {
  font: inherit;
  width: 100%;
  padding: 0.875rem 1rem;
  color: var(--text);
  background: var(--base);
  border: 2px solid var(--edge);
  border-radius: var(--radius);
}

.field textarea {
  resize: vertical;
  min-height: 5.5rem;
  line-height: 1.5;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--lamp);
  outline: none;
}

.field input.code {
  font-family: var(--display);
  font-size: 2rem;
  text-align: center;
  letter-spacing: 0.3em;
  padding-left: 0.3em; /* re-centre against the trailing letter-space */
}

.btn {
  padding: 1rem 1.25rem;
  min-height: 3.25rem;
  font-weight: 600;
  background: var(--terracotta);
  color: #fff;
  border-radius: var(--radius);
  transition: transform 0.08s ease;
}

.btn:active { transform: scale(0.985); }

.btn--quiet {
  background: transparent;
  color: var(--text);
  box-shadow: inset 0 0 0 2px var(--edge);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.notice {
  min-height: 1.4em;
  color: var(--alert);
  font-size: 0.9375rem;
  text-align: left;
}

/* ------------------------------------------------------------ join code */

.code-display {
  font-family: var(--display);
  font-size: clamp(3.5rem, 13vw, 9rem);
  line-height: 1;
  letter-spacing: 0.06em;
  color: var(--lamp);
}

.code-caption {
  color: var(--muted);
  max-width: 28rem;
}

.code-caption b {
  color: var(--text);
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* ---------------------------------------------------------- answer grid */
/*
 * The phone is a buzzer, not a screen. Four targets, each about a fifth of
 * the viewport, reachable without looking down — the question itself is on
 * the big screen where everyone can read it together.
 */

.grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.625rem;
  min-height: 0;
}

.opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem;
  border-radius: var(--radius);
  background: var(--tint);
  color: #241c12;
  font-weight: 600;
  text-align: center;
  transition: transform 0.08s ease, opacity 0.2s ease;
}

.opt:nth-child(1) { --tint: var(--opt-0); }
.opt:nth-child(2) { --tint: var(--opt-1); }
.opt:nth-child(3) { --tint: var(--opt-2); }
.opt:nth-child(4) { --tint: var(--opt-3); }

.opt:active { transform: scale(0.97); }

.opt__glyph {
  font-size: 1.5rem;
  line-height: 1;
}

.opt__label {
  font-size: clamp(0.9375rem, 3.4vw, 1.25rem);
  overflow-wrap: anywhere;
}

/* Odd option counts: last button spans the row rather than leaving a hole. */
.grid[data-count='2'] { grid-template-columns: 1fr; }
.grid[data-count='3'] .opt:nth-child(3) { grid-column: span 2; }

.grid.is-locked .opt { opacity: 0.25; }
.grid.is-locked .opt.is-mine { opacity: 1; }

/* The question on the phone, for guests who can't see the big screen. Capped so
   a long question scrolls instead of squeezing the answer buttons off. */
.player-question {
  flex: none;
  margin: 0;
  text-align: center;
  text-wrap: balance;
  font-size: clamp(1.4rem, 6.5vw, 2.1rem);
  line-height: 1.25;
  max-height: 42vh;
  overflow-y: auto;
}

.player-question:empty { display: none; }

/* On the answering screen, sit the question a touch lower and hold a clear gap
   above the buttons so it reads as a prompt, not a label on the grid. */
#screen-question .player-question {
  margin-top: 0.5rem;
  margin-bottom: var(--gap);
}

/* ---------------------------------------------------------------- result */

.result {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  text-align: center;
  border-radius: var(--radius);
  padding: var(--gap);
  background: var(--base);
}

.result--good { background: #37432b; }
.result--bad { background: #452029; }

.result__headline { font-size: clamp(1.75rem, 7vw, 3rem); }
.result__points { font-family: var(--display); font-size: 2.5rem; color: var(--lamp); }
.result__detail { color: var(--muted); }

/* ----------------------------------------------------------- host: timer */
/*
 * The single loud element on the whole site. A lamp burning down.
 */

.timer {
  flex: none;
  height: 0.75rem;
  border-radius: 99px;
  background: var(--base);
  overflow: hidden;
}

.timer__fill {
  height: 100%;
  width: 100%;
  background: var(--lamp);
  transform-origin: left center;
  box-shadow: 0 0 24px rgba(201, 162, 76, 0.55);
}

.timer.is-urgent .timer__fill { background: var(--alert); box-shadow: none; }

/* ------------------------------------------------------------ host: body */

.question {
  font-size: clamp(1.75rem, 4.6vw, 3.75rem);
  line-height: 1.12;
  text-wrap: balance;
  flex: none;
}

.host-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--gap);
  min-height: 0;
}

.host-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.625rem;
}

.host-opt {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.875rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  background: var(--base);
  box-shadow: inset 0 0 0 2px var(--edge);
  font-size: clamp(1rem, 1.9vw, 1.5rem);
}

.host-opt__glyph { color: var(--tint); font-size: 1.5rem; line-height: 1; }
.host-opt:nth-child(1) { --tint: var(--opt-0); }
.host-opt:nth-child(2) { --tint: var(--opt-1); }
.host-opt:nth-child(3) { --tint: var(--opt-2); }
.host-opt:nth-child(4) { --tint: var(--opt-3); }

.host-opt__count {
  font-family: var(--display);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.host-opt.is-correct {
  background: var(--tint);
  color: #241c12;
  box-shadow: none;
  animation: land 0.32s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.host-opt.is-correct .host-opt__glyph,
.host-opt.is-correct .host-opt__count { color: #241c12; }

@keyframes land {
  from { transform: scale(0.94); }
  to { transform: scale(1); }
}

.note {
  font-family: var(--display);
  font-size: clamp(1.125rem, 2.2vw, 1.625rem);
  color: var(--lamp);
  text-wrap: balance;
  flex: none;
}

/* -------------------------------------------------------------- roster */

.roster {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  align-content: flex-start;
  overflow-y: auto;
  min-height: 0;
  flex: 1;
}

.chip {
  padding: 0.5rem 0.875rem;
  border-radius: 99px;
  background: var(--raised);
  font-size: clamp(0.9375rem, 1.6vw, 1.25rem);
}

.chip.is-away { opacity: 0.4; }

.empty {
  color: var(--muted);
  font-family: var(--display);
  font-size: 1.375rem;
  margin: auto;
}

/* --------------------------------------------------------- leaderboard */

.board {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
  max-width: 34rem;
  margin-inline: auto;
}

.row {
  display: grid;
  grid-template-columns: 2.5rem 1fr auto;
  align-items: baseline;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--base);
  text-align: left;
}

.row:first-child {
  background: var(--raised);
  box-shadow: inset 0 0 0 2px var(--lamp);
}

.row__rank,
.row__score {
  font-family: var(--display);
  font-variant-numeric: tabular-nums;
}

.row__rank { color: var(--muted); }
.row__name { font-size: clamp(1rem, 2.2vw, 1.5rem); overflow-wrap: anywhere; }
.row__score { color: var(--lamp); font-size: clamp(1rem, 2.2vw, 1.5rem); }

.row.is-you { box-shadow: inset 0 0 0 2px var(--opt-1); }

/* ----------------------------------------------------------- host chrome */

.host-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex: none;
}

.status {
  color: var(--muted);
  font-size: 0.9375rem;
}

.status.is-warning { color: var(--lamp); }

.answered {
  font-family: var(--display);
  font-size: clamp(1.25rem, 3vw, 2rem);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.answered b { color: var(--text); }

@media (min-width: 60rem) {
  .host-foot .btn { min-width: 14rem; }
}

@media (max-width: 30rem) {
  .host-options { grid-template-columns: 1fr; }
}

/* -------------------------------------------------------------- teams */

/* Lobby: one chip per team with a live headcount. */
.team-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  flex: none;
}

.team-tags:empty { display: none; }

.team-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.5rem 0.3rem 0.4rem;
  border-radius: 99px;
  background: var(--raised);
  box-shadow: inset 0 0 0 2px var(--edge);
  font-size: clamp(0.9375rem, 1.6vw, 1.25rem);
}

/* The table watercolour, used as an icon in tags and on the leaderboards. */
.team-ic {
  width: 2rem;
  height: 2rem;
  object-fit: contain;
  flex: none;
}

.team-ic--sm { width: 1.6rem; height: 1.6rem; }

.row__name--team {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.team-tag__count {
  min-width: 1.75rem;
  padding: 0.1rem 0.5rem;
  border-radius: 99px;
  background: var(--lamp);
  color: #241c12;
  font-family: var(--display);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

/* Player: find-your-table tiles. The header stays put and the grid scrolls,
   so a roomful of tables still fits on one phone. */
#screen-team .team-head { flex: none; text-align: center; }

.team-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
  gap: 0.625rem;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  align-content: start;
  padding-bottom: 0.25rem;
}

.team-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0.5rem;
  border-radius: var(--radius);
  background: var(--raised);
  box-shadow: inset 0 0 0 2px var(--edge);
  color: var(--text);
  font-weight: 600;
  text-align: center;
  transition: transform 0.08s ease, background 0.15s ease;
}

.team-opt__icon {
  width: 4.5rem;
  height: 4.5rem;
  object-fit: contain;
  pointer-events: none;
}

.team-opt__label {
  font-size: clamp(0.95rem, 3.6vw, 1.25rem);
  overflow-wrap: anywhere;
}

.team-opt:active { transform: scale(0.97); }
.team-opt:disabled { opacity: 0.5; }

/* Host: two leaderboards side by side, stacking when the screen is narrow. */
.boards {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  justify-content: center;
  align-items: flex-start;
  width: 100%;
}

.board-col {
  flex: 1 1 18rem;
  min-width: 0;
  max-width: 34rem;
}

.board-title {
  color: var(--muted);
  font-size: 0.9375rem;
  text-align: center;
  margin: 0 0 0.5rem;
}

/* The winning-team banner on the finish screens. */
.reward {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(1.5rem, 5vw, 2.75rem);
  color: var(--lamp);
  text-align: center;
  text-wrap: balance;
  flex: none;
  margin: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
