/* base: page reset */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
img { max-width: 100%; }

/* Layout: one full-screen white stage; the book slides between two chevrons pinned to the side edges. */
:root {
  --bg: #ffffff;
  --btn: #ffffff;
  --btn-ink: #1d2a33;
  --btn-edge: rgba(29, 42, 51, .12);
  --focus: #c98d1f;
  --shadow: rgba(20, 35, 45, .14);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--bg);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 0;
  overflow: hidden;
}
.stage {
  position: fixed; inset: 0; overflow: hidden;
  perspective: 2000px; perspective-origin: 50% 18%;
}
.floor {
  position: absolute; left: 50%; top: var(--floor-y, 70%);
  width: var(--floor-w, 300px); height: 34px;
  transform: translate(calc(-50% + var(--floor-x, 0px)), -50%);
  background: radial-gradient(closest-side, var(--shadow), transparent);
  filter: blur(5px); pointer-events: none;
}
.book {
  position: absolute; left: 50%; top: 50%;
  width: var(--w); height: var(--h); margin-top: calc(var(--h) / -2);
  transform-style: preserve-3d; transform-origin: 0 50%;
}
.tilt { position: absolute; inset: 0; transform-style: preserve-3d; transform-origin: 0 50%; }
.panel {
  position: absolute; top: 0; left: 0; width: var(--w); height: var(--h);
  transform-origin: 0 50%; transform-style: preserve-3d;
}
.panel .panel { left: 100%; }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; }
.front { transform: translateZ(.5px); }
.back { transform: rotateY(180deg) translateZ(.5px); }
/* every page starts as white paper with a small 歌涓 on it; the photo covers it (inside a white margin) once loaded */
.face {
  background: #fdfdfb var(--ph) center / 100% 100% no-repeat;
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, .09);   /* the sheet's own edge, so white pages read against the white page */
}
/* paper catches the light unevenly: a soft fall-off into each fold, a touch brighter along the top */
.face::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(90deg, rgba(40, 35, 30, .06), rgba(40, 35, 30, 0) 8%, rgba(40, 35, 30, 0) 91%, rgba(40, 35, 30, .04)),
    linear-gradient(180deg, rgba(255, 255, 255, .18), rgba(255, 255, 255, 0) 25%, rgba(0, 0, 0, 0) 85%, rgba(40, 35, 30, .035));
}
.panel.stacked > .face { visibility: hidden; }
.tilt[hidden] { display: none; }
/* page edges peeking out under a closed book */
.tilt.closed > .panel > .front {
  /* the folded sheets underneath: white paper with hairline gaps between them */
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, .09),
    1px 0.5px 0 #e2e2e0, 2px 1px 0 #fdfdfb, 3px 1.5px 0 #dededc, 4px 2px 0 #fdfdfb, 5px 2.5px 0 #d8d8d6, 6px 3px 0 #fbfbf9;
}
.shade { position: absolute; inset: 0; background: #0b1820; opacity: 0; pointer-events: none; }
/* photo pages: each face holds one or more photos, cropped to fill their box (a two-page spread is a box twice as wide) */
.layer { position: absolute; background-size: cover; background-position: center; background-repeat: no-repeat; pointer-events: none; }

.nav {
  position: fixed; top: 50%; transform: translateY(-50%);
  width: 56px; height: 56px; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: #6b6b6b;
  display: grid; place-items: center; cursor: pointer;
  transition: transform .15s ease, opacity .2s ease, color .2s ease;
}
.nav.prev { left: max(20px, calc(env(safe-area-inset-left, 0px) + 12px)); }
.nav.next { right: max(20px, calc(env(safe-area-inset-right, 0px) + 12px)); }
.nav:hover:not(:disabled) { color: #3f3f3f; transform: translateY(-50%) scale(1.05); }
.nav:active:not(:disabled) { transform: translateY(-50%) scale(.96); }
.nav:disabled { opacity: .25; cursor: default; }
.nav:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.nav svg { width: 100%; height: 100%; }
@media (prefers-reduced-motion: reduce) { .nav { transition: none; } }

/* ---------- title and version switch ---------- */
.masthead {
  position: fixed; left: 0; right: 0; z-index: 4;
  top: calc(28px + env(safe-area-inset-top, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  pointer-events: none;
}
/* 歌涓 uses your own font file, kept in the "font" folder next to this stylesheet */
@font-face {
  font-family: "Kayun Hanja";
  src: url("font/chinese.ttf") format("truetype");
  font-display: swap;
}
.masthead h1 {
  /* Baskerville is built into Macs and iPhones; Libre Baskerville (loaded from Google Fonts) stands in elsewhere */
  margin: 0; font-family: Baskerville, "Baskerville Old Face", "Libre Baskerville", Georgia, serif;
  font-weight: 400; font-size: clamp(24px, 3.4vw, 34px); letter-spacing: .01em; line-height: 1.15;
  color: #3f3f3f; text-align: center; text-wrap: balance;
}
.masthead h1 span { color: #8a8a8a; }
.masthead h1 { display: flex; align-items: center; justify-content: center; }
/* your handwritten "streams of joy" sits beside 歌涓; a white background in the PNG blends into the page */
/* the handwriting is small inside its image, so the image is drawn tall enough for the letters to match 歌涓;
   the negative margins stop the image's empty top and bottom from pushing the buttons down */
.masthead .title-img {
  display: block; height: 2.6em; width: auto; margin: -.8em 0 -.8em .15em; mix-blend-mode: multiply;
  opacity: .75;   /* black ink at 75% on white = the same #3f3f3f gray as 歌涓 */
}
/* on the hosted site the empty space is trimmed off the image, so it can be sized to the letters themselves */
.masthead .title-img.trimmed { height: .95em; margin: 0 0 0 .35em; }
.masthead .title-fallback { color: #8a8a8a; margin-left: .3em; }
.masthead h1 .hanja { color: #3f3f3f; font-family: "Kayun Hanja", "Noto Serif KR", "Songti TC", serif; font-weight: 400; font-size: 1em; letter-spacing: .04em; }
/* the version buttons are your handwritten labels; the chosen one is fully inked and underlined, the other faded */
.versions { display: flex; gap: 22px; pointer-events: auto; }
.versions button {
  position: relative; padding: 4px 2px 8px; border: 0; background: transparent; cursor: pointer;
  opacity: .25; transition: opacity .2s;
  font: 500 13px/1 system-ui, -apple-system, "Segoe UI", sans-serif; letter-spacing: .04em; color: #3f3f3f;
}
.versions button img { display: block; height: 34px; width: auto; mix-blend-mode: multiply; }   /* a white background in the PNG disappears */
.versions button:hover { opacity: .5; }
.versions button[aria-pressed="true"] { opacity: .75; }   /* black ink at 75% = the title's #3f3f3f */
.versions button[aria-pressed="true"]::after {
  content: ""; position: absolute; left: 10%; right: 10%; bottom: 0; height: 1.5px; border-radius: 1px; background: #000;
}
.versions button:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 4px; }

/* ---------- info ---------- */
.info-btn {
  position: fixed; z-index: 6;
  left: max(20px, calc(env(safe-area-inset-left, 0px) + 12px));
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%;
  background: transparent; color: #6b6b6b; cursor: pointer;
  display: grid; place-items: center; transition: color .2s, transform .15s;
}
.info-btn:hover, .info-btn[aria-expanded="true"] { color: #3f3f3f; }
.info-btn:hover { transform: scale(1.05); }
.info-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.info-btn svg { width: 100%; height: 100%; }
[hidden] { display: none !important; }
.info-modal {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 16px;
  background: rgba(20, 22, 26, .38);
  animation: info-fade .2s ease-out;
}
.info-card {
  position: relative;
  width: min(820px, 100%);
  background: #fff; color: #3f3f3f;
  border-radius: 18px;
  padding: 26px 26px 22px;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .45);
  font: 14.5px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
  max-height: calc(100vh - 32px); overflow-y: auto; overscroll-behavior: contain;
  animation: info-in .22s ease-out;
}
@keyframes info-fade { from { opacity: 0; } }
@keyframes info-in { from { opacity: 0; transform: translateY(10px) scale(.97); } }
@media (prefers-reduced-motion: reduce) { .info-modal, .info-card { animation: none; } }
.info-close {
  position: absolute; top: 14px; right: 14px;
  width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%;
  background: transparent; color: #6b6b6b; cursor: pointer; display: grid; place-items: center;
}
.info-close:hover { color: #3f3f3f; background: #f2f2f2; }
.info-close:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.info-close svg { width: 18px; height: 18px; }

/* welcome modal: shown when the page opens */
.intro-card { width: min(500px, 100%); text-align: center; padding: clamp(28px, 6vw, 44px) clamp(24px, 7vw, 52px) clamp(28px, 6vw, 40px); outline: none; }
.intro-card img { display: block; width: 100%; height: auto; margin: 14px 0 22px; }
.intro-card p { margin: 0 auto 4px; max-width: 36ch; color: #555; font-size: 15px; line-height: 1.55; }
.intro-card p b { color: #3f3f3f; font-weight: 600; }

.info-card h2 {
  margin: 0 0 16px; text-align: center; font-family: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  font-weight: 500; font-size: 28px; line-height: 1.1;
}
/* pdf frame: zoomable, draggable */
.pdf-frame { border: 1.5px solid #d6d6d6; border-radius: 12px; overflow: hidden; background: #f1f1f1; }
.pdf-tools {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px; background: #fff; border-bottom: 1px solid #e2e2e2;
}
.pdf-tools button {
  height: 30px; min-width: 30px; padding: 0 8px; border: 1.5px solid #c9c9c9; border-radius: 999px;
  background: #fff; color: #555; cursor: pointer; display: grid; place-items: center;
  font: 500 12.5px/1 system-ui, -apple-system, "Segoe UI", sans-serif; letter-spacing: .03em;
}
.pdf-tools button:hover:not(:disabled) { border-color: #6b6b6b; color: #3f3f3f; }
.pdf-tools button:disabled { opacity: .4; cursor: default; }
.pdf-tools button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.pdf-tools button svg { width: 16px; height: 16px; }
.pdf-tools .fit { margin-left: 6px; }
#zoomLevel { min-width: 52px; text-align: center; font: 500 12.5px/1 system-ui, -apple-system, sans-serif; color: #555; font-variant-numeric: tabular-nums; }
.pdf-view {
  height: min(62vh, 620px); overflow: auto; cursor: grab;
  touch-action: none; overscroll-behavior: contain;
}
.pdf-view.panning { cursor: grabbing; }
.pdf-view:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 16px; margin: 0 auto; box-sizing: content-box; }
.pdf-page { width: 100%; background: #fff; box-shadow: 0 2px 10px -4px rgba(0, 0, 0, .25); }
.pdf-page canvas { display: block; width: 100%; height: auto; }
.pdf-page.placeholder { aspect-ratio: 8.5 / 11; display: grid; place-items: center; padding: 24px; }
.pdf-status { color: #8a8a8a; font-size: 13px; text-align: center; max-width: 30ch; line-height: 1.5; }

/* process photos under the pdf: one per row, top to bottom, each the full width of the modal */
.process-photos { display: flex; flex-direction: column; gap: 18px; margin-top: 22px; padding-inline: clamp(8px, 12%, 96px); }
.process-photos img {
  display: block; width: 100%; height: auto;
  background: #f1f1f1;
}

/* ---------- magnifying glass ---------- */
.loupe {
  position: fixed; left: 0; top: 0; width: 0; height: 0; z-index: 5;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.loupe .lens, .loupe .rim, .loupe .handle { position: absolute; cursor: grab; }
.loupe.dragging .lens, .loupe.dragging .rim, .loupe.dragging .handle { cursor: grabbing; }
.loupe .lens {
  width: var(--d); height: var(--d); left: calc(var(--d) / -2); top: calc(var(--d) / -2);
  border-radius: 50%; overflow: hidden; background: #fff;
}
.loupe .lens canvas { display: block; }
.loupe .rim {
  width: var(--d); height: var(--d); left: calc(var(--d) / -2); top: calc(var(--d) / -2);
  border-radius: 50%; box-sizing: border-box; pointer-events: none;
  border: 10px solid #2a2724;
  box-shadow:
    0 0 0 1.5px #6d655b, inset 0 0 0 1.5px #6d655b,
    inset 0 0 22px rgba(30, 40, 60, .28),
    0 14px 28px -10px rgba(0, 0, 0, .45);
  background:
    radial-gradient(circle at 32% 28%, rgba(255,255,255,.55) 0 6%, rgba(255,255,255,.12) 13%, transparent 26%),
    radial-gradient(circle at 70% 76%, rgba(255,255,255,.12), transparent 30%);
}
.loupe .handle {
  /* collar + wooden grip, pointing down and to the right */
  left: 0; top: 0; width: calc(var(--d) * .85); height: 26px;
  transform-origin: 0 50%;
  transform: rotate(45deg) translate(calc(var(--d) / 2 + 4px), -13px);
  border-radius: 6px 14px 14px 6px;
  background:
    linear-gradient(90deg, #3b3632 0 18%, #6d655b 18% 20%, transparent 20%),
    linear-gradient(180deg, #2c2c2c, #444 35%, #1d1d1d 70%, #0f0f0f);
  box-shadow: 0 10px 18px -8px rgba(0, 0, 0, .5);
}
.loupe:focus-visible .rim { outline: 2px solid var(--focus); outline-offset: 4px; }
