/* Village Storybook: parchment, ink, a blood-red accent and double-rule borders.
   Mobile portrait first; every tap target is at least 44px. */

:root {
  --parchment: #f1e6cc;
  --parchment-light: #f8f1de;
  --parchment-deep: #e5d3aa;
  --ink: #2b2118;
  --ink-soft: #5e4b37;
  --accent: #a3312a;
  --accent-deep: #82241f;
  --rule: #6b4e2e;
  --rule-faint: rgba(107, 78, 46, 0.35);
  --shade: rgba(43, 33, 24, 0.55);
  --stripe-a: #e7d8b5;
  --stripe-b: #efe2c4;
  /* Paper grain plus a soft lamp-lit glow; the page and the help layer share it. */
  --paper:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.42 0 0 0 0 0.31 0 0 0 0 0.18 0 0 0 0.14 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E"),
    radial-gradient(ellipse at 50% -10%, var(--parchment-light) 0%, transparent 65%);

  --font-display: 'IM Fell English', 'Pridi', Georgia, serif;
  --font-code: 'IM Fell English', Georgia, serif;
  --font-body: 'Pridi', Georgia, serif;

  --tap: 48px;
  --radius: 4px;
  --gutter: 16px;
  color-scheme: light;
}

/* IM Fell has no Thai glyphs: Thai headings use Pridi throughout. */
html[lang='th'] {
  --font-display: 'Pridi', Georgia, serif;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--parchment);
}

body {
  display: flow-root; /* keeps the frame’s margin inside, so a full-height screen doesn’t scroll */
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  color: var(--ink);
  background-color: var(--parchment);
  background-image: var(--paper);
  font: 400 17px/1.55 var(--font-body);
  overflow-wrap: break-word;
  -webkit-tap-highlight-color: transparent;
}

html[lang='th'] body { line-height: 1.7; }

button, a, input, select, label { touch-action: manipulation; }

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- page frame ---- */

.page {
  position: relative;
  max-width: 34rem;
  min-height: calc(100vh - 16px);
  min-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  margin: 8px max(8px, calc((100% - 34rem) / 2));
  padding: 0 var(--gutter) 24px;
  border: 3px double var(--rule);
  border-radius: 14px;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding-top: 68px;
}

.screen-center {
  min-height: 60vh;
  justify-content: center;
  text-align: center;
}

.lang-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: flex;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--parchment-light);
}

.lang-toggle button {
  min-width: 50px;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 600 15px/1 var(--font-body);
  letter-spacing: 0.06em;
  cursor: pointer;
}

.lang-toggle button.is-on {
  background: var(--ink);
  color: var(--parchment);
}

.corner-btn {
  position: absolute;
  top: 10px;
  left: 10px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--rule-faint);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font: 400 15px/1 var(--font-body);
  cursor: pointer;
}

a.corner-btn {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.page-title {
  margin: 0;
  font: 400 34px/1.15 var(--font-display);
  color: var(--accent);
  text-align: center;
}

html[lang='th'] .page-title { font-weight: 600; font-size: 28px; }

.hint {
  margin: 0;
  color: var(--ink-soft);
  font-size: 15px;
  text-align: center;
}

.resuming {
  margin: 0;
  color: var(--ink-soft);
  font: italic 400 21px/1.4 var(--font-display);
}

html[lang='th'] .resuming { font-style: normal; font-size: 18px; }

/* Chapter heading flanked by a thin double rule, echoing the frame. */
.chapter {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 10px;
  font: 400 23px/1.25 var(--font-display);
  text-align: center;
}

html[lang='th'] .chapter { font-weight: 600; font-size: 20px; }

.chapter::before,
.chapter::after {
  content: '';
  flex: 1;
  min-width: 16px;
  height: 4px;
  border-block: 1px solid var(--rule);
}

/* ---- controls ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 20px;
  border: 1px solid var(--accent-deep);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--parchment);
  box-shadow: inset 0 0 0 3px var(--accent), inset 0 0 0 4px rgba(241, 230, 204, 0.55);
  font: 600 18px/1.2 var(--font-body);
  text-align: center;
  cursor: pointer;
}

.btn:active:not([disabled]) {
  background: var(--accent-deep);
  box-shadow: inset 0 0 0 3px var(--accent-deep), inset 0 0 0 4px rgba(241, 230, 204, 0.55);
}

.btn-quiet {
  border-color: var(--rule);
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 3px var(--parchment), inset 0 0 0 4px var(--rule-faint);
}

.btn-quiet:active:not([disabled]) {
  background: var(--parchment-deep);
  box-shadow: inset 0 0 0 3px var(--parchment-deep), inset 0 0 0 4px var(--rule-faint);
}

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

.btn-small {
  align-self: center;
  width: auto;
  min-height: 44px;
  padding: 8px 18px;
  font-size: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: start;
}

.field-label {
  color: var(--ink-soft);
  font-size: 15px;
}

input,
select {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background-color: var(--parchment-light);
  color: var(--ink);
  box-shadow: inset 0 1px 2px rgba(43, 33, 24, 0.12);
  font: 400 18px/1.3 var(--font-body); /* 16px or more stops iOS zooming on focus */
}

input::placeholder {
  color: var(--ink-soft);
  opacity: 0.65;
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 40px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink) 50%),
    linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 21px) 50%, calc(100% - 15px) 50%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
}

.help-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 28px;
}

.help-links a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--rule-faint);
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
}

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

.home {
  gap: 22px;
  text-align: center;
}

.emblem {
  margin: 0 auto -6px;
  color: var(--accent);
  line-height: 0;
}

.emblem .star { fill: var(--ink); }

.title {
  margin: 0;
  color: var(--accent);
  font: 400 clamp(2.5rem, 12vw, 3.4rem)/1.02 var(--font-display);
  text-wrap: balance;
}

html[lang='th'] .title {
  font-weight: 600;
  font-size: clamp(2.1rem, 10vw, 2.8rem);
  line-height: 1.25;
}

.tagline {
  margin: -8px 0 6px;
  color: var(--ink-soft);
  font: italic 400 19px/1.4 var(--font-display);
}

html[lang='th'] .tagline {
  font-style: normal;
  font-size: 16px;
}

.join-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  text-align: start;
}

.create-form { margin: 0; }

.join-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.join-row .btn {
  width: auto;
  padding-inline: 24px;
}

.code-input {
  padding: 6px 0 6px 0.32em;
  font: 400 28px/1 var(--font-code);
  letter-spacing: 0.32em;
  text-align: center;
  text-transform: uppercase;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  color: var(--ink-soft);
  font-size: 15px;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 4px;
  border-block: 1px solid var(--rule-faint);
}

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

.code-block { text-align: center; }

.code-label {
  margin: 0;
  color: var(--ink-soft);
  font-size: 15px;
}

.room-code {
  margin: 0;
  padding-left: 0.2em; /* balances the trailing letter-spacing */
  font: 400 64px/1.05 var(--font-code);
  letter-spacing: 0.2em;
}

.qr {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 14px 0 0;
}

.qr img {
  display: block;
  width: 176px;
  height: 176px;
  padding: 8px;
  border: 3px double var(--rule);
  border-radius: 6px;
  mix-blend-mode: multiply; /* the QR's white ground becomes parchment */
}

.qr figcaption {
  color: var(--ink-soft);
  font-size: 15px;
}

.warning {
  margin: 14px 0 0;
  padding: 12px 14px;
  border: 1px dashed var(--accent);
  border-radius: var(--radius);
  background: rgba(163, 49, 42, 0.06);
  color: var(--accent-deep);
  font-size: 15px;
  text-align: start;
  overflow-wrap: anywhere;
}

.players {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  column-gap: 18px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Big groups: two columns so the deck isn't pushed far below. */
.players:has(> li:nth-child(11)) {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.players:has(> li:nth-child(11)) .player-tag {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.player {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 46px;
  border-bottom: 1px dashed var(--rule);
}

.seat {
  flex: none;
  min-width: 1.5em;
  color: var(--ink-soft);
  font: 400 16px/1 var(--font-body);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.player-name {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player.is-me .player-name { font-weight: 600; }

.player.is-offline .player-name,
.player.is-offline .seat { opacity: 0.45; }

.player-tag {
  flex: none;
  color: var(--ink-soft);
  font-size: 14px;
}

/* A bot's seat is marked so nobody mistakes it for a phone. */
.tag-bot { color: var(--ink); }

.host-mark { flex: none; }

/* The moderator's row shows a microphone where the seat number would be. */
.seat.mod-mark { text-align: center; }

/* Normal / Moderator: two joined options, one lit. */
.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 2px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}

.mode-option {
  min-height: var(--tap);
  padding: 6px 10px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 600 17px/1.2 var(--font-body);
  cursor: pointer;
}

.mode-option + .mode-option { border-left: 2px solid var(--rule); }

.mode-option.is-on {
  background: var(--accent);
  color: var(--parchment-light);
}

.mode-switch + .hint { margin-top: 8px; }

.kick {
  flex: none;
  width: 44px;
  height: 44px;
  margin-left: auto;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--accent);
  font: 400 26px/1 var(--font-body);
  cursor: pointer;
}

.deck-count {
  margin: 0 0 4px;
  font: 600 20px/1.3 var(--font-body);
  text-align: center;
}

section > .hint + .hint,
section > .hint + .btn-small { margin-top: 6px; }

section > .btn-small { display: flex; margin-inline: auto; }

.deck-editor {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.deck-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 54px;
  border-bottom: 1px dashed var(--rule);
}

.role-name {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: 400 19px/1.2 var(--font-display);
  text-align: start;
  cursor: pointer;
}

.role-label {
  text-decoration: underline dotted var(--rule-faint);
  text-underline-offset: 5px;
}

.role-icon {
  flex: none;
  width: 30px;
  font-size: 22px;
  line-height: 1;
  text-align: center;
}

.deck-row.is-empty .role-name { color: var(--ink-soft); }
.deck-row.is-empty .role-icon { opacity: 0.5; filter: grayscale(1); }

.stepper {
  display: flex;
  flex: none;
  align-items: center;
  gap: 4px;
}

.step {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--parchment-light);
  color: var(--ink);
  font: 400 24px/1 var(--font-body);
  cursor: pointer;
}

.step:active:not([disabled]) { background: var(--parchment-deep); }

.step[disabled] {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Pridi's lining figures: IM Fell's old-style 1 and 0 read as I and o. */
.count {
  min-width: 2ch;
  font: 600 21px/1 var(--font-body);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.deck-row:not(.is-empty) .count { color: var(--accent); }

.deck-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 6px 14px 6px 10px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--parchment-light);
  color: var(--ink);
  font: 400 17px/1.2 var(--font-display);
  cursor: pointer;
}

.chip .role-icon {
  width: auto;
  font-size: 18px;
}

.chip-count {
  color: var(--accent);
  font: 600 15px/1 var(--font-body);
}

.settings {
  display: grid;
  gap: 14px;
}

.setting-read {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 12px;
  margin: 0;
  padding: 10px 0;
  border-bottom: 1px dashed var(--rule);
}

/* Start bar stays in reach while the host scrolls a long lobby (and on game screens). */
.lobby-foot,
.game-foot {
  position: sticky;
  bottom: 0;
  z-index: 1;
  display: grid;
  gap: 8px;
  margin: 0 calc(-1 * var(--gutter)) -24px;
  padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom));
  border-top: 3px double var(--rule);
  border-radius: 0 0 11px 11px;
  background: var(--parchment);
  text-align: center;
}

.deck-status {
  margin: 0;
  font-size: 16px;
}

.deck-status.is-bad { color: var(--accent); }

.waiting {
  margin: 0;
  padding: 6px 0;
  color: var(--ink-soft);
  font: italic 400 19px/1.4 var(--font-display);
}

html[lang='th'] .waiting {
  font-style: normal;
  font-size: 17px;
}

/* ---- game screens ---- */

/* Game screens fill the frame so a short screen's foot sits on its bottom edge. */
.page:has(> .game) {
  display: flex;
  flex-direction: column;
}

.game {
  flex: 1;
  gap: 22px;
}

.game-foot { margin-top: auto; }

.lead {
  margin: 0;
  font-size: 18px;
  text-align: center;
}

.kicker {
  margin: 0;
  color: var(--ink-soft);
  font-size: 15px;
  text-align: center;
}

.foot-count {
  margin: 0;
  font: 600 17px/1.3 var(--font-body);
  font-variant-numeric: tabular-nums;
}

.game-foot .hint { font-size: 14px; }

/* Countdown: lining figures, and a bar that shrinks from the right. */
.timer {
  display: grid;
  gap: 6px;
}

.timer-text {
  font: 600 28px/1 var(--font-body);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.timer-bar {
  height: 8px;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--parchment-deep);
}

.timer-fill {
  display: block;
  height: 100%;
  background: var(--accent);
  transform-origin: left center;
  transition: transform 0.25s linear;
}

/* Hold-to-peek card: back and face share one grid cell, so holding never changes its size. */
.peek {
  display: grid;
  min-height: 200px;
  border: 2px solid var(--rule);
  border-radius: 12px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

.peek > * {
  grid-area: 1 / 1;
  min-width: 0;
  border-radius: 10px;
}

.peek-back {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 18px;
  background: repeating-linear-gradient(45deg, var(--stripe-a) 0 10px, var(--stripe-b) 10px 20px);
  box-shadow: inset 0 0 0 6px var(--parchment-light), inset 0 0 0 7px var(--rule-faint);
  text-align: center;
}

.peek-moon {
  color: var(--accent);
  font-size: 44px;
  line-height: 1;
}

.peek-hint { font: 600 18px/1.3 var(--font-body); }

.peek-sub {
  color: var(--ink-soft);
  font-size: 14px;
}

.peek-face {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 18px 16px;
  overflow: hidden;
  background: var(--parchment-light);
  visibility: hidden;
}

.peek.is-peeking .peek-face { visibility: visible; }

.peek-note {
  margin: 0;
  color: var(--ink-soft);
  text-align: center;
}

.entries + .peek-note { margin-top: 12px; }

.deal .peek { min-height: min(52vh, 340px); }

.role-face {
  display: grid;
  gap: 6px;
  text-align: center;
}

.role-face-icon {
  font-size: 64px;
  line-height: 1.1;
}

.role-face-name {
  margin: 0;
  color: var(--accent);
  font: 400 32px/1.15 var(--font-display);
}

html[lang='th'] .role-face-name { font-weight: 600; font-size: 28px; }

.role-face-ability {
  margin: 4px 0 0;
  font-size: 18px;
}

/* Night entries (results, "My night", the dawn log). */
.entries {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  text-align: start;
}

.entry {
  display: flex;
  gap: 10px;
}

.entry-icon {
  flex: none;
  width: 1.6em;
  text-align: center;
}

/* Name tiles: two columns, so 30 names stay short enough to scan. */
.picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.picker-center { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.pick {
  width: 100%;
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--parchment-light);
  color: var(--ink);
  font: 400 17px/1.25 var(--font-body);
  overflow-wrap: anywhere;
  cursor: pointer;
}

.pick.is-picked {
  border-color: var(--accent-deep);
  background: var(--accent);
  color: var(--parchment);
  font-weight: 600;
}

.pick.is-offline:not(.is-picked) { color: var(--ink-soft); }

.pick[disabled] { cursor: not-allowed; opacity: 0.6; }

.picker-label {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 15px;
  text-align: center;
}

/* Night: one board size for every phone, whatever it holds. It takes the height the wake
   call, timer and stars leave, so a short phone still sees every part of it. */
.night { gap: 14px; }

/* Smaller wake call, so most fit one line and the stars stay above the fold. */
.night .page-title { font-size: 28px; }

.night-board {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  gap: 10px;
  min-height: 300px;
  max-height: 540px;
  padding: 12px;
  border: 3px double var(--rule);
  border-radius: 10px;
  background: var(--parchment);
}

/* Fixed at four lines on every phone: only its words differ. An actor's info and what to do
   now stack inside it. Auto margins centre the lines but give way when a long werewolf list
   overflows, so the box then scrolls from the top. */
.night-prompt {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: center;
  height: calc(4 * 1.45 * 15px);
  margin: 0;
  overflow-y: auto;
  font-size: 15px;
  line-height: 1.45;
  text-align: center;
}

.night-prompt > :first-child { margin-top: auto; }
.night-prompt > :last-child { margin-bottom: auto; }
.night-prompt.is-dense > * { font-size: 13px; }

.night-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow-y: auto; /* only if the center cards alone outgrow it */
}

/* Only the player list scrolls; the center cards stay in view under it. */
.night-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.night-center {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 6px;
}

.night-center .picker-label { margin: 0; }

.night-main > .peek {
  flex: 1;
  min-height: 0;
}

.night .peek-face { font-size: 16px; }

.night-actions {
  display: grid;
  flex: none;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  gap: 10px;
}

.stars {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}

.star {
  min-height: 52px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--parchment-light);
  color: var(--rule);
  font: 400 22px/1 var(--font-body);
  cursor: pointer;
}

.star:active {
  background: var(--ink);
  color: var(--parchment);
}

@media (max-width: 359px) {
  .stars { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Short phones (iPhone SE and the like): tighter spacing leaves the player list more room. */
@media (max-height: 700px) {
  .night { gap: 8px; }
  .night .page-title { font-size: 24px; }
  .night-board { padding: 10px; gap: 8px; }
  .star { min-height: 44px; }
}

/* Day */
.day .peek { min-height: 180px; }

/* Dawn */
.verdict {
  display: grid;
  gap: 8px;
  padding: 16px;
  border: 3px double var(--rule);
  border-radius: 10px;
  background: var(--parchment-light);
  text-align: center;
}

.verdict p { margin: 0; }

.verdict-win {
  color: var(--accent);
  font: 400 26px/1.2 var(--font-display);
}

html[lang='th'] .verdict-win { font-weight: 600; font-size: 22px; }

.verdict-dead { font-size: 17px; }

.badge {
  justify-self: center;
  padding: 4px 16px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font: 600 16px/1.4 var(--font-body);
}

.badge.is-won {
  border-color: var(--accent-deep);
  background: var(--accent);
  color: var(--parchment);
}

.badge.is-lost { color: var(--ink-soft); }

.final-cards {
  margin: 0;
  padding: 0;
  list-style: none;
}

.final-row {
  display: grid;
  gap: 2px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--rule);
}

.final-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
}

.final-name { font-weight: 600; }

.final-row.is-me .final-name { text-decoration: underline; text-underline-offset: 4px; }
.final-row.is-dead .final-name { color: var(--accent); }

.tag {
  padding: 0 8px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 13px;
  line-height: 1.6;
}

.tag-dead { color: var(--accent); }
.tag-won { color: var(--ink); }
.tag-lost { color: var(--ink-soft); }

.final-card,
.center-card {
  display: flex;
  align-items: center;
  gap: 8px;
  font: 400 19px/1.3 var(--font-display);
}

.card-icon { flex: none; }

.final-card { flex-wrap: wrap; row-gap: 0; }

/* The card this player was dealt, quieter than the final card beside it. */
.card-dealt {
  color: var(--ink-soft);
  font: 400 15px/1.3 var(--font-body);
}

.final-vote {
  margin: 0;
  color: var(--ink-soft);
  font-size: 15px;
}

.final-vote > span + span::before {
  content: '·';
  margin: 0 8px;
}

.center-cards {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.center-card {
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--parchment-light);
}

/* ---- popup and role card ---- */

.popup {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow-y: auto;
  background: var(--shade);
  animation: fade-in 0.15s ease-out;
}

.popup-box {
  display: grid;
  gap: 18px;
  width: min(100%, 22rem);
  padding: 22px 20px 18px;
  border: 3px double var(--rule);
  border-radius: 12px;
  background: var(--parchment);
  box-shadow: 0 14px 40px rgba(20, 14, 8, 0.4);
  animation: rise 0.18s ease-out;
}

.role-card {
  display: grid;
  gap: 6px;
  text-align: center;
}

.role-card-icon {
  font-size: 60px;
  line-height: 1.1;
}

.role-card-name {
  margin: 0;
  color: var(--accent);
  font: 400 30px/1.15 var(--font-display);
}

html[lang='th'] .role-card-name {
  font-weight: 600;
  font-size: 26px;
}

/* The role's name in the other language: IM Fell for English, Pridi for Thai. */
.role-card-alt {
  margin: -2px 0 0;
  color: var(--ink-soft);
  font: italic 400 19px/1.3 'IM Fell English', Georgia, serif;
}

.role-card-alt:lang(th) { font: 400 16px/1.5 var(--font-body); }

.role-card-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px 12px;
  margin: 4px 0 0;
}

.role-card-team {
  padding: 2px 12px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 14px;
}

.team-village .role-card-team { color: var(--ink); }
.team-werewolf .role-card-team { color: var(--accent); }
.team-tanner .role-card-team,
.team-copies .role-card-team { color: var(--rule); }

.role-card-wake {
  color: var(--ink-soft);
  font-size: 14px;
}

.role-card-ability {
  margin: 8px 0 0;
  font-size: 18px;
  line-height: 1.5;
  text-wrap: balance;
}

/* Extra rules (the lone wolf, the Doppelgänger's copies), set off by dashed rules. */
.role-card-note {
  display: grid;
  gap: 8px;
  margin: 6px 0 0;
  padding: 10px 2px;
  border-block: 1px dashed var(--rule);
  font-size: 16px;
  text-align: start;
}

.role-card-note p { margin: 0; }

.role-card-cases {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 1.2em;
}

.role-card-tip {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 15px;
  text-align: start;
}

.role-card strong,
.howto-section strong {
  color: var(--accent-deep);
  font-weight: 600;
}

/* ---- help: How to Play and the Role Guide ---- */

/* A full-screen layer over the current screen, which keeps running underneath. It sits under
   popups (10), the reconnect banner (15) and toasts (20). */
.help-layer {
  position: fixed;
  inset: 0;
  z-index: 8;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background-color: var(--parchment);
  background-image: var(--paper);
}

.help-layer:focus { outline: none; }

html.help-open,
html.help-open body { overflow: hidden; }

.help { gap: 24px; }

.help > .help-links { margin-top: -18px; }

.howto-section p { margin: 0 0 12px; }

.howto-section p:last-child { margin-bottom: 0; }

/* Storybook drop cap on the opening line. English only: a Thai first letter would be split
   from its vowel and tone marks. */
html[lang='en'] .howto-section:first-of-type p:first-of-type::first-letter {
  float: left;
  margin: 6px 8px 0 0;
  color: var(--accent);
  font: 400 3.4em/0.8 var(--font-display);
}

.role-index {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.role-guide {
  display: grid;
  gap: 18px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.role-guide > li { scroll-margin-top: 12px; }

.role-guide .role-card {
  padding: 20px 16px 18px;
  border: 3px double var(--rule);
  border-radius: 10px;
  background: var(--parchment-light);
}

/* ---- messages ---- */

.toast {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 16px;
  right: 16px;
  z-index: 20;
  max-width: 30rem;
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--parchment);
  box-shadow: 0 8px 24px rgba(20, 14, 8, 0.35);
  font: 400 16px/1.45 var(--font-body);
  cursor: pointer;
  animation: rise 0.18s ease-out;
}

.toast[hidden] { display: none; }

.conn-banner {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  left: 16px;
  right: 16px;
  z-index: 15;
  max-width: 30rem;
  margin: 0 auto;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--accent-deep);
  color: var(--parchment);
  font-size: 15px;
  text-align: center;
}

@keyframes fade-in {
  from { opacity: 0; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
}

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

/* ---- moderator screens ---- */

/* The line the moderator reads aloud. */
.mod-say {
  margin: 0;
  padding: 12px 14px;
  border-left: 4px solid var(--accent);
  background: var(--parchment-light);
  font: italic 400 20px/1.4 var(--font-display);
}

html[lang='th'] .mod-say { font-style: normal; font-size: 18px; }

.cards-view .peek { min-height: 120px; }

.cards-face { padding: 4px 0; text-align: start; }

.cards-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.cards-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0 10px;
  padding: 4px 2px;
  border-bottom: 1px dashed var(--rule-faint);
  font-size: 14px;
  line-height: 1.3;
}

.cards-name { font-weight: 600; overflow-wrap: anywhere; }
.cards-cards { margin-inline-start: auto; text-align: end; }

.cards-head {
  margin: 10px 0 0;
  font: 600 16px/1.3 var(--font-body);
  color: var(--accent-deep);
}

.vote-rows {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.vote-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: var(--tap);
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--parchment-light);
  color: var(--ink);
  font: 400 17px/1.25 var(--font-body);
  text-align: start;
  cursor: pointer;
}

.vote-row.is-empty .vote-target { color: var(--ink-soft); }
.vote-voter { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.vote-target { min-width: 0; text-align: end; overflow-wrap: anywhere; }

.vote-pop { display: grid; gap: 12px; }
.vote-pop .chapter { margin: 0; text-align: center; }

/* Show card: a full-screen layer held up to a player. Result only. Above popups, under toasts. */
.show-layer {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 24px;
  overflow-y: auto;
  background-color: var(--parchment);
  background-image: var(--paper);
  text-align: center;
  cursor: pointer;
}

.show-face { display: grid; gap: 6px; }
.show-label { margin: 0; color: var(--ink-soft); font: 600 20px/1.3 var(--font-body); }
.show-icon { font-size: 96px; line-height: 1.1; }
.show-name { margin: 0; color: var(--accent); font: 400 40px/1.15 var(--font-display); overflow-wrap: anywhere; }
html[lang='th'] .show-name { font-weight: 600; font-size: 34px; }

/* After the first tap: a face-down cover, nothing on it but how to go on. */
.show-layer.is-cover {
  background: repeating-linear-gradient(45deg, var(--stripe-a) 0 10px, var(--stripe-b) 10px 20px);
  box-shadow: inset 0 0 0 10px var(--parchment-light), inset 0 0 0 11px var(--rule-faint);
}

.show-cover { display: grid; gap: 14px; justify-items: center; max-width: 20rem; }
.show-moon { color: var(--accent); font-size: 72px; line-height: 1; }
.show-cover-text { margin: 0; font: 600 22px/1.45 var(--font-body); }

/* Night script. Everything down to Back / Next fills the first screen (the frame's top edge
   and the screen's top padding come off the viewport height); the cards view and End round
   wait below the fold. On a long step Back / Next stick to the bottom edge.
   Every Werewolf moderator screen (.cmod) is laid out the same way, with the table below. */
.mod-night,
.cmod { gap: 0; }

.mod-night-main,
.cmod-main {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: calc(100vh - 79px);
  min-height: calc(100dvh - 79px - env(safe-area-inset-top));
}

.mod-night .page-title,
.cmod .page-title { font-size: 28px; }

html[lang='th'] .mod-night .page-title,
html[lang='th'] .cmod .page-title { font-size: 25px; }

.mod-script { display: grid; gap: 4px; }

.mod-say-label {
  margin: 0;
  color: var(--accent-deep);
  font: 600 13px/1.3 var(--font-body);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

html[lang='th'] .mod-say-label { font-size: 14px; letter-spacing: 0; }

.mod-say p { margin: 0; }

.mod-say p + p {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--rule-faint);
}

/* For the moderator's eyes only: labelled, plain, never styled like a line to read out. */
.mod-note {
  display: grid;
  gap: 2px;
  padding: 8px 12px;
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.45;
}

.mod-note p { margin: 0; }

.mod-note-label {
  color: var(--ink-soft);
  font: 600 12px/1.3 var(--font-body);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

html[lang='th'] .mod-note-label { font-size: 13px; letter-spacing: 0; }

.mod-note .mod-awake {
  color: var(--ink);
  font: 600 16px/1.4 var(--font-body);
}

.mod-board {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 3px double var(--rule);
  border-radius: 10px;
  background: var(--parchment);
}

.mod-board-name {
  margin: 0;
  font-weight: 600;
  text-align: center;
}

.mod-board-center { display: grid; gap: 6px; }
.mod-board-center .picker-label { margin: 0; }

.mod-board-actions {
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  gap: 10px;
}

.mod-shows { display: grid; gap: 8px; }

.mod-show {
  flex-direction: column;
  gap: 0;
}

.mod-show-what {
  color: var(--ink-soft);
  font: 400 14px/1.3 var(--font-body);
}

.mod-night-nav,
.cmod-nav {
  position: sticky;
  bottom: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  gap: 10px;
  margin: auto calc(-1 * var(--gutter)) 0;
  padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom));
  border-top: 3px double var(--rule);
  background: var(--parchment);
}

.mod-night-more,
.cmod-more {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-top: 24px;
}

/* Werewolf moderator screens with one move (Start night, Start the vote, Reveal, Next). */
.cmod-nav.is-single { grid-template-columns: minmax(0, 1fr); }
.cmod-nav .foot-count { text-align: center; }

.mod-board > .picker-label { margin: 0; }

/* The dawn note: each death's real cause, set like the note around it. */
.mod-note .deaths { gap: 4px; }
.mod-note .death { color: var(--ink); font-size: 15px; }

/* The table: the dead struck through, then the potions and the Bodyguard's last pick. */
.cards-row.is-dead { color: var(--ink-soft); }
.cards-row.is-dead .table-name { text-decoration: line-through; }

.table-fact {
  margin: 8px 0 0;
  font-size: 14px;
  line-height: 1.35;
}

/* Werewolf settings: a labelled on/off switch. */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: var(--tap);
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.switch {
  position: relative;
  flex: none;
  width: 52px;
  height: 30px;
  border: 2px solid var(--rule);
  border-radius: 15px;
  background: transparent;
}

.switch-knob {
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--rule);
  transition: inset-inline-start 0.15s;
}

.switch.is-on { background: var(--accent); border-color: var(--accent-deep); }
.switch.is-on .switch-knob { inset-inline-start: 25px; background: var(--parchment-light); }

/* The help pages' One Night / Werewolf tabs. */
.help-game { margin-bottom: 18px; }

/* ---- Werewolf (full game) screens ---- */

/* Role card face: the team sits under the name. */
.role-face-team {
  margin: 0;
  color: var(--ink-soft);
  font-size: 15px;
}

.role-face.team-werewolf .role-face-team { color: var(--accent); }

.out .peek { min-height: min(52vh, 340px); }

/* The Witch's button looks the same on every phone: a box that fills when it's on. */
.night-toggle {
  display: flex;
  flex: none;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--parchment-light);
  color: var(--ink);
  font: 600 17px/1.25 var(--font-body);
  text-align: start;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.night-toggle-box {
  flex: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--rule);
  border-radius: 3px;
  background: var(--parchment);
}

.night-toggle.is-on {
  border-color: var(--accent-deep);
  background: var(--accent);
  color: var(--parchment);
}

.night-toggle.is-on .night-toggle-box {
  border-color: var(--parchment-light);
  background: var(--parchment-light);
  box-shadow: inset 0 0 0 3px var(--accent);
}

.night-toggle[disabled] { cursor: not-allowed; opacity: 0.6; }

.night-main > .picker-label { flex: none; margin: 0; }

/* The vote's "No one" spans the row under the players. */
.picker-none { grid-template-columns: minmax(0, 1fr); }

/* Dawn and verdict announcements. */
.announce {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  border: 3px double var(--rule);
  border-radius: 10px;
  background: var(--parchment-light);
}

.announce-title {
  margin: 0;
  color: var(--accent);
  font: 400 21px/1.2 var(--font-display);
  text-align: center;
}

html[lang='th'] .announce-title { font-weight: 600; font-size: 19px; }

.announce-none {
  margin: 0;
  font-size: 17px;
  text-align: center;
}

.deaths {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.death {
  display: flex;
  gap: 10px;
  font-size: 17px;
}

.tag-role {
  display: inline-block;
  color: var(--ink);
  white-space: nowrap;
}

/* Who is still alive, and the dead. */
.people {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.person {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 6px;
  max-width: 100%;
  padding: 2px 10px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--parchment-light);
  font-size: 15px;
  overflow-wrap: anywhere;
}

.person.is-me .person-name { font-weight: 600; }

.person.is-dead {
  border-style: dashed;
  background: transparent;
  color: var(--ink-soft);
}

.person.is-dead .person-name { text-decoration: line-through; }

.person .tag-role {
  padding: 0;
  border: 0;
  color: var(--ink-soft);
  font-size: 13px;
}

.people-head {
  margin: 12px 0 6px;
  color: var(--ink-soft);
  font: 600 15px/1.3 var(--font-body);
}

/* My info: your role, what you hold, and what you learned, night by night. */
.my-info {
  display: grid;
  gap: 6px;
  text-align: start;
}

.my-role {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--accent);
  font: 400 22px/1.2 var(--font-display);
}

html[lang='th'] .my-role { font-weight: 600; font-size: 20px; }

.my-role-icon { flex: none; font-size: 30px; }

.my-ability,
.my-fact {
  margin: 0;
  font-size: 15px;
}

.my-ability { color: var(--ink-soft); }

.log-head {
  margin: 8px 0 4px;
  color: var(--ink-soft);
  font: 600 15px/1.3 var(--font-body);
}

.entry-label {
  margin-inline-end: 6px;
  color: var(--ink-soft);
  font-weight: 600;
}

/* Votes, one "A → B" line each. */
.vote-lines {
  margin: 0;
  padding: 0;
  list-style: none;
}

.vote-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: baseline;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--rule-faint);
}

.vote-from { font-weight: 600; overflow-wrap: anywhere; }
.vote-arrow { color: var(--ink-soft); }
.vote-to { text-align: end; overflow-wrap: anywhere; }
.vote-line.is-empty .vote-to { color: var(--ink-soft); }

/* Lobby, host only: the Testing section is folded until opened. */
.testing {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--parchment-light);
}

.testing > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 8px 14px;
  font: 600 17px/1.3 var(--font-body);
  list-style: none;
  cursor: pointer;
}

.testing > summary::-webkit-details-marker { display: none; }

.testing > summary::before {
  content: '';
  flex: none;
  border-block: 6px solid transparent;
  border-inline-start: 9px solid var(--rule);
  transition: transform 0.15s;
}

.testing[open] > summary::before { transform: rotate(90deg); }

.testing-body { padding: 0 14px 12px; }

/* Day 2 on: yesterday's vote, folded under one line until someone taps it. */
.last-vote {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--parchment-light);
}

.last-vote > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 8px 14px;
  font: 600 17px/1.3 var(--font-body);
  list-style: none;
  cursor: pointer;
}

.last-vote > summary::-webkit-details-marker { display: none; }

/* A small triangle that turns down when the section is open. */
.last-vote > summary::before {
  content: '';
  flex: none;
  border-block: 6px solid transparent;
  border-inline-start: 9px solid var(--rule);
  transition: transform 0.15s;
}

.last-vote[open] > summary::before { transform: rotate(90deg); }

.last-vote-body {
  display: grid;
  gap: 4px;
  padding: 0 14px 10px;
}

.last-vote-body > .announce {
  padding: 4px 0 8px;
  border: 0;
  border-bottom: 1px solid var(--rule-faint);
  border-radius: 0;
  background: none;
}

.log-day > .entries,
.log-day > .hint { margin-top: 8px; text-align: start; }

.log-day + .log-day,
.log-night + .log-night { margin-top: 12px; }

/* The Hunter's shot. */
.hunter-actions {
  display: grid;
  gap: 10px;
}

.tag-lover { color: var(--accent); }
