/* Dungeons & Bullshit — an illuminated manuscript found in a damp crypt. */

:root {
  --crypt: #1d1815;
  --crypt-2: #28211c;
  --crypt-3: #3a3029;
  --vellum: #e9dfc4;
  --vellum-2: #dccfae;
  --ink: #2a1f16;
  --ink-soft: #5c4a3a;
  --rubric: #8f1d14;
  --rubric-deep: #6a130d;
  --gilt: #b48a34;
  --moss: #4e6b45;
  --ash: #a89d8c;

  --blackletter: "UnifrakturMaguntia", "Old English Text MT", "Luminari", fantasy, serif;
  --fell: "IM Fell English", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;

  --step--1: 0.875rem;
  --step-0: 1.0625rem;
  --step-1: 1.3rem;
  --step-2: 1.7rem;
  --step-3: 2.4rem;
  --step-4: clamp(3rem, 11vw, 7.5rem);
}

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--crypt); color: var(--vellum); }
body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--fell);
  font-size: var(--step-0);
  line-height: 1.55;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(180, 138, 52, 0.10), transparent 60%),
    var(--crypt);
}

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--gilt); }
:focus-visible { outline: 2px solid var(--gilt); outline-offset: 3px; }
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- masthead & footer ---------- */
.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--crypt-3);
}
.brand { font-family: var(--blackletter); font-size: var(--step-1); text-decoration: none; letter-spacing: 0.01em; }
.masthead-tools { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; justify-content: flex-end; }
.trial-clock { font-size: var(--step--1); color: var(--ash); font-variant-numeric: tabular-nums; }
.trial-clock.low { color: #e0877e; }

.site-footer {
  margin-top: auto;
  padding: 1.5rem clamp(1rem, 3vw, 2rem) 2rem;
  border-top: 1px solid var(--crypt-3);
  color: var(--ash);
  font-size: var(--step--1);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  justify-content: space-between;
}
.site-footer nav { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; }

/* ---------- buttons ---------- */
.btn-seal {
  appearance: none;
  border: 0;
  cursor: pointer;
  padding: 0.6rem 1.3rem 0.65rem;
  border-radius: 999px;
  background: var(--rubric);
  color: #f6ead0;
  font-size: var(--step-0);
  box-shadow: inset 0 -3px 0 var(--rubric-deep), 0 1px 0 rgba(0, 0, 0, 0.4);
  transition: transform 120ms ease, background-color 120ms ease;
}
.btn-seal:hover { background: #a3241a; }
.btn-seal:active { transform: translateY(1px); box-shadow: inset 0 -1px 0 var(--rubric-deep); }
.btn-seal:disabled { opacity: 0.55; cursor: progress; }
.btn-ghost {
  appearance: none;
  cursor: pointer;
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 0.55rem 1.2rem;
}
.btn-quiet {
  appearance: none;
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0.25rem 0;
  color: var(--ash);
  font-size: var(--step--1);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.btn-quiet:hover { color: var(--vellum); }
.linklike { appearance: none; background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- vellum surfaces ---------- */
.vellum {
  background:
    radial-gradient(ellipse at 20% 10%, rgba(255, 250, 235, 0.55), transparent 55%),
    radial-gradient(ellipse at 90% 95%, rgba(120, 90, 50, 0.18), transparent 50%),
    var(--vellum);
  color: var(--ink);
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), 0 18px 40px -18px rgba(0, 0, 0, 0.8), inset 0 0 60px rgba(120, 90, 50, 0.22);
}
.vellum a:hover { color: var(--rubric); }

.initial {
  font-family: var(--blackletter);
  color: var(--rubric);
  float: left;
  font-size: 3.6em;
  line-height: 0.8;
  padding: 0.08em 0.1em 0 0;
  margin-bottom: -0.1em;
}

/* ---------- title screen ---------- */
.screen { width: 100%; }
.title-screen {
  padding: clamp(2rem, 6vw, 5rem) clamp(1rem, 4vw, 2rem) 3rem;
  display: grid;
  justify-items: center;
  gap: 2.5rem;
}
.title-mark {
  font-family: var(--blackletter);
  font-weight: 400;
  font-size: var(--step-4);
  line-height: 0.92;
  text-align: center;
  margin: 0;
  color: var(--vellum);
  text-shadow: 0 2px 0 #000, 0 0 40px rgba(180, 138, 52, 0.25);
}
.title-mark .amp { display: block; font-size: 0.55em; line-height: 1.1; color: var(--ash); }
@media (prefers-reduced-motion: no-preference) {
  .title-mark { animation: candle 900ms ease-out both; }
  @keyframes candle { from { opacity: 0; filter: blur(6px); } to { opacity: 1; filter: blur(0); } }
}

.charter {
  position: relative;
  max-width: 38rem;
  width: 100%;
  padding: clamp(1.5rem, 4vw, 2.5rem) clamp(1.25rem, 4vw, 2.75rem) 2.25rem;
  line-height: 1.65;
}
.charter p { margin: 0 0 1rem; }
.charter .lede { font-size: var(--step-1); line-height: 1.5; }
.charter-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin: 1.75rem 0 1.25rem; }
.charter .fine { font-size: var(--step--1); color: var(--ink-soft); margin: 0; }
.seal {
  position: absolute;
  right: -18px;
  bottom: -22px;
  width: 78px;
  height: 78px;
  border-radius: 47% 53% 50% 50% / 52% 48% 52% 48%;
  background: radial-gradient(circle at 38% 35%, #b8342a, var(--rubric) 55%, var(--rubric-deep));
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5), inset 0 0 0 6px rgba(0, 0, 0, 0.12);
  display: grid;
  place-items: center;
  font-family: var(--blackletter);
  font-size: 1.9rem;
  color: rgba(246, 234, 208, 0.75);
  transform: rotate(-8deg);
}

.howto { max-width: 38rem; width: 100%; color: var(--ash); }
.howto summary { cursor: pointer; color: var(--vellum); }
.howto ul { padding-left: 1.2rem; }
.howto li { margin-bottom: 0.4rem; }

.error { color: var(--rubric); font-style: italic; margin-top: 0.75rem; }
.on-dark .error, .error.on-dark { color: #e0877e; }

/* ---------- character creation ---------- */
.create {
  max-width: 40rem;
  margin: clamp(1.5rem, 5vw, 3rem) auto 3rem;
  padding: clamp(1.5rem, 4vw, 2.5rem);
}
.create h2 { font-family: var(--blackletter); font-weight: 400; font-size: var(--step-3); margin: 0 0 0.25rem; line-height: 1.1; }
.create > p { margin-top: 0; color: var(--ink-soft); }
.field { display: grid; gap: 0.35rem; margin: 1.5rem 0; }
.field label, .field legend { font-size: var(--step-1); }
.text-input {
  width: 100%;
  padding: 0.55rem 0.2rem;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--ink-soft);
  color: var(--ink);
}
.text-input:focus { outline: none; border-bottom: 2px solid var(--rubric); }
fieldset { border: 0; padding: 0; margin: 1.5rem 0; }
.classes { list-style: none; padding: 0; margin: 0.5rem 0 0; }
.classes li + li { border-top: 1px dotted rgba(42, 31, 22, 0.35); }
.class-option { display: grid; grid-template-columns: auto 1fr; gap: 0.1rem 0.75rem; padding: 0.7rem 0.25rem; cursor: pointer; }
.class-option input { grid-row: span 2; margin-top: 0.4rem; accent-color: var(--rubric); }
.class-option strong { font-weight: 400; font-size: var(--step-1); }
.class-option span { color: var(--ink-soft); font-style: italic; }
.class-option:has(input:checked) strong { color: var(--rubric); }
#custom-class { margin-top: 0.25rem; }

/* ---------- game layout ---------- */
.game {
  display: grid;
  grid-template-columns: minmax(0, 46rem) 17.5rem;
  grid-template-areas: "page ledger" "action ledger";
  grid-template-rows: 1fr auto;
  gap: 1rem 1.75rem;
  justify-content: center;
  padding: 1rem clamp(0.75rem, 3vw, 2rem) 1.25rem;
  height: calc(100dvh - 3.6rem);
  min-height: 32rem;
}
.page { grid-area: page; display: flex; flex-direction: column; min-height: 0; }
.log {
  flex: 1;
  overflow-y: auto;
  padding: clamp(1.25rem, 3vw, 2.25rem) clamp(1rem, 4vw, 3rem) 1rem;
  scroll-behavior: smooth;
  line-height: 1.7;
}
@media (prefers-reduced-motion: reduce) { .log { scroll-behavior: auto; } }

.entry-dm { margin: 0 0 1.4rem; max-width: 62ch; }
.entry-dm p { margin: 0 0 0.8rem; }
.entry-dm p:last-of-type { margin-bottom: 0.4rem; }
.entry-dm::after { content: ""; display: block; clear: both; }
.tally { font-size: var(--step--1); color: var(--ink-soft); font-style: italic; clear: both; }
.tally .up { color: var(--moss); }
.tally .down { color: var(--rubric); }

.entry-player {
  margin: 0 0 1.4rem;
  padding-left: 1.6rem;
  text-indent: -1.6rem;
  font-style: italic;
  color: var(--ink-soft);
}
.entry-player::before { content: "☞"; display: inline-block; width: 1.6rem; text-indent: 0; font-style: normal; color: var(--rubric); }

.entry-decree {
  margin: 0.25rem 0 1.6rem;
  padding: 0.9rem 1.1rem 1rem 1.1rem;
  border: 1px solid rgba(143, 29, 20, 0.45);
  border-left: 4px double var(--rubric);
  background: rgba(143, 29, 20, 0.05);
  max-width: 58ch;
}
.entry-decree h3 { margin: 0 0 0.2rem; font-family: var(--blackletter); font-weight: 400; color: var(--rubric); font-size: var(--step-1); }
.entry-decree p { margin: 0; }
@media (prefers-reduced-motion: no-preference) {
  .entry-decree.fresh { animation: stamp 420ms cubic-bezier(.2,1.6,.4,1) both; }
  @keyframes stamp { from { transform: scale(1.06); opacity: 0; } to { transform: none; opacity: 1; } }
}

.entry-system { margin: 0 0 1.2rem; font-size: var(--step--1); color: var(--rubric); font-style: italic; }

.thinking { padding: 0 clamp(1rem, 4vw, 3rem) 1rem; font-style: italic; color: var(--ink-soft); }
@media (prefers-reduced-motion: no-preference) {
  .thinking { animation: flicker 1.6s ease-in-out infinite; }
  @keyframes flicker { 50% { opacity: 0.55; } }
}

/* action bar */
.action-bar { grid-area: action; display: grid; gap: 0.6rem; }
.suggestions { display: flex; flex-wrap: wrap; gap: 0.4rem 0.5rem; min-height: 1.6rem; }
.suggestion {
  appearance: none;
  cursor: pointer;
  background: transparent;
  border: 1px solid var(--crypt-3);
  border-radius: 999px;
  padding: 0.25rem 0.8rem;
  font-size: var(--step--1);
  color: var(--ash);
  font-style: italic;
}
.suggestion:hover { border-color: var(--gilt); color: var(--vellum); }
.action-input {
  width: 100%;
  resize: none;
  background: var(--crypt-2);
  border: 1px solid var(--crypt-3);
  border-radius: 3px;
  padding: 0.7rem 0.9rem;
  color: var(--vellum);
  line-height: 1.45;
}
.action-input::placeholder { color: var(--ash); font-style: italic; }
.action-input:focus { outline: none; border-color: var(--gilt); }
.action-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.char-count { font-size: var(--step--1); color: var(--ash); font-variant-numeric: tabular-nums; }

/* ledger */
.ledger {
  grid-area: ledger;
  overflow-y: auto;
  padding: 0.25rem 0.25rem 1rem;
  color: var(--vellum);
}
.ledger h2 { font-family: var(--blackletter); font-weight: 400; font-size: var(--step-2); margin: 0 0 0.25rem; line-height: 1.1; }
.ledger .who { margin: 0 0 1.25rem; color: var(--ash); font-style: italic; }
.ledger h3 { font-weight: 400; font-size: var(--step-1); margin: 1.5rem 0 0.4rem; color: var(--gilt); }
.stat { display: grid; grid-template-columns: 1fr auto; align-items: baseline; margin-bottom: 0.55rem; }
.stat-value { font-variant-numeric: tabular-nums; }
.meter { grid-column: 1 / -1; height: 5px; background: var(--crypt-3); border-radius: 3px; overflow: hidden; margin-top: 0.2rem; }
.meter > span { display: block; height: 100%; background: var(--rubric); transition: width 400ms ease; }
.meter.dignity > span { background: var(--gilt); }
.ledger ul, .ledger ol { margin: 0; padding-left: 1.2rem; }
.ledger li { margin-bottom: 0.35rem; line-height: 1.4; }
.ledger ol li::marker { color: var(--rubric); font-family: var(--blackletter); }
.ledger .empty { color: var(--ash); font-style: italic; margin: 0; }
.ledger-close { display: none; }

@media (max-width: 900px) {
  .game {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "page" "action";
    height: calc(100dvh - 3.6rem);
  }
  .ledger {
    position: fixed;
    inset: 0 0 0 auto;
    width: min(21rem, 88vw);
    z-index: 20;
    background: var(--crypt-2);
    padding: 1.25rem 1.25rem 2rem;
    box-shadow: -20px 0 40px rgba(0, 0, 0, 0.6);
    transform: translateX(105%);
    transition: transform 220ms ease;
  }
  .ledger.open { transform: none; }
  .ledger-close { display: inline-block; float: right; }
}
@media (min-width: 901px) { #ledger-toggle { display: none !important; } }

/* ---------- dialogs ---------- */
dialog {
  border: 0;
  padding: 0;
  max-width: min(34rem, 92vw);
  width: 100%;
  background: transparent;
  color: var(--ink);
}
dialog::backdrop { background: rgba(10, 7, 5, 0.78); }
.dialog-body { padding: clamp(1.5rem, 4vw, 2.25rem); }
.dialog-body h2 { font-family: var(--blackletter); font-weight: 400; font-size: var(--step-3); line-height: 1.05; margin: 0 0 0.75rem; }
.dialog-body p { margin: 0 0 1rem; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; margin-top: 1.25rem; }
.key-form { display: flex; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; }
.key-form .text-input { flex: 1 1 14rem; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.95rem; }
.divider-note { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px dotted rgba(42, 31, 22, 0.4); font-size: var(--step--1); }

.epitaph {
  text-align: center;
  padding: 1.5rem 1rem;
  margin: 0.5rem 0 1.25rem;
  border-top: 1px solid rgba(42, 31, 22, 0.35);
  border-bottom: 1px solid rgba(42, 31, 22, 0.35);
  font-size: var(--step-1);
  font-style: italic;
  line-height: 1.5;
}
.final-stats { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; justify-content: center; color: var(--ink-soft); font-size: var(--step--1); margin: 0 0 0.5rem; }

/* ---------- document pages (changelog, legal) ---------- */
.doc {
  max-width: 44rem;
  margin: clamp(1.5rem, 5vw, 3.5rem) auto 3rem;
  padding: clamp(1.5rem, 5vw, 3rem) clamp(1.25rem, 5vw, 3.25rem);
  line-height: 1.7;
}
.doc h1 { font-family: var(--blackletter); font-weight: 400; font-size: var(--step-3); line-height: 1.05; margin: 0 0 0.5rem; }
.doc h2 { font-weight: 400; font-size: var(--step-2); margin: 2.25rem 0 0.5rem; line-height: 1.2; }
.doc h3 { font-weight: 400; font-size: var(--step-1); margin: 1.5rem 0 0.25rem; }
.doc .updated { color: var(--ink-soft); font-style: italic; margin-top: 0; }
.doc ul { padding-left: 1.25rem; }
.doc li { margin-bottom: 0.4rem; }
.doc .todo { background: rgba(180, 138, 52, 0.25); padding: 0 0.2em; }
.doc table { border-collapse: collapse; width: 100%; font-size: var(--step--1); margin: 1rem 0; }
.doc th, .doc td { text-align: left; vertical-align: top; padding: 0.5rem 0.6rem; border-bottom: 1px solid rgba(42, 31, 22, 0.25); }
.doc th { font-weight: 400; color: var(--rubric); }
.table-wrap { overflow-x: auto; }

.release { margin-top: 2.5rem; }
.release h2 { margin: 0; }
.release time { color: var(--ink-soft); font-style: italic; }

.notfound { text-align: center; padding: 5rem 1rem; }
.notfound h1 { font-family: var(--blackletter); font-weight: 400; font-size: var(--step-4); margin: 0; line-height: 1; }

.btn-quiet.on-vellum { color: var(--ink-soft); }
.btn-quiet.on-vellum:hover { color: var(--rubric); }
a.btn-seal { display: inline-block; text-decoration: none; }
a.btn-seal:hover { color: #f6ead0; }
.key-hint { margin: 0.75rem 0 0; }

body:not(.in-game) .trial-clock { display: none !important; }
@media (max-width: 520px) { .seal { right: 10px; bottom: -26px; width: 64px; height: 64px; font-size: 1.6rem; } }
