/* Tales from Loche Inn — the wrapper site. Warm, bookish, and out of the way. */

:root {
  --bg: #f6f0e4;
  --card: #fffaf0;
  --ink: #2b2118;
  --muted: #7a6a58;
  --line: #dccfb8;
  --accent: #8a3b12;
  --accent-ink: #fff8ee;
  --focus: #c46a2b;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1713;
    --card: #25201a;
    --ink: #eadfcc;
    --muted: #a8977f;
    --line: #3e352b;
    --accent: #e0915a;
    --accent-ink: #1b1713;
    --focus: #f0b07f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.55 Georgia, 'Iowan Old Style', 'Palatino Linotype', serif;
  padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0);
}
main { max-width: 40rem; margin: 0 auto; padding: 1rem 1rem 3rem; }
h1, h2, h3 { line-height: 1.2; font-weight: normal; }
h1 { font-size: 1.9rem; margin: 0.4em 0 0.2em; }
h2 { font-size: 1.3rem; margin: 1.4em 0 0.4em; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.center { text-align: center; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.masthead { text-align: center; padding: 1rem 1rem 0; }
.brand {
  font-variant: small-caps; letter-spacing: 0.12em; text-decoration: none;
  color: var(--muted); font-size: 0.95rem;
}

/* Library */
.blurb { font-style: italic; color: var(--muted); text-align: center; }
.tales { list-style: none; padding: 0; display: grid; gap: 0.9rem; }
.tale {
  display: block; text-decoration: none; color: inherit;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.1rem;
}
.tale:hover { border-color: var(--accent); }
.tale h2 { margin: 0 0 0.2em; }
.tale .meta { font-size: 0.85rem; color: var(--muted); }
.tale.with-art { display: grid; grid-template-columns: 5.6rem 1fr; gap: 1rem; align-items: start; padding: 0.9rem; }
.tale > div { min-width: 0; }
/* A tale's cover art, on the inn's shelf and on yours. */
.art { display: block; width: 100%; height: auto; border-radius: 3px 6px 6px 3px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); }

/* Shelf: the books bound in this browser. Each tale's cover has a hue of its own. */
.shelf { list-style: none; padding: 0; display: grid; gap: 1rem; margin: 1.4rem 0 0; }
.shelf-book {
  display: grid; grid-template-columns: 5.6rem 1fr; gap: 1rem; align-items: start;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 0.9rem;
}
.cover {
  display: flex; flex-direction: column; justify-content: space-between; aspect-ratio: 2 / 3; max-width: 100%;
  padding: 0.55rem 0.45rem; border-radius: 3px 6px 6px 3px; text-decoration: none; text-align: center;
  color: hsl(var(--hue) 30% 94%); background: hsl(var(--hue) 34% 30%);
  box-shadow: inset 5px 0 0 hsl(var(--hue) 34% 22%), 0 1px 3px rgba(0, 0, 0, 0.25);
}
.cover.with-art { display: block; aspect-ratio: auto; padding: 0; background: none; box-shadow: none; }
.cover-series { font-variant: small-caps; letter-spacing: 0.08em; font-size: 0.55rem; opacity: 0.8; }
.cover-title { font-size: 0.95rem; line-height: 1.15; overflow-wrap: anywhere; }
.cover-for { font-style: italic; font-size: 0.6rem; line-height: 1.25; opacity: 0.85; overflow-wrap: anywhere; }
.shelf-book .about { min-width: 0; }
.shelf-book h2 { margin: 0 0 0.15em; }
.shelf-book h2 a { color: inherit; text-decoration: none; }
.shelf-book .for { margin: 0 0 0.3em; font-style: italic; }
.shelf-book .meta { font-size: 0.85rem; color: var(--muted); margin: 0.3em 0 0.7em; }
.shelf-book .actions { gap: 0.45rem; }
.shelf-book .button { padding: 0.4rem 0.8rem; font-size: 0.95rem; }
.details { list-style: none; padding: 0; margin: 0.3em 0; font-size: 0.85rem; color: var(--muted); }
.details li { margin: 0.1em 0; }
.ready .details { margin: 0.4em auto; }
.note {
  font-size: 0.85rem; border-left: 3px solid var(--accent); padding: 0.2rem 0 0.2rem 0.6rem; margin: 0 0 0.8rem;
}
.actions.center { justify-content: center; }

/* Cast page */
.counts { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.4rem 0 1rem; }
.chip {
  font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 0.35rem 0.95rem; cursor: pointer;
}
.chip[aria-pressed='true'] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.cast-list { display: grid; gap: 0.7rem; margin: 0 0 1.4rem; padding: 0; list-style: none; }
.member {
  display: grid; grid-template-columns: 5.5rem 1fr auto; gap: 0.6rem; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 0.6rem 0.8rem;
}
.member .seat { font-variant: small-caps; color: var(--muted); letter-spacing: 0.05em; }
.member input, .member select {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 0.35rem 0.5rem; min-width: 0; width: 100%;
}
.member .field { display: flex; gap: 0.3rem; align-items: center; min-width: 0; }
/* A seat's own line, when a story gives it one: what that reader can do. */
.member .seat-role { grid-column: 1 / -1; font-size: 0.85rem; font-style: italic; color: var(--muted); }
/* A player's class, in a story that offers classes: the choice, and what that class is like. */
.member .class-pick { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 0.3rem 0.7rem; align-items: center; min-width: 0; }
.member .class-pick select { width: auto; flex: none; }
.member .class-role { font-size: 0.85rem; color: var(--muted); min-width: 0; }
.shuffle {
  font: inherit; font-size: 1.15rem; line-height: 1; flex: none; cursor: pointer;
  color: var(--accent); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 0.3rem 0.45rem;
}
.shuffle:hover { border-color: var(--accent); }
@media (max-width: 30rem) {
  .member { grid-template-columns: 1fr 1fr; }
  .member .seat { grid-column: 1 / -1; }
}
.hint { font-size: 0.85rem; color: var(--muted); }
/* Companions: the role on top (fixed), then the name and pronouns the reader may change. */
.member.companion { grid-template-columns: 1fr auto; }
.companion .bring { grid-column: 1 / -1; display: flex; gap: 0.55rem; align-items: baseline; cursor: pointer; }
.companion .bring input { flex: none; width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
.companion .role { font-variant: small-caps; letter-spacing: 0.03em; color: var(--muted); }
.companion[data-on='false'] { opacity: 0.55; }
.companion[data-on='false'] .role { text-decoration: line-through; }
/* A character nobody picks is still in the tale (Mags reads them), so it fades without being struck through. */
.character[data-on='false'] { opacity: 0.8; }
.character[data-on='false'] .role { text-decoration: none; }
@media (max-width: 30rem) {
  .member.companion { grid-template-columns: 1fr 1fr; }
}

/* Advanced: book settings and the inscription */
@font-face { font-family: 'Inscription Hand'; src: url('fonts/inscription-hand.ttf'); font-display: swap; }
@font-face { font-family: 'Inscription Italic'; src: url('fonts/inscription-italic.ttf'); font-display: swap; }
@font-face { font-family: 'Inscription Caps'; src: url('fonts/inscription-caps.ttf'); font-display: swap; }
.advanced { margin: 0 0 1.4rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); padding: 0.6rem 0.9rem; }
.advanced summary { cursor: pointer; font-variant: small-caps; letter-spacing: 0.05em; color: var(--muted); }
.advanced[open] summary { margin-bottom: 0.8rem; }
.setting { border: 0; padding: 0; margin: 0 0 1.1rem; min-width: 0; }
.setting legend { font-weight: bold; padding: 0; }
.setting .hint { margin: 0.1rem 0 0.4rem; }
.setting label { display: block; margin: 0.25rem 0; }
/* How Mags tells it: the NPCs' names, and the host's choices (a secret's answers stay covered) */
.host .npc .role { font-variant: normal; font-style: italic; letter-spacing: 0; }
.peek { margin: 0.35rem 0 0 1.5rem; }
.peek summary { cursor: pointer; font-size: 0.85rem; color: var(--muted); }
.peek[open] summary { margin-bottom: 0.2rem; }
.choices-row { display: flex; flex-wrap: wrap; gap: 0.2rem 1.2rem; margin: 0.4rem 0; }
.choices-row label { display: inline; margin: 0; }
#ins-text {
  font: inherit; color: var(--ink); background: var(--bg); width: 100%; box-sizing: border-box;
  border: 1px solid var(--line); border-radius: 6px; padding: 0.45rem 0.55rem; resize: vertical;
}
.ins-preview { border: 1px dashed var(--line); border-radius: 8px; padding: 1.4rem 1.2rem; margin-top: 0.6rem; font-size: 1.3rem; line-height: 1.5; overflow-wrap: anywhere; text-align: center; }
.ins-preview p { margin: 0; }
.ins-preview .ornament { color: var(--muted); margin: 0 0 0.6em; }
/* A title page's top, as the book prints it: the inscription is the line under the title. */
.title-preview { font-family: Georgia, 'Times New Roman', serif; font-size: 1rem; }
.title-preview .series { font-variant: small-caps; letter-spacing: 0.12em; color: var(--muted); }
.title-preview .title { font-size: 1.6em; margin: 0.2em 0 0.6em; }
.title-preview .for { font-style: italic; }
/* The inscription's fonts, in the preview and on a bound book's title page in the reader. */
.ins-preview [data-font], .page .title-page .for[data-font] { font-style: normal; font-size: 1.3em; line-height: 1.4; }
.ins-preview [data-font='hand'], .page .title-page .for[data-font='hand'] { font-family: 'Inscription Hand', cursive; }
.ins-preview [data-font='italic'], .page .title-page .for[data-font='italic'] { font-family: 'Inscription Italic', Georgia, serif; }
.ins-preview [data-font='caps'], .page .title-page .for[data-font='caps'] { font-family: 'Inscription Caps', Georgia, serif; }
.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.button {
  font: inherit; cursor: pointer; text-decoration: none; display: inline-block;
  border-radius: 8px; padding: 0.6rem 1.15rem; border: 1px solid var(--accent);
  background: transparent; color: var(--accent);
}
.button.primary { background: var(--accent); color: var(--accent-ink); }
.button[disabled] { opacity: 0.5; cursor: default; }
.linkish { font: inherit; background: none; border: 0; color: var(--accent); text-decoration: underline; cursor: pointer; padding: 0; }
.linkish[disabled] { color: var(--muted); text-decoration: none; cursor: default; }
.error { color: #b3261e; }
@media (prefers-color-scheme: dark) { .error { color: #ff8a80; } }
@media (max-width: 30rem) {
  .shelf-book, .tale.with-art { grid-template-columns: 4.6rem 1fr; gap: 0.8rem; padding: 0.75rem; }
  .cover-for { display: none; }
}

/* Binding animation: a little book riffling its pages. */
.binding { text-align: center; padding-top: 2rem; }
.book { position: relative; width: 120px; height: 84px; margin: 1.5rem auto 1.8rem; perspective: 600px; }
.book::before, .book::after {
  content: ''; position: absolute; top: 0; width: 60px; height: 84px;
  background: var(--card); border: 1px solid var(--line);
}
.book::before { left: 0; border-radius: 6px 0 0 6px; }
.book::after { right: 0; border-radius: 0 6px 6px 0; }
.leaf {
  position: absolute; top: 2px; left: 60px; width: 58px; height: 80px; z-index: 1;
  background: var(--card); border: 1px solid var(--line); border-radius: 0 5px 5px 0;
  transform-origin: left center; animation: riffle 1.6s ease-in-out infinite;
  background-image: repeating-linear-gradient(transparent 0 9px, var(--line) 9px 10px);
  background-size: 70% 100%; background-position: 50% 12px; background-repeat: no-repeat;
}
.leaf:nth-child(2) { animation-delay: 0.2s; }
.leaf:nth-child(3) { animation-delay: 0.4s; }
@keyframes riffle {
  0%, 15% { transform: rotateY(0deg); }
  60%, 100% { transform: rotateY(-180deg); }
}
@media (prefers-reduced-motion: reduce) { .leaf { animation: none; } }
.progress { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; max-width: 18rem; margin: 0.8rem auto; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

/* Ready */
.ready { text-align: center; }
.ready .actions { justify-content: center; margin: 1.2rem 0; }
.share-url { width: 100%; font: 0.8rem/1.4 ui-monospace, Menlo, monospace; padding: 0.4rem; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--ink); }

/* Reader: renders the book's own pages, styled like the ePub. */
.reader-bar {
  position: sticky; top: env(safe-area-inset-top, 0); z-index: 2;
  display: flex; gap: 0.6rem; align-items: center; justify-content: space-between;
  background: var(--bg); border-bottom: 1px solid var(--line); padding: 0.5rem 0;
}
.reader-bar .title { font-variant: small-caps; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page { padding-top: 1rem; font-size: var(--reader-size, 1.05rem); }
.page .turn-banner { border-bottom: 1px solid var(--line); margin-bottom: 1em; padding-bottom: 0.4em; }
.page .whose-turn { font-variant: small-caps; letter-spacing: 0.08em; font-weight: bold; margin: 0; font-size: 1.15em; }
.page .whose-turn .seat { font-weight: normal; color: var(--muted); font-size: 0.75em; }
.page .read-aloud { font-style: italic; color: var(--muted); margin: 0.2em 0 0; }
.page .passage p { text-indent: 1.3em; margin: 0 0 0.6em; }
.page .passage p:first-of-type { text-indent: 0; }
.page .choices { margin-top: 1.4em; border-top: 1px solid var(--line); padding-top: 0.6em; }
.page .choice { margin: 0; }
.page .choice a { display: block; padding: 0.55em 0; text-decoration: none; font-weight: bold; }
.page .choice .turn { display: none; } /* page numbers matter on paper, not here */
.page .handoff, .page .chance { font-style: italic; color: var(--muted); font-size: 0.9em; margin: 0.3em 0 0.2em; }
.page .choice .pass { display: block; margin: -0.45em 0 0.4em; font-size: 0.8em; color: var(--muted); }
/* A proof copy (npm run proof) marks the choices that lead to unwritten pages. */
.page .choice .unwritten { display: block; margin: -0.45em 0 0.4em; font-size: 0.8em; font-style: italic; color: #c0614f; }
.page .choice.return a, .page .choice.turn-page a { font-style: italic; }
.page .choice.turn-page { text-align: right; }
.page .folio { text-align: center; color: var(--muted); margin-top: 2em; font-size: 0.85em; }
.page .stories { list-style: none; padding: 0; }
.page .stories .meta { color: var(--muted); font-size: 0.8em; display: block; }
.page .loche-inn h1, .page .instruction, .page .blurb { text-align: center; }
.page .instruction { font-style: italic; color: var(--muted); }
.page .folio { display: none; } /* page numbers belong to the ePub, not the browser */
/* A tale's title page, mirroring the ePub's own. */
.page .title-page { text-align: center; padding-top: 1.5rem; }
.page .title-page .series { font-variant: small-caps; letter-spacing: 0.12em; color: var(--muted); margin: 0; }
.page .title-page h1 { font-size: 2.2em; margin: 0.25em 0 0.35em; }
.page .title-page .meta { color: var(--muted); font-size: 0.9em; margin: 0; }
.page .title-page .for { font-style: italic; margin: 1.4em 0; }
.page .title-page .blurb { text-align: left; font-style: normal; color: var(--ink); margin: 0 0 1.4em; }
.page .title-page .choice { border-top: 1px solid var(--line); padding-top: 0.4em; }
/* Setpieces and handoffs, mirroring the ePub's own styles. */
.page .flourish, .page .dinkus { text-align: center; color: var(--muted); margin: 0.9em 0; text-indent: 0; }
.page .flourish { font-size: 1.5em; }
.page .dinkus { letter-spacing: 0.4em; }
.page .setpiece p:first-of-type { overflow: hidden; } /* keep the drop cap inside its paragraph */
.page .setpiece p:first-of-type::first-letter { float: left; font-size: 3.2em; line-height: 0.85; padding: 0.06em 0.1em 0 0; font-weight: bold; color: var(--accent); }
