/* Story shelf and reader (stories/index.html, stories/read.html). Uses the shared tokens in site.css. */

/* ---------- Shelf ---------- */
.st-shelf { padding-bottom: 48px; }
.st-count { font: 400 var(--kid-size)/1.5 var(--font-kid); color: var(--ink-2); margin: 4px 0 28px; max-width: 62ch; }
.st-unit { margin: 0 0 40px; }
.st-unit h2 { display: flex; align-items: center; gap: 12px; margin: 0 0 16px; font: 800 clamp(22px, 3vw, 28px)/1.2 var(--font-title); color: var(--ink); }
.st-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--unit); flex: none; box-shadow: 0 0 0 4px var(--unit-l); }
.st-books { list-style: none; padding: 0; margin: 0; display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); }
.st-book { display: flex; flex-direction: column; gap: 10px; padding: 12px 12px 14px; background: var(--paper); border-radius: var(--r-paper-sm); box-shadow: var(--shadow-paper); border: 1px solid rgba(120, 95, 60, .08); }
.st-book:nth-child(even) { border-radius: 11px 14px 10px 15px / 15px 10px 14px 11px; }
.st-book-link { display: grid; gap: 10px; color: var(--ink); text-decoration: none; border-radius: 10px; }
.st-cover { position: relative; display: grid; place-items: center; aspect-ratio: 4 / 3; background: var(--warm); border-radius: 8px; overflow: hidden; }
/* A faint spine shadow on the left edge makes each cover read as a book. */
.st-cover::after { content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  box-shadow: inset 7px 0 8px -7px rgba(60, 40, 20, .32), inset 0 0 0 1px rgba(60, 40, 20, .08); }
.st-cover img { width: 100%; height: 100%; object-fit: contain; }
.st-book-link:hover .st-cover img { transform: translateY(-2px); }
.st-cover img { transition: transform .15s ease; }
.st-book-t cite { display: block; font: var(--st-title-weight, 800) var(--st-card-size, 21px)/1.18 var(--st-title-face, var(--font-title)); font-style: normal;
  letter-spacing: var(--st-title-track, -.005em); color: var(--st-title-ink, var(--ink)); text-wrap: balance; }
.st-book-link:hover cite { text-decoration: underline; text-decoration-thickness: .08em; text-underline-offset: .18em; }
.st-book-t small { display: block; margin-top: 6px; font: 500 14.5px/1.4 var(--font-ui); color: var(--ink-2); }
.st-book-t .st-book-style { margin-top: 2px; font-size: 13.5px; font-style: italic; color: var(--ink-3); }
.st-weeks { display: flex; flex-wrap: wrap; gap: 6px; margin: auto 0 0; }
/* Week links stay one line each and sit several to a row; the K-week notes stay small so cards keep similar heights. */
.st-weeks a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 999px; border: 2px solid var(--unit-l); background: color-mix(in srgb, var(--unit-l) 45%, var(--paper));
  font: 700 18px/1.2 var(--font-kid); color: var(--unit-ink); text-decoration: none; white-space: nowrap; }
.st-k-weeks { margin: 0; font: 400 13px/1.45 var(--font-ui); color: var(--ink-3); }
.st-weeks a:hover { border-color: var(--unit); }
.st-foot { max-width: 70ch; font-size: 15px; }
.st-foot a { display: inline-flex; align-items: center; min-height: 44px; }

/* ---------- Reader: the immersive view (stories/read.html runs with data-osw-chrome="off") ----------
   A fixed full-screen layer on a dim, warm charcoal: light enough that white book pages do not glare against it, dark
   enough to fall away. Position fixed follows Safari's toolbars with no viewport units. stories.js sets --st-a (the
   page's aspect ratio) and, when words show, the sizes that leave the picture as large as possible. */
html:has(body.page-reader), body.page-reader { height: 100%; overflow: hidden; overscroll-behavior: none; background: #262421; }
/* iOS Home Screen apps otherwise get a viewport shorter than the screen (WebKit 301108). */
@media (display-mode: standalone) { html:has(body.page-reader) { min-height: min(100lvh, calc(100% + env(safe-area-inset-top, 0px))); } }
.st-reader { position: fixed; inset: 0; display: grid; grid-template: "stage" minmax(0, 1fr) / minmax(0, 1fr); background: #262421; color: #fff; overflow: hidden;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  touch-action: pan-y pinch-zoom; -webkit-tap-highlight-color: transparent; }
.st-reader.is-zoomed { touch-action: auto; }
.st-reader [hidden] { display: none !important; }
.st-reader noscript p, .st-missing { padding: 48px 24px; color: #fff; }
.st-reader noscript a { color: #fff; }
.st-missing { grid-area: stage; place-self: center; text-align: center; }
.st-missing h1 { margin: 0 0 20px; font: 800 clamp(26px, 4vw, 40px)/1.2 var(--font-title); color: #fff; }
.st-stage { grid-area: stage; position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; container-type: size;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.st-page, .st-ghost { grid-area: 1 / 1; display: block; max-width: none; height: auto; aspect-ratio: var(--st-a, 1.42);
  width: min(100cqw, calc(100cqh * var(--st-a, 1.42)), var(--st-cap, 2100px)); -webkit-user-drag: none; -webkit-touch-callout: none; }
.st-page { background: #fff; color: #fff; opacity: 0; transition: opacity .18s ease; }
.st-page.is-in { opacity: 1; }
.st-ghost { opacity: 0; pointer-events: none; transition: opacity .18s ease; }
.st-ghost.on { opacity: 1; transition: none; }
.st-progress { position: absolute; inset: auto 0 0; height: 3px; background: rgba(140, 128, 110, .22); pointer-events: none; z-index: 3; }
.st-progress span { display: block; height: 100%; background: rgba(140, 128, 110, .8); transition: width .18s ease; }

/* Words and title sheet: beside the picture like a facing page, or under it like a caption band. */
.st-sheet { grid-area: sheet; display: flex; flex-direction: column; justify-content: center; gap: 12px; box-sizing: border-box; min-width: 0; min-height: 0; overflow: hidden;
  color: var(--ink); background: var(--st-band, var(--paper)); }
.st-sheet.is-off { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); }
.st-reader.is-side { grid-template: "stage sheet" minmax(0, 1fr) / var(--st-stage-w) var(--st-panel); justify-content: center; }
/* The side sheet starts below the bar, so a shown bar never covers the title or the words. */
.st-reader.is-side .st-sheet { padding: calc(env(safe-area-inset-top, 0px) + 78px) clamp(20px, 3vw, 40px) calc(env(safe-area-inset-bottom, 0px) + 20px); border-left: 6px solid var(--st-accent, #b9ad98); }
.st-reader.is-under { grid-template: "stage" var(--st-stage-h, minmax(0, 1fr)) "sheet" auto / minmax(0, 1fr); align-content: center; justify-items: center; }
.st-reader.is-under .st-stage { width: 100%; height: 100%; }
.st-reader.is-under .st-sheet { width: var(--st-band-w, 100%); max-height: var(--st-band-max, none); padding: 12px clamp(18px, 3vw, 36px) 14px; border-top: 5px solid var(--st-accent, #b9ad98); }
/* The words: Andika at reading-aloud size, loose leading, ragged right. Long pages scroll inside the sheet. Never a display face. */
.st-words { flex: 0 1 auto; min-height: 0; overflow: auto; font-size: clamp(22px, 2.5vmax, 28px); line-height: 1.55; letter-spacing: .01em; word-spacing: .06em; text-wrap: pretty; hyphens: none;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y pinch-zoom; }
.st-words.is-more { -webkit-mask-image: linear-gradient(#000 calc(100% - 2.2em), transparent); mask-image: linear-gradient(#000 calc(100% - 2.2em), transparent); }
.st-words p { margin: 0 0 .5em; max-width: 34em; }
.st-words p:last-child { margin-bottom: 0; }
.st-words:focus-visible { outline: 3px solid var(--unit-ink); outline-offset: 2px; }
.st-reader.is-under .st-words p { margin-inline: auto; }

/* Title block on page 1: inside an original's sheet, or a quiet caption on an outside book's cover that fades with the controls. */
.st-eyebrow { margin: 0 0 6px; font: 700 12.5px/1.2 var(--font-ui); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2); }
.st-title { margin: 0; font: var(--st-title-weight, 800) calc(var(--st-title-scale, 1) * clamp(28px, 3.4vw, 44px))/1.1 var(--st-title-face, var(--font-title)); letter-spacing: var(--st-title-track, -.005em);
  color: var(--st-title-ink, var(--ink)); text-wrap: balance; }
.st-title cite { font-style: normal; }
.st-by { display: flex; flex-direction: column; gap: 2px; margin: 10px 0 0; font: 500 14.5px/1.35 var(--font-ui); color: var(--ink-2); }
.st-style { font-style: italic; }
.st-reader:not(.is-opening) .st-head { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.st-reader.is-under.is-opening .st-title { font-size: calc(var(--st-title-scale, 1) * clamp(26px, 3vw, 38px)); }
@media (min-width: 700px) {
  /* A wide band holds the title on the left and the first words on the right. */
  .st-reader.is-under.is-opening .st-sheet { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: clamp(16px, 3vw, 36px); align-items: center; }
  .st-reader.is-under.is-opening .st-words p { margin-inline: 0; }
}
.st-lic .st-head { position: absolute; z-index: 4; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 14px); transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px); box-sizing: border-box;
  padding: 10px 18px; border-radius: 14px; background: rgba(30, 28, 26, .9); text-align: center; pointer-events: none; transition: opacity .25s ease; }
.st-lic .st-eyebrow { display: none; }
.st-lic .st-title { font-size: 19px; line-height: 1.2; color: #fff; }
.st-lic .st-by { flex-flow: row wrap; justify-content: center; align-items: center; gap: 2px 10px; margin-top: 3px; font-size: 13.5px; color: #e7e2d8; }
.st-rights { padding: 1px 8px; border: 1px solid rgba(255, 255, 255, .4); border-radius: 999px; font: 600 12.5px/1.4 var(--font-ui); white-space: nowrap; }
.st-rights:empty { display: none; }
.st-reader.is-quiet.st-lic .st-head { opacity: 0; }
.st-reader.is-under.st-lic .st-head, .st-reader.is-side.st-lic .st-head { display: none; }

/* Controls: one bar at the top (Safari's bar and the home indicator stay clear of it). They fade; a middle tap brings them back. */
.st-controls { position: absolute; z-index: 5; inset: 0 0 auto; padding: calc(env(safe-area-inset-top, 0px) + 10px) calc(env(safe-area-inset-right, 0px) + 12px) 26px calc(env(safe-area-inset-left, 0px) + 12px);
  background: linear-gradient(rgba(20, 18, 16, .72), rgba(20, 18, 16, .45) 60%, rgba(20, 18, 16, 0)); pointer-events: none; transition: opacity .25s ease; }
.st-reader.is-quiet .st-controls, .st-reader.is-quiet .st-edge { opacity: 0; }
.st-reader.is-quiet .st-controls * { pointer-events: none; }
/* iPad Safari draws its own close button in the top-left corner while in full screen. */
@media (hover: none) { .st-reader.is-fs .st-controls { padding-left: calc(env(safe-area-inset-left, 0px) + 64px); } }
.st-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; }
.st-back, .st-tool, .st-turn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; box-sizing: border-box; min-height: 56px; min-width: 56px; padding: 0 18px; pointer-events: auto; cursor: pointer;
  border: 2px solid rgba(255, 255, 255, .28); border-radius: 999px; background: rgba(30, 28, 26, .9); color: #fff; font: 700 21px/1.1 var(--font-kid); text-decoration: none; white-space: nowrap;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.st-back:hover, .st-tool:hover, .st-turn:hover:not(:disabled) { background: #3b3833; color: #fff; }
.st-back:focus-visible, .st-tool:focus-visible, .st-turn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.st-back .ico, .st-tool .ico, .st-turn .ico { width: 28px; height: 28px; flex: none; }
.st-tool .ico svg, .st-turn .ico svg, .st-back .ico svg { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.st-tool[aria-pressed="true"], .st-tool[aria-pressed="true"]:hover { background: #fff; border-color: #fff; color: #262421; }
.st-tools { display: flex; gap: 8px; }
.st-nav { display: flex; align-items: center; gap: 8px; }
.st-turn { width: 64px; padding: 0; }
.st-turn:disabled { opacity: .45; cursor: default; }
/* The counter carries its own backing, so it reads the same over a white page or a dark one. */
.st-counter { margin: 0; min-width: 6.4em; padding: 7px 12px; box-sizing: border-box; border-radius: 999px; background: rgba(30, 28, 26, .9); text-align: center; font: 700 20px/1.2 var(--font-kid); color: #fff; pointer-events: none; }
/* Faint chevrons mark the page-turn edges while the controls show. */
.st-edge { position: absolute; z-index: 2; top: 50%; width: 52px; height: 52px; margin-top: -26px; display: grid; place-items: center; border-radius: 50%; background: rgba(30, 28, 26, .65); color: #fff; pointer-events: none; transition: opacity .25s ease; }
.st-edge .ico { width: 30px; height: 30px; }
.st-edge .ico svg { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.st-edge-l { left: calc(env(safe-area-inset-left, 0px) + 12px); }
.st-edge-r { right: calc(env(safe-area-inset-right, 0px) + 12px); }
.st-reader.is-side .st-edge-r { right: calc(var(--st-panel) + 12px + max(0px, (100% - var(--st-stage-w) - var(--st-panel)) / 2)); }
.st-resume { position: absolute; z-index: 4; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 16px); transform: translateX(-50%); }
@media (max-width: 1100px) { .st-tool-fs .st-tool-t { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); } .st-tool-fs { padding: 0; } }
@media (max-width: 760px) {
  .st-bar { flex-wrap: wrap; }
  .st-nav { order: 3; flex: 1 0 100%; justify-content: space-between; }
  .st-controls { padding-left: calc(env(safe-area-inset-left, 0px) + 8px); padding-right: calc(env(safe-area-inset-right, 0px) + 8px); }
  .st-bar { gap: 8px; }
  .st-back, .st-tool { padding: 0 10px; gap: 5px; font-size: 18px; }
  .st-tools { gap: 6px; }
  .st-back .ico, .st-tool .ico { width: 24px; height: 24px; }
  .st-tool-cred .st-tool-t { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .st-tool-cred { padding: 0; }
  .st-edge { display: none; }
}
/* Narrow phones: Words keeps its Aa icon and its spoken name when the row has no room for the label. */
@media (max-width: 480px) and (min-height: 481px) { .st-tools:has(.st-tool-fs:not([hidden])) .st-tool-t { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); } .st-tools:has(.st-tool-fs:not([hidden])) .st-tool { padding: 0; } }
/* The narrowest phones: Back to shelf, Words and Credits come first, so Full screen gives way. */
@media (max-width: 372px) { .st-tools .st-tool-t { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); } .st-tools .st-tool { padding: 0; } .st-tools .st-tool-fs { display: none; } }
/* Phones held sideways: keep one low row. */
@media (max-height: 480px) {
  .st-bar { flex-wrap: nowrap; }
  .st-nav { order: 0; flex: none; }
  .st-counter { min-width: 5.6em; font-size: 18px; }
  .st-back, .st-tool, .st-turn { min-height: 48px; min-width: 48px; }
  /* Short screens keep the first words readable: the title block gives up its small print (credits still has it),
     and the side sheet starts below the bar so the bar never covers the title. */
  .st-reader.is-opening .st-eyebrow, .st-reader.is-opening .st-style, .st-reader.is-opening .st-by { display: none; }
  .st-reader.is-side .st-sheet { justify-content: flex-start; padding: 62px 18px 10px; gap: 6px; }
  .st-reader.is-side.is-opening .st-title { font-size: calc(var(--st-title-scale, 1) * 22px); }
}

/* The end of the book. */
.st-finish { position: absolute; inset: 0; z-index: 6; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; overflow: auto; padding: 24px; background: #262421; }
.st-finish-card { display: grid; justify-items: center; gap: 8px; max-width: min(560px, 100%); padding: 26px clamp(20px, 4vw, 44px) 28px; border-radius: 18px; text-align: center; color: var(--ink); background: var(--st-band, var(--paper)); }
.st-finish-cover { display: block; width: auto; height: auto; max-width: min(260px, 60vw); max-height: 26vh; border-radius: 6px; box-shadow: 0 2px 10px rgba(60, 40, 20, .25); }
.st-end { margin: 8px 0 0; font: 800 clamp(28px, 4vw, 38px)/1.1 var(--font-title); }
.st-finish-t { margin: 0 0 10px; font: var(--st-title-weight, 800) calc(var(--st-title-scale, 1) * 22px)/1.2 var(--st-title-face, var(--font-title)); color: var(--st-title-ink, var(--ink)); text-wrap: balance; }
.st-finish-t cite { font-style: normal; }
.st-finish-go, .st-finish-more { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 0; }
.st-again, .st-again:hover { background: var(--unit-ink); border-color: var(--unit-ink); }
.st-finish-card :focus-visible { outline-color: var(--ink); }

/* Credits panel */
.st-dialog { width: min(720px, calc(100% - 24px)); max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px); padding: 0; border: 0;
  border-radius: var(--r-paper); background: var(--paper); color: var(--ink); box-shadow: var(--shadow-lift); }
.st-dialog::backdrop { background: rgba(29, 42, 49, .5); }
.st-dialog-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px 12px 22px; background: var(--paper); border-bottom: 1px solid var(--rule); }
.st-dialog-head h2 { margin: 0; font: 800 24px/1.2 var(--font-title); }
.st-credits { padding: 14px 22px 24px; font-size: 16px; line-height: 1.5; }
.st-credits p { margin: 0 0 10px; }
.st-credits a { display: inline-flex; align-items: center; min-height: 44px; }
.st-credits h3 { margin: 18px 0 6px; font: 700 17px/1.3 var(--font-ui); }
.st-src { display: flex; flex-wrap: wrap; gap: 0 18px; padding: 0; margin: 0; list-style: none; }
.st-src a { display: inline-flex; align-items: center; min-height: 44px; font-weight: 700; }
.st-attr { white-space: pre-line; overflow-wrap: anywhere; font-size: 14px; color: var(--ink-2); }

/* Reduced motion: page changes are instant. */
@media (prefers-reduced-motion: reduce) {
  .st-page, .st-ghost, .st-cover img, .st-controls, .st-edge, .st-head, .st-progress span { transition: none !important; }
  .st-book-link:hover .st-cover img { transform: none; }
}
html.osw-rm .st-page.is-in { opacity: 1; }
html.osw-rm .st-page, html.osw-rm .st-ghost, html.osw-rm .st-controls, html.osw-rm .st-edge, html.osw-rm .st-head, html.osw-rm .st-progress span { transition: none; }
html.osw-rm .st-book-link:hover .st-cover img { transform: none; }
