* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--jp-font); }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.wrap { max-width: 1200px; margin: 0 auto; padding-bottom: 80px; }
.head { display: flex; min-width: 0; align-items: center; gap: 14px; padding: 22px 20px 12px; }
.home { flex: none; color: var(--accent); font-family: var(--disp); font-size: 44px; font-weight: 700; letter-spacing: .16em; line-height: 1; text-transform: uppercase; white-space: nowrap; }
.home small { margin-left: .4em; color: inherit; font: inherit; }
[data-stories-status], #storiesApp { max-width: 960px; margin-inline: auto; padding: 0 20px; }
[data-stories-status] { color: var(--muted); }
[data-stories-status]:empty { margin: 0; }
.story-title { margin: 24px 0; }
.story-top + .story-title { margin-top: 8px; }
.story-count { color: var(--muted); }
.story-done { color: var(--accent); }
.story-back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); margin: 12px 0; }
.story-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0; }
.story-top .story-back { margin: 0; }
.story-next { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.story-back svg, .story-next svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.story-modes { display: flex; width: fit-content; margin: 16px 0; padding: 2px; border: 1px solid var(--line); border-radius: 999px; }
.story-mode { position: relative; min-width: 56px; height: 28px; padding: 0 16px; border-radius: 999px; color: var(--muted); font-size: 13px; line-height: 28px; text-align: center; text-decoration: none; }
.story-mode::before { content: ""; position: absolute; inset: -8px 0; }
.story-mode[aria-current="page"] { background: var(--accent); color: var(--bg); font-weight: 700; }
.story-pic { aspect-ratio: 16 / 9; position: relative; overflow: hidden; border-radius: 12px; background: var(--surface); margin: 0; }
.story-pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: var(--bg); }
.story-imagine { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--muted); }
.story-text { font-size: clamp(20px, 3.4vw, 34px); font-weight: 500; line-height: 1.6; }
.is-new { text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 3px; text-underline-offset: .22em; }
.story-dock { position: fixed; inset: auto 0 0; z-index: 5; padding: 6px 20px calc(14px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
.story-controls { max-width: 520px; margin-inline: auto; }
.story-sub { display: flex; align-items: center; gap: 4px; }
.story-sub .story-count { margin: 0 0 0 auto; font-size: 14px; }
.story-main { display: grid; grid-template-columns: 1fr 2.2fr; gap: 10px; margin-top: 4px; }
.story-control, .story-play { min-height: 44px; padding: 8px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.story-sub .story-control { padding: 8px 10px; background: none; border: 0; color: var(--ink); font-size: 14px; }
.story-main .story-control { min-height: 54px; font-size: 16px; }
.story-main [data-act="next"] { background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 700; }
.story-control:disabled { opacity: .4; cursor: default; }
.story-sub .story-control:disabled { color: var(--muted); opacity: 1; }
.story-audio-toggle { display: inline-flex; align-items: center; gap: 5px; min-height: 44px; padding: 0 8px; background: none; border: 0; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; }
.story-audio-toggle[hidden] { display: none; }
.story-audio-toggle svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.story-audio-word { min-width: 2em; text-align: left; }
.story-audio-toggle[data-state="new"] { color: var(--accent); }
.story-replay { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 8px 14px; background: none; border: 1px solid var(--line); border-radius: 8px; color: var(--accent); }
.story-replay svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.story-play-slot, .story-end { display: flex; gap: 16px; margin-top: 16px; }
.story-end { padding-bottom: 170px; }
.story-next-mode { color: var(--accent); padding: 12px 0; }
.story-error { color: var(--muted); }
#storiesApp[data-view="shelf"] { max-width: none; padding: 0; }

.wrap:has(> #storiesApp[data-view="shelf"]) { padding-bottom: 16px; }
html:has(#storiesApp[data-view="shelf"]), body:has(#storiesApp[data-view="shelf"]) { overscroll-behavior-y: none; }
.story-shelf-heading { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.library { --H: clamp(210px, 27vw, 330px); --ws: calc(var(--H) * .15); --depth: .72; --d: calc(var(--H) * var(--depth)); --gap: calc(var(--H) * .022); --ease-out: cubic-bezier(.2, .7, .2, 1); --serif-en: Georgia, "Times New Roman", serif; --cap: clamp(1.15rem, 2.6vw, 1.6rem); padding-top: 8px; }
.course-tabs { position: relative; display: flex; justify-content: center; flex-wrap: wrap; gap: .25rem clamp(1.25rem, 4vw, 2.5rem); width: min(100% - 2.5rem, 1120px); margin: 0 auto; }
.course-tab { padding: .45rem 0 .7rem; border: 0; background: none; color: var(--muted); font-size: clamp(.9rem, 1.8vw, 1rem); letter-spacing: .06em; transition: color .25s; }
.course-tab[aria-pressed="true"] { color: var(--ink); }
.tab-indicator { position: absolute; bottom: 0; left: 0; width: 0; height: 2px; border-radius: 2px; background: var(--accent); transition: transform .45s var(--ease-out), width .45s var(--ease-out); }
.shelf { --cover-paper: #fffcf6; --cover-deep: #efe6d8; --cover-ink: #402b1d; --cover-soft: #715a43; position: relative; width: min(100%, 1280px); --view: 4.4; --eye: .57; --line: 1.3; --half: calc((var(--depth) + .16) / 2); --near: calc(var(--view) / (var(--view) - var(--half))); --far: calc(var(--view) / (var(--view) + var(--half))); height: calc(var(--H) * 1.5); margin: clamp(.25rem, 1.5vw, 1rem) auto 0; overflow: hidden; perspective: calc(var(--H) * var(--view)); perspective-origin: 50% 38%; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; transition: opacity .18s; }
.shelf.is-dragging { cursor: grabbing; }
.shelf.is-switching { opacity: 0; }
.shelf-probe { position: absolute; width: var(--gap); height: var(--H); visibility: hidden; pointer-events: none; }
.stage { position: absolute; left: 50%; top: calc(var(--H) * var(--line)); width: 0; height: 0; transform-style: preserve-3d; }


.plank-top, .plank-front { position: absolute; left: 0; width: 100%; pointer-events: none; }
.plank-top { top: calc(var(--H) * (var(--eye) + (var(--line) - var(--eye)) * var(--far))); height: calc(var(--H) * (var(--line) - var(--eye)) * (var(--near) - var(--far))); background: linear-gradient(to bottom, #cdb898, #dcc9ab); }
.plank-front { top: calc(var(--H) * (var(--eye) + (var(--line) - var(--eye)) * var(--near))); height: calc(var(--H) * .055 * var(--near)); background: linear-gradient(to bottom, #b89b77, #9c805f); box-shadow: 0 18px 22px -14px rgba(64, 43, 29, .55); }
.book { position: absolute; bottom: 0; left: calc(var(--ws) / -2); width: var(--ws); height: var(--H); transform-style: preserve-3d; cursor: pointer; -webkit-user-drag: none; -webkit-touch-callout: none; }
.book.is-filtered { display: none; }
.book:focus-visible { outline: none; }
.book:focus-visible .cover { outline: 3px solid var(--accent); outline-offset: 2px; }
.book-body { position: absolute; inset: 0; transform-style: preserve-3d; transform: translateY(var(--lift, 0px)) rotateY(var(--tilt-y, 0deg)) rotateZ(var(--tilt-z, 0deg)); transition: transform .35s var(--ease-out); }
.face { position: absolute; top: 0; height: 100%; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.spine { left: 0; width: var(--ws); display: flex; flex-direction: column; align-items: center; padding: calc(var(--ws) * .16) 0 calc(var(--ws) * .22); border-radius: 2px; background: linear-gradient(90deg, rgba(0, 0, 0, .2), rgba(255, 255, 255, .07) 28%, rgba(0, 0, 0, 0) 62%, rgba(0, 0, 0, .24)), var(--spine); color: var(--spine-ink); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); transform: translateZ(calc(var(--d) / 2)); }
.spine-art { flex: none; width: calc(var(--ws) * .72); height: calc(var(--H) * .15); border-radius: 1px; object-fit: cover; background: rgba(255, 250, 241, .25); box-shadow: 0 0 0 1px rgba(255, 250, 241, .35); }
.spine-title { flex: 1 1 auto; min-height: 0; margin: calc(var(--H) * .03) 0; overflow: hidden; writing-mode: vertical-rl; text-orientation: sideways; text-align: center; white-space: nowrap; font-family: var(--serif-en); font-size: min(calc(var(--H) * .068), calc(var(--H) * .58 / (var(--len) * .5))); letter-spacing: .03em; line-height: 1; }
.spine-foot { flex: none; display: flex; flex-direction: column; align-items: center; }
.spine-mark { font-family: var(--serif-en); font-size: calc(var(--H) * .03); letter-spacing: .12em; opacity: .85; }
.cover { left: calc((var(--ws) - var(--d)) / 2); width: var(--d); display: flex; flex-direction: column; padding: calc(var(--H) * .055) calc(var(--d) * .07) calc(var(--H) * .05); border-radius: 2px 4px 4px 2px; background: var(--cover-paper); color: var(--cover-ink); box-shadow: inset calc(var(--d) * .025) 0 0 var(--spine), inset 0 0 0 1px rgba(64, 43, 29, .14); transform: rotateY(90deg) translateZ(calc(var(--ws) / 2)); }
.cover-course { font-size: calc(var(--H) * .032); letter-spacing: .12em; color: var(--cover-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cover-title { margin-top: calc(var(--H) * .03); display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; font-family: var(--serif-en); font-size: calc(var(--H) * .066); line-height: 1.12; }
.cover-art { margin-top: auto; aspect-ratio: 16 / 9; padding: calc(var(--H) * .008); border: 1px solid rgba(64, 43, 29, .18); background: var(--cover-deep); }
.cover-art img { display: block; width: 100%; height: 100%; object-fit: contain; }
.cover-foot { margin-top: calc(var(--H) * .032); font-family: var(--serif-en); font-size: calc(var(--H) * .03); letter-spacing: .14em; color: var(--cover-soft); }
.back { left: calc((var(--ws) - var(--d)) / 2); width: var(--d); background: linear-gradient(90deg, rgba(0, 0, 0, .28), rgba(0, 0, 0, .12)), var(--spine); transform: rotateY(-90deg) translateZ(calc(var(--ws) / 2)); }
.caption-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: 1rem; width: min(100% - 2.5rem, 760px); margin: clamp(.25rem, 1.5vw, .75rem) auto 0; }
.caption { min-width: 0; text-align: center; }
.caption-title { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; font-family: var(--serif-en); font-size: var(--cap); line-height: 1.4; }
.caption-marks { display: flex; justify-content: center; gap: 8px; min-height: 1.6em; margin-top: .3rem; font-size: .72rem; letter-spacing: .16em; line-height: 1.6; }
.shelf-arrow { display: grid; place-items: center; width: 44px; height: 44px; margin-top: calc((var(--cap) * 1.4 - 44px) / 2); padding: 0; border: 0; background: none; color: var(--muted); transition: color .2s; }
.shelf-arrow svg { width: 12px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
@media (hover: hover) {
  .course-tab:hover, .shelf-arrow:hover { color: var(--ink); }
  .book:not(.is-active):hover .book-body { --lift: calc(var(--H) * -.035); }
}
@media (min-width: 601px) {
  .story-title { margin-bottom: 8px; }
  .story-modes { margin: 8px 0; }
  .story-pic { max-width: max(360px, calc((100svh - 487px) * 16 / 9)); }
  #storiesApp[data-course="long"] .story-pic { max-width: max(360px, calc((100svh - 595px) * 16 / 9)); }
  .story-text { margin: 12px 0 0; }
}
@media (min-width: 601px) and (min-height: 600px) and (max-height: 897px) and (orientation: landscape) and (pointer: coarse) {
  #storiesApp[data-course]:not([data-view="shelf"]) { max-width: 1160px; display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); grid-template-rows: auto auto auto auto auto 1fr; grid-template-areas: "top top" "title title" "modes modes" "pic text" "pic play" "pic end"; column-gap: 24px; align-items: start; }
  #storiesApp[data-course] .story-top { grid-area: top; }
  #storiesApp[data-course] .story-title { grid-area: title; }
  #storiesApp[data-course] .story-modes { grid-area: modes; }
  #storiesApp[data-course] .story-pic { grid-area: pic; width: 100%; max-width: min(100%, calc((100svh - 376px) * 16 / 9)); }
  #storiesApp[data-course] .story-text { grid-area: text; margin: 0; font-size: 26px; }
  #storiesApp[data-course] .story-play-slot { grid-area: play; }
  #storiesApp[data-course] .story-end { grid-area: end; }
}
@media (min-width: 601px) and (max-height: 599px) and (orientation: landscape) and (pointer: coarse) {
  .wrap:has(#storiesApp[data-course]:not([data-view="shelf"])) .head { padding: 8px 20px 0; }
  .wrap:has(#storiesApp[data-course]:not([data-view="shelf"])) .home { font-size: 20px; }
  #storiesApp[data-course]:not([data-view="shelf"]) { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto auto auto 1fr; grid-template-areas: "top top" "pic text" "pic play" "pic end"; column-gap: 28px; align-items: start; }
  #storiesApp[data-course] .story-top { grid-area: top; min-height: 44px; margin: 0; }
  #storiesApp[data-course] .story-modes { grid-row: 1; grid-column: 2; align-self: center; margin: 0; }
  #storiesApp[data-course] .story-title { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
  #storiesApp[data-course] .story-pic { grid-area: pic; width: min(calc((100svh - 223px) * 16 / 9), calc(100vw - 448px)); max-width: none; margin: 14px 0; }
  #storiesApp[data-course] .story-text { grid-area: text; margin: 14px 0 0; font-size: clamp(17px, 2.7vw, 20px); }
  #storiesApp[data-course] .story-play-slot { grid-area: play; margin-top: 8px; }
  #storiesApp[data-course] .story-end { grid-area: end; margin-top: 8px; }
}
@media (max-width: 1023px) {
  .library { --H: clamp(210px, max(27vw, min(calc((100svh - 320px) / 1.5), 80vw)), 520px); }
}
@media (max-width: 600px) {
  .head { gap: 10px; padding: 24px 22px 10px; }
  .home { font-size: 46px; letter-spacing: .2em; }
  .home small { display: none; }
  [data-stories-status], #storiesApp { padding: 0 22px; }
  .library { --ws: max(44px, calc(var(--H) * .15)); }
}
