/* Resource Han Rounded CN (SIL OFL 1.1), subset — the same rounded face as the "100 件小事" prototype. */
@font-face { font-family: 'OMI Round'; font-weight: 500; font-display: swap; src: url('../fonts/OmiRound-Medium.woff2') format('woff2'); }
@font-face { font-family: 'OMI Round'; font-weight: 700; font-display: swap; src: url('../fonts/OmiRound-Bold.woff2') format('woff2'); }

:root {
  /* the OMI palette: cream pages, warm brown ink, an orange pill, coral subtitles */
  --cream: #F4EFE4;
  --paper: #FFFDF8;
  --ink: #4E4038;
  --gray: #8F8278;
  --orange: #F2B147;
  --coral: #D5877A;
  --gold: #FFDF8C;        /* the book's yellow headings (on dark pictures only) */
  --desk: #B87840;        /* the table the cards lie on */
  --on-desk: #FFF8EA;     /* words written straight on the table */
  --topH: 128px;          /* room above the card for the title */
  --botH: 112px;          /* room below the card for the two buttons */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
@media (max-height: 700px) { :root { --topH: 112px; --botH: 92px; } }
@media (max-height: 559px) { :root { --topH: 58px; --botH: 60px; } }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: #FBF8F2; color: var(--ink); overflow: hidden; overscroll-behavior: none;
  font-family: 'OMI Round', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', sans-serif; font-weight: 500;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; padding: 0; background: none; }
:focus-visible { outline: 2px solid var(--orange); outline-offset: 3px; }

/* ---------- the page: a phone-sized stage; on a phone it is the whole screen ---------- */
.page { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; gap: 96px; }
.phone-col { position: relative; flex: none; width: 100%; height: 100%; }
.stage {
  position: relative; width: 100%; height: 100%; overflow: hidden; container-type: size; isolation: isolate;
  /* a warm table: light from the upper left, a fine weave, a little grain */
  background:
    radial-gradient(130% 70% at 24% 8%, rgb(255 210 150 / .26), transparent 62%),
    radial-gradient(110% 60% at 88% 104%, rgb(96 48 16 / .36), transparent 66%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .3 0 0 0 0 .16 0 0 0 0 .05 0 0 0 .55 -.15'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E"),
    repeating-linear-gradient(90deg, rgb(255 236 205 / .055) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(0deg, rgb(86 42 12 / .07) 0 1px, transparent 1px 3px),
    var(--desk);
}
.note, .keys { display: none; flex: none; width: 250px; }
.arrow { display: none; }
@media (min-width: 600px) and (min-height: 560px) {
  .phone-col { width: 390px; height: min(800px, calc(100vh - 48px)); height: min(800px, calc(100dvh - 48px)); }
  .stage { border-radius: 38px; box-shadow: 0 1px 0 rgb(0 0 0 / .04), 0 30px 70px -28px rgb(60 40 20 / .5); }
  .index { border-radius: 38px; }
}
@media (min-width: 600px) and (min-height: 560px) and (hover: hover) {
  .arrow {
    position: absolute; top: 50%; display: grid; place-items: center; width: 52px; height: 52px; margin-top: -26px; border-radius: 50%;
    background: var(--paper); color: var(--ink); box-shadow: 0 1px 0 rgb(0 0 0 / .04), 0 10px 24px -10px rgb(60 40 20 / .4); transition: opacity .25s, transform .15s;
  }
  .arrow.prev { left: -74px; }
  .arrow.next { right: -74px; }
  .arrow:hover { transform: scale(1.06); }
  .arrow:disabled { opacity: 0; pointer-events: none; }
}
@media (min-width: 1180px) and (min-height: 560px) {
  .note, .keys { display: block; }
  .note h1 { font-size: 34px; line-height: 1.2; margin: 0; }
  .note p { font-size: 14px; line-height: 1.8; color: var(--gray); margin: 20px 0 0; }
  .note .fine, .keys .fine { font-size: 12px; line-height: 1.7; margin-top: 16px; color: var(--gray); }
  .keys h2 { font-size: 15px; margin: 0 0 14px; }
  .keys ul { list-style: none; margin: 0; padding: 0; }
  .keys li { display: flex; align-items: baseline; gap: 12px; font-size: 13.5px; line-height: 1.5; color: var(--gray); margin-bottom: 11px; }
  .keys kbd { flex: none; min-width: 58px; padding: 3px 8px; border-radius: 8px; background: var(--paper); color: var(--ink); font: inherit; font-size: 12.5px; font-weight: 700; text-align: center; box-shadow: 0 0 0 1px rgb(78 64 56 / .1), 0 2px 0 rgb(78 64 56 / .1); }
}

/* ---------- the album: cards lying in a row, the next one showing at the edge ---------- */
.album {
  --avail: calc(100cqh - var(--topH) - var(--botH) - var(--sat) - var(--sab));
  --cw: min(78cqw, calc(var(--avail) * .6));
  --ch: min(var(--avail), calc(var(--cw) / .55));
  --gap: calc(var(--cw) * .045);
  position: absolute; inset: 0; z-index: 1; display: flex; align-items: center; gap: var(--gap); outline: none;
  padding: calc(var(--topH) + var(--sat)) 0 calc(var(--botH) + var(--sab)); overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; scrollbar-width: none; touch-action: pan-x; cursor: grab;
}
.album::-webkit-scrollbar { display: none; }
.album.dragging { scroll-snap-type: none; cursor: grabbing; }
/* room at both ends so the first and the last card can sit in the middle */
.album::before, .album::after { content: ''; flex: 0 0 calc((100cqw - var(--cw)) / 2 - var(--gap)); height: 1px; }
.card {
  position: relative; flex: 0 0 var(--cw); height: var(--ch); border-radius: calc(var(--cw) * .07);
  scroll-snap-align: center; scroll-snap-stop: always; user-select: none; -webkit-user-select: none;
  /* no frame round the picture: only the shadow it casts on the table */
  box-shadow: 0 24px 30px -16px rgb(64 30 6 / .58), 0 4px 10px rgb(64 30 6 / .2);
  transform: scale(.955) rotate(var(--tilt, 0deg)); transition: transform .5s cubic-bezier(.2, .8, .2, 1);
}
.card.on { transform: none; }
.face { position: relative; width: 100%; height: 100%; overflow: hidden; border-radius: inherit; background: #2A211B; }
/* a blurred copy of the picture: what shows before the picture loads */
.bg { position: absolute; inset: -12%; background-size: cover; background-position: center; filter: blur(24px) saturate(1.15); }
.pic {
  position: absolute; left: 0; top: 0; max-width: none; display: block; opacity: 0; transition: opacity .5s;
  transform: translate3d(var(--x0, 0), var(--y0, 0), 0); -webkit-user-drag: none;
}
.pic.ready { opacity: 1; }
/* a wide picture does not fit an upright card, so the view drifts slowly across it */
.card.on .pic { will-change: transform; animation: pan var(--dur, 30s) ease-in-out 1.2s infinite alternate; }
@keyframes pan { from { transform: translate3d(var(--x0), var(--y0), 0); } to { transform: translate3d(var(--x1), var(--y1), 0); } }

/* ---------- the words: written straight on the picture — no veil under them, no outline, no shadow ----------
   What keeps them readable is their colour alone: cream on a dark picture, brown on a light one (tone in cards.js,
   measured by scripts/tones.mjs), and where on the card they sit. */
.words {
  --fs: clamp(12.5px, calc(var(--cw) * .0475), 17px);
  position: absolute; left: 0; right: 0; z-index: 2; padding: 0 calc(var(--cw) * .068); color: #FFFBF0;
  opacity: 0; transform: translateY(10px); transition: opacity .7s .2s, transform .7s .2s;
}
.card.on .words { opacity: 1; transform: none; }
.card.m-b .words { bottom: calc(var(--cw) * .078); }
.card.m-t .words { top: calc(var(--cw) * .078); }
.words p { margin: 0 0 .7em; font-size: var(--fs); line-height: 1.86; letter-spacing: .03em; }
.w { position: relative; }
.card.a-r .w { width: fit-content; max-width: 100%; margin-left: auto; }   /* the words stand at the right instead of the left */
.w > :last-child { margin-bottom: 0; }
.words .cl { display: inline-block; }   /* a clause never breaks in the middle; long lines break after a comma */
.words p { font-weight: 700; }
.words .ttl { font-size: calc(var(--fs) * 1.9); font-weight: 700; line-height: 1.2; letter-spacing: .01em; margin: 0 0 .3em; color: var(--gold); }
.words .en { font-size: calc(var(--fs) * .82); line-height: 1.6; letter-spacing: .02em; }
.words .tag { font-size: calc(var(--fs) * 1.12); font-weight: 700; line-height: 1.8; color: var(--gold); }
.words .t-light { color: #FFFBF0; }
.words .t-ink { color: #2B201A; }
.tone-ink .words, .tone-ink .words .ttl, .tone-ink .words .tag, .tone-ink .words h1 { color: #2B201A; }   /* gold only reads on a dark picture */

/* a phone held sideways: no room for an upright card, so the cards lie wide and the words are sized from their height */
@media (max-height: 559px) {
  .album { --cw: min(62cqw, calc(var(--avail) * 1.5)); --ch: var(--avail); --gap: calc(var(--cw) * .03); }
  .card { border-radius: 18px; }
  .words { --fs: clamp(10px, calc(var(--ch) * .046), 15px); padding: 0 calc(var(--ch) * .08); }
  .words p { line-height: 1.7; margin-bottom: .5em; }
  .card.m-b .words { bottom: calc(var(--ch) * .07); }
  .card.m-t .words { top: calc(var(--ch) * .07); }
  .words h1 { font-size: calc(var(--ch) * .17); }
}

/* the cover and the last card */
.words h1 { font-size: calc(var(--cw) * .145); font-weight: 700; line-height: 1.12; letter-spacing: .01em; margin: .1em 0 .12em; white-space: nowrap; color: var(--gold); }
.words .kicker { font-size: calc(var(--fs) * .86); letter-spacing: .22em; line-height: 1.6; margin: 0; }
.words .hint { font-size: calc(var(--fs) * .84); letter-spacing: .06em; line-height: 1.6; margin: 14px 0 0; }
.words .fine { font-size: calc(var(--fs) * .8); line-height: 1.75; }
.words .row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.pill {
  display: inline-flex; align-items: center; gap: 7px; margin-top: 12px; padding: .72em 1.4em; border-radius: 99px;
  background: var(--orange); color: #4A3413; font-size: calc(var(--fs) * 1.02); font-weight: 700; letter-spacing: .05em;
}
.pill.ghost { background: rgb(255 253 248 / .94); color: var(--ink); }
.row .pill { margin-top: 0; }

/* ---------- what is written on the table: the title above, two buttons below ---------- */
.top { position: absolute; left: 0; right: 0; top: 0; z-index: 5; padding: calc(28px + var(--sat)) 26px 0; pointer-events: none; color: var(--on-desk); }
.top h1 { font-size: 27px; font-weight: 700; line-height: 1.2; letter-spacing: .07em; margin: 0; }
.stamp { position: absolute; right: 20px; top: calc(16px + var(--sat)); width: 76px; height: 76px; transform: rotate(-11deg); opacity: .8; display: grid; place-content: center; text-align: center; }
.stamp svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.stamp b { font-size: 17px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.stamp small { font-size: 8.5px; font-weight: 700; line-height: 1; letter-spacing: .08em; margin-top: 3px; }
.chapter { font-size: 13.5px; line-height: 1.5; letter-spacing: .1em; margin: 7px 0 0; opacity: .95; }
.chapter b { font-weight: 700; color: #FFE7A6; }
.bars { display: flex; gap: 4px; margin-top: 12px; }
.bars i { flex: var(--n) 1 0; height: 3px; border-radius: 9px; background: rgb(255 248 234 / .3); overflow: hidden; }
.bars b { display: block; height: 100%; width: var(--p, 0%); background: var(--on-desk); border-radius: 9px; transition: width .35s; }
@media (max-height: 700px) { .top { padding-top: calc(20px + var(--sat)); } .top h1 { font-size: 24px; } }
@media (max-height: 700px) { .stamp { width: 66px; height: 66px; top: calc(12px + var(--sat)); } .stamp b { font-size: 15px; } }
@media (max-height: 559px) { .top { padding-top: calc(14px + var(--sat)); } .top h1 { font-size: 20px; } .chapter, .bars, .stamp svg, .stamp small { display: none; } .stamp { width: auto; height: auto; top: calc(16px + var(--sat)); transform: none; } }

.bottom { position: absolute; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; padding: 0 24px calc(30px + var(--sab)); pointer-events: none; }
.btn { pointer-events: auto; display: inline-flex; align-items: center; gap: 8px; height: 46px; padding: 0 20px 0 16px; border-radius: 99px; font-size: 14.5px; font-weight: 700; letter-spacing: .06em; transition: transform .15s; }
.btn:active { transform: scale(.97); }
.btn.white { background: var(--paper); color: var(--ink); box-shadow: 0 2px 0 rgb(96 48 16 / .18), 0 12px 22px -10px rgb(64 30 6 / .6); }
.btn.white svg { color: var(--orange); }
.btn.line { color: var(--on-desk); background: rgb(255 248 234 / .14); box-shadow: inset 0 0 0 1.5px rgb(255 248 234 / .5); }
.btn.line[aria-pressed="true"] { background: var(--on-desk); color: var(--ink); box-shadow: none; }
@media (max-height: 700px) { .bottom { padding-bottom: calc(20px + var(--sab)); } .btn { height: 42px; } }
@media (max-height: 559px) { .bottom { padding-bottom: calc(10px + var(--sab)); } .btn { height: 38px; font-size: 13px; } }

/* "只看画": the words step aside and the view travels across the whole picture */
body.bare .words { opacity: 0 !important; pointer-events: none; transition: opacity .25s; }

/* ---------- the index: every card as a small postcard, by chapter ---------- */
.index {
  position: absolute; inset: 0; z-index: 30; overflow-y: auto; padding: calc(24px + var(--sat)) 20px calc(36px + var(--sab));
  background-color: var(--cream); background-image: radial-gradient(rgb(78 64 56 / .075) 1px, transparent 1.5px); background-size: 14px 14px;
  animation: rise .24s ease-out; scrollbar-width: none;
}
.index::-webkit-scrollbar { display: none; }
.index[hidden] { display: none; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.index-hd { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.index h2 { font-size: 26px; line-height: 1.2; margin: 0; }
.index .sub { color: var(--gray); font-size: 13px; line-height: 1.6; margin: 5px 0 0; }
.index section { margin-top: 26px; }
.index h3 { display: flex; align-items: baseline; gap: 9px; font-size: 17px; margin: 0 0 13px; }
.index h3 small { color: var(--coral); font-size: 12px; font-weight: 700; letter-spacing: .04em; }
.round { flex: none; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; background: var(--paper); color: var(--ink); box-shadow: 0 2px 12px rgb(50 34 20 / .2); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(98px, 1fr)); gap: 16px 12px; }
.pc {
  display: block; text-align: left; border-radius: 9px; transform: rotate(var(--r, 0deg)); transition: transform .2s;
}
.pc:hover { transform: rotate(0deg) translateY(-3px); }
.pc.cur { outline: 3px solid var(--orange); outline-offset: 4px; }
.pc img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 9px; background: #E6DDCD; box-shadow: 0 10px 18px -10px rgb(60 40 20 / .5); }
.pc span { display: block; padding: 6px 2px 0; font-size: 11px; line-height: 1.35; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc i { font-style: normal; font-weight: 700; color: var(--coral); margin-right: 5px; font-variant-numeric: tabular-nums; }
.credit { margin-top: 34px; color: var(--gray); font-size: 12px; line-height: 1.8; }

/* for screenshots and for people who ask for less motion: no drifting, no fades */
.still *, .still *::before { animation: none !important; transition: none !important; }
.still.end .pic { transform: translate3d(var(--x1, 0), var(--y1, 0), 0); }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
