/* ============================================================================
   念佛助手 — design tokens
   Ported from the Claude Design project "Buddhist App Redesign"
   (ui_kits/website + tokens/*.css).

   Deviation from the source kit: the kit loaded Noto Serif TC / Noto Sans TC
   from Google Fonts as a stand-in and noted "Replace with the licensed
   originals when available." We do exactly that — the display face is the
   app's own HanWangLiSu, subsetted and self-hosted. Google Fonts is
   unreachable for a large share of this app's audience, and self-hosting also
   removes a third-party DNS + TLS hop from the critical path.
   ========================================================================= */

/* ── Brand display face — subset of HanWangLiSuMedium.ttf ─────────────────
   Subsetted to only the glyphs this page renders (both 繁體 and 简体 forms).
   8.5 MB TTF -> see build/subset-fonts.py for the regeneration command. */
@font-face {
  font-family: "HanWangLiSu";
  src: url("../font/hanwang-subset.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  /* CJK only. This face's Latin glyphs are full-width, so "App Store" renders
     letter-spaced and wrong; excluding them lets Latin fall through to the
     serif fallback. */
  unicode-range: U+2E80-9FFF, U+F900-FAFF, U+FF00-FFEF;
}

/* Simplified-mode display face — subset of SJxingkai-C.ttf.
   Only requested when the page is in 简体 mode. */
@font-face {
  font-family: "SJxingkai";
  src: url("../font/xingkai-subset.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+2E80-9FFF, U+F900-FAFF, U+FF00-FFEF;
}

:root {
  /* ── 宣紙 Paper — the ground of every screen ── */
  --paper-100: #fdf9f0;
  --paper-200: #f8f1e2;
  --paper-300: #f3e9d2;
  --paper-400: #eadcbf;
  --paper-500: #dcc9a4;

  /* ── 墨 Ink — text ── */
  --ink-900: #2b1a12;
  --ink-700: #4a3527;
  --ink-500: #6f5a48;
  --ink-300: #a08d7a;

  /* ── 檀木 Sandalwood — bars, plaques, framed panels ── */
  --wood-900: #3b0d05;
  --wood-800: #4d1107;
  --wood-700: #5b2111;
  --wood-600: #722304;
  --wood-500: #8a4a22;

  /* ── 金 Gold — the brand's signal color ── */
  --gold-100: #ffe6ad;
  --gold-200: #f4d69a;
  --gold-300: #edc16f;
  --gold-400: #d49a4b;
  /* 500 and 600 are the two golds that carry TEXT on paper, so they are set by
     contrast rather than by eye: 600 is --text-gold (links, kickers, captions)
     and needs 4.5:1 at body size; 500 draws the 34px 六大功能 numerals and
     needs 3:1. Both are measured against --paper-300, the darkest ground they
     ever sit on. The values one step lighter — #955f28 and #b8823a — came in at
     4.41 and 2.76 and missed. Re-check with the same worst-case paper before
     touching either. */
  --gold-500: #ae7833;
  --gold-600: #8f5a25;
  --gold-700: #6f4418;

  /* ── 硃砂 Cinnabar & 梅 Plum ── */
  --cinnabar-500: #92322b;
  --cinnabar-600: #7a2620;
  --plum-500: #b41325;

  --white: #ffffff;

  /* ── Semantic aliases ── */
  --surface-page: var(--paper-300);
  --surface-page-soft: var(--paper-200);
  --surface-card-warm: var(--paper-100);
  --surface-bar: var(--wood-800);

  --text-primary: var(--ink-900);
  --text-secondary: var(--ink-500);
  --text-muted: var(--ink-300);
  --text-on-dark: var(--gold-100);
  --text-gold: var(--gold-600);

  --border-hairline: rgba(43, 26, 18, 0.12);
  --border-gold: var(--gold-400);
  --border-gold-soft: rgba(212, 154, 75, 0.45);

  --accent: var(--gold-400);
  --danger: var(--plum-500);

  --grad-plaque: linear-gradient(180deg, var(--wood-700) 0%, var(--wood-900) 100%);

  /* ── Type ──
     Display carries the brand. Body uses the reader's own system CJK face:
     it costs zero bytes and paints on the first frame. */
  --font-display: "HanWangLiSu", "Songti TC", "Songti SC", serif;
  --font-body: "PingFang TC", "PingFang SC", "Heiti TC", "Microsoft JhengHei",
               "Noto Sans CJK TC", -apple-system, sans-serif;
  --font-numeral: ui-sans-serif, -apple-system, "Helvetica Neue", sans-serif;

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-bold: 700;

  /* Chinese needs a larger floor than Latin — 14px is the smallest legible
     label, so --text-sm is the floor for anything containing CJK. --text-xs is
     for Latin-only micro-text; nothing on this page qualifies, and the one
     place that used it (the footer colophon, which carries the 迴向偈) was
     moved up to --text-sm. */
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-md: 18px;
  --text-lg: 22px;
  --text-xl: 28px;
  --text-2xl: 34px;

  --leading-tight: 1.25;
  --leading-body: 1.7;
  --leading-sutra: 2;

  --tracking-title: 0.08em;
  --tracking-plaque: 0.18em;

  /* ── Space ── */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-14: 56px;
  --space-18: 72px;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-pill: 999px;

  --tap-min: 44px;   /* never smaller — used one-handed, often by elders */
  --gutter: 16px;

  /* ── Elevation — warm shadows only, never neutral grey ── */
  --shadow-sm: 0 1px 3px rgba(75, 30, 10, 0.10);
  --shadow-card: 0 4px 16px rgba(75, 30, 10, 0.10);
  --shadow-raised: 0 8px 24px rgba(75, 30, 10, 0.16);
  --inset-gold: inset 0 0 0 1px var(--gold-400);

  /* ── Motion — incense-smoke slow, always eases out ── */
  --ease-calm: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast: 160ms;
  --dur-base: 260ms;

  /* ── Textures ──
     The source kit shipped paper.png and wood.png. These are procedural
     equivalents: ~700 bytes inline instead of two raster requests, and they
     never blur when scaled. */
  --texture-paper: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23p)' opacity='0.32'/%3E%3C/svg%3E");
  --texture-wood: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='160'%3E%3Cfilter id='w'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.02 0.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='320' height='160' filter='url(%23w)' opacity='0.22'/%3E%3C/svg%3E");
}

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

body {
  margin: 0;
  background-color: var(--surface-page);
  background-image: var(--texture-paper);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: var(--weight-medium);
  line-height: var(--leading-tight);
  margin: 0 0 var(--space-3);
}

figure { margin: 0; }
/* height:auto is required because the img tags carry intrinsic width/height
   attributes — those reserve layout space and prevent shift while loading. */
img { display: block; max-width: 100%; height: auto; }

a { color: var(--text-gold); text-underline-offset: 3px; }
/* Hover DARKENS. It used to move to --gold-500, which is lighter than
   --text-gold, so the link lost contrast at the moment of interaction. */
a:hover { color: var(--gold-700); }

/* gold-400 measures 2.04:1 on --paper-300 — below the 3:1 a focus indicator
   needs. gold-600 is the same gold two steps down and clears it at 4.76:1. */
:focus-visible { outline: 2px solid var(--gold-600); outline-offset: 2px; }
::selection { background: rgba(212, 154, 75, 0.3); }

/* Simplified mode swaps the display face, matching the previous site. */
html[data-lang="zh_Hans"] {
  --font-display: "SJxingkai", "Songti SC", serif;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
