:root {
  --paper: #faf6ec;
  --surface: #ffffff;
  --ink: #2e2a24;
  --muted: #736a5d;
  --line: #e8dfcc;
  --accent: #f2b84b;
  --forest: #2f6b45;
  --forest-ink: #234a31;
  --forest-soft: #e5efd9;
  --error: #c4453a;
  --warning: #b07a10;
  --ok: #4e9e5f;
  --radius: 18px;
  --radius-lg: 28px;
  --shadow-soft: 0 1px 2px rgb(46 42 36 / 0.06), 0 8px 24px -12px rgb(46 42 36 / 0.18);
  --font-kai: "Kaiti TC", "BiauKai", "DFKai-SB", "KaiTi", "STKaiti", "PingFang HK", "Noto Sans TC", serif;
  --font-ui: "PingFang HK", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --font-song: "Songti TC", "STSongti-TC", "Noto Serif TC", "PMingLiU", serif;
  --font-xing: "Xingkai TC", var(--font-kai);
  --font-wei: "Weibei TC", var(--font-kai);
  --font-yuan: "Yuanti TC", "PingFang HK", "Noto Sans TC", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  line-height: 1.5;
}

a {
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
}

svg {
  display: block;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.fatal {
  max-width: 40rem;
  margin: 20vh auto;
  padding: 0 24px;
  font-size: 20px;
  text-align: center;
}

/* Shelf */

.home {
  max-width: 1160px;
  margin: 0 auto;
  padding: 24px 24px 80px;
}

.hero {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 32px;
  padding: 40px 40px 96px;
  border-radius: var(--radius-lg);
  background: var(--forest-soft);
  overflow: hidden;
}

.hills {
  position: absolute;
  inset: auto 0 0;
  width: 100%;
  height: 72px;
}

.brand {
  position: relative;
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  flex-shrink: 0;
  border-radius: 22px;
  background: var(--forest);
  color: #fff;
  box-shadow: 0 6px 0 var(--forest-ink);
}

.brand-mark svg {
  width: 44px;
  height: 44px;
}

.brand h1 {
  margin: 0;
  color: var(--forest-ink);
  font-family: var(--font-kai);
  font-size: clamp(38px, 5.5vw, 56px);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.06em;
}

.brand-alt {
  margin: 6px 0 0;
  color: var(--forest);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.lang-switch {
  position: relative;
  display: flex;
  padding: 5px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.lang-switch > * {
  display: grid;
  place-items: center;
  min-height: 48px;
  padding: 0 22px;
  border-radius: 999px;
  font-size: 18px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.lang-switch a {
  color: var(--muted);
  transition: color 0.15s, background-color 0.15s;
}

.lang-switch a:hover {
  background: var(--forest-soft);
  color: var(--forest-ink);
}

.lang-switch .is-active {
  background: var(--forest);
  color: #fff;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px 32px;
  margin-bottom: 40px;
}

.filters {
  display: grid;
  gap: 12px;
  flex: 1 1 560px;
}

.filter-row {
  display: grid;
  grid-template-columns: 5.5em 1fr;
  align-items: start;
  gap: 12px;
}

.filter-row + .filter-row {
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.filter-label {
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  line-height: 48px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.filter-row-topic .chips {
  gap: 8px;
}

.filter-row-topic .filter-label {
  line-height: 40px;
}

.filter-row-topic .chip {
  min-height: 40px;
  padding: 0 16px;
  font-size: 16px;
}

.search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 0 1 340px;
}

.search-icon {
  position: absolute;
  left: 18px;
  color: var(--muted);
  pointer-events: none;
}

.search-icon svg {
  width: 20px;
  height: 20px;
}

.search input {
  width: 100%;
  min-height: 48px;
  padding: 0 18px 0 48px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 17px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search input::placeholder {
  color: var(--muted);
}

.search input:focus {
  outline: none;
  border-color: var(--forest);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--forest) 16%, transparent);
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: -16px 0 36px;
}

.active-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 10px 0 14px;
  border: none;
  border-radius: 999px;
  background: var(--forest-soft);
  color: var(--forest-ink);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s;
}

.active-pill svg {
  width: 16px;
  height: 16px;
}

.active-pill:hover {
  background: color-mix(in srgb, var(--forest) 22%, var(--surface));
}

.clear-filters {
  min-height: 40px;
  padding: 0 8px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 15px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.clear-filters:hover {
  color: var(--ink);
}

.no-results {
  margin: 0;
  padding: 56px 24px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 18px;
  text-align: center;
}

.chip {
  --chip-color: var(--ink);
  min-height: 48px;
  padding: 0 22px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}

.chip:hover {
  border-color: var(--chip-color);
}

.chip.is-active {
  border-color: var(--chip-color);
  background: var(--chip-color);
  color: #fff;
}

.chip-count {
  margin-left: 0.45em;
  color: var(--muted);
  font-size: 0.82em;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.chip.is-active .chip-count {
  color: inherit;
  opacity: 0.8;
}

.level + .level {
  margin-top: 56px;
}

.level-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.level-icon {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--forest-soft);
  color: var(--forest);
}

.level-icon svg {
  width: 36px;
  height: 36px;
}

.level-name h2 {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  margin: 0;
  font-family: var(--font-kai);
  font-size: 34px;
  font-weight: 700;
  line-height: 1.2;
}

.level-alt {
  color: var(--forest);
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.level-note {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 16px;
}

.level-count {
  align-self: end;
  color: var(--muted);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.level.is-soon .level-icon {
  background: color-mix(in srgb, var(--line) 60%, transparent);
  color: var(--muted);
}

.level.is-soon .level-name h2,
.level.is-soon .level-alt {
  color: var(--muted);
}

.level-soon {
  margin: 0;
  padding: 28px 24px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 18px;
  text-align: center;
}

.shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 40px 28px;
}

.book-card {
  display: grid;
  align-content: start;
  gap: 8px;
}

.book-link {
  display: grid;
  text-decoration: none;
}

.cover,
.cover-art {
  --cat: var(--cat-color);
  --cat-dark: color-mix(in srgb, var(--cat-color) 66%, #1d1a16);
  container-type: inline-size;
}

.cover {
  position: relative;
  display: block;
  aspect-ratio: 4 / 3;
  border-radius: 6px 16px 16px 6px;
  overflow: hidden;
  background: var(--cat-color);
  box-shadow:
    0 1px 2px rgb(46 42 36 / 0.08),
    0 14px 24px -14px color-mix(in srgb, var(--cat-color) 80%, black);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cover::after,
.cover-art::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 5;
  width: 7%;
  background: linear-gradient(90deg, rgb(0 0 0 / 0.2), rgb(0 0 0 / 0.04) 70%, rgb(255 255 255 / 0.18));
  pointer-events: none;
}

.book-link:hover .cover {
  transform: translateY(-5px);
  box-shadow:
    0 1px 2px rgb(46 42 36 / 0.08),
    0 22px 30px -16px color-mix(in srgb, var(--cat-color) 80%, black);
}

/* Generated cover layouts (app/cover-title.js); sizes are in cqw of the cover */

.lay {
  position: absolute;
  inset: 0;
  background: var(--g);
  color: var(--gi);
}

.g-paper { --g: #f6efe0; --gi: #2b2620; }
.g-deep { --g: var(--cat-dark); --gi: #fff8ec; }
.g-tint { --g: color-mix(in srgb, var(--cat) 22%, #fffaf0); --gi: color-mix(in srgb, var(--cat) 40%, #1d1a16); }
.g-mid { --g: color-mix(in srgb, var(--cat) 88%, #1d1a16); --gi: #fffaf0; }

.lay .pic {
  position: absolute;
  overflow: hidden;
  background:
    radial-gradient(ellipse 60% 48% at 78% 26%, color-mix(in srgb, var(--cat) 34%, transparent), transparent 70%),
    radial-gradient(ellipse 70% 55% at 18% 92%, color-mix(in srgb, var(--cat) 46%, transparent), transparent 72%),
    radial-gradient(circle at 30% 30%, color-mix(in srgb, var(--cat) 16%, transparent) 0 14%, transparent 14.5%),
    color-mix(in srgb, var(--cat) 14%, #fbf6ea);
}

.lay .pic img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  -webkit-user-drag: none;
}

.lay .zone {
  position: absolute;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2cqw;
  text-align: center;
}

.lay .tt {
  display: block;
  font-size: var(--fs);
  line-height: 1.2;
  letter-spacing: var(--ls);
}

.lay .tt .ln {
  display: block;
  margin-inline-end: calc(var(--ls) * -1);
  white-space: nowrap;
}

.lay .tt.v {
  writing-mode: vertical-rl;
  text-orientation: mixed;
}

.lay .orn {
  flex-shrink: 0;
  font-size: 2.6cqw;
  line-height: 1;
  opacity: 0.7;
}

.lay .bar {
  display: block;
  flex-shrink: 0;
  width: 8cqw;
  height: 0.6cqw;
  border-radius: 999px;
  background: var(--gi);
  opacity: 0.85;
}

.f-song { font-family: var(--font-song); font-weight: 900; }
.f-kai { font-family: var(--font-kai); font-weight: 800; }
.f-xing { font-family: var(--font-xing); font-weight: 700; }
.f-wei { font-family: var(--font-wei); font-weight: 700; }
.f-yuan { font-family: var(--font-yuan); font-weight: 700; }

/* The art box is always 4:3 (width set, height from aspect-ratio); cover centre line is 53cqw because of the spine. */
.lay .pic { aspect-ratio: 4 / 3; }

.lay-band .zone { left: 0; right: 0; height: var(--bh); padding: 0 5cqw 0 9cqw; }
.lay-band.at-top .zone { top: 0; }
.lay-band.at-bottom .zone { bottom: 0; }
.lay-band.align-start .zone { justify-content: flex-start; text-align: left; }
.lay-band .pic { left: calc(53cqw - var(--aw) / 2); width: var(--aw); border-radius: 0.8cqw; }
.lay-band.at-top .pic { bottom: 1.5cqw; }
.lay-band.at-bottom .pic { top: 1.5cqw; }
.lay-band .edge { position: absolute; z-index: 2; left: 0; right: 0; height: 1.3cqw; }
.lay-band.edge-scallop.at-top .edge { top: var(--bh); background: radial-gradient(circle at 50% 0, var(--g) 1.1cqw, transparent 1.2cqw) 0 0 / 3cqw 1.3cqw repeat-x; }
.lay-band.edge-scallop.at-bottom .edge { bottom: var(--bh); background: radial-gradient(circle at 50% 100%, var(--g) 1.1cqw, transparent 1.2cqw) 0 0 / 3cqw 1.3cqw repeat-x; }
.lay-band.edge-rule .edge { left: 9cqw; right: 5cqw; height: 0.25cqw; background: var(--gi); opacity: 0.45; }
.lay-band.edge-rule.at-top .edge { top: calc(var(--bh) - 2cqw); }
.lay-band.edge-rule.at-bottom .edge { bottom: calc(var(--bh) - 2cqw); }

.lay-col .zone { top: 0; bottom: 0; width: 24cqw; flex-direction: column; gap: 2.4cqw; padding: 5cqw 0; }
.lay-col.at-left .zone { left: 0; padding-left: 5cqw; box-shadow: inset -0.6cqw 0 0 var(--g), inset -0.85cqw 0 0 var(--gi); }
.lay-col.at-right .zone { right: 0; box-shadow: inset 0.6cqw 0 0 var(--g), inset 0.85cqw 0 0 var(--gi); }
.lay-col .pic { top: 11.6cqw; width: 69cqw; border-radius: 0.8cqw; }
.lay-col.at-left .pic { left: 27cqw; }
.lay-col.at-right .pic { left: 6cqw; }

.lay-frame .pic { left: 20cqw; width: 66cqw; border-radius: 1cqw; box-shadow: 0 0 0 0.7cqw var(--g), 0 0 0 1cqw var(--gi); }
.lay-frame.at-bottom .pic { top: 4cqw; }
.lay-frame.at-bottom .zone { left: 9cqw; right: 5cqw; top: 55cqw; bottom: 1.5cqw; }
.lay-frame.at-top .zone { left: 9cqw; right: 5cqw; top: 1.5cqw; height: 19cqw; }
.lay-frame.at-top .pic { top: 22cqw; }

.lay-photo .pic { top: 13cqw; width: 58cqw; box-sizing: content-box; border: 1.4cqw solid #fffdf8; border-radius: 0.4cqw; box-shadow: 0 1.2cqw 2.4cqw -0.6cqw rgb(0 0 0 / 0.35); transform: rotate(var(--tilt)); }
.lay-photo .zone { top: 6cqw; bottom: 6cqw; flex-direction: column; gap: 2.4cqw; }
.lay-photo.at-left .pic { left: 10cqw; }
.lay-photo.at-left .zone { left: 73cqw; right: 3cqw; }
.lay-photo.at-right .pic { left: 33cqw; }
.lay-photo.at-right .zone { left: 8cqw; width: 23cqw; }

.lay-stamp .stamp { position: absolute; top: 17.9cqw; width: 50.4cqw; height: 39.2cqw; background: radial-gradient(circle, var(--g) 0.75cqw, transparent 0.8cqw) -1.4cqw -1.4cqw / 2.8cqw 2.8cqw, #fffdf7; filter: drop-shadow(0 0.8cqw 1.2cqw rgb(0 0 0 / 0.25)); transform: rotate(var(--tilt)); }
.lay-stamp .pic { top: 20.1cqw; width: 46.4cqw; transform: rotate(var(--tilt)); }
.lay-stamp .zone { top: 6cqw; bottom: 6cqw; flex-direction: column; gap: 2.6cqw; }
.lay-stamp.at-left .stamp { left: 10cqw; }
.lay-stamp.at-left .pic { left: 12cqw; }
.lay-stamp.at-left .zone { left: 64cqw; right: 3cqw; align-items: flex-start; text-align: left; }
.lay-stamp.at-right .stamp { left: 41cqw; }
.lay-stamp.at-right .pic { left: 43cqw; }
.lay-stamp.at-right .zone { left: 8cqw; width: 30cqw; align-items: flex-end; text-align: right; }

.lay-split .panel { position: absolute; top: 0; bottom: 0; width: 62cqw; background: color-mix(in srgb, var(--g) 90%, #1d1a16); }
.lay-split .pic { top: 16.5cqw; width: 56cqw; border-radius: 0.6cqw; }
.lay-split .zone { top: 0; bottom: 0; flex-direction: column; align-items: flex-start; justify-content: flex-end; gap: 2.6cqw; text-align: left; }
.lay-split.at-right .panel { left: 0; }
.lay-split.at-right .pic { left: 5cqw; }
.lay-split.at-right .zone { left: 62cqw; right: 0; padding: 6cqw 3.5cqw 6cqw 4cqw; }
.lay-split.at-left .panel { right: 0; }
.lay-split.at-left .pic { left: 41cqw; }
.lay-split.at-left .zone { left: 0; right: 62cqw; padding: 6cqw 2.5cqw 6cqw 8cqw; }

.lay-corner .pic { width: 74cqw; }
.lay-corner .zone { left: 9cqw; right: 4cqw; height: 17cqw; }
.lay-corner.at-br .pic { right: 0; bottom: 0; border-top-left-radius: 1.6cqw; }
.lay-corner.at-br .zone { top: 1.5cqw; justify-content: flex-start; text-align: left; }
.lay-corner.at-tl .pic { left: 0; top: 0; border-bottom-right-radius: 1.6cqw; }
.lay-corner.at-tl .zone { bottom: 1.5cqw; justify-content: flex-end; text-align: right; }

.lay-ribbon .pic { top: 2.5cqw; left: 19cqw; width: 68cqw; border-radius: 1cqw; }
.lay-ribbon .zone { left: 16cqw; right: 10cqw; top: 57.5cqw; height: 14cqw; background: var(--gi); color: var(--g); }
.lay-ribbon .zone::before,
.lay-ribbon .zone::after { content: ""; position: absolute; top: 1.6cqw; width: 6cqw; height: 100%; background: color-mix(in srgb, var(--gi) 78%, #000); }
.lay-ribbon .zone::before { left: -6cqw; clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 34% 50%); }
.lay-ribbon .zone::after { right: -6cqw; clip-path: polygon(0 0, 100% 0, 66% 50%, 100% 100%, 0 100%); }
.g-deep.lay-ribbon .zone::before,
.g-deep.lay-ribbon .zone::after { background: color-mix(in srgb, var(--gi) 82%, var(--cat)); }

.lay-polaroid .card { position: absolute; top: 8.5cqw; left: 23cqw; width: 60cqw; padding: 2.4cqw 2.4cqw 0; background: #fffdf8; box-shadow: 0 1.4cqw 3cqw -0.8cqw rgb(0 0 0 / 0.4); transform: rotate(var(--tilt)); }
.lay-polaroid .pic { position: relative; width: 100%; }
.lay-polaroid .zone { position: relative; height: 13cqw; color: #2b2620; }

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 32px;
  padding: 0 12px;
  border: 1.5px solid transparent;
  border-radius: 999px;
  background: #f0e9da;
  color: #5c5346;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}

.tag-topic,
.tag-link {
  background: color-mix(in srgb, var(--cat-color) 13%, var(--surface));
  color: color-mix(in srgb, var(--cat-color) 58%, var(--ink));
}

.tag:hover {
  border-color: currentColor;
}

.tag.is-active {
  background: #5c5346;
  color: #fff;
}

.tag-topic.is-active {
  background: color-mix(in srgb, var(--cat-color) 58%, var(--ink));
}

/* Reader */

.reader {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  --cat-color: var(--forest);
}

.reader-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px 12px;
  padding: 14px 20px 0;
}

.reader-title {
  min-width: 0;
  text-align: center;
}

.reader-title h1 {
  margin: 0;
  font-family: var(--font-kai);
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
}

.reader-meta {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.reader-meta:empty {
  display: none;
}

.back {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 48px;
  padding: 0 18px 0 12px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  font-size: 18px;
  font-weight: 600;
  text-decoration: none;
  transition: color 0.15s;
}

.back svg {
  width: 22px;
  height: 22px;
}

.back:hover {
  color: var(--cat-color);
}

.pager {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 2px;
}

.pager-jump {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s;
}

.pager-jump svg {
  width: 22px;
  height: 22px;
}

.pager-jump:hover:not(:disabled) {
  background: var(--surface);
  color: var(--cat-color);
  box-shadow: var(--shadow-soft);
}

.pager-jump:disabled {
  color: var(--line);
  cursor: default;
}

.counter {
  min-width: 4.5em;
  color: var(--muted);
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.progress {
  grid-column: 1 / -1;
  height: 6px;
  margin: 4px 0 16px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--cat-color);
  transition: width 0.3s ease;
}

.stage {
  min-height: 0;
  padding: 0 108px 24px;
}

.stage.is-entering {
  animation: enter 0.22s ease-out;
}

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* Picture and text are one unit centred in the stage; the text box always reserves --text-lines
   so the picture does not jump between pages with one or two lines. */
.stage-page {
  --fs: clamp(30px, min(4.2cqw, 5.6cqh), 64px);
  --text-lines: 2;
  --text-h: calc(var(--fs) * 1.55 * var(--text-lines));
  --gap: clamp(16px, 3.2cqh, 40px);
  --art-w: min(100cqw, (100cqh - var(--text-h) - var(--gap)) * 4 / 3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  overflow-y: auto;
  container-type: size;
  touch-action: pan-y;
  user-select: none;
}

.stage-page .art-frame {
  flex: none;
  display: block;
  container-type: normal;
}

.stage-page .art {
  width: var(--art-w);
  container-type: inline-size;
}

.art-frame {
  min-height: 0;
  display: grid;
  place-items: center;
  container-type: size;
}

.art {
  position: relative;
  width: min(100cqw, 100cqh * 4 / 3);
  aspect-ratio: 4 / 3;
  margin: 0;
  border: 8px solid var(--surface);
  border-radius: 24px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 2px 0 var(--line), 0 18px 40px -18px rgb(46 42 36 / 0.3);
}

.art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  -webkit-user-drag: none;
}

.art-placeholder {
  display: none;
}

.art.is-missing img {
  display: none;
}

.art.is-missing .art-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  padding: 8% 14%;
  border-radius: 16px;
  background:
    radial-gradient(circle at 12% 18%, color-mix(in srgb, var(--cat-color) 10%, transparent) 0 14%, transparent 14.5%),
    radial-gradient(circle at 92% 88%, color-mix(in srgb, var(--cat-color) 12%, transparent) 0 22%, transparent 22.5%),
    color-mix(in srgb, var(--cat-color) 7%, var(--surface));
  color: color-mix(in srgb, var(--cat-color) 55%, var(--ink));
  font-family: var(--font-kai);
  font-size: clamp(17px, 3.2cqw, 26px);
  line-height: 1.6;
  text-align: center;
  text-wrap: balance;
}

.art-placeholder svg {
  width: clamp(40px, 8cqw, 64px);
  height: auto;
  opacity: 0.5;
}

.story-text {
  flex: none;
  width: var(--art-w);
  margin-top: var(--gap);
  min-height: var(--text-h);
  font-family: var(--font-kai);
  font-size: var(--fs);
  line-height: 1.55;
  letter-spacing: 0.04em;
  text-align: center;
  text-wrap: balance;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.story-text p {
  margin: 0;
}

mark {
  background: none;
  color: inherit;
}

.new-word {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 0.12em;
  text-underline-offset: 0.2em;
}

.sentence,
.tok {
  border-radius: 0.18em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  transition: background-color 0.15s;
}

.can-speak .tok {
  cursor: pointer;
}

.sentence.is-reading {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
}

.tok.is-current,
.tok.is-speaking {
  background: color-mix(in srgb, var(--accent) 55%, transparent);
}

@media (hover: hover) {
  .can-speak .tok:hover {
    background: color-mix(in srgb, var(--accent) 28%, transparent);
  }
}

.read-toggle {
  color: var(--cat-color);
}

.read-toggle[aria-pressed="true"],
.read-toggle[aria-pressed="true"]:hover:not(:disabled) {
  background: var(--cat-color);
  color: #fff;
}

body:not(.can-speak) .speak {
  display: none;
}

.speak.is-speaking {
  border-color: var(--cat-color);
  background: var(--cat-color);
  color: #fff;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 10;
  width: max-content;
  max-width: calc(100vw - 32px);
  margin: 0;
  padding: 12px 20px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--paper);
  font-size: 17px;
  line-height: 1.5;
  box-shadow: var(--shadow-soft);
  transform: translateX(-50%);
}

.turn {
  position: fixed;
  top: 50%;
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 4px 0 var(--line), var(--shadow-soft);
  cursor: pointer;
  transform: translateY(-50%);
  transition: color 0.15s, background-color 0.15s;
}

.turn svg {
  width: 30px;
  height: 30px;
}

.turn:hover {
  color: var(--cat-color);
}

.turn-next {
  right: 24px;
  background: var(--cat-color);
  color: #fff;
  box-shadow: 0 4px 0 color-mix(in srgb, var(--cat-color) 70%, black), var(--shadow-soft);
}

.turn-next:hover {
  color: #fff;
  background: color-mix(in srgb, var(--cat-color) 88%, black);
}

.turn:active {
  box-shadow: 0 1px 0 var(--line);
  transform: translateY(calc(-50% + 3px));
}

.turn-prev {
  left: 24px;
}

.cover-art {
  border: 0;
  border-radius: 8px 24px 24px 8px;
  background: var(--cat-color);
  box-shadow: 0 2px 2px rgb(46 42 36 / 0.08), 0 28px 44px -24px color-mix(in srgb, var(--cat-color) 80%, black);
}

.cover-art::after {
  width: 5%;
}

/* Intro */

.stage-intro {
  overflow-y: auto;
  padding-top: 8px;
  padding-bottom: 48px;
}

.intro {
  display: grid;
  justify-items: start;
  gap: 20px;
  max-width: 760px;
  margin: 0 auto;
}

.tag-level {
  background: var(--forest-soft);
  color: var(--forest-ink);
  cursor: default;
}

.tag-level:hover {
  border-color: transparent;
}

.tag-level svg {
  width: 18px;
  height: 18px;
}

.intro-tags .tag {
  min-height: 36px;
  font-size: 15px;
}

.intro-summary {
  margin: 4px 0 0;
  font-family: var(--font-kai);
  font-size: clamp(26px, 3vw, 34px);
  line-height: 1.6;
}

.intro-facts {
  margin: -8px 0 0;
  color: var(--muted);
  font-size: 16px;
}

.intro-prompt,
.intro-characters {
  width: 100%;
}

.intro-prompt {
  padding: 18px 22px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--cat-color) 10%, var(--surface));
}

.intro-prompt h2,
.intro-characters h2 {
  margin: 0 0 8px;
  color: color-mix(in srgb, var(--cat-color) 58%, var(--ink));
  font-size: 16px;
  font-weight: 700;
}

.intro-prompt p {
  margin: 0;
  font-family: var(--font-kai);
  font-size: 24px;
  line-height: 1.5;
}

.intro-characters ul {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.intro-characters li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.avatar {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--cat-color);
  color: #fff;
  font-family: var(--font-kai);
  font-size: 22px;
  font-weight: 700;
}

.intro-characters strong {
  display: block;
  font-family: var(--font-kai);
  font-size: 20px;
}

.character-desc {
  color: var(--muted);
  font-size: 15px;
}

.intro-start {
  justify-self: center;
  gap: 6px;
  margin-top: 8px;
}

.intro-start svg {
  width: 22px;
  height: 22px;
}

/* Ending */

.stage-ending {
  overflow-y: auto;
  padding-top: 8px;
  padding-bottom: 48px;
}

.ending-title {
  margin: 0 auto 20px;
  max-width: 1080px;
  font-family: var(--font-kai);
  font-size: 32px;
  font-weight: 700;
}

.word-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 20px;
  max-width: 1080px;
  margin: 0 auto;
}

.word-card {
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 20px 22px;
  border-top: 6px solid var(--cat-color);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.word-card:hover {
  transform: translateY(-3px);
}

.word-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.word {
  min-width: 0;
  overflow-wrap: break-word;
  font-family: var(--font-kai);
  font-size: 40px;
  font-weight: 700;
  line-height: 1.2;
}

.pos {
  margin-left: 6px;
  font-style: italic;
}

:lang(en) .word {
  font-size: 34px;
}

.speak {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  margin-left: auto;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
  cursor: pointer;
}

.speak:hover {
  border-color: var(--cat-color);
  color: var(--cat-color);
}

.syllables {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.syllable.s0 { color: #d9694f; }
.syllable.s1 { color: #3e86c9; }
.syllable.s2 { color: #4e9e5f; }
.syllable.s3 { color: #9a5fb5; }

.dot {
  margin: 0 4px;
  color: var(--muted);
}

.ipa,
.jyutping {
  color: var(--muted);
  font-size: 18px;
}

.meaning {
  font-size: 20px;
}

.example {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  color: var(--muted);
  font-family: var(--font-kai);
  font-size: 20px;
  line-height: 1.6;
}

.example p {
  flex: 1;
  margin: 0;
}

.example-word {
  padding: 0 2px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 40%, transparent);
  color: var(--ink);
}

.observe {
  max-width: 1080px;
  margin: 28px auto 0;
  padding: 20px 24px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--cat-color) 10%, var(--surface));
  font-size: 20px;
}

.observe h2 {
  margin: 0 0 6px;
  font-family: var(--font-kai);
  font-size: 24px;
}

.observe p {
  margin: 0;
}

.ending-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin-top: 36px;
}

.action {
  display: inline-flex;
  align-items: center;
  min-height: 56px;
  padding: 0 28px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  font-size: 20px;
  font-weight: 600;
  text-decoration: none;
}

.action:hover {
  color: var(--cat-color);
}

.action.is-primary {
  background: var(--cat-color);
  color: #fff;
}

/* Content check */

.check {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.check-header h1 {
  margin: 0 0 16px;
  font-size: 28px;
}

.summary {
  margin: 0 0 24px;
  padding: 14px 18px;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 600;
}

.summary.is-ok {
  background: color-mix(in srgb, var(--ok) 14%, var(--surface));
}

.summary.is-error {
  background: color-mix(in srgb, var(--error) 12%, var(--surface));
}

.check-group {
  margin-bottom: 24px;
}

.check-group h2 {
  margin: 0 0 8px;
  padding-left: 12px;
  border-left: 6px solid var(--cat-color, var(--ink));
  font-size: 20px;
}

.check-group ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.check-book {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.check-book-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  font-weight: 600;
}

.check-book-head::before {
  content: "●";
  font-size: 12px;
}

.check-book.is-ok .check-book-head::before { color: var(--ok); }
.check-book.is-warning .check-book-head::before { color: var(--warning); }
.check-book.is-error .check-book-head::before { color: var(--error); }

.check-book code {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.check-book ul {
  margin: 6px 0 0 20px;
}

.issue.is-error { color: var(--error); }
.issue.is-warning { color: var(--warning); }

/* Small screens */

@media (max-width: 720px) {
  .home {
    padding: 16px 16px 64px;
  }

  .hero {
    padding: 24px 20px 80px;
    border-radius: 22px;
  }

  .brand-mark {
    width: 56px;
    height: 56px;
    border-radius: 18px;
  }

  .brand-mark svg {
    width: 34px;
    height: 34px;
  }

  .lang-switch {
    width: 100%;
  }

  .lang-switch > * {
    flex: 1;
    padding: 0 12px;
  }

  .toolbar {
    margin-bottom: 32px;
  }

  .search {
    order: -1;
    flex-basis: 100%;
  }

  .filter-row {
    grid-template-columns: 4.6em 1fr;
    gap: 8px;
  }

  .chip {
    padding: 0 16px;
    font-size: 17px;
  }

  .level-head {
    grid-template-columns: auto 1fr;
  }

  .level-count {
    display: none;
  }

  .level-icon {
    width: 52px;
    height: 52px;
  }

  .level-name h2 {
    font-size: 28px;
  }

  .shelf-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 28px 16px;
  }

  .reader-meta {
    display: none;
  }

  .pager-jump {
    width: 40px;
  }

  .counter {
    min-width: 3.5em;
  }

  .reader-bar {
    padding: 10px 16px 0;
  }

  .reader-title h1 {
    font-size: 20px;
  }

  .back {
    padding: 0 12px 0 8px;
  }

  .back span {
    display: none;
  }

  .stage {
    padding: 0 16px 104px;
  }

  .stage-page {
    --fs: clamp(22px, 6.6cqw, 34px);
    --text-lines: 3;
  }

  .turn {
    top: auto;
    bottom: 20px;
    transform: none;
  }

  .turn:active {
    transform: translateY(3px);
  }

  .read-toggle {
    position: fixed;
    bottom: 26px;
    left: 50%;
    width: 56px;
    height: 56px;
    background: var(--surface);
    box-shadow: 0 4px 0 var(--line), var(--shadow-soft);
    transform: translateX(-50%);
  }

  .read-toggle svg {
    width: 26px;
    height: 26px;
  }

  .toast {
    bottom: 104px;
  }
}

/* Browsers without container queries (older Android WebViews such as Quark) cannot resolve the cq
   units above, which collapses the picture to zero width; size from the viewport instead.
   The subtracted heights approximate the reader bar and the stage padding. */
@supports not (container-type: size) {
  .stage-page {
    --fs: clamp(26px, min(3.6vw, 4.6vh), 56px);
    --gap: clamp(14px, 2.6vh, 32px);
    --art-w: min(100vw - 216px, (100vh - 130px - var(--text-h) - var(--gap)) * 4 / 3);
  }

  @media (max-width: 720px) {
    .stage-page {
      --fs: clamp(20px, 5.6vw, 30px);
      --art-w: min(100vw - 32px, (100vh - 210px - var(--text-h) - var(--gap)) * 4 / 3);
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
