@font-face {
  font-family: "Anek Latin";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("./fonts/anek-latin-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Anek Latin";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("./fonts/anek-latin-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --table: #18121c;
  --table-deep: #0f0b12;
  --paper: #f8f2e9;
  --paper-muted: #cec4c0;
  --coral: #f07163;
  --coral-dark: #cf5148;
  --plum: #2a1e31;
  --line: rgba(248, 242, 233, .16);
  --line-strong: rgba(248, 242, 233, .32);
  --field-line: rgba(248, 242, 233, .42);
  --danger: #ff9a8e;
  --focus: #fff1a8;
}

* { box-sizing: border-box; }

html { background: var(--table-deep); scroll-padding-bottom: 6rem; }

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 88% 6%, rgba(240, 113, 99, .11), transparent 30rem),
    radial-gradient(circle at 4% 100%, rgba(89, 62, 105, .3), transparent 34rem),
    var(--table-deep);
  color: var(--paper);
  font-family: "Anek Latin", "Avenir Next", Avenir, "Helvetica Neue", Helvetica, Arial, sans-serif;
  word-spacing: .1em;
  -webkit-font-smoothing: antialiased;
}

/* Form controls reset word-spacing by default; they follow the body like any other text. */
button, input, select { font: inherit; word-spacing: inherit; }
button, input, select { min-height: 48px; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

/* The shell spans the viewport and clips the full-width start dock; the stage is the centred column. */
.app-shell { min-height: 100dvh; overflow-x: clip; }
.game-stage { --stage-pad: clamp(1.35rem, 5vw, 2.75rem); width: min(100%, 42rem); min-height: 100dvh; margin: 0 auto; padding: var(--stage-pad); display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 44px; margin-bottom: clamp(1.25rem, 6vh, 4rem); }
.brand { margin: 0; color: var(--paper); font-size: 1.15rem; font-weight: 800; letter-spacing: -.02em; }
.screen { flex: 1; display: flex; flex-direction: column; width: 100%; }

.eyebrow {
  overflow-wrap: anywhere;
  margin: 0 0 .8rem;
  color: var(--coral);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 {
  max-width: 11ch;
  margin-bottom: 1.2rem;
  color: var(--paper);
  font-size: clamp(2.75rem, 13vw, 5.6rem);
  font-weight: 700;
  line-height: .98;
  letter-spacing: -.025em;
}
h2 { margin-bottom: .15rem; color: var(--paper); font-size: 1.15rem; font-weight: 700; letter-spacing: -.01em; }
.screen--setup h1 { max-width: none; margin-bottom: .5rem; font-size: clamp(2rem, 8.5vw, 3rem); }
.screen--setup .lead { margin-bottom: 1rem; }
.lead { max-width: 32rem; margin-bottom: 1.5rem; color: var(--paper-muted); font-size: clamp(1rem, 4.2vw, 1.15rem); line-height: 1.48; }
.stack { display: grid; gap: 1rem; }

.setup-form { flex: 1; display: flex; flex-direction: column; gap: 1rem; }
.setup-section { display: grid; gap: .9rem; padding: 1.25rem 0; border-top: 1px solid var(--line); }
.setup-section:last-of-type { border-bottom: 1px solid var(--line); }
.player-row { position: relative; display: grid; grid-template-columns: 2.75rem minmax(0, 1fr) 2.75rem; gap: .35rem; align-items: start; }
.player-drag-handle {
  display: grid;
  place-items: center;
  min-width: 44px;
  border: 0;
  border-radius: .85rem;
  background: transparent;
  color: var(--paper-muted);
  padding: 0;
  touch-action: none;
}
.player-drag-handle:hover { background: rgba(255, 255, 255, .06); color: var(--paper); }
.player-row[data-dragging] { opacity: .45; }
.player-row[data-drop-target]::before { position: absolute; top: -.45rem; right: 0; left: 0; height: 2px; border-radius: 99px; background: var(--coral); content: ''; }
label { display: grid; gap: .5rem; color: var(--paper-muted); font-size: .85rem; font-weight: 600; letter-spacing: .015em; }
input, select {
  width: 100%;
  border: 1px solid var(--field-line);
  border-radius: .85rem;
  background: rgba(255, 255, 255, .05);
  color: var(--paper);
  padding: .75rem .85rem;
  font-weight: 500;
}
input::placeholder { color: var(--paper-muted); opacity: .8; }
option { color: #1a151d; background: var(--paper); }
.field-pair { display: grid; gap: .9rem; }
.field-help { margin: 0; color: var(--paper-muted); font-size: .9rem; line-height: 1.45; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

.button {
  width: 100%;
  border: 1px solid transparent;
  border-radius: .9rem;
  background: var(--paper);
  color: var(--table-deep);
  padding: .82rem 1rem;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .005em;
  text-align: center;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}
.button:hover { transform: translateY(-1px); background: #fff; }
.button--accent { border-color: var(--coral); background: var(--coral); color: #251319; }
.button--accent:hover { background: #ff897a; }
.button--quiet { width: auto; border-color: var(--line-strong); background: transparent; color: var(--paper); }
.button--quiet:hover { border-color: var(--paper); background: rgba(255, 255, 255, .08); }
.button--text { width: auto; min-height: auto; align-self: center; background: transparent; color: var(--paper-muted); padding: .45rem .2rem; font-size: .95rem; font-weight: 600; }
.button--text:hover { background: transparent; color: var(--paper); transform: none; }
.button--danger { color: var(--danger); }
.screen-actions { display: grid; gap: .65rem; margin-top: auto; padding-top: 1.5rem; }
/* The start button stays in reach as a dock at the bottom edge while the form scrolls underneath. */
.screen-actions--sticky { position: sticky; bottom: 0; z-index: 1; margin-bottom: calc(-1 * var(--stage-pad)); padding: .5rem 0 max(1rem, env(safe-area-inset-bottom)); }
.screen-actions--sticky::before { position: absolute; inset: -1.5rem calc(-1 * var(--stage-pad)) 0; z-index: -1; background: linear-gradient(to bottom, rgba(15, 11, 18, 0), var(--table-deep) 1.5rem); content: ''; pointer-events: none; }

.error { margin: 0; line-height: 1.45; }

.role-card {
  min-height: clamp(19rem, 52dvh, 31rem);
  display: grid;
  align-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
  border: 1px solid var(--line);
  border-radius: 1.75rem;
  padding: 1.5rem;
  background: linear-gradient(145deg, rgba(61, 45, 70, .92), rgba(20, 14, 24, .98));
  box-shadow: 0 1.4rem 4rem rgba(0, 0, 0, .25), inset 0 1px rgba(255, 255, 255, .08);
  color: var(--paper);
  text-align: center;
}
.role-card > p { margin: 0; }

/* Jaali lattice: the card carries it face down (handover), face up (role) and in the final reveal. */
.role-card, .card-back, .result-card { position: relative; overflow: hidden; isolation: isolate; }
.role-card::before, .card-back::before, .result-card::before { position: absolute; inset: 0; z-index: -1; background: url("./jaali.svg") center / 46px 46px; content: ''; pointer-events: none; }
/* Face up, the lattice clears towards the middle so that it never competes with the word. */
.role-card::before, .result-card::before {
  -webkit-mask-image: radial-gradient(ellipse 74% 62% at 50% 50%, transparent 34%, #000 100%);
  mask-image: radial-gradient(ellipse 74% 62% at 50% 50%, transparent 34%, #000 100%);
}
.card-back, .result-card {
  border: 1px solid var(--line);
  border-radius: 1.75rem;
  background: linear-gradient(145deg, rgba(42, 30, 49, .96), rgba(15, 11, 18, .99));
  box-shadow: 0 1.4rem 4rem rgba(0, 0, 0, .25), inset 0 1px rgba(255, 255, 255, .08);
}
.card-back { flex: 1 1 6rem; min-height: 6rem; max-height: 22rem; }
.result-card { display: grid; gap: .6rem; padding: 1.75rem 1.5rem; text-align: center; }
.role-card, .result-card { animation: card-open 180ms ease-out both; }
@keyframes card-open { from { opacity: 0; transform: scale(.97); } }
.role-card--citizen { background: linear-gradient(145deg, rgba(42, 30, 49, .96), rgba(15, 11, 18, .99)); border-color: var(--line); color: var(--paper); }
.role-word { margin: 0; font-size: clamp(2rem, 10vw, 4rem); font-weight: 700; line-height: 1.08; letter-spacing: -.02em; overflow-wrap: anywhere; hyphens: auto; text-wrap: balance; }
.role-label { margin: 0; color: var(--paper-muted); font-size: .78rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.role-card:not(.role-card--citizen) .role-label { color: var(--coral); }
.role-card--citizen .role-label { color: var(--paper-muted); }

.player-choice { display: grid; gap: .55rem; }
.player-choice .button { border-color: var(--line); background: rgba(255, 255, 255, .04); color: var(--paper); text-align: left; }
.player-choice .button:hover { border-color: var(--coral); background: rgba(240, 113, 99, .12); }

.result-stage { margin-bottom: 1rem; padding: 1.25rem 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.result-stage--reveal { padding-top: 0; border-top: 0; }
.vote-result { margin: 0; color: var(--paper); font-size: clamp(2.75rem, 13vw, 5rem); font-weight: 700; line-height: .98; letter-spacing: -.025em; }
.vote-result--imposter { color: var(--coral); }
.result-list { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }
.result-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .85rem 0; border-bottom: 1px solid var(--line); }
.result-list li:last-child { border-bottom: 0; }
.status { color: var(--paper-muted); }
.status--imposter { color: var(--coral); font-weight: 700; }
.divider { height: 1px; margin: .5rem 0; background: var(--line); }

@media (min-width: 42rem) {
  .game-stage { --stage-pad: 2.75rem; padding: var(--stage-pad) 3.5rem; }
  .screen-actions--sticky::before { right: -100vmax; left: -100vmax; }
  .role-card { padding: 2.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

input { font-size: 16px; }
select { font-size: 16px; }
.team-summary { margin: 0; color: var(--paper-muted); line-height: 1.5; }
.legal-links { display: flex; justify-content: center; gap: 1rem; margin-top: auto; padding-top: .5rem; }
.legal-links + .screen-actions { margin-top: 0; }
.legal-links a { display: inline-flex; align-items: center; min-height: 44px; color: var(--paper-muted); font-size: .8rem; }
.legal-links a:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.remove-player { width: 44px; min-width: 44px; border-color: transparent; color: var(--paper-muted); padding: .5rem; display: grid; place-items: center; }
.remove-player:hover { border-color: transparent; background: rgba(255, 255, 255, .06); color: var(--danger); transform: none; }
.error { color: var(--danger); }
.field-error { font-size: .85rem; font-weight: 500; line-height: 1.4; letter-spacing: normal; }
[aria-invalid="true"] { border-color: var(--danger); }
summary { cursor: pointer; min-height: 48px; padding: .75rem 0; font-weight: 600; }
.rules { display: grid; }
.rules section { padding: 1rem 0; border-top: 1px solid var(--line); }
.rules h2 { margin-bottom: .4rem; }
.rules p { max-width: 34rem; margin: 0; color: var(--paper-muted); line-height: 1.5; }
/* The storage note is a footnote to the rules, not a fourth rule block. */
.rules-note { max-width: 34rem; margin: 1.25rem 0 0; color: var(--paper-muted); font-size: .9rem; line-height: 1.5; }
details .stack { padding: .5rem 0; }
.screen:focus { outline: none; }
h1, .result-list li, .player-choice button { overflow-wrap: anywhere; }
.button--text { min-height: 44px; }
@media (max-width: 36rem) { h1 { font-size: clamp(2.5rem, 11vw, 3.7rem); } .setup-section { padding: .9rem 0; gap: .65rem; } }
@media (min-width: 30rem) { .field-pair { grid-template-columns: 1fr 1fr; } }
