/* ==========================================================================
   QUAD: design tokens
   Light, warm and flat. Burgundy is the one accent; tan is used for
   borders and quiet surfaces. Fraunces for headlines, DM Sans for text.
   ========================================================================== */
:root {
  --bg: #f7f2ea;
  --surface: #ffffff;
  --surface-2: #efe6d8;     /* tan */
  --ink: #2a1a1c;
  --muted: #6e5c58;
  --line: #e4d8c6;
  --accent: #6b1d2a;        /* burgundy */
  --accent-hover: #58161f;
  --accent-ink: #ffffff;
  --accent-soft: #f3e4e2;
  --good: #2f6b45;
  --warn: #a3321f;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "DM Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "DM Mono", ui-monospace, monospace;

  --t-xs: 0.78rem;
  --t-sm: 0.9rem;
  --t-base: 1rem;
  --t-lg: 1.15rem;
  --t-xl: clamp(1.5rem, 1.2rem + 1.2vw, 2rem);
  --t-hero: clamp(2.5rem, 1.4rem + 4.2vw, 4.5rem);

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 72px; --s9: 104px;
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --shadow: 0 1px 2px rgba(42, 26, 28, .05), 0 8px 24px -12px rgba(42, 26, 28, .14);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --gutter: clamp(16px, 4vw, 40px);
  --maxw: 1080px;
}

/* ==========================================================================
   Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--t-base)/1.6 var(--font-body);
  -webkit-font-smoothing: antialiased;
  overflow: hidden; /* every screen is exactly one viewport tall */
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 500; line-height: 1.08; margin: 0; letter-spacing: -0.02em; }
p { margin: 0; }
a { color: inherit; }
video { display: block; max-width: 100%; }
kbd {
  font: 500 var(--t-xs) var(--font-mono);
  padding: 1px 6px; border-radius: 5px;
  border: 1px solid currentColor; opacity: .75;
}
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: var(--s4); top: -60px; z-index: 100; background: var(--accent); color: var(--accent-ink); padding: var(--s2) var(--s4); border-radius: var(--r-sm); }
.skip-link:focus { top: var(--s4); }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  font: 600 var(--t-base)/1 var(--font-body);
  color: var(--accent-ink); background: var(--accent);
  border: 0; border-radius: var(--r); padding: 14px 22px; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, transform .1s;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }
.btn--small { padding: 10px 16px; font-size: var(--t-sm); border-radius: var(--r-sm); }

.linkbtn {
  background: none; border: 0; padding: var(--s1) 0; cursor: pointer; align-self: flex-start;
  font: 500 var(--t-sm) var(--font-body); color: var(--muted);
  text-decoration: underline; text-underline-offset: 3px;
}
.linkbtn:hover { color: var(--ink); }

.eyebrow {
  display: inline-flex; align-items: center; gap: var(--s2);
  font: 500 var(--t-xs) var(--font-mono); text-transform: uppercase; letter-spacing: .1em; color: var(--muted);
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); }

/* ==========================================================================
   Logo: a plain wordmark
   ========================================================================== */
.logo {
  font: 600 1.25rem/1 var(--font-display); letter-spacing: .08em;
  color: var(--accent); text-decoration: none;
}
.logo--small { font-size: 1.05rem; }

/* ==========================================================================
   Nav (sticky, condenses on scroll)
   ========================================================================== */
.nav { z-index: 50; }
.nav__inner {
  max-width: var(--maxw); margin: 0 auto; padding: var(--s5) var(--gutter);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s4);
}
.nav__links { display: flex; align-items: center; gap: var(--s5); }
.nav__links a[aria-current="page"] { color: var(--ink); text-decoration: underline; text-underline-offset: 6px; text-decoration-color: var(--accent); }
.nav__links a:not(.btn) { text-decoration: none; font-weight: 500; font-size: var(--t-sm); color: var(--muted); }
.nav__links a:not(.btn):hover { color: var(--ink); }

@media (max-width: 520px) {
  .nav__inner { padding-top: var(--s4); padding-bottom: var(--s4); }
  .nav__links { gap: var(--s4); }
}

/* ==========================================================================
   Hero
   ========================================================================== */
.hero {
  max-width: 640px; margin: 0 auto;
  padding: var(--s5) var(--gutter);
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s5);
}
.hero__title { font-size: var(--t-hero); }
.hero__title em { font-style: italic; color: var(--accent); }
.hero__sub { font-size: var(--t-lg); color: var(--muted); max-width: 36ch; }

/* --- Sign-in card --- */
.auth {
  width: 100%; margin-top: var(--s3); text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s5); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: var(--s4);
}
.auth__step { display: flex; flex-direction: column; gap: var(--s2); }
.auth__label { font-size: var(--t-sm); font-weight: 500; color: var(--ink); }
.field { display: flex; gap: var(--s2); }
.field input {
  flex: 1; min-width: 0; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--r);
  font: 400 var(--t-base) var(--font-body); padding: 13px 14px;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input::placeholder { color: #a39490; }
.field.is-error input { border-color: var(--warn); }
.field.is-ok input { border-color: var(--good); }
.code-input { font-family: var(--font-mono) !important; letter-spacing: .35em; }
.auth__msg { font-size: var(--t-sm); color: var(--muted); min-height: 1.6em; }
.auth__msg.is-error { color: var(--warn); }
.auth__msg.is-ok { color: var(--good); }
.auth__msg code { font-family: var(--font-mono); background: var(--surface-2); padding: 1px 6px; border-radius: 4px; color: var(--ink); }

.consent { display: flex; gap: var(--s3); align-items: flex-start; font-size: var(--t-sm); color: var(--muted); cursor: pointer; padding-top: var(--s4); border-top: 1px solid var(--line); }
.consent input { width: 17px; height: 17px; margin: 3px 0 0; accent-color: var(--accent); flex-shrink: 0; }
.consent.is-error span { color: var(--warn); }

.facts { list-style: none; margin: var(--s2) 0 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: var(--s2) var(--s5); font-size: var(--t-sm); color: var(--muted); }
.facts li { display: inline-flex; align-items: center; gap: var(--s2); }
.facts li::before { content: ""; width: 4px; height: 4px; border-radius: 50%; background: var(--accent); }

/* ==========================================================================
   Rules
   ========================================================================== */
.rules { max-width: 640px; margin: 0 auto; padding: var(--s5) var(--gutter); width: 100%; }
.rules__back { margin-top: var(--s6); }
.section-title { font-size: var(--t-xl); margin-bottom: var(--s5); }
.rules__list { list-style: none; counter-reset: rule; margin: 0; padding: 0; }
.rules__list li {
  counter-increment: rule; display: grid; grid-template-columns: 40px 1fr; gap: var(--s3);
  padding: var(--s4) 0; border-bottom: 1px solid var(--line); color: var(--muted);
}
.rules__list li::before { content: counter(rule, decimal-leading-zero); font: 500 var(--t-sm)/1.8 var(--font-mono); color: var(--accent); }
.rules__list strong { color: var(--ink); font-weight: 600; }

/* ==========================================================================
   Footer
   ========================================================================== */
.footer { padding: var(--s4) var(--gutter); }
.footer__inner { max-width: var(--maxw); margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; }
.footer__fine { font-size: var(--t-xs); color: var(--muted); }

/* ==========================================================================
   One-screen landing: nav, a single view, footer. The page never scrolls;
   "House rules" swaps the view instead.
   ========================================================================== */
#landing { height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; }
.views { position: relative; min-height: 0; display: grid; place-items: center; overflow-y: auto; } /* inner scroll only if a tiny screen can't fit it */
.view { animation: viewIn .35s var(--ease); }
@keyframes viewIn { from { opacity: 0; } } /* fade only: no movement that could overflow the screen */

/* short screens: tighten up so everything still fits */
@media (max-height: 760px) {
  .hero { gap: var(--s4); }
  .facts { display: none; }
}

@media (max-width: 520px) {
  .hero { gap: var(--s4); }
  .field { flex-direction: column; }
  .field .btn { width: 100%; }
}

/* ==========================================================================
   Chat app
   ========================================================================== */
.app { height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; }
.app__bar { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); padding: var(--s4) var(--gutter); border-bottom: 1px solid var(--line); }
.namefield { flex: 1; display: flex; align-items: center; justify-content: center; gap: var(--s2); min-width: 0; }
.namefield__label { font: 500 var(--t-xs) var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.namefield input {
  width: 100%; max-width: 220px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: var(--r-sm); padding: 8px 12px; font: 500 var(--t-sm) var(--font-body);
  transition: border-color .15s, box-shadow .15s;
}
.namefield input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.namefield input::placeholder { color: #a39490; font-weight: 400; }
.app__online { display: inline-flex; align-items: center; gap: var(--s2); font: 500 var(--t-xs) var(--font-mono); color: var(--muted); }
.app__online:not(:empty)::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--good); }

/* One centered column: their video front and center, chat underneath. */
.stage {
  display: grid; grid-template-rows: 1fr auto; gap: var(--s4);
  width: 100%; max-width: 960px; margin: 0 auto;
  padding: var(--s4) var(--gutter); min-height: 0;
}
.screens { display: grid; grid-template-rows: 1fr; position: relative; min-height: 0; }
.screen { position: relative; border-radius: var(--r-lg); overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); min-height: 0; }
.screen video { width: 100%; height: 100%; object-fit: cover; }
.screen--them video { opacity: 0; transition: opacity .35s var(--ease); }
.screen--them.is-live video { opacity: 1; }
.screen--me video { transform: scaleX(-1); } /* mirror yourself */
/* your own camera: a picture-in-picture in the corner of theirs */
.screen--me {
  position: absolute; right: var(--s4); top: var(--s4); z-index: 4;
  width: 22%; max-width: 200px; aspect-ratio: 4 / 3;
  border-radius: var(--r); border: 2px solid #fff; box-shadow: var(--shadow);
}
.screen--me .tag { left: var(--s2); bottom: var(--s2); }
.screen--them.is-fade video { opacity: 0; transition: none; }

.screen__status {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s2);
  text-align: center; padding: var(--s5); transition: opacity .3s;
}
.screen--them.is-live .screen__status { opacity: 0; pointer-events: none; }
.status__big { font: 500 var(--t-xl)/1.15 var(--font-display); color: var(--ink); }
.status__small { font-size: var(--t-sm); color: var(--muted); }
/* a gentle pulsing dot while waiting */
.status__big::before {
  content: ""; display: block; width: 10px; height: 10px; margin: 0 auto var(--s4); border-radius: 50%;
  background: var(--accent); animation: breathe 1.6s ease-in-out infinite;
}
@keyframes breathe { 50% { transform: scale(1.6); opacity: .35; } }
.screen__status:not(.is-waiting) .status__big::before { display: none; }

.tag {
  position: absolute; left: var(--s3); bottom: var(--s3); z-index: 3;
  font: 500 var(--t-xs) var(--font-body);
  background: rgba(255, 255, 255, .9); color: var(--ink); padding: 5px 10px; border-radius: 6px;
}
.screen__off { position: absolute; inset: 0; display: grid; place-items: center; font-size: var(--t-sm); color: var(--muted); background: var(--surface-2); }

.chat { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); min-height: 0; overflow: hidden; }
.chat__log { list-style: none; margin: 0; padding: var(--s4); flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: var(--s2); }
.chat__log li { max-width: 85%; padding: 8px 12px; border-radius: 12px; font-size: var(--t-sm); line-height: 1.45; overflow-wrap: anywhere; }
.chat__log .me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.chat__log .them { align-self: flex-start; background: var(--surface-2); }
.chat__log .sys { align-self: center; background: none; color: var(--muted); font-size: var(--t-xs); text-align: center; padding: var(--s1) 0; }
.chat__form { display: flex; gap: var(--s2); padding: var(--s3); border-top: 1px solid var(--line); }
.chat__form input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: var(--r-sm); padding: 10px 12px; font: 400 var(--t-sm) var(--font-body); }
.chat__form input:focus { outline: none; border-color: var(--accent); }

.controls { display: flex; align-items: center; justify-content: center; gap: var(--s3); padding: var(--s3) var(--gutter) max(var(--s4), env(safe-area-inset-bottom)); }
.ctrl {
  width: 48px; height: 48px; border-radius: var(--r); display: grid; place-items: center; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  transition: background .15s, color .15s;
}
.ctrl svg { width: 20px; height: 20px; fill: currentColor; }
.ctrl:hover { background: var(--surface-2); }
.ctrl[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.ctrl--warn:hover { color: var(--warn); }
.btn--next { min-width: 180px; padding: 15px 24px; }
.btn--next kbd { opacity: .6; }

.chat { max-height: 180px; }

@media (max-width: 640px) {
  .screen--me { right: var(--s3); top: var(--s3); width: 28%; max-width: 140px; aspect-ratio: 3 / 4; }
  .screen--me .tag { display: none; }
}
@media (max-width: 520px) {
  .btn--next { min-width: 0; flex: 1; max-width: 200px; }
  .btn--next kbd { display: none; }
  .ctrl { width: 44px; height: 44px; }
  .controls { gap: var(--s2); }
  .chat { max-height: 140px; }
}

/* ==========================================================================
   Dialog + toast
   ========================================================================== */
.dialog { border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s6); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); width: min(92vw, 380px); }
.dialog::backdrop { background: rgba(42, 26, 28, .35); }
.dialog h2 { font-size: var(--t-xl); margin-bottom: var(--s1); }
.dialog p { color: var(--muted); margin-bottom: var(--s5); font-size: var(--t-sm); }
.dialog__options { display: grid; gap: var(--s2); margin-bottom: var(--s3); }
.dialog__options button {
  text-align: left; padding: 12px 14px; border-radius: var(--r-sm); cursor: pointer;
  background: var(--bg); border: 1px solid var(--line); color: var(--ink); font: 500 var(--t-sm) var(--font-body);
  transition: border-color .15s;
}
.dialog__options button:hover { border-color: var(--accent); }

.toast {
  position: fixed; left: 50%; top: 72px; transform: translateX(-50%); z-index: 200;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: var(--r-sm);
  font: 500 var(--t-sm) var(--font-body); box-shadow: var(--shadow);
  max-width: calc(100vw - 32px); text-align: center;
}

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