:root {
  --table: #1b1b1b;
  --table-2: #252525;
  --ink: #222222;
  --cream: #fffdf3;
  --paper: #fffefe;
  --grey: #9c9c9c;
  --muted: #9a9a95;
  --line: rgba(255, 253, 243, 0.14);
  --radius: 12px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: dark;
}

/* Level palettes, sampled from the PDF. */
.lvl-1 { --card-bg: #fffdf3; --card-fg: #222222; --card-mark: rgba(34, 34, 34, 0.14); }
.lvl-2 { --card-bg: #9c9c9c; --card-fg: #1f1f1f; --card-mark: rgba(31, 31, 31, 0.18); }
.lvl-3 { --card-bg: #222222; --card-fg: #fffdf3; --card-mark: rgba(255, 253, 243, 0.12); }
.lvl-inf { --card-bg: #222222; --card-fg: #fffdf3; --card-mark: rgba(156, 156, 156, 0.55); }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background: radial-gradient(120% 80% at 50% 0%, #262626 0%, var(--table) 60%) fixed, var(--table);
  color: var(--cream);
  font-family: Roboto, system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  animation: fade-in 0.35s var(--ease);
}
.center { justify-content: center; text-align: center; }
.stack { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 340px; }
.wide { width: 100%; max-width: 720px; }

/* ---------- Type ---------- */
.title {
  font-weight: 700;
  font-size: clamp(2.1rem, 9vw, 3.4rem);
  line-height: 1.12;
  letter-spacing: 0.01em;
  margin: 0 0 18px;
}
.tagline { color: var(--muted); font-weight: 500; line-height: 1.5; margin: 0 0 40px; }
.tagline em { color: var(--cream); font-weight: 700; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.16em; font-size: 0.72rem; font-weight: 700; color: var(--muted); }
h2 { font-size: 1.4rem; margin: 0; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: 1.5px solid var(--cream);
  background: var(--cream);
  color: var(--ink);
  border-radius: 999px;
  padding: 14px 22px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.15s var(--ease), background 0.15s, opacity 0.15s;
  min-height: 48px;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--cream); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--cream); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn.quiet:hover { color: var(--cream); }
.btn.small { padding: 8px 14px; min-height: 38px; font-size: 0.9rem; }
.btn:focus-visible, .card-back:focus-visible, .tab:focus-visible, .stepper button:focus-visible {
  outline: 2px solid var(--cream);
  outline-offset: 3px;
}
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn .sub { display: block; font-weight: 500; font-size: 0.78rem; opacity: 0.7; margin-top: 2px; }

/* ---------- Top bar ---------- */
.topbar {
  width: 100%;
  max-width: 720px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.topbar .brand { font-weight: 900; letter-spacing: 0.02em; white-space: nowrap; }
/* Full name where there's room; the abbreviation on phones. */
.brand-full { display: none; }
@media (min-width: 560px) {
  .brand-full { display: inline; }
  .brand-short { display: none; }
}
.icon-btn {
  appearance: none; background: transparent; border: 1.5px solid var(--line); color: var(--cream);
  width: 42px; height: 42px; border-radius: 50%; cursor: pointer; display: grid; place-items: center;
}
.icon-btn:hover { border-color: var(--cream); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- Level tabs / progress ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin: 8px 0 4px; }
.tab {
  appearance: none; cursor: pointer; border-radius: 999px; padding: 8px 14px; font-weight: 700; font-size: 0.85rem;
  border: 1.5px solid var(--line); background: transparent; color: var(--muted);
}
.tab[aria-pressed='true'] { background: var(--card-bg); color: var(--card-fg); border-color: var(--card-bg); }
.lvl-3 .tab[aria-pressed='true'], .lvl-inf .tab[aria-pressed='true'], .tab.lvl-3[aria-pressed='true'], .tab.lvl-inf[aria-pressed='true'] {
  border-color: var(--cream);
}
.tab .count { opacity: 0.6; font-weight: 500; margin-left: 4px; }

.status { text-align: center; margin: 14px 0 6px; min-height: 64px; }
.status .who { font-size: clamp(1.5rem, 6vw, 2rem); font-weight: 700; margin: 6px 0 4px; }
.status .hint { color: var(--muted); font-size: 0.95rem; }
.levels-track { display: flex; gap: 14px; justify-content: center; align-items: center; margin-top: 6px; }
.levels-track .lvl { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 0.75rem; font-weight: 700; }
.levels-track .lvl.here { color: var(--cream); }
.dot { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid currentColor; }
.dot.on { background: currentColor; }

/* ---------- Cards ---------- */
.spread {
  width: 100%;
  max-width: 720px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
  gap: 14px 10px;
  padding: 18px 6px 28px;
}
@media (min-width: 560px) { .spread { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 20px 18px; } }

.card-back {
  appearance: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  position: relative;
  aspect-ratio: 0.707;
  border-radius: 10px;
  background: var(--card-bg);
  color: var(--card-fg);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 8px 20px rgba(0, 0, 0, 0.45);
  transform: rotate(var(--rot, 0deg));
  transition: transform 0.22s var(--ease), box-shadow 0.22s var(--ease);
  animation: deal 0.45s var(--ease) backwards;
  animation-delay: var(--delay, 0ms);
}
.spread.settled .card-back { animation: none; }
.card-back:hover {
  transform: rotate(0deg) translateY(-8px) scale(1.03);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.55);
}
.lvl-3 .card-back, .lvl-inf .card-back { box-shadow: 0 0 0 1px rgba(255, 253, 243, 0.12) inset, 0 8px 20px rgba(0, 0, 0, 0.5); }

/* The half-coloured circle motif from the "connection" page. */
.motif {
  position: absolute;
  left: 50%; top: 44%;
  width: 46%; aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid var(--card-mark);
  background: linear-gradient(90deg, var(--card-mark) 50%, transparent 50%);
}
.lvl-inf .motif { background: var(--card-mark); }
.card-back .mark {
  position: absolute; left: 0; right: 0; bottom: 9%;
  font-weight: 900; font-size: 0.7rem; letter-spacing: 0.08em; opacity: 0.75;
}
.card-back .num { position: absolute; top: 7%; left: 9%; font-weight: 900; font-size: 0.85rem; opacity: 0.6; }

.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* ---------- Open card (overlay) ---------- */
#overlay {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(10, 10, 10, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 16px;
  animation: fade-in 0.25s var(--ease);
  overflow-y: auto;
}
.flip { width: min(84vw, 360px, calc(62dvh * 0.707)); aspect-ratio: 0.707; perspective: 1400px; }
.flip-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.7s var(--ease);
  animation: lift 0.35s var(--ease);
}
.flip.is-flipped .flip-inner { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 16px;
  background: var(--card-bg);
  color: var(--card-fg);
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
}
.lvl-3 .face, .lvl-inf .face { box-shadow: 0 0 0 1px rgba(255, 253, 243, 0.14) inset, 0 30px 60px rgba(0, 0, 0, 0.6); }
.face.back .mark { font-size: 0.95rem; }
.face.front {
  transform: rotateY(180deg);
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  padding: 12% 10%;
  text-align: center;
}
.question {
  font-weight: 700;
  text-transform: uppercase;
  font-size: clamp(1.05rem, 5.2vw, 1.5rem);
  line-height: 1.35;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
}
.face .foot { position: absolute; bottom: 7%; left: 0; right: 0; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; }
.face .foot em { font-style: italic; }
.face .tag {
  position: absolute; top: 7%; left: 0; right: 0;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; opacity: 0.55;
}
.open-prompt { margin: 22px 0 14px; color: var(--cream); text-align: center; font-weight: 500; max-width: 360px; line-height: 1.45; }
.open-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; opacity: 0; animation: fade-in 0.3s 0.55s var(--ease) forwards; }

/* ---------- Pages: interludes / intros ---------- */
.page {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  padding: 48px 24px max(32px, env(safe-area-inset-bottom));
  animation: fade-in 0.5s var(--ease);
  cursor: pointer;
}
.page.paper { background: var(--paper); color: var(--ink); }
.page.level { background: var(--card-bg); color: var(--card-fg); }
.page .body { max-width: 30rem; }
.page p.line {
  text-transform: uppercase; line-height: 1.55; margin: 0 0 1.3em;
  font-size: clamp(0.95rem, 3.8vw, 1.15rem);
  white-space: pre-line;
  opacity: 0; animation: rise 0.6s var(--ease) forwards;
}
.page .sig { font-weight: 700; font-size: 0.8rem; margin-top: 28px; }
.page .sig + .continue, .page .continue { margin-top: 28px; }
.page .continue { font-weight: 700; font-size: 0.8rem; letter-spacing: 0.14em; text-transform: uppercase; opacity: 0.55; background: none; border: 0; cursor: pointer; padding: 12px; color: inherit; }
.page .big { font-weight: 700; text-transform: uppercase; font-size: clamp(1.6rem, 7vw, 2.4rem); margin: 0 0 22px; }
.page .big.inf { font-size: clamp(4rem, 18vw, 6rem); color: var(--grey); font-weight: 900; }
.page .blurb { max-width: 26rem; line-height: 1.55; font-weight: 500; opacity: 0.85; margin: 0 auto; }

/* ---------- Rules ---------- */
.rules { max-width: 560px; width: 100%; line-height: 1.6; }
.rules section { border-top: 1px solid var(--line); padding: 22px 0; }
.rules h3 { margin: 0 0 10px; font-size: 1.05rem; text-transform: lowercase; }
.rules p { margin: 0 0 10px; color: #dcdad0; }
.rules .chip { display: inline-block; min-width: 26px; text-align: center; border-radius: 6px; padding: 0 6px; margin-right: 6px; font-weight: 900; background: var(--card-bg); color: var(--card-fg); }
.lvl-3 .chip, .lvl-inf .chip, .chip.lvl-3, .chip.lvl-inf { box-shadow: 0 0 0 1px var(--line) inset; }
.rules .motto { font-size: 1.4rem; font-weight: 700; margin: 0; color: var(--cream); }

/* ---------- Setup ---------- */
.stepper { display: flex; align-items: center; justify-content: center; gap: 22px; margin: 18px 0 34px; }
.stepper button {
  appearance: none; width: 56px; height: 56px; border-radius: 50%; border: 1.5px solid var(--line);
  background: transparent; font-size: 1.6rem; cursor: pointer;
}
.stepper button:hover { border-color: var(--cream); }
.stepper output { font-size: 3.4rem; font-weight: 900; min-width: 2ch; text-align: center; }

/* ---------- Custom cards ---------- */
.custom-form { display: flex; flex-direction: column; gap: 10px; margin: 14px 0 20px; }
.custom-form textarea {
  width: 100%; min-height: 92px; resize: vertical;
  background: var(--table-2); color: var(--cream); border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; font: inherit; font-size: 1rem;
}
.custom-form textarea:focus { outline: none; border-color: var(--cream); }
.custom-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.custom-list li {
  display: flex; gap: 12px; align-items: flex-start; justify-content: space-between;
  background: var(--card-bg); color: var(--card-fg); border-radius: var(--radius); padding: 14px 14px 14px 16px;
}
.lvl-3 .custom-list li, .lvl-inf .custom-list li { box-shadow: 0 0 0 1px var(--line) inset; }
.custom-list li span { text-transform: uppercase; font-weight: 700; font-size: 0.9rem; line-height: 1.4; overflow-wrap: anywhere; }
.custom-list li button {
  flex: none; appearance: none; border: 0; background: transparent; color: inherit; opacity: 0.6; cursor: pointer;
  font-size: 0.8rem; font-weight: 700; padding: 4px;
}
.custom-list li button:hover { opacity: 1; }
.note { color: var(--muted); font-size: 0.85rem; line-height: 1.5; }

/* ---------- Menu sheet ---------- */
.sheet {
  width: 100%; max-width: 360px; background: var(--table-2); border: 1px solid var(--line); border-radius: 18px;
  padding: 22px; display: flex; flex-direction: column; gap: 10px; animation: lift 0.3s var(--ease);
}
.sheet h2 { margin-bottom: 6px; }

/* ---------- Play on phones ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.field { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.field .optional { text-transform: none; letter-spacing: 0; font-weight: 500; }
.field input, .code-input {
  width: 100%; min-height: 48px;
  background: var(--table-2); color: var(--cream); border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; font: inherit; font-size: 1rem;
}
.field input:focus, .code-input:focus { outline: none; border-color: var(--cream); }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 0.85rem; margin: 10px 0 0; }
.or::before, .or::after { content: ''; flex: 1; border-top: 1px solid var(--line); }
.join-row { display: flex; gap: 10px; }
.join-row .btn { flex: none; }
.code-input {
  flex: 1; min-width: 0; text-align: center; text-transform: uppercase;
  font-size: 1.4rem; font-weight: 900; letter-spacing: 0.3em;
}
.code-input::placeholder { color: var(--muted); opacity: 0.6; }

.lobby { max-width: 380px; margin-top: 4px; }
.lobby > .eyebrow, .sheet > .eyebrow { margin: 14px 0 0; }
.invite { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.room-code { font-size: clamp(2.6rem, 14vw, 3.4rem); font-weight: 900; letter-spacing: 0.22em; padding-left: 0.22em; line-height: 1; }
.qr { width: min(52vw, 200px); height: auto; border-radius: 10px; display: block; }
.code-line { position: relative; }
.code-lock { position: absolute; left: 100%; top: 50%; margin-left: 2px; width: 26px; height: 26px; transform: translateY(-50%); color: var(--muted); }
.code-lock svg { display: block; width: 100%; height: 100%; }
.invite.locked .qr { opacity: 0.18; }
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius);
  background: transparent; color: var(--cream); font: inherit; font-weight: 700; text-align: left; cursor: pointer;
}
.switch-row:focus-visible { outline: 3px solid var(--cream); outline-offset: 3px; }
.switch-row .sub { display: block; margin-top: 2px; font-weight: 500; font-size: 0.78rem; color: var(--muted); }
.switch { flex: none; position: relative; width: 46px; height: 26px; border: 1.5px solid var(--muted); border-radius: 13px; transition: background 0.15s; }
.switch::after { content: ''; position: absolute; left: 3px; top: 3px; width: 17px; height: 17px; border-radius: 50%; background: var(--muted); transition: transform 0.15s, background 0.15s; }
.switch-row[aria-checked="true"] .switch { background: var(--cream); border-color: var(--cream); }
.switch-row[aria-checked="true"] .switch::after { transform: translateX(20px); background: var(--ink); }
.people { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.people li {
  display: flex; align-items: center; gap: 12px; min-height: 48px;
  padding: 10px 14px; background: var(--table-2); border: 1px solid var(--line); border-radius: var(--radius);
}
.people .who-name { flex: 1; font-weight: 700; overflow-wrap: anywhere; }
.people .tag { font-weight: 500; font-size: 0.8rem; color: var(--muted); }
.people .presence { flex: none; width: 9px; height: 9px; border-radius: 50%; background: #7bc47f; }
.people li.away .presence { background: transparent; border: 1.5px solid var(--muted); }
.people li.away .who-name { color: var(--muted); }
.link {
  appearance: none; border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 0.85rem; font-weight: 700; padding: 8px 4px;
}
.link:hover { color: var(--cream); }
.waiting { text-align: center; color: var(--muted); line-height: 1.5; margin: 14px 0 0; }
.sheet { max-height: calc(100dvh - 32px); overflow-y: auto; }
.card-back:disabled { cursor: default; }
.card-back:disabled:hover { transform: rotate(var(--rot, 0deg)); box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 8px 20px rgba(0, 0, 0, 0.45); }

/* A room update redraws the same screen: skip its entrance animation. */
#app.still .screen, #app.still .page, #app.still .page p.line { animation: none; opacity: 1; }
#overlay.still .sheet { animation: none; }

#toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); translate: -50% 0; z-index: 30;
  width: max-content; max-width: calc(100vw - 32px);
  background: var(--cream); color: var(--ink); border-radius: 999px; padding: 12px 18px;
  font-weight: 700; font-size: 0.9rem; text-align: center; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: rise 0.25s var(--ease);
}
body.offline::before {
  content: 'Reconnecting…';
  position: fixed; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 20;
  background: var(--table-2); border: 1px solid var(--line); color: var(--cream); border-radius: 999px;
  padding: 6px 14px; font-size: 0.8rem; font-weight: 700;
}

/* ---------- Motion ---------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes lift { from { opacity: 0; transform: translateY(24px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes deal {
  from { opacity: 0; transform: translateY(-40px) rotate(calc(var(--rot, 0deg) * -3)) scale(0.9); }
  to { opacity: 1; transform: rotate(var(--rot, 0deg)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0ms !important; transition-duration: 0.01ms !important; }
}
