/* ---------- fonts (self-hosted subsets, see scripts/subset-fonts.py) ---------- */
@font-face { font-family: 'HY Hand'; src: url('../fonts/longcang.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'HY Serif'; src: url('../fonts/notoserifsc-900.woff2') format('woff2'); font-weight: 900; font-display: swap; }
@font-face { font-family: 'Archivo Black'; src: url('../fonts/archivoblack.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Space Mono'; src: url('../fonts/spacemono-400.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Space Mono'; src: url('../fonts/spacemono-700.woff2') format('woff2'); font-weight: 700; font-display: swap; }

:root {
  --bg: #F7F5F0;
  --ink: #1E1B18;
  --muted: #5A524A;
  --red: #B8322A;
  --red-tab: #C8372D;
  --paper: #FBF8F1;
  --kraft: #C9A274;
  --yellow: #FFE14A;
  --hand: 'HY Hand', 'Kaiti SC', 'STKaiti', 'KaiTi', cursive;
  --serif: 'HY Serif', 'Songti SC', 'STSong', 'SimSun', serif;
  --sans: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', system-ui, sans-serif;
  --display: 'Archivo Black', 'Arial Black', var(--sans);
  --mono: 'Space Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --ease: cubic-bezier(.2,.8,.2,1);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
body { overflow: hidden; }
button { font: inherit; color: inherit; }
a { color: inherit; }
.grow { flex-grow: 1; }
.red { color: var(--red); }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.hand { font-family: var(--hand); }
.spaced { letter-spacing: 2px; }
:focus-visible { outline: 3px solid #2B6CB0; outline-offset: 3px; }

/* ---------- scaled stage ---------- */
.viewport { position: fixed; inset: 0; overflow: hidden; }
.stage {
  --W: 1280px; --H: 800px;
  position: absolute; left: 50%; top: 50%;
  width: var(--W); height: var(--H);
  transform: translate(-50%, -50%) scale(var(--s, 1));
  transform-origin: 50% 50%;
}
.m .stage { --W: 440px; --H: 900px; }

/* ---------- top bar ---------- */
.topbar { position: absolute; left: 40px; right: 40px; top: 28px; display: flex; justify-content: space-between; align-items: center; z-index: 10; }
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand-mark { font-family: var(--display); font-size: 24px; letter-spacing: -.5px; }
.brand-sub { font-family: var(--mono); font-size: 12px; letter-spacing: 2px; color: var(--muted); }
.topnav { display: flex; gap: 12px; font-family: var(--mono); font-size: 13px; }
.pill { text-decoration: none; border-radius: 999px; padding: 11px 18px; line-height: 1; }
.pill-outline { border: 1.5px solid var(--ink); padding: 10px 17px; }
.pill-solid { background: var(--ink); color: var(--bg); }
.m .topbar { left: 20px; right: 20px; top: 20px; }
.m .brand-sub { display: none; }
.m .topnav { gap: 8px; font-size: 12px; }

/* ---------- decorations ---------- */
.deco { position: absolute; pointer-events: none; transition: opacity .5s; }
.deco-open { opacity: 0; transition: opacity .6s .3s; }
.stage:is([data-stage=list],[data-stage=detail]) .deco-closed { opacity: 0; }
.stage:is([data-stage=list],[data-stage=detail]) .deco-open { opacity: 1; }

.bubble { left: 905px; top: 130px; width: 230px; height: 190px; transform: rotate(-6deg); }
.bubble-tail { position: absolute; left: 6px; top: 150px; width: 44px; height: 44px; background: var(--yellow); transform: rotate(35deg); border-radius: 4px; }
.bubble-body { position: absolute; inset: 0; background: var(--yellow); border-radius: 52% 48% 50% 46%; display: flex; align-items: center; justify-content: center; font-family: var(--display); font-size: 27px; line-height: 1.02; }
.doodle { left: 150px; top: 500px; transform: rotate(-12deg); color: var(--ink); }
.doodle-text { font-family: var(--hand); font-size: 52px; line-height: 1; }
.doodle svg { display: block; margin-top: 4px; }
.slash { left: 300px; top: 150px; color: var(--ink); }
.hand-hint { left: 860px; top: 590px; display: flex; align-items: center; gap: 10px; font-family: var(--hand); font-size: 26px; }
.polaroid { left: 66px; top: 150px; width: 180px; transform: rotate(-5deg); }
.tape { position: absolute; left: 60px; top: -12px; width: 64px; height: 22px; background: rgba(255,225,74,.85); transform: rotate(4deg); z-index: 1; }
.polaroid-frame { background: #fff; padding: 10px 10px 36px; box-shadow: 0 6px 18px rgba(30,27,24,.14); }
.polaroid-photo { height: 180px; background: #E6E0D5 center / cover no-repeat; display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.polaroid-caption { position: absolute; left: 0; right: 0; bottom: 8px; text-align: center; font-family: var(--hand); font-size: 22px; }
.index-note { left: 70px; top: 470px; width: 190px; font-family: var(--mono); font-size: 12px; line-height: 1.7; color: var(--muted); }
.index-title { color: var(--red); font-weight: 700; letter-spacing: 2px; }
.collapse-hint { left: 1000px; top: 300px; transform: rotate(-4deg); font-family: var(--hand); font-size: 28px; color: var(--red); }

.m .bubble { left: 282px; top: 92px; width: 140px; height: 112px; }
.m .bubble-tail { left: 2px; top: 86px; width: 28px; height: 28px; }
.m .bubble-body { font-size: 16px; }
.m .doodle { left: 26px; top: 730px; }
.m .doodle-text { font-size: 38px; }
.m .doodle svg { width: 140px; }
.m .slash { left: 40px; top: 120px; }
.m .hand-hint { left: 270px; top: 718px; font-size: 22px; }
.m .polaroid, .m .index-note, .m .collapse-hint { display: none; }

/* ---------- folder ---------- */
.folder {
  position: absolute; left: 460px; top: 190px; width: 360px; height: 480px;
  padding: 0; margin: 0; border: 0; background: transparent; cursor: pointer; z-index: 3;
  transition: transform .9s var(--ease); touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
}
.folder span { display: block; }
.stage:is([data-stage=list],[data-stage=detail]) .folder { transform: translate(430px,130px) scale(.6) rotate(7deg); }
.m .folder { left: 40px; top: 210px; }
.m .stage:is([data-stage=list],[data-stage=detail]) .folder { transform: translate(0px,370px) scale(.26) rotate(4deg); }

.folder-shadow { position: absolute; left: 30px; top: 478px; width: 300px; height: 34px; border-radius: 50%; background: rgba(30,27,24,.22); filter: blur(14px); }
.folder-3d {
  --rx: 6deg; --ry: -16deg;
  position: absolute; inset: 0; transform-style: preserve-3d;
  transform: perspective(1400px) rotateX(var(--rx)) rotateY(var(--ry));
  transition: transform .8s var(--ease);
}
.stage.tracking .folder-3d { transition-duration: .12s; }
.stage:not([data-stage=closed]) .folder-3d { --rx: 0deg !important; --ry: 0deg !important; }

.f-back { position: absolute; inset: 0; border-radius: 3px; background: #B68C5E; transform: translateZ(-7px); }
.f-flap { position: absolute; left: 0; top: 0; width: 360px; height: 104px; transform-origin: 50% 0; transform: translateZ(-8px) rotateX(0deg); transition: transform .65s cubic-bezier(.3,.7,.2,1); }
.stage:not([data-stage=closed]) .f-flap { transform: translateZ(-8px) rotateX(180deg); }
.f-flap-shape { position: absolute; inset: 0; background-color: #C49C6D; background-image: radial-gradient(rgba(90,60,30,.16) 1px, transparent 1.3px); background-size: 7px 7px; clip-path: polygon(0 0, 100% 0, 86% 100%, 14% 100%); }
.f-button { position: absolute; width: 28px; height: 28px; border-radius: 50%; background: #D8BC93; border: 2px solid #8C6A44; }
.f-button-flap { left: 166px; top: 64px; }
.f-side { position: absolute; background: #A57D52; }
.f-side-l { left: -7px; top: 0; width: 14px; height: 480px; transform: rotateY(90deg); }
.f-side-r { left: 353px; top: 0; width: 14px; height: 480px; transform: rotateY(90deg); }
.f-side-b { left: 0; top: 473px; width: 360px; height: 14px; background: #9C754B; transform: rotateX(90deg); }

.f-front {
  position: absolute; inset: 0; border-radius: 3px; transform: translateZ(7px); text-align: left;
  background-color: var(--kraft);
  background-image: radial-gradient(rgba(90,60,30,.18) 1px, transparent 1.3px), radial-gradient(rgba(255,240,210,.28) 1px, transparent 1.3px);
  background-size: 7px 7px, 11px 11px; background-position: 0 0, 3px 5px;
  box-shadow: inset 0 0 0 1px rgba(120,85,50,.25), inset 0 -30px 40px rgba(90,60,30,.10);
}
.f-button-front { left: 166px; top: 18px; }
.f-string { position: absolute; left: 140px; top: -6px; }
.string-part { transition: opacity .3s; }
.stage:not([data-stage=closed]) .string-part { opacity: 0; }
.f-tag { position: absolute; left: 16px; top: 14px; width: 112px; padding: 6px 8px; background: #F3EEE4; transform: rotate(-3deg); box-shadow: 0 1px 2px rgba(0,0,0,.15); font-family: var(--mono); font-size: 10px; color: var(--red); }
.f-tag .hand { display: inline; font-size: 18px; }
.f-label { position: absolute; left: 14px; top: 64px; width: 332px; height: 128px; padding: 10px 12px; background: #EFEBE3; border-radius: 2px; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.f-label-row { display: flex !important; align-items: center; gap: 8px; }
.f-name { font-family: var(--display); font-size: 28px; line-height: 1; }
.f-year { border: 1.5px solid var(--ink); font-family: var(--mono); font-size: 11px; font-weight: 700; padding: 1px 6px; }
.f-no { border: 1px solid var(--red); color: var(--red); font-family: var(--mono); font-size: 8px; padding: 2px 4px; }
.f-small { font-family: var(--mono); font-size: 8px; line-height: 1.25; margin-top: 3px; color: #3A342E; }
.f-label-bottom { display: flex !important; align-items: flex-end; justify-content: space-between; margin-top: 4px; }
.f-title-cn { font-family: var(--serif); font-weight: 900; font-size: 26px; line-height: 1.1; }
.f-title-en { font-family: var(--mono); font-size: 8px; letter-spacing: 3px; }
.barcode { width: 96px; height: 28px; background-image: repeating-linear-gradient(90deg, var(--ink) 0 2px, transparent 2px 3px, var(--ink) 3px 4px, transparent 4px 7px, var(--ink) 7px 10px, transparent 10px 12px); }
.barcode-num { font-family: var(--mono); font-size: 7px; letter-spacing: 2px; text-align: center; }
.barcode-sm { display: inline-block; width: 70px; height: 24px; }
.f-ledger { position: absolute; left: 18px; top: 210px; width: 324px; border: 1.5px solid var(--red); font-size: 10px; color: var(--red); }
.f-ledger-head, .f-ledger-row { display: grid !important; grid-template-columns: 30px 1fr 64px 44px; }
.f-ledger-head { border-bottom: 1.5px solid var(--red); font-weight: 700; text-align: center; }
.f-ledger-head > span { padding: 3px 0; }
.f-ledger-head > span:not(:last-child), .f-ledger-row > span:not(:last-child) { border-right: 1px solid var(--red); }
.f-ledger-row { height: 25px; border-bottom: 1px solid rgba(184,50,42,.6); line-height: 25px; }
.f-ledger-row > span:nth-child(1) { text-align: center; }
.f-ledger-row > span:nth-child(2) { padding-left: 8px; font-family: var(--hand); font-size: 19px; color: var(--ink); white-space: nowrap; overflow: hidden; }
.f-ledger-row > span:nth-child(3) { text-align: center; font-family: var(--hand); font-size: 15px; color: var(--ink); white-space: nowrap; overflow: hidden; }
.f-ledger-foot { display: flex !important; justify-content: space-between; padding: 5px 8px; font-weight: 700; }
.f-ledger-foot b { font-family: var(--display); font-size: 12px; color: #5E7C17; font-weight: 400; }
.f-tab { position: absolute; left: 352px; top: 96px; width: 24px; height: 92px; background: var(--red-tab); border-radius: 0 3px 3px 0; display: flex !important; align-items: center; justify-content: center; box-shadow: 1px 1px 2px rgba(0,0,0,.2); }
.f-tab span { writing-mode: vertical-rl; font-family: var(--display); font-size: 11px; color: #fff; letter-spacing: 1px; }
.f-sticker { position: absolute; left: 262px; top: 376px; width: 70px; height: 70px; background: var(--yellow); transform: rotate(9deg); border: 2px solid var(--ink); display: flex !important; flex-direction: column; align-items: center; justify-content: center; font-family: var(--display); font-size: 13px; line-height: 1.05; }
.f-warn { position: absolute; left: 22px; top: 446px; background: #EFEBE3; padding: 3px 8px; font-family: var(--mono); font-size: 8px; letter-spacing: 1px; transform: rotate(-1deg); }

/* ---------- paper ---------- */
.paper {
  position: absolute; left: 300px; top: 50px; width: 520px; height: 700px; z-index: 4;
  transform-origin: 50% 0; perspective: 2000px; pointer-events: none;
  transform: translate(80px,170px) scale(.62); clip-path: inset(0px 0px 700px 0px);
  transition: transform .9s var(--ease), clip-path .9s var(--ease);
}
.stage[data-stage=pulling] .paper { transform: translate(80px,-40px) scale(.62); clip-path: inset(0px 0px 410px 0px); }
.stage:is([data-stage=list],[data-stage=detail]) .paper { transform: translate(0px,0px) scale(1); clip-path: none; pointer-events: auto; }
.stage.anim .paper { clip-path: inset(0px 0px 0px 0px) !important; }

.m .paper { left: 10px; top: 80px; width: 420px; height: 660px; transform: translate(0px,150px) scale(.62); clip-path: inset(0px 0px 660px 0px); }
.m .stage[data-stage=pulling] .paper { transform: translate(0px,-20px) scale(.62); clip-path: inset(0px 0px 418px 0px); }
.m .stage:is([data-stage=list],[data-stage=detail]) .paper { transform: translate(0px,0px) scale(1); clip-path: none; }

.paper-3d { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform .8s cubic-bezier(.3,.7,.2,1); }
.stage[data-stage=detail] .paper-3d { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--paper); box-shadow: 0 14px 40px rgba(30,27,24,.18), 0 2px 4px rgba(30,27,24,.08);
  display: flex; flex-direction: column; gap: 14px;
}
.face-front { padding: 30px 34px; }
.face-back { padding: 26px 34px; transform: rotateY(180deg); }
.m .face-front { padding: 20px 22px; gap: 10px; overflow-y: auto; overscroll-behavior: contain; }
.m .face > * { flex-shrink: 0; }
.m .face-back { padding: 20px 22px; overflow-y: auto; overscroll-behavior: contain; }

.pf-top { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 11px; }
.pf-title { display: flex; justify-content: space-between; align-items: center; }
.pf-title h1 { margin: 0; font-family: var(--serif); font-weight: 900; font-size: 40px; line-height: 1.1; }
.mono-sub { font-family: var(--mono); font-size: 11px; letter-spacing: 4px; color: var(--muted); margin-top: 4px; }
.stamp { border-radius: 50%; border: 3px solid var(--red); color: var(--red); display: flex; flex-direction: column; align-items: center; justify-content: center; opacity: .88; font-weight: 700; line-height: 1.15; flex-shrink: 0; }
.stamp small { font-family: var(--mono); font-size: 9px; letter-spacing: 1px; }
.stamp-year { width: 82px; height: 82px; transform: rotate(12deg); font-size: 17px; }
.m .pf-top .spaced { display: none; }
.avatar-m { display: none; }
.m .avatar-m { display: block; flex-shrink: 0; width: 66px; padding: 4px; background: #fff; box-shadow: 0 3px 10px rgba(30,27,24,.16); transform: rotate(-4deg); margin-right: 14px; }
.m .avatar-m div { height: 74px; background: #E6E0D5 center / cover no-repeat; }
.m .pf-title-text { flex-grow: 1; min-width: 0; }
.m .pf-title h1 { font-size: 30px; }
.m .mono-sub { letter-spacing: 2px; font-size: 10px; }
.m .stamp-year { width: 70px; height: 70px; font-size: 15px; }

.info { margin: 0; border: 1.5px solid var(--red); display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); }
.info > div { display: flex; align-items: center; gap: 10px; height: 42px; padding: 0 10px; border-bottom: 1px solid var(--red); }
.info > div:nth-child(odd):not(.span2) { border-right: 1px solid var(--red); }
.info > div.span2 { grid-column: span 2; border-bottom: 0; }
.info dt { font-size: 11px; color: var(--red); font-weight: 700; width: 30px; flex-shrink: 0; }
.info dd { margin: 0; font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.info dd.sm { font-size: 13px; }
.info .mono { font-size: 12px; }
.m .info { grid-template-columns: minmax(0,1fr); }
.m .info > div { height: 32px; border-right: 0 !important; }
.m .info > div.span2 { grid-column: auto; }

.ledger { border: 1.5px solid var(--red); }
.ledger-head, .row { display: grid; grid-template-columns: 46px 1fr 80px 116px 30px; align-items: center; text-align: center; }
.ledger-head { height: 28px; border-bottom: 1.5px solid var(--red); font-size: 11px; font-weight: 700; color: var(--red); }
.ledger-head .l { text-align: left; padding-left: 10px; }
.row { width: 100%; height: 40px; padding: 0; margin: 0; border: 0; border-bottom: 1px solid rgba(184,50,42,.5); background: transparent; cursor: pointer; transition: background .2s; }
.row:last-child { border-bottom: 0; }
.row:hover, .row:focus-visible { background: rgba(255,225,74,.35); }
.row-no { font-family: var(--mono); font-size: 12px; color: var(--red); }
.row-name { text-align: left; padding-left: 10px; font-family: var(--hand); font-size: 24px; line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: underline 2px transparent; text-underline-offset: 4px; transition: text-decoration-color .2s; }
.row:hover .row-name, .row:focus-visible .row-name { text-decoration-color: var(--red); }
.row-type { font-size: 12px; }
.row-time { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.row-arrow { color: var(--red); font-size: 16px; }
.m .ledger-head, .m .row { grid-template-columns: 34px 1fr 76px 24px; }
.m .col-time { display: none; }
.m .row { height: 38px; }
.m .row-name { font-size: 22px; }
.m .pf-hint { font-size: 19px; }

.pf-hint { text-align: right; font-family: var(--hand); font-size: 22px; color: var(--red); transform: rotate(-2deg); margin-top: -4px; }
.pf-foot { margin-top: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.btn-dark { background: var(--ink); color: var(--paper); text-decoration: none; font-size: 13px; padding: 12px 16px; border-radius: 2px; }
.link { font-size: 12px; padding: 12px 4px; text-decoration: none; }
.link:hover { text-decoration: underline; }
.m .pf-foot .barcode-sm { display: none; }

/* back face */
.pb-top { display: flex; justify-content: space-between; align-items: center; font-size: 11px; }
.btn-outline { background: transparent; border: 1.5px solid var(--ink); border-radius: 999px; padding: 10px 16px; font-family: var(--mono); font-size: 12px; cursor: pointer; }
.btn-outline:hover { background: var(--ink); color: var(--paper); }
.pb-head { position: relative; }
.pb-head .mono { font-size: 11px; letter-spacing: 3px; }
.pb-head h2 { margin: 4px 0 0; font-family: var(--serif); font-weight: 900; font-size: 32px; line-height: 1.2; padding-right: 110px; }
.pb-head .muted { font-size: 13px; margin-top: 6px; padding-right: 100px; }
.stamp-archived { position: absolute; right: 0; top: 0; width: 92px; height: 92px; border-style: double; transform: rotate(-14deg); opacity: .85; font-size: 17px; }
.pb-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; flex-grow: 1; min-height: 0; }
.pb-col { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.box { border: 1.5px solid var(--red); padding: 10px 12px; }
.box.grow { flex-grow: 1; }
.box h3 { margin: 0 0 4px; font-size: 11px; font-weight: 700; color: var(--red); }
.box p { margin: 0; font-size: 13px; line-height: 1.65; }
.box ol { margin: 0; padding: 0; list-style: none; counter-reset: did; }
.box li { counter-increment: did; display: flex; gap: 8px; font-size: 13px; line-height: 1.6; margin-top: 4px; }
.box li::before { content: counter(did, decimal-leading-zero); color: var(--red); font-family: var(--mono); }
.res-list { margin: 4px 0 0; padding: 0; list-style: none; }
.box .res-list li { counter-increment: none; font-size: 12px; line-height: 1.5; margin-top: 3px; gap: 6px; }
.box .res-list li::before { content: '—'; font-family: var(--mono); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { font-family: var(--mono); font-size: 11px; border: 1px solid var(--ink); border-radius: 999px; padding: 3px 9px; }
.shot { height: 150px; border: 1.5px dashed #8C8378; background: #F1ECE2 center / cover no-repeat; display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 12px; color: var(--muted); transform: rotate(1deg); flex-shrink: 0; }
.shot[hidden] { display: none; }
.shot.has-img { border-style: solid; color: transparent; }
.pb-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.pb-foot .link { word-break: break-all; }
.pb-links { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-width: 0; }
.btn-demo { padding: 9px 14px; white-space: nowrap; }
.btn-demo[hidden] { display: none; }
.sign { white-space: nowrap; }
.sign { font-family: var(--hand); font-size: 22px; color: var(--red); }
.m .pb-head h2 { font-size: 26px; padding-right: 84px; }
.m .pb-head .muted { padding-right: 0; }
.m .stamp-archived { width: 74px; height: 74px; font-size: 14px; }
.m .pb-grid { grid-template-columns: minmax(0,1fr); flex-grow: 0; }
.m .shot { height: 130px; }

/* ---------- caption ---------- */
.caption { position: absolute; left: 0; right: 0; bottom: 24px; text-align: center; font-family: var(--mono); font-size: 12px; letter-spacing: 1px; color: var(--muted); z-index: 6; pointer-events: none; }
.m .caption { bottom: 18px; font-size: 11px; }
.m .stage:is([data-stage=list],[data-stage=detail]) .caption { opacity: 0; }

.stage.no-anim, .stage.no-anim * { transition: none !important; }

@media (prefers-reduced-motion: reduce) {
  .stage *, .stage *::before { transition-duration: .01s !important; transition-delay: 0s !important; }
}
