/* ============================================================
   CookieRun Classic Wiki — design system
   Warm bakery chrome; grade-colored accents; light + dark.
   ============================================================ */

/* Fredoka (OFL) — self-hosted rounded display face; display slots only */
@font-face {
  font-family: "Fredoka";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("fonts/fredoka-latin.woff2") format("woff2");
}

:root {
  color-scheme: light;

  /* surfaces */
  --page: #faf5ec;
  --surface: #fffdf8;
  --surface-2: #f6efe2;
  --surface-3: #efe6d4;
  --header-bg: rgba(255, 253, 248, 0.92);

  /* ink (muted still clears 4.5:1 on page & cards) */
  --ink: #33241a;
  --ink-2: #6b5847;
  /* clears 4.5:1 on every light surface incl. surface-2 (rel-card hover) */
  --ink-3: #73614f;
  --hairline: #e7dcc9;
  --hairline-2: #d9cbb2;

  /* brand — --brand is decorative/large-text only; text-bearing states use
     --brand-strong (white text 5.25:1) / --brand-2 (5.2:1 on brand-soft) */
  --brand: #e0731f;
  --brand-display: #da6a12;
  --brand-strong: #ab5407;
  --brand-2: #a04607;
  --brand-ink: #ffffff;
  --brand-soft: #fbe8d4;
  --link: #a34a0d;
  --link-hover: #8a3e0a;

  /* warm cocoa heading ink on the cream surfaces */
  --cocoa: #4b3320;
  /* decorative "toasted crust" rule (non-text) */
  --crust: #c9b593;
  /* candy money button — the coffee CTA only, never nav/filter states */
  --candy-bg: #ef8127;
  --candy-ink: #2a1708;
  --candy-edge: #b35a10;
  /* single site-wide :focus-visible ring */
  --focus: #c1560a;

  /* grade colors (badges carry a letter label too — never color alone) */
  /* grade colors — every light step ≥4.5:1 with white badge text */
  --grade-c: #7c7368;
  --grade-b: #418234;
  --grade-a: #2f73c9;
  --grade-s: #8e55d8;
  --grade-ss: #0d7d89;
  --grade-l: #966b10;
  --grade-e: #d43954;
  --grade-x: #7e7466;

  /* status */
  --good: #0ca30c;
  --warn: #c98500;
  --bad: #d03b3b;

  /* dataviz (validated reference palette, light mode) */
  --viz-surface: #fcfcfb;
  --series-1: #2a78d6;
  /* ordinal grade ramp (validated: monotone L, single hue) C -> S */
  --viz-ord-c: #e89546;
  --viz-ord-b: #d06413;
  --viz-ord-a: #a34a0d;
  --viz-ord-s: #6f3406;
  --viz-ord-c-ink: #2a1708;
  --viz-ord-b-ink: #2a1708;
  --viz-ord-a-ink: #ffffff;
  --viz-ord-s-ink: #ffffff;
  --series-2: #008300;
  --series-3: #e87ba4;
  --series-4: #eda100;
  --series-5: #1baf7a;
  --series-6: #eb6834;
  --series-7: #4a3aa7;
  --series-8: #e34948;
  --viz-grid: #e1e0d9;
  --viz-axis: #c3c2b7;
  --viz-ink: #0b0b0b;
  --viz-ink-2: #52514e;
  --viz-muted: #6c6a63;

  --header-h: 64px;
  --radius: 14px;
  --radius-sm: 9px;
  /* the inset top highlight is the "sugar glaze" on cards/tables */
  --shadow: 0 1px 2px rgba(59, 42, 30, 0.06), 0 4px 14px rgba(59, 42, 30, 0.07), inset 0 1px 0 rgba(255, 255, 255, 0.65);
  --shadow-lift: 0 2px 4px rgba(59, 42, 30, 0.09), 0 10px 28px rgba(59, 42, 30, 0.13);

  --sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --display: "Fredoka", "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Code", Consolas, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #17110d;
    --surface: #211913;
    --surface-2: #2a2018;
    --surface-3: #33271d;
    --header-bg: rgba(26, 19, 14, 0.92);
    --ink: #f3e9da;
    --ink-2: #c4b09b;
    --ink-3: #9c8a75;
    --hairline: #372b20;
    --hairline-2: #46372a;
    --brand: #f08a3c;
    --brand-display: #f08a3c;
    --brand-strong: #f08a3c;
    --brand-2: #f49c58;
    --brand-ink: #2a1708;
    --brand-soft: #3a2410;
    --link: #f0a05c;
    --link-hover: #f7b87e;
    --cocoa: #ecd9bd;
    --crust: #52402e;
    --candy-bg: #f08a3c;
    --candy-ink: #2a1708;
    --candy-edge: #c2660f;
    --focus: #f08a3c;
    --grade-c: #948a7d;
    --grade-b: #5cae4c;
    --grade-a: #5b94e0;
    --grade-s: #a674ec;
    --grade-ss: #35b5c2;
    --grade-l: #ecb43b;
    --grade-e: #ea6c84;
    --grade-x: #8f8676;
    --good: #0ca30c;
    --warn: #fab219;
    --bad: #e66767;
    --viz-surface: #1f1813;
    --series-1: #3987e5;
    --viz-ord-c: #8a4a10;
    --viz-ord-b: #b05408;
    --viz-ord-a: #e88433;
    --viz-ord-s: #f5ad74;
    --viz-ord-c-ink: #ffffff;
    --viz-ord-b-ink: #ffffff;
    --viz-ord-a-ink: #2a1708;
    --viz-ord-s-ink: #2a1708;
    --series-2: #008300;
    --series-3: #d55181;
    --series-4: #c98500;
    --series-5: #199e70;
    --series-6: #d95926;
    --series-7: #9085e9;
    --series-8: #e66767;
    --viz-grid: #2c2c2a;
    --viz-axis: #383835;
    --viz-ink: #ffffff;
    --viz-ink-2: #c3c2b7;
    --viz-muted: #898781;
    --shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-lift: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 2px 4px rgba(0, 0, 0, 0.5), 0 10px 28px rgba(0, 0, 0, 0.45);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #17110d;
  --surface: #211913;
  --surface-2: #2a2018;
  --surface-3: #33271d;
  --header-bg: rgba(26, 19, 14, 0.92);
  --ink: #f3e9da;
  --ink-2: #c4b09b;
  --ink-3: #9c8a75;
  --hairline: #372b20;
  --hairline-2: #46372a;
  --brand: #f08a3c;
  --brand-display: #f08a3c;
  --brand-strong: #f08a3c;
  --brand-2: #f49c58;
  --brand-ink: #2a1708;
  --brand-soft: #3a2410;
  --link: #f0a05c;
  --link-hover: #f7b87e;
  --cocoa: #ecd9bd;
  --crust: #52402e;
  --candy-bg: #f08a3c;
  --candy-ink: #2a1708;
  --candy-edge: #c2660f;
  --focus: #f08a3c;
  --grade-c: #948a7d;
  --grade-b: #5cae4c;
  --grade-a: #5b94e0;
  --grade-s: #a674ec;
  --grade-ss: #35b5c2;
  --grade-l: #ecb43b;
  --grade-e: #ea6c84;
  --grade-x: #8f8676;
  --good: #0ca30c;
  --warn: #fab219;
  --bad: #e66767;
  --viz-surface: #1f1813;
  --series-1: #3987e5;
  --viz-ord-c: #8a4a10;
  --viz-ord-b: #b05408;
  --viz-ord-a: #e88433;
  --viz-ord-s: #f5ad74;
  --viz-ord-c-ink: #ffffff;
  --viz-ord-b-ink: #ffffff;
  --viz-ord-a-ink: #2a1708;
  --viz-ord-s-ink: #2a1708;
  --series-2: #008300;
  --series-3: #d55181;
  --series-4: #c98500;
  --series-5: #199e70;
  --series-6: #d95926;
  --series-7: #9085e9;
  --series-8: #e66767;
  --viz-grid: #2c2c2a;
  --viz-axis: #383835;
  --viz-ink: #ffffff;
  --viz-ink-2: #c3c2b7;
  --viz-muted: #898781;
  --shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lift: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 2px 4px rgba(0, 0, 0, 0.5), 0 10px 28px rgba(0, 0, 0, 0.45);
}

/* ---------- reset / base ---------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  /* short pages: main stretches so the footer always sits at the bottom */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
img { max-width: 100%; image-rendering: auto; }
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 0.5em; font-weight: 800; letter-spacing: -0.01em; color: var(--cocoa); }
h1, h2 { font-family: var(--display); font-weight: 600; letter-spacing: 0; }
h1 { font-size: 2rem; }
h2 { font-size: 1.45rem; margin-top: 1.6em; }
h3 { font-size: 1.15rem; margin-top: 1.3em; }
p { margin: 0.5em 0 1em; }
code { font-family: var(--mono); font-size: 0.85em; background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 5px; }

/* one focus ring for the whole site */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
main.wrap { padding-top: 14px; padding-bottom: 70px; flex: 1 0 auto; width: 100%; }

/* ---------- skip link ---------- */
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--brand-strong); color: var(--brand-ink);
  padding: 10px 18px; border-radius: 0 0 10px 0; font-weight: 700;
}
.skip-link:focus { left: 0; text-decoration: none; }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--header-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hairline);
}
.site-header .wrap {
  display: flex; align-items: center; gap: 12px;
  min-height: 64px;
}
/* stacked brand lockup: "CookieRun" over small-caps "CLASSIC WIKI" */
.logo {
  display: flex; align-items: center; gap: 10px;
  white-space: nowrap;
}
.logo:hover { text-decoration: none; }
.logo:hover .logo-brand { color: var(--link); }
.logo img { width: 34px; height: 34px; flex: none; }
.logo-text { display: flex; flex-direction: column; min-width: 0; }
.logo-brand { color: var(--ink); font-family: var(--display); font-weight: 600; font-size: 1.06rem; line-height: 1.15; }
:lang(th) .logo-brand { line-height: 1.4; }
.logo-sub {
  font-weight: 800; font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.14em; line-height: 1.2;
}
.logo-edition { color: var(--brand-2); }
.logo-suffix { color: var(--ink-3); }
/* desktop: one inline row, never wrapped — if it can't fit, JS collapses it
   into the hamburger dropdown (.nav-collapsed) instead of wrapping */
.nav-links { display: flex; flex-wrap: nowrap; gap: 1px; margin-left: 4px; min-width: 0; }
.nav-links a {
  padding: 5px 8px; border-radius: 99px; color: var(--ink-2);
  font-size: 0.85rem; font-weight: 600; white-space: nowrap;
}
.nav-links a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav-links a.active { background: var(--brand-soft); color: var(--brand-2); }
.header-spacer { flex: 1; }

/* search */
.searchbox { position: relative; width: 220px; flex: none; }
.searchbox input {
  width: 100%; padding: 8px 13px 8px 34px;
  border: 1px solid var(--hairline-2); border-radius: 99px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: 0.9rem;
}
.searchbox input:focus { outline: 2px solid var(--focus); outline-offset: -1px; }
.searchbox .search-ico {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--ink-3); pointer-events: none;
}
.search-results {
  position: absolute; top: calc(100% + 8px); right: 0; width: 340px; max-width: 84vw;
  max-height: 60vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); box-shadow: var(--shadow-lift);
  display: none;
}
.search-results.open { display: block; }
.search-results a {
  display: flex; align-items: center; gap: 11px; padding: 8px 13px;
  color: var(--ink); border-bottom: 1px solid var(--hairline);
}
.search-results a:last-child { border-bottom: 0; }
.search-results a:hover, .search-results a.sel { background: var(--surface-2); text-decoration: none; }
.search-results img { width: 32px; height: 32px; object-fit: contain; flex: none; }
.search-results .s-type { margin-left: auto; font-size: 0.78rem; color: var(--ink-3); text-transform: capitalize; flex: none; }
.search-results a:hover .s-type, .search-results a.sel .s-type { color: var(--ink-2); }
.search-results .s-empty { padding: 14px; color: var(--ink-3); font-size: 0.9rem; }

.theme-toggle {
  border: 1px solid var(--hairline-2); background: var(--surface);
  color: var(--ink-2); border-radius: 99px; width: 40px; height: 40px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 1rem; flex: none;
}
.theme-toggle:hover { background: var(--surface-2); }

/* hamburger nav toggle — desktop shows the nav inline, so it's hidden there;
   the media query turns it on for phones */
.nav-toggle {
  display: none; flex: none; width: 44px; height: 44px; cursor: pointer;
  align-items: center; justify-content: center;
  border: 1px solid var(--hairline-2); background: var(--surface); border-radius: 10px;
}
.nav-toggle span { position: relative; display: block; width: 20px; height: 2px;
  border-radius: 2px; background: var(--ink-2); transition: background 0.15s; }
.nav-toggle span::before, .nav-toggle span::after {
  content: ""; position: absolute; left: 0; width: 20px; height: 2px;
  border-radius: 2px; background: var(--ink-2); transition: transform 0.15s, top 0.15s;
}
.nav-toggle span::before { top: -6px; }
.nav-toggle span::after { top: 6px; }
.nav-toggle[aria-expanded="true"] span { background: transparent; }
.nav-toggle[aria-expanded="true"] span::before { top: 0; transform: rotate(45deg); }
.nav-toggle[aria-expanded="true"] span::after { top: 0; transform: rotate(-45deg); }

/* desktop priority+ overflow menu: JS moves ONLY the topics that don't fit
   into this "More" dropdown, keeping the rest inline (the nav never wraps) */
.nav-more { position: relative; display: flex; align-items: center; }
.nav-more[hidden] { display: none; }
.nav-more-btn {
  border: 0; background: transparent; cursor: pointer; font: inherit;
  color: var(--ink-2); font-size: 0.85rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 10px; border-radius: 8px;
}
.nav-more-btn:hover { background: var(--surface-2); color: var(--ink); }
/* the active pill hops onto the More button when JS tucks the current
   section's link into the overflow menu */
.nav-more-btn.has-active { background: var(--brand-soft); color: var(--brand-2); }
.nav-more-caret { font-size: 0.9em; }
.nav-more-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 60;
  flex-direction: column; gap: 2px; min-width: 190px;
  background: var(--surface); border: 1px solid var(--hairline-2);
  border-radius: 12px; box-shadow: var(--shadow-lift); padding: 8px; display: none;
}
.nav-more.open .nav-more-menu { display: flex; }
.nav-more-menu a { width: 100%; min-height: 42px; display: flex; align-items: center; padding: 7px 12px; border-radius: 8px; }

/* collapsed nav (mobile hamburger): the whole nav becomes a dropdown panel */
.site-header:not(.nav-collapsed) .nav-links { flex-shrink: 0; }
.site-header.nav-collapsed .nav-toggle { display: inline-flex; }
.site-header.nav-collapsed .nav-links {
  position: absolute; top: calc(100% + 1px); right: 8px; z-index: 60;
  flex-direction: column; gap: 2px; margin: 0;
  min-width: 210px; max-width: calc(100vw - 16px);
  background: var(--surface); border: 1px solid var(--hairline-2);
  border-radius: 12px; box-shadow: var(--shadow-lift); padding: 8px;
  max-height: 72vh; overflow-y: auto; display: none;
}
.site-header.nav-collapsed .nav-links.open { display: flex; }
.site-header.nav-collapsed .nav-links a {
  width: 100%; min-height: 44px; display: flex; align-items: center;
  padding: 8px 14px; border-radius: 8px;
}

/* language switcher (EN ⇄ ไทย) */
.lang-toggle {
  display: inline-flex; align-items: center; gap: 2px; flex: none;
  border: 1px solid var(--hairline-2); border-radius: 99px; padding: 2px;
  background: var(--surface); font-size: 0.82rem; font-weight: 700;
}
.lang-toggle .lang-cur, .lang-toggle a {
  display: inline-flex; align-items: center; min-height: 40px;
  padding: 0 12px; border-radius: 99px; line-height: 1; text-decoration: none;
}
.lang-toggle .lang-cur { background: var(--brand-strong); color: var(--brand-ink); }
.lang-toggle a { color: var(--ink-3); }
.lang-toggle a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }

/* ---------- breadcrumbs ---------- */
.crumbs { font-size: 0.85rem; color: var(--ink-3); margin-bottom: 8px; }
/* padding+negative-margin gives a ~41px tap target without shifting layout */
.crumbs a { color: var(--ink-2); display: inline-block; padding: 10px 6px; margin: -10px -2px; }
.crumbs .sep { margin: 0 9px; color: var(--crust); }
.crumbs span[aria-current="page"] { color: var(--ink-2); font-weight: 600; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.8rem; font-weight: 700; letter-spacing: 0.04em;
  padding: 2px 9px; border-radius: 99px;
  background: var(--surface-2); color: var(--ink-2);
  white-space: nowrap; vertical-align: middle;
}
.badge.grade { color: #fff; }
.badge.grade-C, .badge.grade-c { background: var(--grade-c); }
.badge.grade-B, .badge.grade-b { background: var(--grade-b); }
.badge.grade-A, .badge.grade-a { background: var(--grade-a); }
.badge.grade-S, .badge.grade-s { background: var(--grade-s); }
.badge.grade-SS, .badge.grade-ss { background: var(--grade-ss); }
.badge.grade-L, .badge.grade-l { background: var(--grade-l); }
.badge.grade-E, .badge.grade-e { background: var(--grade-e); }
.badge.grade-unk { background: var(--grade-x); }
:root[data-theme="dark"] .badge.grade,
:root:not([data-theme="light"]) .badge.grade { color: #17110d; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .badge.grade { color: #fff; }
}
.badge.soft { background: var(--brand-soft); color: var(--brand-2); }
.badge.outline { background: transparent; border: 1px solid var(--hairline-2); }

/* ---------- cards & galleries ---------- */
.card-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  margin: 18px 0;
}
.card-grid.wide { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.ecard {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 14px 10px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  text-align: center; color: var(--ink);
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  position: relative; overflow: hidden;
}
.ecard::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--accent, var(--hairline-2));
}
.ecard:hover { transform: translateY(-3px); box-shadow: var(--shadow-lift); text-decoration: none; }
.ecard .icon-frame {
  width: 84px; height: 84px; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 62%, color-mix(in srgb, var(--accent, var(--hairline)) 22%, transparent), transparent 72%),
    var(--surface-2);
  border-radius: 12px;
}
.ecard img { max-width: 72px; max-height: 72px; object-fit: contain; }
.ecard .e-name { font-weight: 700; font-size: 0.92rem; line-height: 1.25; }
.ecard .e-sub {
  font-size: 0.76rem; color: var(--ink-3); margin-top: -4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
/* grid rows stretch cards to equal height — pin the grade badge to the card
   bottom so badges align across a row even when names wrap to extra lines */
.ecard .badge.grade { margin-top: auto; }
.no-icon {
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-3); font-size: 1.5rem; font-weight: 800;
  width: 72px; height: 72px; border-radius: 10px;
  border: 2px dashed var(--hairline-2);
}
.no-icon.small { width: 32px; height: 32px; font-size: 0.85rem; border-radius: 7px; border-width: 1.5px; }

/* filter bar above galleries */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: 9px; align-items: center;
  padding: 12px 0 4px;
  position: relative;
}
.filter-bar input[type="search"] {
  padding: 7px 13px; border: 1px solid var(--hairline-2); border-radius: 99px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: 0.9rem; width: 220px;
}
/* multi-select dropdowns: native <details> + checkboxes — reliable on Android
   touch (custom tap-chips misbehaved there; a <select> lost multi-pick) */
.filter-bar .f-dd { position: relative; }
.filter-bar .f-dd summary {
  list-style: none; display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--hairline-2); border-radius: 99px; padding: 8px 15px;
  background: var(--surface); color: var(--ink-2); font-size: 0.9rem; font-weight: 700;
  cursor: pointer; user-select: none; -webkit-user-select: none;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s, transform 0.15s, background 0.15s, color 0.15s;
}
.filter-bar .f-dd summary::-webkit-details-marker { display: none; }
.filter-bar .f-dd summary:hover { box-shadow: var(--shadow-lift); transform: translateY(-1px); }
.filter-bar .f-dd[open] summary {
  background: var(--brand-soft); border-color: var(--brand-soft); color: var(--brand-2);
  transform: none;
}
.filter-bar .f-dd.has-sel summary {
  background: var(--brand-strong); border-color: var(--brand-strong); color: var(--brand-ink);
}
.filter-bar .f-caret { font-size: 0.9em; opacity: 0.9; transition: transform 0.15s; }
.filter-bar .f-dd[open] .f-caret { transform: rotate(180deg); }
.filter-bar .f-menu {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 30;
  min-width: 200px; max-height: 330px; overflow: auto;
  background: var(--surface); border: 1px solid var(--hairline-2);
  border-radius: 14px; box-shadow: var(--shadow-lift); padding: 8px;
  animation: f-menu-in 0.12s ease-out;
}
@keyframes f-menu-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}
.filter-bar .f-menu label {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-radius: 9px; font-size: 0.9rem; color: var(--ink); cursor: pointer;
  white-space: nowrap;
}
.filter-bar .f-menu label:hover { background: var(--surface-2); }
.filter-bar .f-menu input[type="checkbox"] {
  accent-color: var(--brand-strong); width: 17px; height: 17px; margin: 0; flex: none;
}
/* one filter button holding every group */
.filter-bar .f-ico { width: 15px; height: 15px; flex: none; }
.filter-bar .f-all summary { padding-left: 13px; }
.filter-bar .f-group-h {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.07em;
  font-weight: 800; color: var(--ink-3); padding: 3px 12px 4px;
}
.filter-bar .f-group + .f-group {
  margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--hairline);
}
.filter-bar .f-clear {
  display: block; width: 100%; margin-top: 4px; padding: 11px 12px; min-height: 44px;
  border: 0; border-top: 1px solid var(--hairline); border-radius: 0 0 9px 9px;
  background: none; color: var(--link); font: inherit; font-size: 0.85rem;
  font-weight: 600; text-align: left; cursor: pointer;
}
.filter-bar .f-clear:hover { background: var(--surface-2); color: var(--link-hover); }
.filter-bar .count { margin-left: auto; font-size: 0.83rem; color: var(--ink-3); }

/* ---------- page head (listing/topic pages) ---------- */
.page-head { margin: 0 0 16px; }
.page-head h1 { font-size: 2.05rem; margin-bottom: 5px; }
.page-head h1::after {
  content: ""; display: block; width: 52px; height: 4px; margin-top: 7px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--brand), var(--grade-l));
}
.page-head .muted { max-width: 76ch; }

/* ---------- hero (entity page header) ---------- */
.hero {
  display: flex; gap: 28px; align-items: center;
  background:
    radial-gradient(120% 160% at 12% 20%, color-mix(in srgb, color-mix(in srgb, var(--accent, var(--brand)) 60%, var(--brand)) 16%, transparent), transparent 55%),
    radial-gradient(75% 140% at 92% 12%, color-mix(in srgb, color-mix(in srgb, var(--accent, var(--brand)) 60%, var(--brand)) 10%, transparent), transparent 60%),
    var(--surface);
  border: 1px solid var(--hairline); border-radius: 20px;
  padding: 18px 26px; margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.hero .hero-icon {
  width: 132px; height: 132px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 65%, color-mix(in srgb, var(--accent, var(--brand)) 30%, transparent), transparent 75%),
    var(--surface-2);
  border: 3px solid var(--accent, var(--hairline-2));
  border-radius: 22px;
}
.hero .hero-icon img { max-width: 106px; max-height: 106px; object-fit: contain; }
.hero .hero-icon .no-icon { width: 100px; height: 100px; font-size: 2rem; border: 0; }
.hero h1 { margin-bottom: 6px; font-size: clamp(2.1rem, 1.6rem + 1.2vw, 2.6rem); }
.hero .hero-kicker { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 4px; }
.hero .hero-badges { display: flex; flex-wrap: wrap; gap: 7px; margin: 8px 0 4px; }
.hero .hero-desc { color: var(--ink-2); max-width: 62ch; margin: 8px 0 0; }
.hero .hero-desc em { color: var(--ink); font-style: normal; font-weight: 600; }

/* cover variant: episode artwork strip on top, text on the solid card below —
   text never sits on the image, so contrast guarantees are untouched */
.hero.has-cover { flex-direction: column; align-items: stretch; gap: 0; padding: 0; overflow: hidden; }
.hero-cover {
  height: clamp(150px, 24vw, 230px);
  background-size: cover; background-position: center 30%;
  position: relative;
}
.hero-cover::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to bottom,
    rgba(20, 12, 5, 0.18), transparent 28%, transparent 80%, var(--surface));
}
.hero.has-cover .hero-body {
  display: flex; gap: 24px; align-items: center;
  padding: 0 28px 24px; position: relative;
}
.hero.has-cover .hero-icon { margin-top: -52px; background: var(--surface-2); box-shadow: var(--shadow); }
.hero.has-cover .hero-body > div:last-child { padding-top: 16px; }

/* episodes gallery: wide emblem art gets a media-card treatment */
[id^="ep-grid"] .ecard .icon-frame { width: 100%; height: 104px; border-radius: 10px; }
[id^="ep-grid"] .ecard .icon-frame img { max-width: 180px; max-height: 92px; }

/* ---------- stage chip grid ---------- */
.stage-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 8px 12px; margin: 14px 0 22px;
}
.stage-chip {
  display: flex; align-items: center; gap: 9px; padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: 10px; font-size: 0.9rem; box-shadow: var(--shadow);
}
.stage-chip .n {
  flex: none; min-width: 24px; height: 24px; border-radius: 99px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 800;
  background: var(--brand-soft); color: var(--brand-2); padding: 0 4px;
}

/* ---------- info tables ---------- */
.tbl-wrap.narrow { max-width: min(720px, 100%); }
.tbl-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 22px; align-items: start; }
.tbl-cols .tbl-wrap { max-width: none; }
@media (max-width: 900px) { .tbl-cols { grid-template-columns: 1fr; } }
.tbl-wrap.slim { max-width: min(620px, 100%); }
/* the wrap is only a horizontal scroller on narrow screens — on desktop it
   stays overflow-visible so sticky column headers actually stick (a sticky
   th inside an overflow ancestor scrolls away with the page) */
.tbl-wrap { border: 1px solid var(--hairline); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); margin: 14px 0 22px; }
@media (max-width: 900px) {
  .tbl-wrap:not(.narrow):not(.slim) {
    overflow-x: auto;
    /* scroll cue: edge shadows that fade as you reach either end */
    background:
      linear-gradient(to right, var(--surface) 30%, transparent),
      linear-gradient(to left, var(--surface) 30%, transparent) 100% 0,
      radial-gradient(farthest-side at 0 50%, rgba(59, 42, 30, 0.22), transparent),
      radial-gradient(farthest-side at 100% 50%, rgba(59, 42, 30, 0.22), transparent) 100% 0;
    background-color: var(--surface);
    background-repeat: no-repeat;
    background-size: 46px 100%, 46px 100%, 16px 100%, 16px 100%;
    background-attachment: local, local, scroll, scroll;
  }
}
table.tbl { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
table.tbl th, table.tbl td { padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--hairline); }
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl th {
  background: var(--surface-3); color: var(--cocoa);
  border-bottom: 1px solid var(--hairline-2);
  font-size: 0.78rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  position: sticky; top: var(--header-h); z-index: 2;
}
@media (max-width: 900px) { .tbl-wrap:not(.narrow):not(.slim) table.tbl th { position: static; } }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl tr:hover td { background: color-mix(in srgb, var(--brand-soft) 40%, transparent); }
table.tbl .cell-ent { display: flex; align-items: center; gap: 9px; }
table.tbl .cell-ent img { width: 30px; height: 30px; object-fit: contain; flex: none; }
table.tbl .dim { color: var(--ink-3); }

/* key-value infobox */
.kv {
  width: fit-content; min-width: min(460px, 100%); max-width: 100%;
  display: grid; grid-template-columns: max-content 1fr; gap: 0;
  border: 1px solid var(--hairline); border-radius: var(--radius);
  background: var(--surface); overflow: hidden; box-shadow: var(--shadow);
  margin: 14px 0 22px; font-size: 0.93rem;
}
.kv > div { padding: 8px 14px; border-bottom: 1px solid var(--hairline); }
.kv > div:nth-last-child(-n+2) { border-bottom: 0; }
.kv .k { background: var(--surface-2); color: var(--cocoa); font-weight: 700; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
.kv .v { font-variant-numeric: tabular-nums; }
/* Combi bonus magnitude (the game's own "+5 HP" text) beside a partner link */
.combi-mag {
  display: inline-block; font-size: 0.82em; font-weight: 700;
  color: var(--brand-2); background: var(--brand-soft);
  border-radius: 99px; padding: 1px 8px; white-space: nowrap;
}

/* ---------- sections / callouts ---------- */
.section-head { display: flex; align-items: baseline; gap: 12px; border-bottom: 3px double var(--crust); padding-bottom: 9px; margin-top: 2em; }
.section-head h2 { margin: 0; position: relative; padding-left: 15px; }
.section-head h2::before {
  content: ""; position: absolute; left: 0; top: 0.14em; bottom: 0.14em;
  width: 5px; border-radius: 99px; background: var(--brand-display);
}
.section-head .more { margin-left: auto; font-size: 0.87rem; white-space: nowrap; }

/* foldable subtopics: every section can collapse; heavy table sections on
   long pages start closed so the end of the page is reachable */
details.fold > summary { list-style: none; cursor: pointer; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary:hover h2 { color: var(--brand-2); }
.fold-caret {
  margin-left: auto; align-self: center; flex: none;
  color: var(--ink-2); font-size: 1.2rem; line-height: 1; transition: transform 0.15s;
}
.section-head .more + .fold-caret,
.section-head .more ~ .fold-caret { margin-left: 0; }
details.fold[open] > summary .fold-caret { transform: rotate(180deg); }
details.fold:not([open]) > summary .section-head { margin-bottom: 14px; }
.callout {
  font-size: 0.86rem; line-height: 1.5; max-width: 96ch;
  border-left: 4px solid var(--warn); background: var(--surface-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 10px 16px; margin: 14px 0; font-size: 0.9rem; color: var(--ink-2);
}
.callout.info { border-left-color: var(--grade-a); }
.callout b { color: var(--ink); }

/* related-entity strip */
.rel-strip { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0 20px; }
.rel-card {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius-sm);
  padding: 8px 14px 8px 9px; color: var(--ink); font-size: 0.9rem; font-weight: 600;
  box-shadow: var(--shadow);
}
.rel-card:hover { background: var(--surface-2); text-decoration: none; transform: translateY(-2px); }
.rel-card img { width: 36px; height: 36px; object-fit: contain; }
.rel-card .rc-sub { display: block; font-size: 0.78rem; color: var(--ink-3); font-weight: 500; }

/* ---------- landing ---------- */
.landing-hero {
  text-align: center; padding: 28px 20px 24px;
  background: radial-gradient(55% 75% at 50% 6%,
    color-mix(in srgb, var(--brand) 10%, transparent), transparent 78%);
  border-radius: 0 0 32px 32px;
}
.landing-hero h1 { font-size: clamp(2rem, 5.5vw, 3.1rem); }
.landing-hero h1 .accent { color: var(--brand-display); }
.landing-hero p { color: var(--ink-2); max-width: 60ch; margin: 10px auto 0; font-size: 1.05rem; }
/* toasted-crust ornament closing the hero */
.landing-hero::after {
  content: ""; display: block; width: 180px; margin: 20px auto 0;
  border-top: 3px double var(--crust);
}
.landing-strip {
  display: flex; justify-content: center; flex-wrap: wrap; margin: 26px 0 8px; padding: 0 8px;
}
.landing-strip a { margin: 0 -4px; position: relative; }
.landing-strip a:hover { z-index: 2; }
.landing-strip a:nth-child(even) { transform: translateY(7px); }
.landing-strip img {
  width: 62px; height: 62px; object-fit: contain; transition: transform .15s ease;
  filter: drop-shadow(0 4px 6px rgba(59, 42, 30, 0.18));
}
.landing-strip img:hover { transform: translateY(-4px) scale(1.14); }
.cat-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin: 28px 0; }
.cat-card {
  display: flex; flex-direction: column; gap: 7px;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius);
  padding: 22px 20px 18px; color: var(--ink); box-shadow: var(--shadow);
  position: relative; overflow: hidden;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.cat-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--brand), var(--grade-l));
  opacity: 0; transition: opacity 0.12s ease;
}
.cat-card:hover::before { opacity: 1; }
/* cards with a corner icon reserve its gutter so text never runs under it */
.cat-card:has(.cat-ico) { padding-right: 94px; }
.cat-card .cat-ico {
  position: absolute; right: 14px; top: 16px; width: 64px; height: 64px;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 62%, color-mix(in srgb, var(--brand) 16%, transparent), transparent 72%),
    var(--surface-2);
  border-radius: 14px;
}
.cat-card .cat-ico img { max-width: 52px; max-height: 52px; object-fit: contain; }
.cat-card:hover { text-decoration: none; transform: translateY(-3px); box-shadow: var(--shadow-lift); }
.cat-card .cat-name { font-family: var(--display); font-weight: 600; font-size: 1.25rem; order: 1; color: var(--cocoa); }
.cat-card .cat-count {
  order: 2; width: max-content; font-size: 0.8rem; font-weight: 700; line-height: 1.4;
  color: var(--brand-2); background: var(--brand-soft);
  border-radius: 99px; padding: 2px 10px;
}
.cat-card .cat-desc { order: 3; font-size: 0.85rem; color: var(--ink-2); max-width: 32ch; }
/* small inline icon inside section headings (gacha pool eggs/tickets) */
.section-head h2 img.h-ico {
  width: 28px; height: 28px; object-fit: contain;
  vertical-align: -6px; margin-right: 7px;
}

/* visually hidden, exposed to assistive tech (chart data tables) */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- charts (inline SVG) ---------- */
.viz {
  background:
    linear-gradient(to right, var(--viz-surface) 30%, transparent),
    linear-gradient(to left, var(--viz-surface) 30%, transparent) 100% 0,
    radial-gradient(farthest-side at 0 50%, rgba(59, 42, 30, 0.20), transparent),
    radial-gradient(farthest-side at 100% 50%, rgba(59, 42, 30, 0.20), transparent) 100% 0;
  background-color: var(--viz-surface);
  background-repeat: no-repeat;
  background-size: 46px 100%, 46px 100%, 16px 100%, 16px 100%;
  background-attachment: local, local, scroll, scroll;
  border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 18px; margin: 16px 0 24px;
  box-shadow: var(--shadow); overflow-x: auto;
}
.viz .viz-title { font-weight: 700; font-size: 0.98rem; color: var(--ink); margin-bottom: 2px; }
.viz .viz-sub { font-size: 0.8rem; color: var(--ink-3); margin-bottom: 12px; }
.viz svg { display: block; width: 100%; min-width: 560px; height: auto; }
.viz svg text { font-family: var(--sans); }
.viz .axis-label { fill: var(--viz-muted); font-size: 12px; }
.viz .bar-label { fill: var(--viz-ink); font-size: 12.5px; font-weight: 600; }
.viz .val-label { fill: var(--viz-ink-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.viz .gridline { stroke: var(--viz-grid); stroke-width: 1; }
.viz .baseline { stroke: var(--viz-axis); stroke-width: 1; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 6px; border-bottom: 2px solid var(--hairline); margin: 16px 0 0; flex-wrap: wrap; }
.tabs button {
  border: 0; background: transparent; font: inherit; font-weight: 600; font-size: 0.9rem;
  color: var(--ink-2); padding: 11px 16px; cursor: pointer;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0; margin-bottom: -2px;
  border-bottom: 2px solid transparent;
}
.tabs button:hover { background: var(--surface-2); }
.tabpanel { padding-top: 18px; }
.tabs button.on { color: var(--brand-2); border-bottom-color: var(--brand); }
.tabpanel { display: none; }
.tabpanel.on { display: block; }
.tabpanel[hidden] { display: none !important; }

/* ---------- footer: warm cream band with a scalloped doily edge ---------- */
.site-footer {
  position: relative; margin-top: 34px;
  background: var(--surface-2); color: var(--ink-3);
  font-size: 0.85rem;
}
/* upward scallop opening the band (footer only — never on the sticky
   header). Integer-px tile so it can't seam at DPI scaling. */
.site-footer::before {
  content: ""; position: absolute; bottom: 100%; left: 0; right: 0; height: 8px;
  pointer-events: none;
  background: radial-gradient(circle at 11px 13px, var(--surface-2) 11px, transparent 11.5px) left top / 22px 8px repeat-x;
}
.site-footer .f-grid {
  display: grid; grid-template-columns: 1fr auto; align-items: center;
  gap: 10px 32px; padding-top: 18px; padding-bottom: 9px;
}
.site-footer .f-brand-col { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; }
.site-footer .f-brand-row { display: flex; gap: 10px; align-items: center; }
.site-footer .f-logo {
  border-radius: 8px; flex-shrink: 0; background: var(--surface);
  border: 1px solid var(--hairline); padding: 2px;
}
.site-footer .f-brand {
  font-family: var(--display); font-weight: 600; font-size: 1rem; color: var(--ink);
}
.site-footer .f-desc { margin: 0; max-width: 72ch; line-height: 1.5; }
.site-footer .f-actions { display: inline-flex; align-items: center; gap: 20px; justify-self: end; }
.site-footer .f-actions .f-about { color: var(--ink-2); font-weight: 600; white-space: nowrap; }
.site-footer .f-actions .f-about:hover { color: var(--brand-2); text-decoration: none; }
.site-footer .f-legal {
  grid-column: 1 / -1; border-top: 1px solid var(--hairline);
  padding-top: 8px; font-size: 0.75rem; color: var(--ink-3);
}

/* ---------- support page: left-aligned, generous prose width ---------- */
.support-page { max-width: 860px; }
.support-page > p { margin: 0.95em 0; }
.s-covers {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 8px 20px; margin: 18px 0;
  box-shadow: var(--shadow);
}
.s-covers ul { list-style: none; margin: 0; padding: 0; }
.s-covers li { display: flex; gap: 13px; align-items: center; padding: 9px 0; }
.s-covers li + li { border-top: 1px solid var(--hairline); }
.s-covers li > span:first-child { flex: none; font-size: 1.2rem; line-height: 1; }
.s-cta { text-align: center; margin: 26px 0; }
.s-cta .candy-btn { font-size: 1rem; padding: 12px 26px; }

/* candy money button — the site's ONE glossy button (coffee CTA only) */
.candy-btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--candy-bg); color: var(--candy-ink);
  font-weight: 700; font-size: 0.88rem; border-radius: 99px; padding: 9px 16px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.28), 0 3px 0 var(--candy-edge);
  white-space: nowrap; border: 0;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.candy-btn:hover { color: var(--candy-ink); text-decoration: none; transform: translateY(-1px); }
.candy-btn:active { transform: translateY(1px); box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.28); }

@media (max-width: 760px) {
  .site-footer .f-grid { grid-template-columns: 1fr; gap: 12px; padding-top: 18px; padding-bottom: 12px; }
  .site-footer .f-actions { justify-self: start; }
}

/* reward cell: currency/item sprite beside the reward text */
.reward { display: inline-flex; align-items: center; gap: 7px; vertical-align: middle; }
.reward img { width: 24px; height: 24px; object-fit: contain; flex: none; }
.reward-row { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- quest list ---------- */
.quest-row td:first-child { min-width: 220px; }
.q-title { font-weight: 700; }
.q-desc { font-size: 0.83rem; color: var(--ink-2); }

/* ---------- misc ---------- */
.muted { color: var(--ink-3); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
hr.soft { border: 0; border-top: 1px solid var(--hairline); margin: 26px 0; }

/* ---------- responsive ---------- */
@media (max-width: 1150px) and (min-width: 761px) {
  /* tablet: one header row; the nav collapses into the hamburger (via JS
     .nav-collapsed) rather than wrapping onto its own line */
  .header-spacer { display: none; }
  .searchbox { margin-left: auto; }
}

@media (max-width: 760px) {
  /* compact STICKY header: it stays put on scroll, and the nav collapses into
     a hamburger dropdown so the sticky bar is only ~2 short rows tall */
  .site-header { position: sticky; top: 0; }
  .site-header .wrap {
    display: grid; height: auto;
    grid-template-columns: 1fr auto auto auto;
    grid-template-areas: "logo lang theme ham" "search search search search";
    padding-top: 7px; padding-bottom: 8px; row-gap: 7px; column-gap: 8px;
  }
  .logo { grid-area: logo; min-width: 0; overflow: hidden; align-self: center; }
  .nav-toggle { grid-area: ham; display: inline-flex; }
  .lang-toggle { grid-area: lang; align-self: center; }
  .lang-toggle .lang-cur, .lang-toggle a { min-height: 44px; }
  .theme-toggle { grid-area: theme; width: 44px; height: 44px; }
  .header-spacer { display: none; }
  .searchbox { grid-area: search; width: 100%; }
  .search-results { left: 0; right: 0; width: auto; max-width: none; }
  :root { --header-h: 0px; }
  /* phone: the whole nav is the hamburger dropdown, so the desktop "More"
     overflow menu is not used here */
  .nav-more { display: none; }
  /* the nav dropdown itself is styled by .nav-collapsed;
     JS always collapses at phone widths */
  .hero { flex-direction: column; text-align: center; padding: 22px 16px; }
  .hero .hero-badges { justify-content: center; }
  .hero .hero-desc { margin-left: auto; margin-right: auto; }
  .site-header { position: static; }
  table.tbl th, table.tbl td { padding: 8px 9px; overflow-wrap: anywhere; }
  .reward img { width: 20px; height: 20px; }
  .reward { gap: 5px; }
  .hero.has-cover { padding: 0; }
  .hero-cover { height: clamp(120px, 34vw, 180px); }
  .hero.has-cover .hero-body { flex-direction: column; align-items: center; padding: 0 16px 20px; }
  .hero.has-cover .hero-icon { margin-top: -58px; }
  .hero.has-cover .hero-body > div:last-child { padding-top: 4px; }
  .kv { grid-template-columns: 1fr; }
  .kv .k { border-bottom: 0; padding-bottom: 2px; }
  .kv > div:nth-last-child(-n+2) { border-bottom: 1px solid var(--hairline); }
  .kv > div:last-child { border-bottom: 0; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
}

@media print {
  .site-header, .site-footer, .filter-bar, .theme-toggle, .searchbox { display: none; }
}

/* dark theme: card borders one step stronger so containers keep definition
   (shadows alone vanish on the dark page) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tbl-wrap,
  :root:not([data-theme="light"]) .kv,
  :root:not([data-theme="light"]) .hero,
  :root:not([data-theme="light"]) .viz,
  :root:not([data-theme="light"]) .ecard,
  :root:not([data-theme="light"]) .cat-card { border-color: var(--hairline-2); }
}
:root[data-theme="dark"] .tbl-wrap,
:root[data-theme="dark"] .kv,
:root[data-theme="dark"] .hero,
:root[data-theme="dark"] .viz,
:root[data-theme="dark"] .ecard,
:root[data-theme="dark"] .cat-card { border-color: var(--hairline-2); }

/* respect reduced-motion: no smooth scroll, no hover motion */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* draw-composition bars: one 100% stacked bar per chest tier */
.comp-row { display: flex; align-items: center; gap: 12px; margin: 12px 0; }
.comp-row > img { width: 40px; height: 40px; object-fit: contain; flex: none; }
.comp-lbl { flex: none; width: 92px; font-weight: 700; }
.comp-track { display: flex; flex: 1; height: 34px; border-radius: 9px; overflow: hidden; }
.comp-seg {
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700; white-space: nowrap; min-width: 0;
}
.comp-seg + .comp-seg { margin-left: 2px; }
.comp-seg.seg-c { background: var(--viz-ord-c); color: var(--viz-ord-c-ink); }
.comp-seg.seg-b { background: var(--viz-ord-b); color: var(--viz-ord-b-ink); }
.comp-seg.seg-a { background: var(--viz-ord-a); color: var(--viz-ord-a-ink); }
.comp-seg.seg-s { background: var(--viz-ord-s); color: var(--viz-ord-s-ink); }
@media (max-width: 640px) {
  .comp-row { flex-wrap: wrap; }
  .comp-lbl { width: auto; }
  .comp-track { flex-basis: 100%; }
}

/* ============================================================
   Mobile / touch compatibility (audit fixes)
   ============================================================ */
/* [3] never let an overflowing child scroll the whole page; clip (not
   hidden/auto) so position:sticky keeps working elsewhere */
html, body { overflow-x: clip; }
/* [13] off-screen gallery cards skip layout & paint (1,131-card treasure grid) */
.ecard { content-visibility: auto; contain-intrinsic-size: 0 168px; }
/* [5] Thai has no intra-phrase spaces — allow a last-resort glyph break so a
   long run can't exceed the viewport (Latin text is unaffected: it only breaks
   when there is no other opportunity) */
:lang(th) :where(p, li, h1, h2, h3, .hero-desc, .cat-desc, .callout,
  .page-head .muted, .landing-hero p, .kv .v, .q-desc, .e-sub, .rc-sub, .comp-lbl) {
  overflow-wrap: anywhere;
}
/* [11] Thai stacks tone marks + vowels — headings need more leading than 1.2 */
:lang(th) h1, :lang(th) h2, :lang(th) h3, :lang(th) h4 { line-height: 1.4; }

@media (max-width: 760px) {
  /* [1] iOS Safari zooms the page when a focused input is < 16px (both were ~14px) */
  .searchbox input, .filter-bar input[type="search"] { font-size: 16px; }
  /* let the filter search share the bar instead of a fixed 220px */
  .filter-bar input[type="search"] { width: auto; flex: 1 1 150px; min-width: 0; }
  /* [2] anchor the dropdown menu to the trigger's right edge so it can't run
     off the right side of a 360px screen */
  .filter-bar .f-menu { left: auto; right: 0; max-width: calc(100vw - 24px); }
  /* [4] main nav: 44px tap targets with real spacing between wrapped pills */
  .nav-links { gap: 6px; }
  .nav-links a { min-height: 44px; display: inline-flex; align-items: center; padding: 8px 12px; }
  /* [8] table & KV links get a full-height hit box */
  table.tbl td a { display: inline-block; padding: 9px 2px; margin: -9px 0; }
  .kv .v a { display: inline-block; padding: 8px 0; }
  /* [20] narrow cards: allow 3 lines of effect text before truncating */
  .ecard .e-sub { -webkit-line-clamp: 3; }
}
@media (max-width: 640px) {
  /* [21] give thin composition segments a floor so their % label isn't clipped */
  .comp-seg { min-width: 2.6em; }
}
@media (max-width: 430px) {
  /* very narrow phones: slim the lang pills so the full lockup keeps room
     beside ham + lang + theme */
  .lang-toggle .lang-cur, .lang-toggle a { padding: 0 9px; }
}
