/* PHANDALIN AT NIGHT — shared design and gate. Complete replacement.
   Source Serif 4 / Source Sans 3. No framework, build or image required.
   Optional artwork: put phandalin-night.webp next to this file.
   Other pages' old embedded styles are migrated in delivery part 4. */
:root {
  color-scheme: dark;
  --paper: #0b1020;
  --paper-2: #151e30;
  --surface-raised: #1c2940;
  --ink: #f2eee6;
  --ink-soft: #b8c2d3;
  --gold: #c6a66b;
  --gold-pale: #ebd3a2;
  --rule: #42516b;
  --rule-soft: #2a3850;
  --ember: #ffaaaa;
  --healing: #9bd7bf;
  --arcane: #b6a4e8;
  --sans: "Source Sans 3", ui-sans-serif, system-ui, sans-serif;
  --serif: "Source Serif 4", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  --terug-ink: var(--ink);
  --terug-soft: var(--ink-soft);
  --terug-rule: var(--rule);
  --radius: 6px;
  --shadow: 0 20px 70px #0006;
  --landscape: url("./phandalin-night.webp");
  --star: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-100 -100 200 200'%3E%3Cpath d='M0-88 12-29 62-62 29-12 88 0 29 12 62 62 12 29 0 88-12 29-62 62-29 12-88 0-29-12-62-62-12-29Z' fill='none' stroke='%23c6a66b' stroke-width='5'/%3E%3Ccircle r='14' fill='none' stroke='%23c6a66b' stroke-width='4'/%3E%3C/svg%3E");
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 6rem; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--sans); font-size: 18px; line-height: 1.6;
}
[hidden], .hidden { display: none !important; }
img, svg { max-width: 100%; }
img { height: auto; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button { touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--gold-pale); outline-offset: 4px; }
::selection { background: #c6a66b; color: #0b1020; }
a { color: var(--gold-pale); text-underline-offset: .22em; }
a:hover { color: var(--ink); }
h1, h2, h3, h4 { font-family: var(--serif); line-height: 1.2; text-wrap: balance; }
p { overflow-wrap: anywhere; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0;
  margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
.skip-link { position: fixed; left: 1rem; top: -10rem; z-index: 100; padding: .8rem 1rem; background: var(--paper-2); }
.skip-link:focus { top: 1rem; }
.crest { display: block; width: 64px; height: 64px; color: var(--gold); flex-shrink: 0; }

/* Staged migration: the original handouts have local white surfaces.
   Keep their old tokens until part 4 adds body.handout-page and removes
   their embedded styles. These selectors do not match the gate or app. */
:root:has(body:not(.handout-page) > .page),
:root:has(body:not(.handout-page) > .sheet) {
  color-scheme: light;
  --paper: #f7f5ef; --paper-2: #efece2;
  --ink: #1e2a47; --ink-soft: #54607a;
  --gold: #9c7b1c; --gold-pale: #70551a;
  --rule: #c9c2ae; --rule-soft: #ded8c8;
  --ember: #8c2b24;
}

/* Shared navigation and handout index. */
.terug {
  display: flex; align-items: center; gap: .7rem; min-height: 48px;
  margin: 0 0 1.6rem; padding: .5rem 0 .8rem;
  border-bottom: 1px solid var(--terug-rule); font: 16px/1.4 var(--sans);
  color: var(--terug-soft); text-decoration: none;
}
.terug::before { content: ""; flex: 0 0 26px; height: 26px; background: var(--star) center/contain no-repeat; }
.terug b { font-weight: 600; color: var(--terug-ink); }
.terug span { color: var(--terug-soft); }
.terug:hover b, .terug:hover span { color: var(--gold-pale); }
.toc { list-style: none; margin: 0 0 2rem; padding: 0; display: grid; gap: 1rem; }
.toc li {
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--paper-2); padding: 1.15rem 1.25rem; min-width: 0;
}
.toc .row { display: flex; align-items: baseline; gap: .8rem; flex-wrap: wrap; }
.toc a { display: inline-flex; align-items: center; min-height: 48px; font: 600 1.25rem/1.3 var(--serif); text-decoration: none; color: var(--ink); overflow-wrap: anywhere; }
.toc a:hover { color: var(--gold-pale); }
.toc .leader { flex: 1; }
.toc .tag { font-size: 14px; color: var(--gold); }
.toc p { margin: .4rem 0 0; color: var(--ink-soft); max-width: 62ch; font-size: 17px; }
.section-label { font: 600 .85rem/1.5 var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--gold-pale); margin: 2rem 0 1rem; }

/* Gate only: never style the playable .sheet as the login screen. */
.gate-page {
  min-height: 100vh; min-height: 100svh; isolation: isolate;
  background: radial-gradient(ellipse at 25% 15%, #293957, transparent 65%), var(--paper);
}
.gate-page::before {
  content: ""; position: fixed; inset: 0; z-index: -2; pointer-events: none;
  background-image: linear-gradient(90deg, #08101bd9, #0b10205e 50%, #0b1020b8), linear-gradient(0deg, #0b1020, transparent 65%), var(--landscape);
  background-position: center; background-size: cover;
}
.gate-page::after {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(ellipse at 30% 65%, #98b5dc14, transparent 55%);
  animation: gate-mist 24s ease-in-out infinite alternate;
}
@keyframes gate-mist { to { transform: translateY(-3%); opacity: .35; } }
.gate-header, .gate-footer { max-width: 1440px; margin: auto; padding: 1.25rem clamp(1rem, 4vw, 4rem); display: flex; gap: 1rem; justify-content: space-between; align-items: center; }
.gate-header { border-bottom: 1px solid #c6a66b40; }
.gate-brand { display: inline-flex; gap: .8rem; align-items: center; color: var(--gold-pale); font: 600 1.45rem/1.2 var(--serif); text-decoration: none; letter-spacing: .035em; }
.gate-brand .crest { width: 40px; height: 40px; }
.gate-header-note { margin: 0; font-size: 14px; color: var(--ink-soft); }
.gate-layout { max-width: 1440px; margin: auto; padding: clamp(2rem, 7vw, 6rem) clamp(1rem, 4vw, 4rem); display: grid; grid-template-columns: 1fr minmax(0, 460px); gap: clamp(2rem, 6vw, 7rem); align-items: center; min-height: calc(100svh - 170px); }
.gate-story { max-width: 640px; }
.eyebrow { margin: 0 0 1rem; color: var(--gold-pale); font-size: 13px; font-weight: 600; letter-spacing: .17em; text-transform: uppercase; }
.gate-story h1 { font-size: clamp(2.7rem, 5.8vw, 5.6rem); font-weight: 600; line-height: 1.03; margin: 0 0 1.5rem; letter-spacing: -.045em; text-shadow: 0 4px 28px #0008; }
.gate-story .lede { max-width: 38ch; font-size: clamp(1.1rem, 1.6vw, 1.3rem); color: var(--ink-soft); }
.story-rule { width: 76px; height: 1px; background: var(--gold); margin: 2rem 0; }
.story-signature { color: var(--gold-pale); font-family: var(--serif); font-style: italic; }
.auth-card { background: linear-gradient(145deg, #182337f5, #0c1423fa); border: 1px solid #c6a66b80; border-radius: var(--radius); padding: clamp(1.25rem, 3vw, 2.3rem); box-shadow: var(--shadow); min-width: 0; }
.auth-crest { margin: 0 auto 1.2rem; width: 56px; height: 56px; }
.auth-head { text-align: center; margin-bottom: 1.3rem; }
.auth-head h2 { font-size: clamp(1.65rem, 3vw, 2rem); margin: 0 0 .6rem; font-weight: 600; }
.auth-head p { color: var(--ink-soft); margin: 0; font-size: 17px; }
.auth-switch { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-bottom: 1.4rem; padding-bottom: 1rem; border-bottom: 1px solid var(--rule); }
.gate-page button, .gate-page .btn { min-height: 48px; border-radius: 4px; padding: .65rem .9rem; border: 1px solid var(--rule); background: var(--paper-2); color: var(--ink); font: 600 16px/1.4 var(--sans); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; transition: background .18s, border-color .18s; }
.gate-page button:hover, .gate-page .btn:hover { border-color: var(--gold); background: var(--surface-raised); }
.gate-page button[aria-pressed="true"] { border-color: var(--gold); color: var(--gold-pale); background: #c6a66b12; }
.gate-page button.primary, .gate-page .btn.primary { background: linear-gradient(110deg, #e5cb92, #c6a66b); border-color: var(--gold-pale); color: #121a27; }
.gate-page button.primary:hover, .gate-page .btn.primary:hover { background: #ebd3a2; }
.gate-page button.link { background: transparent; border-color: transparent; color: var(--gold-pale); text-decoration: underline; text-underline-offset: .25em; }
.gate-page button:disabled { opacity: .6; cursor: wait; }
.gate-page label { display: block; font-size: 16px; font-weight: 600; margin-bottom: .4rem; }
.gate-page input { display: block; min-width: 0; width: 100%; min-height: 50px; background: #0b1322; color: var(--ink); border: 1px solid #62718a; border-radius: 4px; padding: .65rem .8rem; font: 18px/1.4 var(--sans); }
.gate-page input::placeholder { color: #9caac0; opacity: 1; }
.gate-page input:focus { border-color: var(--gold-pale); }
.gate-page input:disabled { opacity: .7; }
.gate-page .field { margin-bottom: 1.1rem; }
.gate-page .field-hint { margin: .4rem 0 0; color: var(--ink-soft); font-size: 15px; }
.password-wrap { display: flex; align-items: stretch; gap: .5rem; }
.password-wrap input { flex: 1; }
.password-wrap button { flex: 0 0 auto; font-size: 14px; }
.auth-actions { display: grid; gap: .65rem; margin-top: 1.3rem; }
.auth-bottom { margin-top: .7rem; display: flex; justify-content: center; flex-wrap: wrap; }
.auth-message { padding: .9rem 1rem; margin: 1.1rem 0 0; border: 1px solid var(--rule); border-left-width: 3px; border-radius: 4px; font-size: 16px; background: #0b1322; }
.auth-message[data-state="success"] { border-color: var(--healing); color: #c0ecdb; }
.auth-message[data-state="error"] { border-color: var(--ember); color: #ffd0d0; }
.auth-message[data-state="loading"] { color: var(--gold-pale); border-color: var(--gold); }
.auth-message:empty { display: none; }
.auth-fineprint { margin: 1.4rem 0 0; padding-top: 1rem; border-top: 1px solid var(--rule); color: var(--ink-soft); font-size: 14px; text-align: center; }
.gate-footer { color: var(--ink-soft); font-size: 14px; border-top: 1px solid #c6a66b30; flex-wrap: wrap; }
.gate-footer .sig { color: var(--gold-pale); }
.hub { max-width: 1200px; margin: auto; padding: 3rem clamp(1rem, 4vw, 3rem) 5rem; }
.hub-head { margin-bottom: 2rem; padding: clamp(1.5rem, 4vw, 3rem); border: 1px solid #c6a66b70; background: #0b1322e8; border-radius: var(--radius); }
.hub-head h1 { font-size: clamp(2rem, 5vw, 3.6rem); margin: .3rem 0 1rem; }
.hub .who { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem; }
.hub .badge { color: var(--gold-pale); border: 1px solid var(--gold); border-radius: 3px; padding: .1rem .45rem; margin-left: .4rem; font-size: 14px; }
.hub .toc { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.hub .toc li:first-child { border-color: var(--gold); }
.hub-loading { max-width: 40rem; margin: 4rem auto; padding: 2rem; background: var(--paper-2); border: 1px solid var(--rule); }
@media (max-width: 800px) {
  .gate-layout { grid-template-columns: 1fr; gap: 1.5rem; max-width: 560px; min-height: auto; padding-top: 1.75rem; }
  .gate-story h1 { font-size: 2.6rem; margin-bottom: .7rem; }
  .gate-story .lede { font-size: 17px; margin-bottom: 0; }
  .gate-story .eyebrow { font-size: 11px; }
  .story-rule, .story-signature { display: none; }
  .gate-header-note { display: none; }
  .gate-header { padding-block: .8rem; }
  .hub .toc { grid-template-columns: 1fr; }
  .gate-page::before { background-position: 58% center; }
}
@media (max-width: 600px) {
  .gate-story { display: none; }
  .gate-layout { padding-top: 1rem; padding-bottom: 1.5rem; }
  .auth-crest { display: none; }
  .auth-head h2 { font-size: 1.65rem; }
  .auth-switch { gap: .4rem; }
  .auth-switch button { padding-inline: .4rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media print {
  :root { color-scheme: light; --paper: #fff; --paper-2: #f3f3f3; --ink: #111; --ink-soft: #333; --gold: #604719; --gold-pale: #604719; --rule: #999; --rule-soft: #ccc; }
  body { background: #fff !important; color: #111 !important; }
  .terug, .skip-link, .gate-page::before, .gate-page::after { display: none !important; }
  .toc li { box-shadow: none; break-inside: avoid; }
}

/* Entrance and music. The landscape first, then one button, because a
   browser will not play sound before someone clicked something. The
   head script on the gate sets .entrance-pending before first paint;
   player.js drives the rest. */
.entrance { display: none; }
.entrance-pending .entrance {
  position: fixed; inset: 0; z-index: 70;
  display: grid; place-items: center; padding: 1.5rem; text-align: center;
  background: radial-gradient(ellipse at 50% 55%, #0b1020d9, #0b102066 70%);
  transition: opacity .6s ease;
}
.entrance-pending:not(.entered) .gate-header,
.entrance-pending:not(.entered) main,
.entrance-pending:not(.entered) .gate-footer,
.entrance-pending:not(.entered) .muziek { visibility: hidden; }
.entrance.gone { opacity: 0; pointer-events: none; }
.entrance-inner { display: grid; justify-items: center; gap: .5rem; max-width: 34rem; }
.entrance .crest { width: 96px; height: 96px; color: var(--gold); filter: drop-shadow(0 8px 28px #000a); }
.entrance .eyebrow { margin: 1rem 0 0; }
.entrance h1 {
  margin: 0 0 1.6rem; font-size: clamp(3rem, 9vw, 5.4rem); font-weight: 600;
  line-height: 1; letter-spacing: -.03em; color: var(--ink); text-shadow: 0 4px 28px #000b;
}
.entrance button.primary { min-width: 16rem; font-size: 18px; }
.entrance button.link { margin-top: .4rem; font-size: 15px; }

/* The small player, bottom right on every page. Gold on night blue in
   fixed colours on purpose: the handouts are light, this is not. */
.muziek {
  position: fixed; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 60; display: flex; align-items: center; gap: 10px; padding: 4px 4px 4px 12px;
  background: #0b1020; border: 1px solid #c6a66b; border-radius: 6px;
  box-shadow: 0 10px 30px #0008; color: #c6a66b;
}
.muziek input.muziek-volume {
  display: block; width: 84px; min-width: 0; min-height: 0; margin: 0; padding: 0;
  border: 0; background: transparent; accent-color: #c6a66b; cursor: pointer;
}
.muziek button.muziek-knop {
  width: 48px; height: 48px; min-width: 48px; min-height: 48px; padding: 0; margin: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid #c6a66b; border-radius: 4px; background: #151e30; color: #c6a66b;
  cursor: pointer; font: inherit; transition: background .18s, color .18s;
}
.muziek button.muziek-knop:hover { background: #1c2940; }
.muziek button.muziek-knop[aria-pressed="true"] { background: #c6a66b; color: #0b1020; }
@media print { .muziek, .entrance { display: none !important; } }
