@font-face {
  font-family: "Plus Jakarta Sans";
  src: url(plus-jakarta-sans-latin-ext-wght-normal.woff2) format("woff2");
  font-weight: 200 800;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF,
    U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Plus Jakarta Sans";
  src: url(plus-jakarta-sans-latin-wght-normal.woff2) format("woff2");
  font-weight: 200 800;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F,
    U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --deep: #10233a;
  --navy: #1d3a5a;
  --accent: #5bb4e6;
  --bar: 60px;
  --rail: 0px;
  --pad: 24px;
  --vh: 100vh;
  --top: env(safe-area-inset-top, 0px);
  --right: env(safe-area-inset-right, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  --left: env(safe-area-inset-left, 0px);
}
@supports (height: 100dvh) {
  :root { --vh: 100dvh; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--deep);
  color: #fff;
  font: 500 16px/1.4 "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Reader */
#reader {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: radial-gradient(90% 80% at 50% 45%, var(--navy) 0%, var(--deep) 100%);
}
#stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: var(--top);
  padding-left: var(--left);
}

#book {
  --w: calc(100vw - var(--rail) - 2 * var(--pad) - var(--left) - var(--right));
  --h: calc(var(--vh) - var(--bar) - 2 * var(--pad) - var(--top) - var(--bottom));
  width: min(var(--w), calc(var(--h) * 1.41421));
  aspect-ratio: 1.41421;
  flex: none;
  transform: translateX(0);
  transition: transform .45s ease;
  /* The library's pan-y would switch pinch-zoom off on the book. */
  touch-action: pinch-zoom;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.zoomed #book { touch-action: auto; }

/* A closed book sits in the middle of the screen, not on half of a spread. */
#book.at-cover { transform: translateX(-25%); }
#book.at-back { transform: translateX(25%); }

#book::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35), 0 22px 56px -8px rgba(0, 0, 0, .65);
  transition: left .45s ease, right .45s ease;
}
#book.at-cover::before { left: 50%; }
#book.at-back::before { right: 50%; }

.page { overflow: hidden; background: var(--navy) url(logo.png) center / 46% no-repeat; }
.page img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  -webkit-user-drag: none;
}
/* Spine: paper falls away into the gutter on both sides. */
.page::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
.page.--left::after {
  background: linear-gradient(to left, rgba(0, 0, 0, .3), rgba(0, 0, 0, .11) 2%, rgba(0, 0, 0, .04) 6%, transparent 13%);
}
.page.--right::after {
  background: linear-gradient(to right, rgba(0, 0, 0, .3), rgba(0, 0, 0, .11) 2%, rgba(0, 0, 0, .04) 6%, transparent 13%);
}

#bar {
  flex: none;
  height: calc(var(--bar) + var(--bottom));
  padding: 0 calc(10px + var(--right)) var(--bottom) calc(10px + var(--left));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: rgba(16, 35, 58, .82);
  border-top: 1px solid rgba(255, 255, 255, .09);
}
#bar button {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  transition: background .15s, color .15s, opacity .15s;
}
#bar button:hover:not(:disabled) { background: rgba(255, 255, 255, .1); color: var(--accent); }
#bar button:disabled { opacity: .3; cursor: default; }
#bar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#bar svg .fill { fill: currentColor; }
#sound .mute { display: none; }
#sound[aria-pressed="false"] .mute { display: block; }
#sound[aria-pressed="false"] .waves { display: none; }
#lang { font-size: 14px; font-weight: 700; letter-spacing: .04em; }
#indicator { min-width: 92px; text-align: center; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.gap { width: 18px; flex: none; }

/* Short landscape screens need the height for the book, so the bar becomes a side rail. */
@media (max-height: 480px) and (orientation: landscape) {
  :root { --bar: 0px; --rail: 56px; --pad: 6px; }
  #reader { flex-direction: row; }
  #bar {
    flex-direction: column;
    height: auto;
    width: calc(var(--rail) + var(--right));
    padding: var(--top) var(--right) var(--bottom) 0;
    gap: 0;
    border-top: 0;
    border-left: 1px solid rgba(255, 255, 255, .09);
  }
  #bar button { height: 42px; }
  #indicator { order: -1; min-width: 0; font-size: 11px; line-height: 1.25; margin-bottom: 2px; }
  .gap { height: 4px; }
}
@media (max-width: 480px) {
  :root { --pad: 8px; }
  .gap { width: 6px; }
  #indicator { min-width: 84px; font-size: 14px; }
}

#hint {
  position: absolute;
  top: calc(14px + var(--top));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 24px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--deep);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  text-align: left;
}
#hint b { font-size: 20px; line-height: 1; }
@media (orientation: landscape), (min-width: 768px) {
  #hint { display: none; }
}

/* Enlarged view: native scrolling and pinch, nothing shared with the flip gestures. */
#zoomview {
  position: fixed;
  inset: 0;
  z-index: 5;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--deep);
}
#zoomview .spread { display: flex; align-items: center; width: max-content; min-height: 100%; margin: 0 auto; }
#zoomview img { display: block; width: min(100vw, 1200px); height: auto; }
#zoomclose {
  position: fixed;
  top: calc(12px + var(--top));
  right: calc(12px + var(--right));
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--deep);
  font-size: 26px;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
}
