/* ==========================================================================
   蘇州古典園林 · Classical Gardens of Suzhou — flippable thread-bound book
   Design space: 1px = 1pt of the PDF. A page is 558 × 810 (the PDF trim box
   halves). The whole book is scaled to the viewport by script.js, so all
   type sizes below are print sizes: English body 9pt Helvetica, Chinese body 10pt;
   the smallest Chinese text is 10pt, above the 11px-equivalent floor (8.25pt).
   Light source: upper left. Every shadow therefore falls to the lower right.
   ========================================================================== */

:root {
  --W: 558px;
  --H: 810px;
  --paper: #FEFDF8;
  --ink: #231f20;
  --red: #a31e23;
  --green: #5c913f;
  --cloth: #7a3b36;   /* muted red cloth (was indigo) */
  --thread: #f2eee4;
  --zh: "Noto Serif TC", "Songti TC", "PMingLiU", "MingLiU", serif;
  /* All Latin text is Helvetica; Google Sans (Google Fonts) stands in where Helvetica is not installed. */
  --sans: "Helvetica Neue", Helvetica, "Google Sans", Arial, sans-serif;
  --times: var(--sans);
  --gut: 1; /* gutter shadow strength, driven by how open the book is */

  /* paper grain: feTurbulence, multiplied over the paper base */
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n' x='0' y='0'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .42  0 0 0 0 .36  0 0 0 0 .27  0 0 0 -1.1 .95'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  /* long, faint fibre streaks (stretched noise) */
  --fibre: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='558' height='420'><filter id='f' x='0' y='0'><feTurbulence type='fractalNoise' baseFrequency='.006 .21' numOctaves='2' seed='7' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .5  0 0 0 0 .42  0 0 0 0 .3  0 0 0 .75 -.45'/></filter><rect width='100%' height='100%' filter='url(%23f)'/></svg>");
  /* cloth: fine noise + light flecks + long fibres for the indigo cover */
  --cloth-noise: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='260' height='260'><filter id='c' x='0' y='0'><feTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .78  0 0 0 0 .76  0 0 0 0 .9  0 0 0 .55 -.22'/></filter><rect width='100%' height='100%' filter='url(%23c)'/></svg>");
  --flecks: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='380' height='380'><filter id='k' x='0' y='0'><feTurbulence type='fractalNoise' baseFrequency='.55' numOctaves='2' seed='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .86  0 0 0 0 .84  0 0 0 0 .9  0 0 0 9 -6.75'/></filter><rect width='100%' height='100%' filter='url(%23k)'/></svg>");
  --cloth-fibre: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='558' height='400'><filter id='g' x='0' y='0'><feTurbulence type='fractalNoise' baseFrequency='.02 .34' numOctaves='2' seed='11' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .75  0 0 0 0 .72  0 0 0 0 .85  0 0 0 .5 -.31'/></filter><rect width='100%' height='100%' filter='url(%23g)'/></svg>");
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #2c2621;
  color: #e9e1d2;
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- desk: deep warm neutral with a soft vignette (never pure white/black) */
#desk {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 95% at 42% 38%, rgba(0,0,0,0) 0%, rgba(0,0,0,.18) 55%, rgba(8,5,3,.55) 100%),
    var(--cloth-noise),
    radial-gradient(90% 70% at 40% 35%, #52473d 0%, #3d342c 45%, #2b241f 100%);
  background-size: auto, 260px 260px, auto;
  background-blend-mode: normal, soft-light, normal;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#scaler {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}

#book {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(var(--W) * 2);
  height: var(--H);
  will-change: transform;
}

/* drop shadow of the whole book on the desk; moves with the visible extent */
.bshadow {
  position: absolute;
  top: 0;
  height: var(--H);
  border-radius: 2px;
  background: transparent;
  box-shadow:
    12px 18px 30px 2px rgba(10, 6, 3, .55),
    4px 6px 9px rgba(10, 6, 3, .45),
    26px 40px 70px rgba(10, 6, 3, .35);
}

/* stack-thickness edges: outer side and bottom (we look slightly from the front) */
.edge {
  position: absolute;
  pointer-events: none;
}
.edge.r, .edge.l { top: 1px; height: var(--H); }
.edge.rb, .edge.lb { top: var(--H); }
.edge.r {
  left: calc(var(--W) * 2);
  border-radius: 0 2px 2px 0;
  background:
    linear-gradient(90deg, rgba(40,28,16,.28), rgba(40,28,16,0) 3px),
    repeating-linear-gradient(90deg, #dcd4bf 0 .5px, #c3b9a1 .5px 1px);
}
.edge.l {
  border-radius: 2px 0 0 2px;
  background:
    linear-gradient(270deg, rgba(40,28,16,.22), rgba(40,28,16,0) 3px),
    repeating-linear-gradient(90deg, #e2dbc7 0 .5px, #c9c0a9 .5px 1px);
}
.edge.rb, .edge.lb {
  background:
    linear-gradient(180deg, rgba(40,28,16,.30), rgba(40,28,16,0) 3px),
    repeating-linear-gradient(180deg, #d3cbb5 0 .5px, #b9af97 .5px 1px);
  border-radius: 0 0 2px 2px;
}
/* indigo cover board showing at the outside of a stack */
.edge.cov-out.r { box-shadow: inset -1.6px 0 0 var(--cloth); }
.edge.cov-out.l { box-shadow: inset 1.6px 0 0 var(--cloth); }
.edge.cov-out.rb, .edge.cov-out.lb { box-shadow: inset 0 -1.6px 0 var(--cloth); }

/* spine side of the closed book: folded sheets bound by the thread */
.spine {
  position: absolute;
  top: 0;
  height: var(--H);
  width: 9px;
  pointer-events: none;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.07) 0 .5px, rgba(0,0,0,.18) .5px 1.1px),
    linear-gradient(90deg, #4e2420, #84433d 60%, #5f2c27);
  overflow: hidden;
}
.spine.f { left: calc(var(--W) - 9px); border-radius: 3px 0 0 3px; }
.spine.b { left: var(--W); transform: scaleX(-1); border-radius: 3px 0 0 3px; }
.spine svg { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; }

/* ---------- leaves */
.sheets {
  position: absolute;
  inset: 0;
  perspective: 2200px;
  perspective-origin: 50% 42%;
}
.leaf {
  position: absolute;
  top: 0;
  width: var(--W);
  height: var(--H);
}
.leaf.fr, .leaf.turn { left: var(--W); }
.leaf.fl { left: 0; }
.leaf.turn { transform-style: preserve-3d; transform: translateZ(.5px); }

.strip {
  position: absolute;
  top: 0;
  height: var(--H);
  transform-style: preserve-3d;
  transform-origin: 0 50%;
}
.sface {
  position: absolute;
  top: 0;
  left: 0;
  height: var(--H);
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.sface.back { transform: rotateY(180deg); }
.sface > .face { position: absolute; top: 0; }
.lt { position: absolute; inset: 0; pointer-events: none; }

/* cast shadows of a lifting leaf on the pages underneath */
.cast {
  position: absolute;
  top: 0;
  width: var(--W);
  height: var(--H);
  pointer-events: none;
  opacity: 0;
}
.cast.r { left: var(--W); }
.cast.l { left: 0; }

/* ---------- faces */
.face {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--W);
  height: var(--H);
  overflow: hidden;
  contain: layout paint;
}
.face.paper { background-color: var(--paper); color: var(--ink); }
.face.paper::before,
.face.paper::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: multiply;
}
.face.paper::before {
  background: var(--grain);
  background-size: 240px 240px;
  opacity: .16;
}
.face.paper::after {
  /* per-leaf warm tone variation (--tone) + long fibre streaks */
  background:
    var(--fibre),
    linear-gradient(var(--tone-a, 160deg), rgba(250, 226, 180, var(--tone, .02)), rgba(255, 245, 225, 0) 70%);
  background-size: 558px 420px, auto;
  opacity: .5;
}
.face .content, .face .ghost {
  position: absolute;
  inset: 0;
}
/* translucency: reverse side ghosted at ~5% and mirrored */
.face .ghost {
  transform: scaleX(-1);
  opacity: .05;
  filter: grayscale(.3);
  pointer-events: none;
}
.face .ghost img { opacity: .4; } /* photos show through faintly, not as grey blocks */
.face .content { z-index: 1; }

/* gutter shadow, deepening as the book opens (light from upper left) */
.face .gutter {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 70px;
  z-index: 3;
  pointer-events: none;
  opacity: var(--gut);
}
.face.sp-l .gutter {
  left: 0;
  background: linear-gradient(90deg, rgba(70,48,24,.30) 0, rgba(70,48,24,.14) 7px, rgba(70,48,24,.05) 22px, rgba(70,48,24,0) 60px);
}
.face.sp-r .gutter {
  right: 0;
  background: linear-gradient(270deg, rgba(70,48,24,.36) 0, rgba(70,48,24,.17) 8px, rgba(70,48,24,.06) 26px, rgba(70,48,24,0) 66px);
}
/* fore-edge: a hint of the folded sheet (thread-bound sheets fold at the fore-edge) */
.face.paper .fold {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 5px;
  z-index: 3;
  pointer-events: none;
}
.face.sp-l .fold { right: 0; background: linear-gradient(270deg, rgba(120,100,70,.12), rgba(255,255,255,0)); }
.face.sp-r .fold { left: 0; background: linear-gradient(90deg, rgba(255,255,255,.5), rgba(255,255,255,0)); }

/* ---------- die-cut lattice leaf (花窗): red paper, openings cut with a CSS mask */
.face.dcw { background: none; overflow: visible; contain: none; }
.face.paper.diecut {
  background-color: #EAA898;   /* a touch redder than the spec's #EDB9AE, as requested */
  z-index: 1;
}
.face.paper.diecut::after {
  /* same fibre system as the other pages, warmer */
  background:
    var(--fibre),
    linear-gradient(var(--tone-a, 160deg), rgba(230, 150, 120, var(--tone, .03)), rgba(255, 220, 200, 0) 70%);
  background-size: 558px 420px, auto;
  opacity: .55;
}
.dc-vig {
  /* slightly deeper toward the edges, with warm variation */
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(120% 95% at 55% 48%, rgba(160, 70, 55, 0) 55%, rgba(160, 70, 55, .16) 100%),
    radial-gradient(60% 40% at 30% 70%, rgba(255, 210, 190, .10), rgba(255, 210, 190, 0) 70%);
}
.dc-bevel, .dc-shadow {
  position: absolute; inset: 0; pointer-events: none;
  background-size: 558px 810px; background-repeat: no-repeat;
}
.dc-bevel { z-index: 2; }
.dc-shadow { z-index: 0; }

/* ---------- tracing / mulberry (kozo) paper */
.face.paper.tracing {
  background-color: rgba(251, 247, 237, .66);     /* alpha 0.62–0.70: the page beneath reads at ~35–45% contrast */
  box-shadow: inset 0 0 0 .8px rgba(150, 128, 96, .38), inset 0 0 3px rgba(150, 128, 96, .12);  /* visible edge */
}
.face.paper.tracing::before { opacity: .07; }
.face.paper.tracing::after { opacity: .35; }
.tr-fibres, .tr-cockle { position: absolute; inset: 0; pointer-events: none; }
.tr-fibres { background-size: 558px 810px; opacity: .9; }
.tr-cockle {
  /* cockle: slow, uneven lighting across the sheet */
  background:
    radial-gradient(40% 28% at 28% 22%, rgba(255, 255, 255, .16), rgba(255, 255, 255, 0) 70%),
    radial-gradient(45% 30% at 74% 58%, rgba(120, 100, 70, .07), rgba(120, 100, 70, 0) 70%),
    radial-gradient(35% 25% at 40% 86%, rgba(255, 255, 255, .12), rgba(255, 255, 255, 0) 70%),
    radial-gradient(50% 22% at 80% 12%, rgba(120, 100, 70, .05), rgba(120, 100, 70, 0) 70%);
}
.trace-photo { filter: grayscale(1); opacity: .5; }
.trace-art { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; }
.face.tracing .ghost { opacity: .28; filter: none; }   /* the other side's art shows through at ~28% */
.face.tracing .gutter { opacity: calc(var(--gut) * .5); }

/* ---------- typography (positioned blocks from the PDF) */
.b { position: absolute; margin: 0; }
.tm { font-family: var(--times); }
.b.sf, .le.sf, .he, .b.tm, .le.tm, .tm { font-family: var(--sans); letter-spacing: 0; }
.it { font-style: italic; }
.b.tm { white-space: normal; }

.zh {
  font-family: var(--zh);
  font-size: 10px;
  line-height: 14px;
  letter-spacing: .01em;
  text-align: justify;
  text-justify: inter-character;
  line-break: strict;
  color: var(--ink);
  font-weight: 400;
}
.zh .zh-en { margin-top: 6px; text-align: left; letter-spacing: 0; color: var(--ink); }  /* page 1: English under the Chinese */
.zh.nb { text-align: left; line-height: 13px; margin-bottom: 1px; }

/* bilingual heading: Chinese large, English small beneath */
.hd .hz {
  font-family: var(--zh);
  font-weight: 600;
  letter-spacing: .04em;
  white-space: nowrap;
}
.hd .he {
  margin-top: 1px;
  line-height: 1.15;
  letter-spacing: .01em;
  opacity: .92;
}

/* bilingual label */
.lb .lz {
  font-family: var(--zh);
  font-weight: 600;
  line-height: 13px;
  letter-spacing: .02em;
}
.lb .le {
  font-size: 7.5px;
  line-height: 9px;
  margin-top: 1px;
  opacity: .9;
}
.lb .le.tm { font-size: 7.5px; }

/* garden entries: Chinese name, English name as subtitle, red rule beneath */
.gname .gz {
  font-family: var(--zh);
  font-weight: 600;
  font-size: 13px;
  line-height: 15px;
  letter-spacing: .08em;
}
.gname .ge {
  font-family: var(--sans);
  font-style: italic;
  font-size: 7.5px;
  line-height: 9px;
  opacity: .9;
}
.garden .gl { line-height: 12px; margin-bottom: 3px; text-align: left; white-space: nowrap; }
ruby { ruby-position: under; -webkit-ruby-position: after; ruby-align: center; margin-right: 3px; }
rt {
  font-family: var(--sans);
  font-size: 5.6px;
  line-height: 1;
  letter-spacing: .02em;
  color: #6b6461;
  font-style: italic;
}
.contact { font-size: 9px; line-height: 15.5px; white-space: nowrap; }
.contact rt { font-size: 5.6px; }
.raw .tm { font-size: 9px; line-height: 12px; }

.ph { position: absolute; display: block; object-fit: cover; }
.ico { position: absolute; width: 21.88px; height: 21.08px; overflow: visible; }
.rule { position: absolute; height: 1px; }

/* thread + holes overlay */
.thread { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 4; pointer-events: none; overflow: visible; }

/* ---------- covers: indigo-black cloth */
.face.cloth {
  background-color: var(--cloth);
  background-image:
    radial-gradient(130px 110px at 0 0, rgba(240,215,200,.10), rgba(0,0,0,0) 70%),
    radial-gradient(130px 110px at 100% 0, rgba(240,215,200,.09), rgba(0,0,0,0) 70%),
    radial-gradient(150px 120px at 100% 100%, rgba(240,215,200,.10), rgba(0,0,0,0) 70%),
    radial-gradient(130px 110px at 0 100%, rgba(240,215,200,.07), rgba(0,0,0,0) 70%),
    radial-gradient(70% 55% at 62% 46%, rgba(255,255,255,.035), rgba(0,0,0,0) 70%),
    var(--flecks),
    var(--cloth-fibre),
    var(--cloth-noise),
    repeating-linear-gradient(0deg, rgba(255,255,255,.03) 0 .6px, rgba(0,0,0,0) .6px 1.7px),
    repeating-linear-gradient(90deg, rgba(0,0,0,.10) 0 .6px, rgba(0,0,0,0) .6px 1.5px);
  background-size: auto, auto, auto, auto, auto, 380px 380px, 558px 400px, 260px 260px, auto, auto;
  box-shadow:
    inset 0 0 0 1px rgba(245, 220, 205, .12),
    inset 0 0 6px rgba(245, 220, 205, .08),
    inset -1px -1px 0 rgba(0, 0, 0, .35);
}
.face.cloth.inside {
  /* inside of a thread-bound cover: the paper lining, a little warmer and darker */
  background-color: #f1ead8;
  background-image: none;
  box-shadow: none;
}

/* cover: the booklet's own cover layout (PDF p2 left) printed on the red cloth */
.cover-layout { z-index: 1; }
.cover-layout .ph {
  /* photographs tipped onto the cloth: thin paper margin, shadow to the lower right */
  outline: 2.5px solid #f3ead8;
  box-shadow: 1.5px 2.5px 0 2px rgba(40, 12, 8, .35), 3px 5px 9px rgba(40, 12, 8, .45);
}
.cover-layout .fan { position: absolute; width: 145px; height: 92px; color: #efe1bf; opacity: .95; }
.cover-cap {
  width: 127.4px;
  text-align: center;
  color: #f4e8cf;
  font-family: var(--sans);
  font-style: italic;
  font-size: 10px;
  line-height: 13px;
}
.cover-cap span { display: block; white-space: nowrap; }
.cover-cap .cc-zh { font-family: var(--zh); font-style: normal; font-size: 10px; letter-spacing: .2em; margin-top: 2px; }

/* ---------- controls */
#controls {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(24, 19, 15, .55);
  box-shadow: 0 1px 0 rgba(255,255,255,.06) inset, 0 6px 18px rgba(0,0,0,.35);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 10;
}
#controls button {
  appearance: none;
  border: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  color: #e7dccb;
  cursor: pointer;
  display: grid;
  place-items: center;
}
#controls button:hover { background: rgba(255,255,255,.08); }
#controls button:focus-visible { outline: 2px solid #c9a86a; outline-offset: 1px; }
#controls button:disabled { opacity: .3; cursor: default; background: transparent; }
#controls svg { width: 16px; height: 16px; }
#indicator {
  min-width: 112px;
  text-align: center;
  font-size: 12px;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  padding: 0 6px;
}
#indicator .zh-i { display: block; font-family: var(--zh); font-size: 12px; color: #f1e8d8; }
#indicator .en-i { display: block; font-size: 10px; color: #b9ad99; letter-spacing: .02em; }

@media (max-width: 699px) {
  #indicator { min-width: 96px; }
  #controls button { width: 40px; height: 40px; }
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

template { display: none; }
