/* ==========================================================================
   Design tokens — themes (data-theme) × colour-vision palettes (data-cvd)
   Every colour used by the site, rule pages, tables, tags, search and the
   admin panel comes from these variables. Contrast is checked by
   tools/check-contrast.mjs (WCAG 2.2 AA: text ≥ 4.5:1, UI ≥ 3:1).
   ========================================================================== */

@font-face { font-family: 'IBM Plex Sans Thai'; font-style: normal; font-weight: 400; font-display: swap; src: url(../fonts/plex-thai-thai-400.woff2) format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'IBM Plex Sans Thai'; font-style: normal; font-weight: 500; font-display: swap; src: url(../fonts/plex-thai-thai-500.woff2) format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'IBM Plex Sans Thai'; font-style: normal; font-weight: 600; font-display: swap; src: url(../fonts/plex-thai-thai-600.woff2) format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'IBM Plex Sans Thai'; font-style: normal; font-weight: 700; font-display: swap; src: url(../fonts/plex-thai-thai-700.woff2) format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'IBM Plex Sans Thai'; font-style: normal; font-weight: 400; font-display: swap; src: url(../fonts/plex-thai-latin-400.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'IBM Plex Sans Thai'; font-style: normal; font-weight: 500; font-display: swap; src: url(../fonts/plex-thai-latin-500.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'IBM Plex Sans Thai'; font-style: normal; font-weight: 600; font-display: swap; src: url(../fonts/plex-thai-latin-600.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'IBM Plex Sans Thai'; font-style: normal; font-weight: 700; font-display: swap; src: url(../fonts/plex-thai-latin-700.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  --font: 'IBM Plex Sans Thai', 'Noto Sans Thai', 'Leelawadee UI', 'Thonburi', 'Sarabun', Tahoma, system-ui, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --border-w: 1px;
  --focus-w: 3px;
  --topbar-h: 3.5rem;
  --sidebar-w: 17.5rem;
  --measure: 46rem;
  --shadow: 0 10px 30px rgb(0 0 0 / .18);
  color-scheme: dark;
}

/* ---------- Dark (default) ---------- */
:root, [data-theme="dark"] {
  --bg: #0f1015;
  --bg-elev: #16181f;
  --surface-2: #1c1f28;
  --line: #2a2e3a;
  --line-strong: #6b7285;
  --text: #eceef3;
  --text-2: #c3c8d2;
  --text-3: #959cab;
  --accent: #e7c46a;
  --accent-text: #ecc970;
  --pill-bg: #e7c46a;
  --pill-ink: #1a1405;
  --focus: #ffd75e;
  --overlay: rgb(5 6 9 / .66);
  --topbar-bg: rgb(15 16 21 / .9);
  --mark-bg: #6b5410;
  --mark-ink: #fff6d6;
  --danger: #ff8f8f; --warn: #f5c451; --info: #8fb8ff; --ok: #7fd6a6;
  --tint: 13%;
}
[data-theme="dark"][data-cvd="rg"] { --danger: #ffa75e; --warn: #f0e442; --info: #c2a8ff; --ok: #6cc4ff; }
[data-theme="dark"][data-cvd="by"] { --danger: #ff7b8a; --warn: #ffb066; --info: #5fd8e6; --ok: #e4e4e4; }

/* ---------- Light ---------- */
[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f4f0;
  --bg-elev: #ffffff;
  --surface-2: #eeece6;
  --line: #dcd8ce;
  --line-strong: #8f8a7e;
  --text: #16171b;
  --text-2: #363a43;
  --text-3: #575e6b;
  --accent: #c99a2e;
  --accent-text: #7d5a0e;
  --pill-bg: #1d1e24;
  --pill-ink: #f7e3ad;
  --focus: #0b57d0;
  --overlay: rgb(20 20 25 / .45);
  --topbar-bg: rgb(255 255 255 / .92);
  --mark-bg: #ffe08a;
  --mark-ink: #1a1405;
  --shadow: 0 10px 30px rgb(30 25 10 / .08);
  --danger: #b3261e; --warn: #845400; --info: #1d5fc4; --ok: #17784a;
  --tint: 9%;
}
[data-theme="light"][data-cvd="rg"] { --danger: #a34900; --warn: #685c00; --info: #6a3fb8; --ok: #0a5fa8; }
[data-theme="light"][data-cvd="by"] { --danger: #b0204a; --warn: #9c4400; --info: #006b75; --ok: #4a4a4a; }

/* ---------- Warm / Sepia ---------- */
[data-theme="sepia"] {
  color-scheme: light;
  --bg: #f3ead7;
  --bg-elev: #faf4e6;
  --surface-2: #ece0c6;
  --line: #d9c9a6;
  --line-strong: #8c7a58;
  --text: #33291b;
  --text-2: #4a3d2b;
  --text-3: #64543d;
  --accent: #b07d22;
  --accent-text: #74490c;
  --pill-bg: #4a3215;
  --pill-ink: #fbecc6;
  --focus: #0b57d0;
  --overlay: rgb(40 28 10 / .4);
  --topbar-bg: rgb(250 244 230 / .94);
  --mark-bg: #f7cf6b;
  --mark-ink: #2b1d06;
  --shadow: 0 10px 30px rgb(60 40 10 / .08);
  --danger: #a3231b; --warn: #7a4c00; --info: #1c5aa8; --ok: #146c42;
  --tint: 10%;
}
[data-theme="sepia"][data-cvd="rg"] { --danger: #934200; --warn: #5e5300; --info: #613aa8; --ok: #0a5797; }
[data-theme="sepia"][data-cvd="by"] { --danger: #a01d44; --warn: #8f3d00; --info: #006169; --ok: #454545; }

/* ---------- High contrast ---------- */
[data-theme="hc"] {
  --bg: #000000;
  --bg-elev: #000000;
  --surface-2: #121212;
  --line: #ffffff;
  --line-strong: #ffffff;
  --text: #ffffff;
  --text-2: #ffffff;
  --text-3: #ececec;
  --accent: #ffd400;
  --accent-text: #ffd400;
  --pill-bg: #ffd400;
  --pill-ink: #000000;
  --focus: #00e5ff;
  --overlay: rgb(0 0 0 / .85);
  --topbar-bg: #000000;
  --mark-bg: #ffd400;
  --mark-ink: #000000;
  --border-w: 2px;
  --focus-w: 4px;
  --shadow: none;
  --danger: #ff9b9b; --warn: #ffd400; --info: #9cc8ff; --ok: #8cffb5;
  --tint: 0%;
}
[data-theme="hc"][data-cvd="rg"] { --danger: #ffb066; --warn: #fff04d; --info: #d9c2ff; --ok: #8fd3ff; }
[data-theme="hc"][data-cvd="by"] { --danger: #ff9bb0; --warn: #ffc28f; --info: #7ff3ff; --ok: #ffffff; }

/* ---------- Font size (reader preference) ---------- */
html { font-size: 100%; }
html[data-fs="sm"] { font-size: 93.75%; }
html[data-fs="lg"] { font-size: 112.5%; }
html[data-fs="xl"] { font-size: 125%; }
html[data-fs="xxl"] { font-size: 140%; }
[data-theme="light"]{--bg:#f5f5f7;--surface-2:#f0f1f5;--line:#e2e4e9;--line-strong:#858b97;--text:#1d1d1f;--text-2:#474c56;--text-3:#626874;--accent:#0064d9;--accent-text:#0064d9;--pill-bg:#0064d9;--pill-ink:#fff;--topbar-bg:rgb(250 250 252 / .88);--focus:#005ecb;--shadow:0 20px 80px rgb(20 30 50 / .12)}
[data-theme="dark"]{--bg:#101113;--bg-elev:#1c1d20;--surface-2:#282a2f;--line:#34363d;--text:#f5f5f7;--text-2:#c6c8d0;--text-3:#a1a7b3;--accent:#9bc8ff;--accent-text:#9bc8ff;--pill-bg:#9bc8ff;--pill-ink:#101a29;--topbar-bg:rgb(20 21 24 / .9);--ios-blue:#9bc8ff;--ios-blue-tint:#222e40;--ios-shadow:0 8px 30px rgb(0 0 0 / .08)}
