/* Erfurt Latrine Disaster — manuscript stylesheet
   Codex Manesse palette: jewel-blue, vermillion, gilt, parchment cream. */

:root {
  --parchment:   #ecdcb4;
  --parchment-2: #d8c189;
  --ink:         #2a1a0a;
  --vermillion:  #a82b2b;
  --azure:       #2c3a6b;
  --verdigris:   #2a5a3a;
  --gilt:        #d4af37;
  --gilt-deep:   #9a6f1a;
  --filth:       #4a2a14;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  min-height: 100%;
  background:
    radial-gradient(ellipse at 30% 20%, #f3e3b8 0%, #d6bd80 60%, #b89a55 100%);
  color: var(--ink);
  font-family: 'IM Fell English', 'Cormorant Garamond', Georgia, serif;
  font-size: 18px;
  line-height: 1.6;
}

/* The bound codex — a two-column spread on wide screens, single column on narrow */
.codex {
  max-width: 1100px;
  margin: 2rem auto;
  padding: 1rem;
}

.page {
  position: relative;
  background:
    repeating-linear-gradient(0deg, transparent 0 28px, rgba(90,50,20,.04) 28px 29px),
    radial-gradient(ellipse at 50% 0%, #f4e3b8, var(--parchment) 60%, var(--parchment-2) 100%);
  border-radius: 4px;
  box-shadow:
    0 2px 0 rgba(0,0,0,.08),
    0 18px 40px -10px rgba(60,30,10,.45),
    inset 0 0 60px rgba(120,70,20,.18);
  padding: 3.2rem 3rem 2.4rem;
  overflow: hidden;
  transform-origin: left center;
}

/* Page-turn flourish on passage change */
.page.turn { animation: pageTurn .6s ease-out; }
@keyframes pageTurn {
  0%   { transform: perspective(1400px) rotateY(-22deg); opacity: .2; }
  60%  { opacity: 1; }
  100% { transform: perspective(1400px) rotateY(0); opacity: 1; }
}

/* Illuminated border (CSS placeholder; replace with painted PNG strips later) */
.border-frame { position: absolute; inset: 0; pointer-events: none; }
.border-top, .border-bottom, .border-left, .border-right {
  position: absolute;
  background:
    linear-gradient(90deg, var(--gilt) 0 8px, transparent 8px) repeat-x,
    repeating-linear-gradient(45deg, var(--vermillion) 0 12px, var(--azure) 12px 24px, var(--verdigris) 24px 36px);
  background-size: 24px 100%, 36px 36px;
  opacity: .85;
}
.border-top, .border-bottom { left: 0; right: 0; height: 16px; }
.border-top    { top: 0; }
.border-bottom { bottom: 0; }
.border-left, .border-right { top: 0; bottom: 0; width: 16px; }
.border-left  { left: 0; }
.border-right { right: 0; }

.rosette {
  position: absolute; width: 28px; height: 28px;
  background: radial-gradient(circle, var(--gilt) 30%, var(--gilt-deep) 60%, var(--vermillion) 100%);
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--parchment), 0 0 0 4px var(--gilt-deep);
}
.rosette.tl { top: 2px; left: 2px; }
.rosette.tr { top: 2px; right: 2px; }
.rosette.bl { bottom: 2px; left: 2px; }
.rosette.br { bottom: 2px; right: 2px; }

/* Illumination (scene art) */
.illumination {
  position: relative;
  margin: 0 auto 1.4rem;
  max-width: 720px;
  border: 3px solid var(--gilt-deep);
  outline: 1px solid var(--ink);
  box-shadow: 0 0 0 6px var(--parchment), 0 6px 18px rgba(0,0,0,.35);
  overflow: hidden;
  background: #0a0a0a;
}
.scene { display: block; width: 100%; height: auto; }
.scene-painting { display: block; width: 100%; height: auto; }
.scene-painting[hidden] { display: none; }

/* Text column */
.vellum { max-width: 720px; margin: 0 auto; }

.title {
  font-family: 'UnifrakturMaguntia', 'IM Fell English', serif;
  font-weight: 400;
  font-size: 2.1rem;
  text-align: center;
  color: var(--vermillion);
  margin: 0 0 1rem;
  letter-spacing: .01em;
  text-shadow: 0 1px 0 rgba(0,0,0,.15);
}

.prose p {
  margin: 0 0 1rem;
  text-align: justify;
  hyphens: auto;
}

.dropcap {
  float: left;
  font-family: 'UnifrakturMaguntia', serif;
  font-size: 3.6em;
  line-height: .85;
  padding: .08em .12em 0 0;
  margin: .05em .08em -.1em 0;
  color: var(--vermillion);
  text-shadow: 1px 1px 0 var(--gilt);
}

/* Glossed German terms */
.ger {
  font-style: italic;
  color: var(--gilt-deep);
  border-bottom: 1px dotted var(--gilt-deep);
  cursor: pointer;
  user-select: none;
}
.ger:hover { color: var(--vermillion); border-bottom-color: var(--vermillion); }
.ger.oath { color: var(--vermillion); font-weight: 600; }

/* Speech-bubble tooltip for German glosses */
.ger-bubble {
  position: fixed;
  z-index: 1000;
  max-width: 22em;
  padding: .55rem .85rem;
  background: linear-gradient(180deg, #f7e7bd, var(--parchment));
  color: var(--ink);
  border: 1px solid var(--gilt-deep);
  border-radius: 4px;
  box-shadow:
    0 0 0 2px rgba(212,175,55,.25),
    0 6px 18px rgba(60,30,10,.4);
  font-family: 'IM Fell English', 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 1rem;
  line-height: 1.4;
  pointer-events: auto;
  animation: bubbleIn .14s ease-out;
}
.ger-bubble[hidden] { display: none; }

/* Tail (default: pointing down, bubble above the word) — two stacked triangles for gilt border + parchment fill */
.ger-bubble::after,
.ger-bubble::before {
  content: ""; position: absolute; left: 50%;
  width: 0; height: 0; border: 8px solid transparent;
}
.ger-bubble::after  { top: 100%; transform: translateX(-50%); border-top-color: var(--gilt-deep); }
.ger-bubble::before { top: 100%; transform: translateX(-50%) translateY(-1.5px); border-top-color: var(--parchment); border-width: 7px; margin-left: -7px; z-index: 1; }

/* Flipped tail (when bubble sits below the word) */
.ger-bubble.below::after  { top: auto; bottom: 100%; border-top-color: transparent; border-bottom-color: var(--gilt-deep); }
.ger-bubble.below::before { top: auto; bottom: 100%; border-top-color: transparent; border-bottom-color: var(--parchment); transform: translateX(-50%) translateY(1.5px); }

@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(4px) scale(.96); }
  to   { opacity: 1; transform: translateY(0)   scale(1);   }
}

/* Choices */
.choices {
  list-style: none;
  padding: 0;
  margin: 1.6rem 0 0;
  display: grid;
  gap: .6rem;
}
.choice {
  display: block;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 1.02rem;
  line-height: 1.5;
  background: linear-gradient(180deg, #f3e3b8, var(--parchment));
  color: var(--ink);
  border: 1px solid var(--gilt-deep);
  border-left: 6px solid var(--vermillion);
  padding: .7rem .9rem;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(0,0,0,.15), inset 0 0 0 1px rgba(255,255,255,.4);
  transition: transform .12s ease, background .2s ease, border-color .2s ease;
}
.choice:hover {
  background: linear-gradient(180deg, #fff0c4, #f0d99a);
  border-left-color: var(--gilt-deep);
  transform: translateX(3px);
}
.choice:focus-visible { outline: 2px solid var(--azure); outline-offset: 2px; }

/* Stat annotation on choices — marginal note showing what the choice grants or requires */
.choice-tag {
  display: inline-block;
  margin-left: .55em;
  padding: 0 .4em;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: .78rem;
  font-weight: 600;
  font-variant: small-caps;
  letter-spacing: .04em;
  color: var(--gilt-deep);
  background: rgba(212, 175, 55, .14);
  border: 1px solid rgba(154, 111, 26, .45);
  border-radius: 2px;
  vertical-align: .14em;
  white-space: nowrap;
}
.choice-tag.req {
  color: var(--vermillion);
  background: rgba(168, 43, 43, .09);
  border-color: rgba(168, 43, 43, .45);
}

/* Post-click flash pill — appears in the same slot the old prewarning tag occupied */
.choice-flash {
  display: inline-block;
  margin-left: .55em;
  padding: 0 .55em;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: .82rem;
  font-weight: 700;
  font-variant: small-caps;
  letter-spacing: .06em;
  border-radius: 2px;
  vertical-align: .14em;
  white-space: nowrap;
  animation: flashIn .55s cubic-bezier(.34,1.56,.64,1);
}
.choice-flash.gain,
.choice-flash.success {
  color: #1d6a32;
  background: rgba(45, 160, 60, .18);
  border: 1px solid rgba(45, 160, 60, .55);
  box-shadow: 0 0 8px rgba(45, 160, 60, .45);
}
.choice-flash.fail {
  color: #6a0e0e;
  background: rgba(168, 43, 43, .15);
  border: 1px solid rgba(168, 43, 43, .55);
  box-shadow: 0 0 8px rgba(168, 43, 43, .45);
}
@keyframes flashIn {
  0%   { opacity: 0; transform: scale(.55); }
  60%  { opacity: 1; transform: scale(1.18); }
  100% { opacity: 1; transform: scale(1);    }
}

/* Glowing pulse for a stat that just went up in the colophon */
#stats span { display: inline-block; transition: color .2s ease; }
#stats .stat-glow {
  color: #1d6a32;
  font-weight: 700;
  text-shadow:
    0 0 6px  rgba(45, 160, 60, .9),
    0 0 14px rgba(45, 160, 60, .55);
  animation: statPulse 950ms ease-out;
}
@keyframes statPulse {
  0%   { transform: scale(1);   }
  25%  { transform: scale(1.7); }
  60%  { transform: scale(1.1); }
  100% { transform: scale(1);   }
}

/* Stat-flavoured aside — wry inner reaction set off from the main narrative */
.aside {
  margin: .4rem 0 1rem 1rem;
  padding: .35rem .9rem;
  font-style: italic;
  color: var(--gilt-deep);
  border-left: 2px solid var(--gilt-deep);
  background: rgba(212, 175, 55, .05);
  opacity: .92;
}

/* Closing epitaph — a 4-line verse rendered as illuminated quotation */
.epitaph {
  margin: 1.8rem auto 0;
  padding: 1.1rem 1.4rem 1.2rem;
  max-width: 28em;
  text-align: center;
  font-family: 'IM Fell English', 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 1.12rem;
  line-height: 1.55;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255,255,255,.25), rgba(120,70,20,.04));
  border-top: 1px solid var(--gilt-deep);
  border-bottom: 1px solid var(--gilt-deep);
  position: relative;
}
.epitaph::before,
.epitaph::after {
  content: "❧";
  display: block;
  color: var(--gilt-deep);
  font-style: normal;
  font-size: 1.1rem;
  line-height: 1;
}
.epitaph::before { margin-bottom: .55rem; }
.epitaph::after  { margin-top:    .55rem; transform: rotate(180deg); }
.epitaph.survived { color: #3a2410; }
.epitaph.perished { color: var(--filth); background: linear-gradient(180deg, rgba(74,42,20,.08), rgba(74,42,20,.18)); }
.epitaph.delivered {
  color: var(--azure);
  background: linear-gradient(180deg, rgba(44,58,107,.06), rgba(212,175,55,.10));
  border-top-color: var(--azure);
  border-bottom-color: var(--azure);
}
.epitaph.vigorous {
  color: #3a4a14;
  background: linear-gradient(180deg, rgba(120,70,20,.05), rgba(42,90,58,.12));
  border-top-color: var(--verdigris);
  border-bottom-color: var(--verdigris);
}
.epitaph.rescued {
  color: #3a2a14;
  background: linear-gradient(180deg, rgba(255,255,255,.28), rgba(120,70,20,.06));
}

.colophon {
  margin-top: 2rem;
  padding-top: .8rem;
  border-top: 1px dashed var(--gilt-deep);
  display: flex; justify-content: space-between; align-items: center;
  font-style: italic;
  color: var(--gilt-deep);
  font-size: .9rem;
}
.restart {
  background: transparent;
  border: 1px solid var(--gilt-deep);
  color: var(--gilt-deep);
  font: inherit;
  padding: .3rem .7rem;
  cursor: pointer;
  border-radius: 2px;
}
.restart:hover { background: var(--gilt); color: var(--ink); }

/* ---------- Cover scene (opening book) ---------- */
body.scene-cover .page {
  position: relative;
  padding: 0;
  overflow: hidden;
  background: #0c0602;
  box-shadow:
    0 2px 0 rgba(0,0,0,.18),
    0 22px 50px -10px rgba(0,0,0,.7);
}
body.scene-cover .border-frame { display: none; }
body.scene-cover .illumination {
  max-width: none;
  width: 100%;
  margin: 0;
  border: none;
  outline: none;
  box-shadow: none;
  background: transparent;
}
body.scene-cover .illumination .scene-painting {
  display: block;
  width: 100%;
  height: auto;
}
body.scene-cover .vellum {
  position: absolute;
  bottom: 6%;
  left: 50%;
  transform: translateX(-50%) rotate(-1deg);
  width: min(440px, 80%);
  margin: 0;
  padding: 1.5rem 1.5rem 1.2rem;
  background: linear-gradient(180deg, #f7e9c1 0%, var(--parchment) 50%, #cdb47a 100%);
  color: var(--ink);
  box-shadow:
    0 16px 36px rgba(0,0,0,.65),
    0 0 0 1px rgba(60,30,10,.35);
  border-radius: 3px;
  z-index: 2;
}
/* Rolled-scroll ends, top and bottom */
body.scene-cover .vellum::before,
body.scene-cover .vellum::after {
  content: "";
  position: absolute; left: -10px; right: -10px;
  height: 16px;
  background: linear-gradient(180deg, #b89a55, #e2c587 50%, #8a6f30);
  border-radius: 9px;
  box-shadow: 0 3px 6px rgba(0,0,0,.5);
}
body.scene-cover .vellum::before { top: -8px; }
body.scene-cover .vellum::after  { bottom: -8px; }

body.scene-cover .title {
  font-size: 1.55rem;
  margin: 0 0 .8rem;
  text-align: center;
}
body.scene-cover .colophon { display: none; }

.cover-tag {
  text-align: center;
  font-style: italic;
  color: var(--gilt-deep);
  font-size: .92rem;
  margin: 0 0 .9rem;
  letter-spacing: .03em;
}
.cover-disclaimer {
  margin-top: 1.1rem;
  padding: .75rem 1rem;
  font-style: italic;
  font-size: .92rem;
  line-height: 1.55;
  color: #3a2410;
  background: rgba(255,255,255,.32);
  border-left: 3px solid var(--gilt-deep);
  border-radius: 0 2px 2px 0;
}
.disclaimer-link {
  color: var(--vermillion);
  text-decoration: underline;
  text-decoration-color: rgba(168, 43, 43, .5);
  text-underline-offset: 2px;
  transition: text-decoration-color .15s ease;
}
.disclaimer-link:hover,
.disclaimer-link:focus-visible {
  text-decoration-color: var(--vermillion);
}

/* Narrow screens */
@media (max-width: 640px) {
  html, body { font-size: 16px; }
  .codex { padding: 1rem .6rem; }
  .page { padding: 1.6rem 1.5rem 1.4rem; }
  .title { font-size: 1.3rem; line-height: 1.25; margin-bottom: .85rem; }
  .dropcap { font-size: 3em; }
  .prose p { line-height: 1.55; margin-bottom: .85rem; }
  .choice { font-size: .92rem; padding: .55rem .75rem; }
  .aside { font-size: .85rem; padding: .35rem .75rem; margin-left: .7rem; }
  .epitaph { font-size: .95rem; padding: .9rem 1rem; max-width: 24em; }
  .colophon { font-size: .78rem; }

  /* Cover scroll — shrink so it sits within the leather cover without clipping */
  body.scene-cover .page { padding: 0; }
  body.scene-cover .vellum {
    width: min(320px, 86%);
    padding: 1rem 1rem .9rem;
    bottom: 4%;
  }
  body.scene-cover .title {
    font-size: 1.15rem;
    margin-bottom: .55rem;
  }
  body.scene-cover .prose p {
    font-size: .82rem;
    line-height: 1.45;
    margin-bottom: .65rem;
  }
  body.scene-cover .cover-tag {
    font-size: .78rem;
    margin-bottom: .55rem;
  }
  body.scene-cover .cover-disclaimer {
    font-size: .76rem;
    padding: .5rem .7rem;
    margin-top: .65rem;
    line-height: 1.4;
  }
  body.scene-cover .vellum::before,
  body.scene-cover .vellum::after {
    height: 11px;
    left: -6px; right: -6px;
  }
  body.scene-cover .vellum::before { top: -6px; }
  body.scene-cover .vellum::after  { bottom: -6px; }
  body.scene-cover .choice {
    font-size: .9rem;
    padding: .5rem .7rem;
  }
}

@media (max-width: 400px) {
  body.scene-cover .vellum {
    width: 88%;
    padding: .85rem .85rem .8rem;
  }
  body.scene-cover .title       { font-size: 1.05rem; }
  body.scene-cover .prose p     { font-size: .76rem; }
  body.scene-cover .cover-tag   { font-size: .72rem; }
  body.scene-cover .cover-disclaimer { font-size: .72rem; padding: .45rem .6rem; }
  body.scene-cover .choice      { font-size: .82rem; padding: .42rem .6rem; }
}
