:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, Arial, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --purple-950: #25113f;
  --purple-900: #351554;
  --purple-800: #4a2478;
  --purple-700: #63339a;
  --purple-600: #7e42b3;
  --purple-100: #f0e9f9;
  --yellow: #ffd72b;
  --ink: #231b2c;
  --muted: #6e6478;
  --surface: #fff;
  --page-ratio: 0.71;
}

* { box-sizing: border-box; }
html { min-width: 320px; min-height: 100%; background: #f8f6fb; }
body { min-width: 320px; min-height: 100vh; margin: 0; color: var(--ink); }
button { color: inherit; font: inherit; }
button:focus-visible, a:focus-visible, .page-viewport:focus-visible { outline: 3px solid #dfb90d; outline-offset: 3px; }

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 49% 38%, rgba(255, 255, 255, .98) 0, rgba(249, 247, 252, .93) 42%, rgba(238, 232, 246, .94) 100%),
    #f4f0f8;
}
.app-shell:fullscreen { width: 100vw; height: 100dvh; min-height: 100dvh; }

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px clamp(18px, 4vw, 58px);
  border-bottom: 1px solid rgba(79, 43, 111, .09);
  background: rgba(255, 255, 255, .68);
  backdrop-filter: blur(16px);
}
.brand { display: inline-flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; padding: 7px; border-radius: 13px; background: var(--purple-900); box-shadow: 0 5px 14px rgba(53, 21, 84, .18); }
.brand-mark img { display: block; width: 100%; height: 100%; }
.brand-copy { display: grid; gap: 1px; }
.brand-title { color: var(--purple-950); font-size: 16px; font-weight: 800; letter-spacing: .01em; line-height: 1.2; }
.brand-subtitle { color: var(--muted); font-size: 11px; font-weight: 500; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.prototype-tag { display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px; border: 1px solid rgba(99, 51, 154, .15); border-radius: 99px; color: var(--purple-800); background: rgba(240, 233, 249, .78); font-size: 11px; font-weight: 700; white-space: nowrap; }
.tag-dot { width: 7px; height: 7px; border-radius: 50%; background: #29a66c; box-shadow: 0 0 0 3px rgba(41, 166, 108, .13); }
.icon-button { min-height: 39px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 0 12px; border: 1px solid rgba(72, 36, 127, .14); border-radius: 11px; background: #fff; color: var(--purple-800); cursor: pointer; font-size: 12px; font-weight: 700; transition: background .18s ease, transform .18s ease; }
.icon-button:hover { background: var(--purple-100); transform: translateY(-1px); }
.tag-short { display: none; }
.pages-button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.fit-screen-button svg { width: 18px; height: 18px; transform: rotate(45deg); }
.icon-button svg, .page-arrow svg, .control-button svg, .audio-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.reader { flex: 1; width: min(100%, 1130px); margin: 0 auto; padding: 19px 22px 8px; display: flex; flex-direction: column; align-items: center; }
.reader-heading { width: min(100%, 800px); display: flex; align-items: end; justify-content: space-between; gap: 22px; margin: 0 auto 8px; }
.reader-heading > div { min-width: 0; }
.eyebrow { margin: 0 0 3px; color: var(--purple-600); font-size: 9px; font-weight: 800; letter-spacing: .16em; direction: ltr; text-align: right; }
.reader-heading h1 { margin: 0; color: var(--purple-950); font-size: clamp(18px, 2.2vw, 24px); line-height: 1.35; font-weight: 800; }
.reader-description { max-width: 355px; margin: 0 0 2px; color: var(--muted); font-size: 11px; line-height: 1.7; text-align: left; }

.book-area { position: relative; flex: 0 1 auto; display: grid; place-items: center; width: 100%; min-height: 0; padding: 0 66px; }
.page-viewport {
  position: relative;
  width: min(520px, 82vw, calc((100svh - 258px) * var(--page-ratio)));
  max-height: calc(100svh - 258px);
  aspect-ratio: 0.71 / 1;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(99, 51, 154, .55) rgba(240, 233, 249, .55);
  direction: ltr;
  border-radius: 4px;
  box-shadow: 0 22px 54px rgba(48, 29, 67, .17), 0 5px 13px rgba(52, 24, 75, .1), 0 0 0 7px rgba(255, 255, 255, .8);
  touch-action: pan-x pan-y;
}
.reader.is-screen-fit .page-viewport { width: min(560px, 94vw, calc((100dvh - 258px) * var(--page-ratio))); max-height: calc(100dvh - 258px); }
.page-frame {
  position: relative;
  width: 100%;
  height: 100%;
  aspect-ratio: 0.71 / 1;
  isolation: isolate;
  overflow: hidden;
  border: 1px solid rgba(53, 21, 84, .1);
  border-radius: 4px;
  background: #fff;
  transform-style: preserve-3d;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.book-page { position: absolute; inset: 0; z-index: 1; display: block; width: 100%; height: 100%; object-fit: fill; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.hotspots-layer { position: absolute; inset: 0; z-index: 3; }
.hotspot {
  position: absolute;
  display: block;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(255, 215, 43, .18);
}
.hotspot:hover, .hotspot:focus-visible { border: 1.5px dashed rgba(99, 51, 154, .83); background: rgba(255, 215, 43, .1); outline: none; }
.hotspot::after { content: attr(data-hint); position: absolute; bottom: calc(100% + 5px); inset-inline-start: 0; display: none; max-width: min(210px, 70vw); padding: 5px 8px; border-radius: 7px; color: #fff; background: rgba(37, 17, 63, .9); font-size: 10px; line-height: 1.4; white-space: nowrap; pointer-events: none; }
.hotspot:hover::after, .hotspot:focus-visible::after { display: block; }
.page-loading { position: absolute; z-index: 4; inset: 0; display: grid; place-items: center; background: rgba(255, 255, 255, .77); opacity: 0; pointer-events: none; transition: opacity .16s ease; }
.page-loading.is-visible { opacity: 1; }
.page-loading span { width: 29px; height: 29px; border: 3px solid #e6d9f4; border-top-color: var(--purple-700); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.page-arrow { position: absolute; z-index: 5; top: 50%; width: 43px; height: 43px; display: grid; place-items: center; border: 1px solid rgba(77, 45, 105, .12); border-radius: 50%; background: rgba(255, 255, 255, .88); color: var(--purple-800); box-shadow: 0 4px 13px rgba(42, 23, 61, .1); cursor: pointer; transform: translateY(-50%); transition: transform .18s ease, background .18s ease, opacity .18s ease; }
.page-arrow:hover:not(:disabled) { background: var(--yellow); transform: translateY(-50%) scale(1.06); }
.page-arrow:disabled { cursor: default; opacity: .35; }
.page-arrow-prev { inset-inline-start: max(4px, calc(50% - 350px)); }
.page-arrow-next { inset-inline-end: max(4px, calc(50% - 350px)); }

.reader-controls { width: min(100%, 640px); display: flex; align-items: center; justify-content: space-between; gap: 22px; padding: 11px 12px; margin: 14px auto 0; border: 1px solid rgba(76, 46, 104, .1); border-radius: 16px; background: rgba(255, 255, 255, .8); box-shadow: 0 5px 20px rgba(42, 25, 62, .045); }
.pagination-controls { display: flex; align-items: center; gap: 12px; }
.control-button { min-height: 36px; display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 0 10px; border: 0; border-radius: 9px; background: transparent; color: var(--purple-800); cursor: pointer; font-size: 11px; font-weight: 700; }
.control-button:hover:not(:disabled) { background: var(--purple-100); }
.control-button:disabled { color: #b7aebf; cursor: default; }
.control-button svg { width: 16px; height: 16px; }
.page-count { display: grid; min-width: 92px; justify-items: center; line-height: 1.25; }
.page-count > span:first-child { color: var(--purple-950); font-size: 13px; font-weight: 800; }
.count-label { margin-top: 2px; color: var(--muted); font-size: 9px; }
.audio-controls { min-width: 0; display: flex; align-items: center; gap: 10px; }
.audio-indicator { min-width: 0; display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 10px; line-height: 1.45; }
.audio-indicator > span:last-child { max-width: 176px; }
.audio-dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: #d9d1e2; }
.audio-indicator.is-playing .audio-dot { background: #26a269; box-shadow: 0 0 0 4px rgba(38, 162, 105, .13); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(38, 162, 105, 0); } }
.audio-buttons { display: flex; gap: 5px; }
.audio-button { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid rgba(99, 51, 154, .13); border-radius: 10px; background: #fff; color: var(--purple-700); cursor: pointer; }
.audio-button:hover:not(:disabled) { background: var(--purple-100); }
.audio-button:disabled { color: #c8c0d0; background: #faf9fb; cursor: default; }
.audio-button svg { width: 16px; height: 16px; }
.speed-button { width: 43px; padding: 0 4px; font-size: 10px; font-weight: 800; font-variant-numeric: tabular-nums; }
.native-audio { display: block; width: min(100%, 420px); height: 38px; margin: 8px auto 0; }
.native-audio[hidden] { display: none; }
.reader-hint { margin: 7px 0 0; color: #7c7188; font-size: 10px; text-align: center; line-height: 1.6; }
.reader-hint a { color: var(--purple-700); font-weight: 700; text-underline-offset: 2px; }
.hint-spark { color: #d1a900; margin-inline-end: 3px; }
.footer-note { display: flex; align-items: center; justify-content: center; gap: 9px; min-height: 38px; padding: 4px 16px; color: #82798c; font-size: 9px; line-height: 1.2; text-align: center; }
.footer-separator { color: #c7bdcf; }
.creator-credit { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; max-width: 100%; text-align: center; }
.creator-title { display: block; color: #6f6680; font-size: 9px; font-weight: 600; line-height: 1.2; letter-spacing: .1px; text-align: center; }
.creator-links { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 3px 12px; max-width: 100%; font-size: 9px; line-height: 1.2; }
.creator-credit strong { color: var(--purple-900); font-weight: 800; }
.creator-credit a { display: inline-flex; align-items: center; gap: 4px; color: var(--purple-700); font-weight: 700; text-decoration: none; text-underline-offset: 2px; }
.gmail-icon { display: block; width: 13px; height: 13px; flex: none; }
.creator-credit a:hover, .creator-credit a:focus-visible { text-decoration: underline; }

.modal-backdrop { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 22px; background: rgba(30, 16, 45, .48); backdrop-filter: blur(5px); }
.modal-backdrop[hidden] { display: none; }
.story-modal { position: relative; width: min(100%, 460px); max-height: min(82vh, 700px); overflow: auto; padding: 30px clamp(22px, 5vw, 38px) 28px; border: 1px solid rgba(255, 255, 255, .65); border-radius: 23px; background: #fff; box-shadow: 0 22px 70px rgba(28, 14, 44, .28); animation: modal-in .22s ease-out both; }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(.985); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-close { position: absolute; top: 12px; inset-inline-end: 12px; width: 35px; height: 35px; display: grid; place-items: center; padding: 0 0 3px; border: 0; border-radius: 50%; background: var(--purple-100); color: var(--purple-800); cursor: pointer; font-size: 26px; line-height: 1; }
.modal-close:hover { background: var(--yellow); }
.modal-kicker { margin: 1px 0 6px; color: var(--purple-600); font-size: 11px; font-weight: 800; }
.story-modal h2 { margin: 0 0 15px; color: var(--purple-950); font-size: clamp(21px, 5vw, 27px); line-height: 1.4; }
.modal-content { color: #4f4659; font-size: 15px; line-height: 1.9; }
.modal-content p { margin: 0 0 10px; }
.modal-content img { display: block; max-width: 100%; max-height: 40vh; margin: 14px auto 0; border-radius: 12px; object-fit: contain; }
.page-picker-backdrop { position: fixed; z-index: 22; inset: 0; display: grid; place-items: center; padding: clamp(10px, 2.5vw, 26px); background: rgba(30, 16, 45, .52); backdrop-filter: blur(6px); }
.page-picker-backdrop[hidden] { display: none; }
.page-picker-dialog { position: relative; width: min(100%, 940px); max-height: min(88vh, 900px); display: flex; flex-direction: column; overflow: hidden; border: 1px solid rgba(255,255,255,.7); border-radius: 22px; background: #fff; box-shadow: 0 24px 80px rgba(28, 14, 44, .3); animation: modal-in .22s ease-out both; }
.page-picker-header { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 18px; padding: 17px 22px; border-bottom: 1px solid rgba(79, 43, 111, .1); }
.page-picker-header .eyebrow { margin-bottom: 2px; }
.page-picker-header h2 { margin: 0; color: var(--purple-950); font-size: 20px; }
.page-picker-description { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.page-picker-close { position: static; flex: none; }
.page-picker-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; overflow: auto; padding: 16px; overscroll-behavior: contain; }
.page-tile { min-width: 0; display: grid; align-content: start; gap: 6px; padding: 8px; border: 1px solid rgba(76, 46, 104, .12); border-radius: 13px; background: #fff; color: var(--ink); cursor: pointer; text-align: center; transition: border-color .16s ease, background .16s ease, transform .16s ease, box-shadow .16s ease; }
.page-tile:hover { border-color: rgba(99, 51, 154, .55); background: #faf7fd; transform: translateY(-2px); box-shadow: 0 7px 18px rgba(53, 21, 84, .1); }
.page-tile[aria-current="page"] { border-color: var(--purple-700); background: var(--purple-100); box-shadow: 0 0 0 2px rgba(99, 51, 154, .12); }
.page-tile img { display: block; width: 100%; aspect-ratio: .71 / 1; border-radius: 6px; background: #f4f0f8; object-fit: cover; }
.page-tile-number { color: var(--purple-900); font-size: 11px; font-weight: 800; }
.page-tile-title { overflow: hidden; color: var(--muted); font-size: 9px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.toast { position: fixed; z-index: 30; inset-inline: 50% auto; bottom: max(22px, env(safe-area-inset-bottom)); width: max-content; max-width: min(90vw, 440px); padding: 11px 15px; border: 1px solid rgba(255,255,255,.16); border-radius: 12px; color: #fff; background: rgba(37, 17, 63, .94); box-shadow: 0 8px 28px rgba(27, 15, 42, .22); font-size: 12px; line-height: 1.6; text-align: center; opacity: 0; visibility: hidden; transform: translate(-50%, 10px); transition: opacity .2s ease, transform .2s ease, visibility .2s; }
.toast.is-visible { opacity: 1; visibility: visible; transform: translate(-50%, 0); }

.page-frame.is-turning-next { animation: flip-next .38s cubic-bezier(.4,0,.2,1); }
.page-frame.is-turning-prev { animation: flip-prev .38s cubic-bezier(.4,0,.2,1); }
@keyframes flip-next { 0% { transform: perspective(1200px) rotateY(0deg); } 48% { transform: perspective(1200px) rotateY(-13deg); filter: brightness(.92); } 100% { transform: perspective(1200px) rotateY(0deg); filter: brightness(1); } }
@keyframes flip-prev { 0% { transform: perspective(1200px) rotateY(0deg); } 48% { transform: perspective(1200px) rotateY(13deg); filter: brightness(.92); } 100% { transform: perspective(1200px) rotateY(0deg); filter: brightness(1); } }

@media (max-width: 700px) {
  .topbar { min-height: 62px; padding: 8px 14px; }
  .brand-mark { width: 37px; height: 37px; border-radius: 12px; }
  .brand-title { font-size: 14px; }
  .brand-subtitle { font-size: 10px; }
  .prototype-tag { padding: 6px 9px; font-size: 10px; }
  .tag-full { display: none; }
  .tag-short { display: inline; }
  .topbar-actions { gap: 7px; }
  .pages-button { width: 37px; min-width: 37px; height: 37px; padding: 0; }
  .pages-button span { display: none; }
  .fit-screen-button { width: 37px; min-width: 37px; height: 37px; padding: 0; }
  .fit-screen-button span { display: none; }
  .share-button { width: 37px; min-width: 37px; height: 37px; padding: 0; }
  .share-button span { display: none; }
  .reader { padding: 13px 12px 5px; }
  .reader-heading { align-items: start; gap: 8px; margin-bottom: 7px; }
  .eyebrow { margin-bottom: 2px; font-size: 8px; }
  .reader-heading h1 { font-size: 18px; }
  .reader-description { max-width: 46%; font-size: 9px; line-height: 1.55; }
  .book-area { padding: 0 30px; }
  .page-viewport { width: min(82vw, calc((100svh - 246px) * var(--page-ratio))); max-height: calc(100svh - 246px); }
  .reader.is-screen-fit .book-area { width: calc(100% + 16px); margin-inline: -8px; padding-inline: 4px; }
  .reader.is-screen-fit .page-viewport { width: min(100vw, calc((100dvh - 246px) * var(--page-ratio))); max-height: calc(100dvh - 246px); }
  .reader.is-screen-fit .page-arrow { display: none; }
  .page-viewport { box-shadow: 0 13px 32px rgba(48, 29, 67, .16), 0 0 0 5px rgba(255, 255, 255, .8); }
  .page-arrow { width: 34px; height: 34px; }
  .page-arrow svg { width: 16px; height: 16px; }
  .page-arrow-prev { inset-inline-start: 2px; }
  .page-arrow-next { inset-inline-end: 2px; }
  .reader-controls { width: min(100%, 480px); gap: 8px; padding: 8px 7px; margin-top: 11px; border-radius: 14px; }
  .pagination-controls { gap: 3px; }
  .control-button { min-height: 34px; gap: 2px; padding: 0 5px; font-size: 10px; }
  .page-count { min-width: 66px; }
  .page-count > span:first-child { font-size: 12px; }
  .count-label { font-size: 8px; }
  .audio-controls { flex: 1; justify-content: flex-end; gap: 6px; }
  .audio-indicator { font-size: 9px; }
  .audio-indicator > span:last-child { max-width: 95px; }
  .audio-buttons { gap: 3px; }
  .audio-button { width: 29px; height: 29px; border-radius: 9px; }
  .speed-button { width: 37px; font-size: 9px; }
  .reader-hint { max-width: 96%; font-size: 9px; }
  .footer-note { min-height: 26px; padding: 3px 12px; font-size: 8px; }
}

@media (max-width: 390px) {
  .prototype-tag { padding: 6px 7px; }
  .topbar { gap: 8px; padding-inline: 10px; }
  .brand { gap: 7px; }
  .brand-mark { width: 34px; height: 34px; }
  .topbar-actions { gap: 4px; }
  .pages-button, .fit-screen-button, .share-button { width: 34px; min-width: 34px; height: 34px; }
  .fit-screen-button svg { width: 16px; height: 16px; }
  .reader-description { max-width: 42%; }
  .reader-heading h1 { font-size: 16px; }
  .book-area { padding-inline: 27px; }
  .page-viewport { width: min(80vw, calc((100svh - 238px) * var(--page-ratio))); max-height: calc(100svh - 238px); }
  .reader.is-screen-fit .book-area { padding-inline: 4px; }
  .reader.is-screen-fit .page-viewport { width: min(100vw, calc((100dvh - 238px) * var(--page-ratio))); max-height: calc(100dvh - 238px); }
  .reader-controls { gap: 4px; padding-inline: 4px; }
  .audio-indicator > span:last-child { max-width: 75px; }
  .control-button span { font-size: 9px; }
  .pagination-controls { gap: 0; }
  .footer-separator { display: none; }
  .footer-note { flex-direction: column; gap: 0; padding-block: 2px; line-height: 1.2; }
}

@media (max-width: 700px) {
  .page-picker-dialog { max-height: 90vh; border-radius: 17px; }
  .page-picker-header { padding: 13px 15px; }
  .page-picker-header h2 { font-size: 18px; }
  .page-picker-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 10px; }
  .page-tile { gap: 4px; padding: 5px; border-radius: 10px; }
  .page-tile-number { font-size: 10px; }
  .page-tile-title { font-size: 8px; }
}

@media (max-height: 700px) and (min-width: 701px) {
  .reader { padding-top: 9px; }
  .reader-heading { margin-bottom: 3px; }
  .page-viewport { width: min(465px, 77vw, calc((100svh - 218px) * var(--page-ratio))); max-height: calc(100svh - 218px); }
  .reader-controls { margin-top: 9px; padding-block: 8px; }
  .footer-note { min-height: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
