/*
 * Guildfall web front end.
 *
 * Dark-first: the lore is about a light going out, and a bright white page
 * fights it. Light mode is a real override rather than an afterthought,
 * because people read long text on whatever their phone is set to.
 *
 * The palette is ash and iron with one warm accent (#c08a4a), which is the
 * same gold the in-game forge screen uses for a selected card. Ember red is
 * for the wardens' eyebrow text and nothing else - the moment it becomes a
 * general-purpose highlight it stops meaning anything.
 */

:root {
  color-scheme: dark;

  --ink:        #d8d3cb;   /* warm off-white; pure #fff is too clean for this */
  --ink-dim:    #8f887e;
  /*
   * "Faint" still has to be READ. Hints, the code note and the empty-seat
   * label all use it, and at the original #635d55 it sat at 2.9:1 on this
   * ground - decorative-looking text carrying real instructions. Both schemes
   * are now pinned above the 4.5:1 floor for normal text, measured against the
   * PANEL rather than the body: panels are the lighter surface, so tuning
   * against the darker ground passes the test and still fails the form.
   */
  --ink-faint:  #8d867c;

  --ground:     #131211;   /* near-black with a little brown in it, not blue */
  --surface:    #1c1a18;
  --surface-2:  #24211e;
  --line:       #322e2a;
  --line-lit:   #4a443d;

  --gold:       #c08a4a;
  --gold-hi:    #d9a463;
  /*
   * Text ON the gold button. It has to flip with the scheme: dark mode's gold
   * is bright and wants near-black on it, light mode's is a dark ochre and
   * wants near-white. Hardcoding the dark-mode choice left the light-mode
   * button at 3.2:1 - the one control on the page you cannot afford to lose.
   */
  --on-gold:    #17130e;
  --ember:      #a8563a;
  --bad:        #b4553f;
  --good:       #7d9464;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua",
           Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;

  --measure: 64ch;
  --radius: 3px;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --ink:       #24211d;
    --ink-dim:   #5f584f;
    --ink-faint: #726b62;
    --ground:    #f4f1ec;
    --surface:   #fbf9f5;
    --surface-2: #ece7df;
    --line:      #d9d2c7;
    --line-lit:  #bdb4a6;
    --gold:      #8a5d24;
    --gold-hi:   #6f4a1a;
    --on-gold:   #fbf9f5;
    --ember:     #8d422a;
    --bad:       #9c3f2a;
    --good:      #4f6338;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.65;
  /* Long lore paragraphs read better with the ligatures and old-style figures
     a serif face gives, but the UI chrome stays sans. */
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 400;
  line-height: 1.2;
  margin: 0 0 0.6em;
  color: var(--ink);
}

a { color: var(--gold); text-decoration-color: color-mix(in srgb, var(--gold) 40%, transparent); }
a:hover { color: var(--gold-hi); text-decoration-color: currentColor; }

/* One visible focus style everywhere. Removing outlines without replacing them
   is how a page becomes unusable by keyboard without anyone noticing. */
:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-radius: 2px;
}

/*
 * Safe areas on the pages too.
 *
 * These are where a phone actually arrives - someone reads the lore in bed and
 * joins a table from a link - and in landscape the cutout is on the side, so a
 * gutter of exactly 1.25rem puts the first character of every line underneath
 * it. max() rather than addition: on a device with no inset this stays exactly
 * 1.25rem instead of collapsing to zero.
 */
.wrap {
  max-width: 62rem; margin: 0 auto;
  padding-left: max(1.25rem, env(safe-area-inset-left, 0px));
  padding-right: max(1.25rem, env(safe-area-inset-right, 0px));
}
.prose { max-width: var(--measure); }

/* ------------------------------------------------------------------- nav */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem;
  padding: max(1rem, env(safe-area-inset-top, 0px)) max(1.25rem, env(safe-area-inset-right, 0px))
           1rem max(1.25rem, env(safe-area-inset-left, 0px));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--ground) 85%, transparent);
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(8px);
}
.brand {
  font-family: var(--serif); font-size: 1.25rem; letter-spacing: 0.04em;
  color: var(--ink); text-decoration: none;
}
.brand:hover { color: var(--gold); }
.topbar nav { display: flex; align-items: center; gap: 1.25rem; font-size: 0.925rem; }

/*
 * Topbar links are text, and text is about 24px tall. That is fine to click
 * and too small to tap, so on a touch device they get the 44px WCAG 2.5.5
 * target without changing how they look - the box grows, the type does not.
 */
@media (pointer: coarse) {
  .topbar nav a, .brand, .alt a, footer a {
    display: inline-flex; align-items: center; min-height: 44px;
  }
  .topbar nav { gap: 1rem; }
}

/* ----------------------------------------------------------------- hero */

.masthead { padding: clamp(3rem, 10vw, 6rem) 0 clamp(2.5rem, 6vw, 4rem); text-align: center; }
.masthead h1 {
  font-size: clamp(2.75rem, 9vw, 4.5rem);
  letter-spacing: 0.02em;
  margin-bottom: 0.15em;
}
.masthead .tagline {
  font-family: var(--serif); font-style: italic;
  color: var(--gold); font-size: clamp(1rem, 2.6vw, 1.2rem);
  margin: 0 0 1.75rem;
}
.masthead .pitch {
  max-width: 46ch; margin: 0 auto 2rem; color: var(--ink-dim);
}
.masthead .cta-row { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap; }

.facts {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 0.5rem 1.5rem; margin-top: 2.5rem;
  font-size: 0.8rem; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--ink-faint);
}
.facts span { white-space: nowrap; }

/* --------------------------------------------------------------- buttons */

.btn {
  display: inline-block; cursor: pointer;
  font: inherit; font-size: 0.95rem;
  padding: 0.7rem 1.4rem;
  border-radius: var(--radius);
  border: 1px solid var(--gold);
  background: var(--gold);
  color: var(--on-gold);
  text-decoration: none;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.btn:hover { background: var(--gold-hi); border-color: var(--gold-hi); color: var(--on-gold); }
.btn:disabled, .btn[aria-disabled="true"] {
  background: transparent; color: var(--ink-faint);
  border-color: var(--line); cursor: not-allowed;
}
.btn.ghost {
  background: transparent; color: var(--ink);
  border-color: var(--line-lit);
}
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); border-color: var(--gold); }
.btn.wide { width: 100%; text-align: center; }

/* ----------------------------------------------------------------- lore */

.section { padding: clamp(2.5rem, 7vw, 4.5rem) 0; border-top: 1px solid var(--line); }
.section > .wrap > h2 {
  font-size: clamp(1.6rem, 4vw, 2.1rem);
  margin-bottom: 1.5rem;
}
.eyebrow {
  display: block; font-family: var(--sans);
  font-size: 0.72rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ember); margin-bottom: 0.5rem;
}

.lore p { font-family: var(--serif); font-size: 1.075rem; line-height: 1.75; margin: 0 0 1.3em; }
.lore p strong { color: var(--gold); font-weight: 400; }
.lore .turn {
  /* The two-sentence beat where the coal answers. Given room on purpose. */
  font-size: 1.25rem; color: var(--ink);
  margin: 1.8em 0; padding-left: 1.1rem;
  border-left: 2px solid var(--ember);
}
.lore .close { color: var(--ink); }

/* ---------------------------------------------------------- disciplines */

.roster {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  margin-top: 2rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.card h3 { font-size: 1.2rem; margin-bottom: 0.35rem; color: var(--gold); }
.card .held { color: var(--ink-faint); font-size: 0.85rem; font-style: italic; margin: 0 0 0.7rem; }
.card p.text { margin: 0; font-size: 0.925rem; color: var(--ink-dim); line-height: 1.6; }
.card .tag {
  display: inline-block; margin-top: 0.8rem;
  font-size: 0.68rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ember); border: 1px solid var(--line-lit);
  border-radius: 2px; padding: 0.15rem 0.45rem;
}

/* ---------------------------------------------------------------- forms */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(1.5rem, 4vw, 2.25rem);
  max-width: 30rem; margin: clamp(2rem, 6vw, 3.5rem) auto;
}
.panel h1 { font-size: 1.75rem; margin-bottom: 0.3rem; }
.panel .sub { color: var(--ink-dim); font-size: 0.925rem; margin: 0 0 1.75rem; }

.field { margin-bottom: 1.15rem; }
.field label {
  display: block; margin-bottom: 0.35rem;
  font-size: 0.83rem; letter-spacing: 0.04em; color: var(--ink-dim);
}
.field .hint { font-size: 0.78rem; color: var(--ink-faint); margin-top: 0.35rem; }
.field input, .field select {
  width: 100%; font: inherit; font-size: 0.975rem;
  padding: 0.6rem 0.7rem;
  color: var(--ink);
  background: var(--ground);
  border: 1px solid var(--line-lit);
  border-radius: var(--radius);
}
.field input:focus, .field select:focus { border-color: var(--gold); outline-offset: 1px; }
.field input:invalid:not(:placeholder-shown) { border-color: var(--bad); }

/* Reserve the line so an appearing error does not shove the button down
   under the user's finger mid-tap. */
.msg { min-height: 1.4em; font-size: 0.875rem; margin: 0.25rem 0 1rem; }
.msg.err { color: var(--bad); }
.msg.ok  { color: var(--good); }

.alt { margin-top: 1.5rem; text-align: center; font-size: 0.9rem; color: var(--ink-dim); }

/* -------------------------------------------------------- discipline pick */

.pick { display: grid; gap: 0.5rem; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); }
.pick label {
  /* position:relative so the hidden radio below is contained by its own label
     rather than escaping to whatever ancestor happens to be positioned. */
  position: relative;
  display: block; cursor: pointer; margin: 0;
  border: 1px solid var(--line-lit); border-radius: var(--radius);
  padding: 0.6rem 0.7rem; background: var(--ground);
  transition: border-color 120ms ease, background 120ms ease;
}
.pick label:hover { border-color: var(--line-lit); background: var(--surface-2); }
/*
 * Visually hidden, still focusable, still clickable.
 *
 * `opacity: 0; pointer-events: none` looks equivalent and is not: the radio
 * stops receiving clicks, so anything that targets the input directly - a
 * test driver, an assistive tool clicking by accessible name - silently does
 * nothing while a human clicking the label sees it work.
 */
.pick input {
  position: absolute;
  width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; white-space: nowrap;
  clip: rect(0 0 0 0); clip-path: inset(50%);
  border: 0;
}
.pick .name { display: block; color: var(--ink); font-size: 0.95rem; }
.pick .warden { display: block; font-size: 0.75rem; color: var(--ink-faint); font-style: italic; }
/* :has() drives the selected state off the radio itself, so there is no
   JavaScript keeping a class in sync with a form value that already knows. */
.pick label:has(input:checked) { border-color: var(--gold); background: var(--surface-2); }
.pick label:has(input:checked) .name { color: var(--gold); }
.pick label:has(input:focus-visible) { outline: 2px solid var(--gold); outline-offset: 2px; }
#pickText { font-size: 0.85rem; color: var(--ink-dim); margin-top: 0.7rem; min-height: 3.2em; }

/* ---------------------------------------------------------------- lobby */

.lobby-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.choices { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); margin-top: 1.5rem; }

.code {
  font-family: var(--mono);
  font-size: clamp(2.25rem, 11vw, 3.5rem);
  letter-spacing: 0.28em;
  /* letter-spacing adds a trailing gap after the last glyph, which makes a
     centred code sit visibly left. Pull it back. */
  text-indent: 0.28em;
  text-align: center;
  color: var(--gold);
  background: var(--surface);
  border: 1px solid var(--line-lit);
  border-radius: var(--radius);
  padding: 0.7rem 0.5rem;
  margin: 0.75rem 0 0.5rem;
  user-select: all;
}
.code-note { text-align: center; color: var(--ink-faint); font-size: 0.82rem; margin: 0 0 1.5rem; }

.joinrow { display: flex; gap: 0.5rem; }
.joinrow input {
  flex: 1 1 auto; min-width: 0;
  font-family: var(--mono); font-size: 1.15rem;
  letter-spacing: 0.22em; text-align: center; text-transform: uppercase;
}

.seats { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); margin-top: 1rem; }
.seat {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); padding: 0.9rem;
  min-height: 6.25rem;
  display: flex; flex-direction: column; gap: 0.15rem;
}
.seat.empty {
  border-style: dashed; background: transparent;
  align-items: center; justify-content: center;
  color: var(--ink-faint); font-style: italic; font-size: 0.9rem;
}
.seat.you { border-color: var(--gold); }
.seat .who { color: var(--ink); font-size: 1rem; }
.seat .disc { color: var(--ember); font-size: 0.78rem; letter-spacing: 0.1em; text-transform: uppercase; }
.seat .state { margin-top: auto; font-size: 0.78rem; color: var(--ink-faint); }
.seat .state.ready { color: var(--good); }
.seat .state.gone  { color: var(--bad); }

.lobby-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1.5rem; align-items: center; }

.notice {
  border: 1px solid var(--line-lit); border-left: 3px solid var(--ember);
  background: var(--surface); border-radius: var(--radius);
  padding: 0.85rem 1rem; font-size: 0.9rem; color: var(--ink-dim);
  margin: 1rem 0;
}

footer {
  border-top: 1px solid var(--line);
  padding: 2rem max(1.25rem, env(safe-area-inset-right, 0px))
           max(3rem, calc(2rem + env(safe-area-inset-bottom, 0px)))
           max(1.25rem, env(safe-area-inset-left, 0px));
  color: var(--ink-faint); font-size: 0.85rem; text-align: center;
}

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
