/* The one place for inner-page sizes, spacing and motion (03-UI约束.md). Colors are not here:
   every color of the site lives at the top of site.css, which inner pages load too.
   Page CSS only references these variables. Every size is written as
   calc(N * var(--u)), N being the prototype's px value (04-适配实施方案.md). */
html {
  font-size: 100%; /* never a px value: rem must follow the reader's default font size */
  -webkit-text-size-adjust: 100%;
}
/* --px is 1px at the browser's default 16px and grows with the reader's setting.
   Phones (≤600) keep --u fixed; pads (601–1024) and wide screens add a slowly
   growing amount on top. Pads start at 37.5rem so the phone/pad edge moves with
   the default font size like the breakpoint does; 1.09 = desktop / phone reading
   text (20 / 18) rounded down so pad and desktop sizes stay within 10% at 1024/1025. */
:root {
  --px: .0625rem;
  --u: var(--px);
  --layout: phone;
}
@media (width > 37.5em) and (width <= 64em) {
  :root {
    --u: clamp(var(--px), calc(var(--px) + (100vw - 37.5rem) / 1500), calc(1.09 * var(--px)));
    --layout: pad;
  }
}
@media (width > 64em) {
  :root {
    --u: clamp(var(--px), calc(var(--px) + (100vw - 1440px) / 2400), calc(1.33 * var(--px)));
    --layout: desktop;
  }
}
:root {
  --drawer-edge: 1px solid var(--color-line);

  /* Type scale: six levels (R0, user decision 2026-10-27). Page CSS uses these levels, or a
     per-part variable below that points at one. Values are desktop; phones and pads further down.
     经文 has two steps: 卦辞 and 爻辞. */
  --size-title: calc(56.16 * var(--u));
  --size-heading: calc(24 * var(--u));
  --size-judgment: calc(24 * var(--u));
  --size-line: calc(20 * var(--u));
  --size-body: calc(15 * var(--u));
  --size-aux: calc(14 * var(--u));
  --size-label: calc(12 * var(--u));

  /* Motion */
  --motion-drawer: 280ms;
  /* Divination pages: button hover, die tumble, coin toss (the three coins start 40ms apart),
     the result sliding in once six lines are cast, and the loading mark. */
  --motion-button: 200ms;
  --motion-die-roll: 580ms;
  --motion-coin-toss: 650ms;
  --motion-coin-stagger: 40ms;
  --motion-cast-complete: 700ms;
  --motion-loading: 1800ms;

  /* Top bar: 64 high and 28 side padding at 1440x900 in the prototype. */
  --hit-size: calc(44 * var(--u));
  /* Smallest hit area on touch screens; it never shrinks (三稿 3.5). */
  --touch-target: 44px;
  /* Space above the top bar: desktop and pad 8, phone 4, × --u (user 2026-10-27). */
  --topbar-top: calc(8 * var(--u));
  --topbar-height: calc(63.9 * var(--u));
  --topbar-padding: calc(28.08 * var(--u));
  --topbar-gap: calc(8 * var(--u));
  /* Logo sized against the icons (user 2026-10-27, replaces the 2.77 lockup ratio): the lotus
     image includes the dot above it, so its body is about .8 of the image height and here
     matches the icon size; the wordmark is about 2/3 of the icon. */
  --brand-logo-height: calc(30 * var(--u));
  --brand-text-height: calc(16 * var(--u));
  --brand-gap: calc(10 * var(--u));
  --icon-size: calc(24 * var(--u));
  --radius-round: calc(22 * var(--u));
  --radius-item: calc(8 * var(--u));
  --radius-menu: calc(10 * var(--u));

  /* Page column: 648 at 1440 (45%), about 36 characters of reading text per line;
     the side gutters (at least 8% each) take whatever width is left. */
  --content-top: calc(55.8 * var(--u));
  --content-bottom: calc(45 * var(--u));
  --content-width: calc(648 * var(--u));
  --content-gutter: 8%;

  /* Breadcrumb */
  --crumb-size: var(--size-label);
  --crumb-gap: calc(12 * var(--u));
  --label-tracking: .2em;

  /* Drawer */
  --drawer-width: calc(320 * var(--u));
  --drawer-pad: calc(16 * var(--u)) calc(20 * var(--u));
  --drawer-item-height: calc(48 * var(--u));
  --drawer-item-size: calc(17 * var(--u));
  --drawer-sub-height: var(--hit-size);
  --drawer-sub-size: calc(15 * var(--u));
  --drawer-sub-indent: calc(38 * var(--u));
  --drawer-icon-size: calc(22 * var(--u));

  /* Language menu */
  --menu-width: calc(168 * var(--u));
  --menu-item-size: calc(15 * var(--u));

  /* Catalog page */
  --catalog-gap: calc(56 * var(--u));
  --catalog-list-top: calc(64 * var(--u));
  --catalog-name-size: var(--size-heading);
  --catalog-note-size: var(--size-body);
  --catalog-item-pad: calc(14 * var(--u));
  --catalog-heading-size: var(--size-label);
  --h1-size: var(--size-title);
  --intro-size: var(--size-body);

  /* Hexagram pages (prototype Hexagram board at 1440) */
  --hex-meta-size: var(--size-aux);
  --hex-table-top: calc(48 * var(--u));
  --hex-table-size: var(--size-body);
  --hex-row-height: calc(34 * var(--u));
  --hex-bar-width: calc(64 * var(--u));
  --hex-bar-height: calc(6 * var(--u));
  --hex-text-top: calc(80 * var(--u));
  --hex-label-size: var(--size-aux);
  --hex-label-gap: calc(16 * var(--u));
  --hex-judgment-size: var(--size-judgment);
  --hex-line-size: var(--size-line);
  --hex-body-size: var(--size-body);
  --hex-row-gap: calc(8 * var(--u));
  --hex-lines-gap: calc(88 * var(--u));
  --hex-first-line-gap: calc(24 * var(--u));
  --hex-line-gap: calc(64 * var(--u));
  --hex-nav-top: calc(96 * var(--u));
  --hex-index-columns: 3;
  --hex-index-size: calc(17 * var(--u));

  /* Reading page (我是谁 prototype at 1440): sections, the timeline and key/text rows.
     Keys and timeline years take a fixed column left of the text. */
  --reading-text-top: calc(44 * var(--u));
  --reading-para-gap: calc(14 * var(--u));
  --reading-section-gap: calc(96 * var(--u));
  --reading-label-pad: calc(14 * var(--u));
  --reading-list-top: calc(32 * var(--u));
  --reading-key-width: calc(168 * var(--u));
  --reading-entry-indent: calc(28 * var(--u));
  --reading-entry-gap: calc(44 * var(--u));
  --reading-row-gap: calc(28 * var(--u));
  --reading-title-gap: calc(8 * var(--u));

  /* 三家注解 panel (prototype board 三家注解 · 三种状态, values at 1440). */
  --note-top: calc(10 * var(--u));
  --note-toggle-size: var(--size-aux);
  --note-books-size: var(--size-label);
  --note-icon-size: calc(14 * var(--u));
  --note-pad-y: calc(22.032 * var(--u));
  --note-pad-x: calc(24.048 * var(--u));
  --note-book-gap: calc(22.032 * var(--u));
  --note-size: var(--size-body);
  --note-quote-size: var(--size-aux);
  --note-para-gap: calc(8.064 * var(--u));

  /* Hexagram overlay on the six-yao result page: right panel (540 at 1440). */
  --sheet-width: calc(540 * var(--u));
  --sheet-top: 0px;
  --sheet-radius: 0px;
  --sheet-pad: calc(24 * var(--u)) calc(40 * var(--u));
  --sheet-head-pad: calc(16 * var(--u)) calc(24 * var(--u)) calc(16 * var(--u)) calc(32 * var(--u));
  --motion-sheet: 280ms;
  /* The overlay's own reading sizes: narrower than the page, so smaller than the six levels. */
  --sheet-title-size: calc(32 * var(--u));
  --sheet-judgment-size: calc(21 * var(--u));
  --sheet-line-size: calc(19 * var(--u));
  --sheet-body-size: calc(14 * var(--u));

  /* Symbols, not text: the astrology dice glyphs (the last die's glyph is smaller) and the
     six-yao loading mark. */
  --size-die-glyph: calc(45 * var(--u));
  --size-die-glyph-last: calc(38 * var(--u));
  --size-loading-mark: calc(24 * var(--u));
}
/* Phones and pads: the phone prototype's values and arrangement
   (one column, stacked catalog, bottom sheet). Pads keep the desktop top bar
   and drawer (see the two blocks after this one). */
@media (width <= 64em) {
  :root {
    --content-top: calc(36.292 * var(--u));
    --content-bottom: max(calc(25.32 * var(--u)), env(safe-area-inset-bottom, 0px));
    /* Type scale on phones and pads: only the title, heading and 经文 differ from desktop. */
    --size-title: calc(35.1 * var(--u));
    --size-heading: calc(22 * var(--u));
    --size-judgment: calc(20 * var(--u));
    --size-line: calc(18 * var(--u));
    --crumb-gap: calc(10 * var(--u));
    --catalog-list-top: calc(36 * var(--u));
    --catalog-item-pad: calc(12 * var(--u));
    --hex-table-top: calc(36 * var(--u));
    --hex-bar-width: calc(48 * var(--u));
    --hex-text-top: calc(56 * var(--u));
    --hex-label-gap: calc(12 * var(--u));
    --hex-lines-gap: calc(64 * var(--u));
    --hex-line-gap: calc(44 * var(--u));
    --hex-nav-top: calc(72 * var(--u));
    --hex-index-columns: 2;
    --hex-index-size: calc(16 * var(--u));
    --reading-text-top: calc(28 * var(--u));
    --reading-para-gap: calc(12 * var(--u));
    --reading-section-gap: calc(56 * var(--u));
    --reading-label-pad: calc(10 * var(--u));
    --reading-list-top: calc(20 * var(--u));
    --reading-entry-indent: calc(18 * var(--u));
    --reading-entry-gap: calc(28 * var(--u));
    --reading-row-gap: calc(18 * var(--u));
    --reading-title-gap: calc(6 * var(--u));
    /* 三家注解 at 390 (the former clamp() minimums). */
    --note-top: calc(4 * var(--u));
    --note-icon-size: calc(12 * var(--u));
    --note-pad-y: calc(16 * var(--u));
    --note-pad-x: calc(16 * var(--u));
    --note-book-gap: calc(16 * var(--u));
    --note-para-gap: calc(6 * var(--u));
    /* Bottom sheet: the page shows above it. */
    --sheet-width: 100%;
    --sheet-top: calc(84 * var(--u));
    --sheet-radius: calc(16 * var(--u));
    --sheet-pad: calc(20 * var(--u)) calc(24 * var(--u));
    --sheet-head-pad: calc(6 * var(--u)) calc(8 * var(--u)) calc(10 * var(--u)) calc(16 * var(--u));
    --size-die-glyph: calc(34 * var(--u));
    --size-die-glyph-last: calc(29 * var(--u));
  }
}
/* Phones only: the phone top bar and drawer. */
@media (width <= 37.5em) {
  :root {
    --drawer-edge: 0;
    --topbar-top: calc(4 * var(--u));
    --topbar-height: calc(55.704 * var(--u));
    --topbar-padding: max(calc(10 * var(--u)), env(safe-area-inset-left, 0px));
    --topbar-gap: calc(2 * var(--u));
    --brand-logo-height: calc(26 * var(--u));
    --brand-text-height: calc(13 * var(--u));
    --brand-gap: calc(8 * var(--u));
    --icon-size: calc(22 * var(--u));
    --drawer-width: min(calc(300 * var(--u)), 85vw);
    --drawer-pad: calc(12 * var(--u)) calc(14 * var(--u));
  }
}
/* Pads: the desktop top bar, sized between phone and desktop so neither edge
   (600/601, 1024/1025) jumps by more than 10%. */
@media (width > 37.5em) and (width <= 64em) {
  :root {
    --topbar-height: calc(59 * var(--u));
    --topbar-padding: max(calc(20 * var(--u)), env(safe-area-inset-left, 0px));
    --topbar-gap: calc(6 * var(--u));
    --brand-logo-height: calc(28 * var(--u));
    --brand-text-height: calc(14 * var(--u));
    --brand-gap: calc(9 * var(--u));
    --icon-size: calc(23 * var(--u));
  }
}
/* Short windows (landscape phones): less empty space above and below the
   column and a taller bottom sheet; text sizes stay. */
@media (height <= 31.25em) {
  :root {
    --content-top: calc(20 * var(--u));
    --content-bottom: max(calc(12 * var(--u)), env(safe-area-inset-bottom, 0px));
  }
}
@media (height <= 31.25em) and (width <= 64em) {
  :root {
    --sheet-top: 15dvh;
  }
}
