/* ==========================================================================
   Ergenverse — minimal, friendly, readable
   Light first (ink theme), dark optional (night theme). Thai type: Anuphan.
   ========================================================================== */

:root {
  --font: 'Anuphan', 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-zh: 'Noto Serif SC', 'Songti SC', 'SimSun', serif;

  --r-sm: 10px;
  --r: 14px;
  --r-lg: 20px;
  --r-pill: 999px;
  --wrap: 1160px;
  --header-h: 64px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --fast: 160ms;
  --mid: 240ms;
}

[data-theme='ink'] {
  --bg: #f7f7fb;
  --surface: #ffffff;
  --surface-2: #f1f1f7;
  --text: #14141f;
  --text-2: #3f3f55;
  --muted: #6b6b80;
  --line: #e7e7ef;
  --line-strong: #d4d4e1;
  --primary: #5b4bdb;
  --primary-600: #4a3bc5;
  --primary-50: #f1effd;
  --primary-100: #e3dffb;
  --on-primary: #ffffff;
  --accent: #f08a24;
  --danger: #e5484d;
  --shadow-sm: 0 1px 2px rgba(22, 20, 50, .05);
  --shadow: 0 1px 2px rgba(22, 20, 50, .04), 0 6px 20px rgba(22, 20, 50, .06);
  --shadow-lg: 0 2px 4px rgba(22, 20, 50, .05), 0 16px 40px rgba(22, 20, 50, .12);
  color-scheme: light;
}

[data-theme='night'] {
  --bg: #0e0e14;
  --surface: #16161f;
  --surface-2: #1e1e2a;
  --text: #f2f2f7;
  --text-2: #c9c9d6;
  --muted: #9494a7;
  --line: #2a2a38;
  --line-strong: #3a3a4c;
  --primary: #8f84f2;
  --primary-600: #a89ff6;
  --primary-50: #1f1b38;
  --primary-100: #2b2552;
  --on-primary: #0e0e14;
  --accent: #f4a259;
  --danger: #f2686c;
  --shadow-sm: none;
  --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset;
  --shadow-lg: 0 18px 40px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + 16px); overflow-x: clip; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 16px; line-height: 1.7;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  transition: background-color var(--mid), color var(--mid);
}
main { flex: 1; outline: none; }
img { max-width: 100%; display: block; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-600); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3, h4 { margin: 0; line-height: 1.35; font-weight: 700; letter-spacing: -.005em; color: var(--text); }
p { margin: 0 0 1em; }
.zh { font-family: var(--font-zh); font-weight: 500; }
.muted { color: var(--muted); }
.pinyin { color: var(--muted); font-size: .92em; }
.wrap { width: min(var(--wrap), 100% - 2.5rem); margin-inline: auto; }
.icon { width: 1.15em; height: 1.15em; flex: none; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.skip-link { position: absolute; left: 1rem; top: -4rem; z-index: 100; background: var(--primary); color: var(--on-primary); padding: .5rem 1rem; border-radius: var(--r-sm); }
.skip-link:focus { top: 1rem; }

/* reading progress bar (entry pages) */
.progress { position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 60; transform-origin: 0 50%; transform: scaleX(0); background: linear-gradient(90deg, var(--primary), var(--accent)); pointer-events: none; }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 40; height: var(--header-h);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid transparent; transition: border-color var(--mid), background-color var(--mid);
}
.site-header.scrolled { border-bottom-color: var(--line); }
.header-inner { width: min(var(--wrap), 100% - 2rem); margin-inline: auto; height: 100%; display: flex; align-items: center; gap: 1rem; }
.brand { display: flex; align-items: center; gap: .6rem; color: var(--text); flex: none; }
.brand:hover { color: var(--text); }
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 55%, var(--accent)));
  color: #fff; font-family: var(--font-zh); font-weight: 700; font-size: 1.05rem; box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 35%, transparent);
}
.brand-logo-wrap { position: relative; display: block; transition: transform var(--mid) var(--ease); }
.brand-logo { height: 38px; width: auto; display: block; filter: drop-shadow(0 2px 6px rgba(10, 10, 30, .18)); transition: filter var(--mid); }
.brand-logo-wrap .logo-shine { -webkit-mask-image: url(/images/brand/logo-sm.webp); mask-image: url(/images/brand/logo-sm.webp); }
.brand:hover .brand-logo-wrap { transform: scale(1.04); }
.brand:hover .brand-logo { filter: drop-shadow(0 3px 10px color-mix(in srgb, var(--primary) 45%, transparent)); }
.brand:hover .logo-shine::before { animation: shine-once .9s var(--ease); }
@keyframes shine-once { from { transform: translateX(-120%) skewX(-18deg); } to { transform: translateX(420%) skewX(-18deg); } }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 1rem; }
.brand-sub { font-size: .72rem; color: var(--muted); }

.main-nav { display: flex; gap: .15rem; margin-left: .75rem; }
.main-nav a {
  position: relative; padding: .45rem .75rem; border-radius: var(--r-pill);
  color: var(--text-2); font-size: .93rem; font-weight: 500; white-space: nowrap;
  transition: background-color var(--fast), color var(--fast);
}
.main-nav a:hover { background: var(--surface-2); color: var(--text); }
.main-nav a[aria-current='page'] { background: var(--primary-50); color: var(--primary); }

.header-tools { margin-left: auto; display: flex; align-items: center; gap: .4rem; }
.search-trigger {
  display: flex; align-items: center; gap: .55rem; height: 40px; min-width: 240px; padding: 0 .55rem 0 .85rem;
  border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--surface); color: var(--muted);
  cursor: pointer; transition: border-color var(--fast), box-shadow var(--fast);
}
.search-trigger:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.search-trigger span { flex: 1; text-align: left; font-size: .9rem; }
kbd { font: 500 .72rem/1 var(--font); padding: .3rem .45rem; border-radius: 7px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text-2); cursor: pointer;
  transition: background-color var(--fast), color var(--fast), transform var(--fast);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.94); }
.theme-icon-dark { display: none; }
[data-theme='night'] .theme-icon-dark { display: block; }
[data-theme='night'] .theme-icon-light { display: none; }
.menu-btn { display: none; }

/* ---------- buttons, chips, badges ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem; height: 44px; padding: 0 1.2rem;
  border-radius: var(--r-pill); border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-weight: 600; font-size: .95rem; cursor: pointer; transition: transform var(--fast), box-shadow var(--fast), background-color var(--fast);
}
.btn:hover { color: var(--text); box-shadow: var(--shadow); transform: translateY(-1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-600); color: var(--on-primary); }

.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip {
  display: inline-flex; align-items: center; gap: .4rem; height: 36px; padding: 0 .9rem; border-radius: var(--r-pill);
  border: 1px solid var(--line); background: var(--surface); color: var(--text-2); font-size: .9rem; font-weight: 500;
  cursor: pointer; transition: all var(--fast); white-space: nowrap; flex: none;
}
.chip:hover { border-color: var(--primary-100); color: var(--primary); }
.chip[aria-current='true'], .chip[aria-pressed='true'] { background: var(--text); border-color: var(--text); color: var(--bg); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-c, var(--primary)); }
.chip-row { overflow-x: auto; flex-wrap: nowrap; padding-bottom: .25rem; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }

.badge { display: inline-flex; align-items: center; height: 24px; padding: 0 .6rem; border-radius: var(--r-pill); font-size: .76rem; font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.badge.primary { background: var(--primary-50); color: var(--primary); }
.badge.warn { background: color-mix(in srgb, var(--accent) 14%, transparent); color: color-mix(in srgb, var(--accent) 80%, var(--text)); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-c, var(--primary)); margin-right: .35rem; }

/* ---------- layout pieces ---------- */
.page { padding-block: 2rem 5rem; }
.section { margin-top: 3.5rem; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.section-head h2 { font-size: clamp(1.25rem, 2.2vw, 1.55rem); }
.section-head p { margin: .2rem 0 0; color: var(--muted); font-size: .95rem; }
.more { display: inline-flex; align-items: center; gap: .3rem; font-weight: 600; font-size: .92rem; white-space: nowrap; }
.more .icon { transition: transform var(--fast); }
.more:hover .icon { transform: translateX(3px); }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; font-size: .88rem; color: var(--muted); margin-bottom: 1rem; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--primary); }
.crumbs .icon { width: .9em; height: .9em; }

.page-head { margin-bottom: 1.75rem; }
.page-head h1 { font-size: clamp(1.75rem, 3.6vw, 2.4rem); }
.page-head p { margin: .5rem 0 0; color: var(--muted); max-width: 60ch; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }

/* ---------- home hero ---------- */
.hero { padding: clamp(2.5rem, 7vw, 5rem) 0 1rem; text-align: center; position: relative; }
.hero::before { /* soft glow */
  content: ''; position: absolute; top: -80px; left: 50%; width: 100vw; transform: translateX(-50%); height: 460px; z-index: -1; pointer-events: none;
  background: radial-gradient(min(640px, 90vw) 280px at 50% 30%, color-mix(in srgb, var(--primary) 15%, transparent), transparent 72%);
}
/* hero emblem: tilt (JS sets --rx/--ry) → entrance → float; shine and twinkles sit on top */
.hero-emblem { width: min(440px, 82vw); margin: -.5rem auto 1rem; perspective: 900px; }
.logo-stack {
  position: relative; transform: rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)); transform-style: preserve-3d;
  transition: transform .5s var(--ease); animation: logo-in .8s var(--ease) both;
}
.hero-emblem.is-tilting .logo-stack { transition-duration: .12s; }
.hero-logo { display: block; width: 100%; height: auto; filter: drop-shadow(0 18px 30px rgba(20, 16, 60, .18)); animation: logo-float 7s ease-in-out .8s infinite; }
@keyframes logo-in { from { opacity: 0; translate: 0 10px; scale: .97; } to { opacity: 1; translate: none; scale: none; } }
@keyframes logo-float { 50% { translate: 0 -6px; } }

/* a band of light clipped to the logo's own shape */
.logo-shine {
  position: absolute; inset: 0; pointer-events: none; overflow: hidden;
  -webkit-mask: url(/images/brand/logo.webp) center / 100% 100% no-repeat; mask: url(/images/brand/logo.webp) center / 100% 100% no-repeat;
}
.logo-shine::before {
  content: ''; position: absolute; inset: -20% auto -20% 0; width: 32%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .0) 20%, rgba(255, 255, 255, .85) 50%, rgba(190, 180, 255, .35) 62%, transparent 80%);
  transform: translateX(-120%) skewX(-18deg); mix-blend-mode: screen;
}
.hero-emblem .logo-shine { animation: logo-float 7s ease-in-out .8s infinite; }
.hero-emblem .logo-shine::before { animation: shine 5.5s var(--ease) 1.2s infinite; }
@keyframes shine { 0% { transform: translateX(-120%) skewX(-18deg); } 38%, 100% { transform: translateX(420%) skewX(-18deg); } }

/* four-point stars that sit on the logo's own star glints */
.twinkle {
  position: absolute; left: var(--x); top: var(--y); width: calc(34px * var(--s)); aspect-ratio: 1; translate: -50% -50%; pointer-events: none;
  background: radial-gradient(closest-side, #fff, rgba(255, 255, 255, .6) 25%, transparent 70%);
  clip-path: polygon(50% 0, 57% 43%, 100% 50%, 57% 57%, 50% 100%, 43% 57%, 0 50%, 43% 43%);
  opacity: 0; scale: .3; animation: twinkle 3.6s ease-in-out var(--d) infinite; mix-blend-mode: screen;
}
@keyframes twinkle { 0%, 100% { opacity: 0; scale: .3; rotate: 0deg; } 45% { opacity: 1; scale: 1; rotate: 45deg; } 60% { opacity: .2; scale: .5; } }
.hero-badge { display: inline-flex; align-items: center; gap: .5rem; padding: .35rem .5rem .35rem .4rem; border-radius: var(--r-pill); background: var(--surface); border: 1px solid var(--line); font-size: .85rem; color: var(--text-2); box-shadow: var(--shadow-sm); }
.hero-badge b { background: var(--primary-50); color: var(--primary); padding: .1rem .55rem; border-radius: var(--r-pill); font-weight: 600; }
.hero h1 { margin: 1.1rem auto .8rem; font-size: clamp(2rem, 5.2vw, 3.4rem); max-width: 18ch; text-wrap: balance; }
.hero h1 .hl { background: linear-gradient(100deg, var(--primary), color-mix(in srgb, var(--primary) 40%, var(--accent))); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-lede { color: var(--muted); font-size: clamp(1rem, 1.6vw, 1.1rem); max-width: 46ch; margin: 0 auto 1.75rem; text-wrap: pretty; }
.hero-search {
  display: flex; align-items: center; gap: .75rem; width: min(640px, 100%); height: 60px; margin: 0 auto; padding: 0 .5rem 0 1.25rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-pill); box-shadow: var(--shadow-lg);
  color: var(--muted); cursor: text; transition: border-color var(--fast), transform var(--fast);
}
.hero-search:hover { border-color: var(--primary-100); }
.hero-search span { flex: 1; text-align: left; font-size: 1rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.hero-search .btn { height: 46px; }
.hero-suggest { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem; margin-top: 1rem; font-size: .88rem; color: var(--muted); }
.hero-suggest a { padding: .25rem .75rem; border-radius: var(--r-pill); background: var(--surface); border: 1px solid var(--line); color: var(--text-2); }
.hero-suggest a:hover { border-color: var(--primary-100); color: var(--primary); }

/* ---------- category tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .85rem; }
.tile {
  display: flex; flex-direction: column; gap: .7rem; padding: 1rem; border-radius: var(--r-lg);
  background: var(--surface); border: 1px solid var(--line); color: var(--text); box-shadow: var(--shadow-sm);
  transition: transform var(--mid) var(--ease), box-shadow var(--mid), border-color var(--mid);
}
.tile:hover { color: var(--text); transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: transparent; }
.tile-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--tile-bg, var(--primary-50)); color: var(--tile-fg, var(--primary)); }
.tile-icon .icon { width: 22px; height: 22px; }
.tile-text { display: flex; flex-direction: column; line-height: 1.35; }
.tile b { font-size: 1rem; }
.tile small { color: var(--muted); font-size: .82rem; }

/* ---------- work cards ---------- */
.works-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(175px, 1fr)); gap: 1.1rem; }
.work-card { display: flex; flex-direction: column; gap: .7rem; color: var(--text); }
.work-card:hover { color: var(--text); }
.cover {
  position: relative; aspect-ratio: 3 / 4; border-radius: var(--r-lg); overflow: hidden; background: var(--surface-2);
  box-shadow: var(--shadow); isolation: isolate; transition: transform var(--mid) var(--ease), box-shadow var(--mid);
}
.work-card:hover .cover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.cover img { width: 100%; height: 100%; object-fit: cover; transition: transform .5s var(--ease); }
.work-card:hover .cover img { transform: scale(1.04); }
.cover-fallback { position: absolute; inset: 0; display: grid; place-items: end start; color: #fff; isolation: isolate; }
.cover-fallback .avatar-art { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; }
.cover-fallback::after { content: ''; position: absolute; inset: 0; z-index: -1; background: linear-gradient(to top, rgba(8, 8, 20, .55), transparent 60%); }
.cover-fallback-text { display: grid; gap: .2rem; padding: .9rem; text-shadow: 0 1px 6px rgba(0, 0, 0, .35); }
.cover-fallback-text b { font-size: 1.05rem; line-height: 1.25; font-weight: 700; letter-spacing: .01em; }
.cover-fallback-text small { font-family: var(--font-zh); font-size: .85rem; opacity: .85; }
.cover-index { position: absolute; left: .6rem; top: .6rem; z-index: 2; height: 26px; padding: 0 .55rem; display: inline-flex; align-items: center; border-radius: var(--r-pill); background: rgba(10, 10, 20, .55); color: #fff; font-size: .74rem; font-weight: 600; backdrop-filter: blur(6px); }
.work-card h3 { font-size: 1rem; line-height: 1.4; }
.work-meta { display: flex; flex-wrap: wrap; gap: .25rem .6rem; color: var(--muted); font-size: .84rem; }
.work-meta .zh { color: var(--text-2); }

/* ---------- entry cards ---------- */
.entry-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: .9rem; }
.entry-card {
  display: grid; grid-template-columns: auto 1fr; gap: .9rem; align-items: start; padding: 1rem 1.1rem;
  border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); color: var(--text);
  transition: transform var(--mid) var(--ease), box-shadow var(--mid), border-color var(--mid);
}
.entry-card:hover { color: var(--text); transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--primary-100); }
.avatar {
  position: relative; width: 48px; height: 48px; border-radius: 14px; flex: none; overflow: hidden;
  display: grid; place-items: center; color: #fff; isolation: isolate;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .14), 0 2px 6px rgba(20, 18, 50, .12);
}
.avatar-art { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; }
.avatar::after { content: ''; position: absolute; inset: 0; background: linear-gradient(160deg, rgba(255, 255, 255, .22), transparent 45%); pointer-events: none; }
.avatar .avatar-icon { width: 44%; height: 44%; stroke-width: 1.8; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .25)); }
.avatar.has-photo img { width: 100%; height: 100%; object-fit: cover; transition: transform var(--mid) var(--ease); }
.entry-card:hover .avatar.has-photo img { transform: scale(1.06); }
.entry-card h3 { font-size: 1rem; display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .5rem; }
.entry-card h3 .zh { font-size: .9rem; color: var(--muted); font-weight: 500; }
.entry-card p { margin: .2rem 0 .55rem; color: var(--text-2); font-size: .9rem; line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.entry-card .badges { display: flex; flex-wrap: wrap; gap: .35rem; }

/* horizontal scroller (featured characters) */
.scroller { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 300px); gap: .9rem; overflow-x: auto; padding: .25rem .25rem 1rem; margin-inline: -.25rem; scroll-snap-type: x mandatory; scrollbar-width: thin; }
.scroller > * { scroll-snap-align: start; }

/* ---------- toolbar: filter + chips ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-bottom: 1.25rem; }
.filter {
  display: flex; align-items: center; gap: .5rem; height: 44px; padding: 0 .9rem; flex: 1 1 260px; max-width: 380px;
  border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--surface); color: var(--muted);
}
.filter:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-50); }
.filter input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: .95rem; }
.count { color: var(--muted); font-size: .88rem; margin: 0 0 1rem; }
.empty { padding: 3rem 1rem; text-align: center; color: var(--muted); }

/* ---------- tabs with sliding indicator ---------- */
.tabs { position: relative; display: flex; gap: .25rem; padding: .3rem; border-radius: var(--r-pill); background: var(--surface-2); width: max-content; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { position: relative; z-index: 1; height: 38px; padding: 0 1rem; border: 0; border-radius: var(--r-pill); background: transparent; color: var(--muted); font-weight: 600; font-size: .9rem; cursor: pointer; white-space: nowrap; transition: color var(--fast); }
.tab[aria-selected='true'] { color: var(--text); }
.tab-ink { position: absolute; z-index: 0; top: .3rem; height: 38px; border-radius: var(--r-pill); background: var(--surface); box-shadow: var(--shadow); transition: transform var(--mid) var(--ease), width var(--mid) var(--ease); }
.tab-panel[hidden] { display: none; }
.tab-panel { margin-top: 1.25rem; animation: fade-in var(--mid) var(--ease); }

/* ---------- work detail ---------- */
.work-head { display: grid; grid-template-columns: 220px 1fr; gap: 2rem; align-items: start; }
.work-head .cover { aspect-ratio: 3 / 4; }
.work-head h1 { font-size: clamp(1.7rem, 3.4vw, 2.4rem); }
.work-head .zh-title { font-family: var(--font-zh); font-size: 1.2rem; color: var(--muted); margin-top: .25rem; }
.facts { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1rem 0; padding: 0; list-style: none; }
.facts li { padding: .35rem .75rem; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--line); font-size: .85rem; color: var(--text-2); }
.facts b { color: var(--muted); font-weight: 500; margin-right: .3rem; }
.tagline { font-size: 1.05rem; color: var(--text-2); margin: 0 0 1rem; }
.credit { font-size: .78rem; color: var(--muted); }

/* ---------- prose / article ---------- */
.prose { color: var(--text-2); max-width: 70ch; }
.prose p { margin: 0 0 1em; }
.prose p:last-child { margin-bottom: 0; }
.prose a { font-weight: 500; text-decoration: underline; text-decoration-color: var(--primary-100); text-underline-offset: 3px; text-decoration-thickness: 2px; }
.prose a:hover { text-decoration-color: var(--primary); }
.broken-link { color: var(--muted); }

.article { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 2.5rem; align-items: start; }
.article-head { display: flex; gap: 1.1rem; align-items: center; margin-bottom: 1.25rem; }
.article-head .avatar { width: 72px; height: 72px; border-radius: 20px; }
.article-head h1 { font-size: clamp(1.7rem, 3.4vw, 2.3rem); }
.article-head .sub { color: var(--muted); font-size: .95rem; margin-top: .15rem; }
.summary { padding: 1.1rem 1.25rem; border-radius: var(--r-lg); background: var(--primary-50); color: var(--text); margin-bottom: 1.5rem; font-size: 1.02rem; }
.summary .prose { color: var(--text); }
.hint { display: flex; gap: .5rem; align-items: center; font-size: .85rem; color: var(--muted); margin-bottom: 1rem; }
.side { position: sticky; top: calc(var(--header-h) + 1rem); display: grid; gap: 1rem; }
.side .card { padding: 1rem 1.1rem; }
.side h2 { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: .6rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .35rem .9rem; font-size: .92rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.link-list { list-style: none; margin: 0; padding: 0; }
.link-list a { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .5rem .6rem; margin-inline: -.6rem; border-radius: var(--r-sm); color: var(--text); font-size: .93rem; transition: background-color var(--fast); }
.link-list a:hover { background: var(--surface-2); color: var(--text); }
.link-list .zh { color: var(--muted); font-size: .85rem; }

/* ---------- spoilers ---------- */
.spoiler {
  color: transparent; background: var(--surface-2); border-radius: 6px; padding: 0 .25em; cursor: pointer;
  text-shadow: 0 0 8px color-mix(in srgb, var(--text) 70%, transparent); transition: color var(--mid), text-shadow var(--mid), background-color var(--mid);
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
.spoiler a { color: transparent !important; pointer-events: none; text-decoration: none !important; }
.spoiler:hover { background: var(--primary-50); }
.spoiler.revealed, [data-spoilers='shown'] .spoiler { color: inherit; text-shadow: none; background: transparent; cursor: auto; }
.spoiler.revealed a, [data-spoilers='shown'] .spoiler a { color: var(--primary) !important; pointer-events: auto; }

/* ---------- realms: stepper ---------- */
.realm-path { margin-bottom: 2rem; }
.realm-path-title { display: flex; align-items: center; gap: .5rem; font-size: 1.05rem; margin-bottom: .4rem; }
.realm-note { color: var(--muted); font-size: .9rem; margin-bottom: 1rem; max-width: 75ch; }
.step-label { display: inline-flex; margin: 1.1rem 0 .55rem; padding: .25rem .7rem; border-radius: var(--r-pill); background: var(--primary-50); color: var(--primary); font-size: .8rem; font-weight: 600; }
.steps { list-style: none; margin: 0; padding: 0; counter-reset: realm; position: relative; }
.steps li {
  counter-increment: realm; position: relative; display: grid; grid-template-columns: 34px 1fr; gap: .9rem; padding: .7rem 0 .7rem;
}
.steps li::before {
  content: counter(realm); width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; z-index: 1;
  background: var(--surface); border: 2px solid var(--primary-100); color: var(--primary); font-weight: 700; font-size: .85rem;
}
.steps li::after { content: ''; position: absolute; left: 16px; top: 44px; bottom: -10px; width: 2px; background: var(--line); }
.steps li:last-child::after { display: none; }
.step-body { padding-top: .2rem; }
.step-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: .15rem .6rem; font-weight: 600; }
.step-title .zh { font-size: .95rem; color: var(--text-2); font-weight: 500; }
.step-alias { display: block; font-size: .84rem; color: var(--primary); }
.step-note { display: block; font-size: .88rem; color: var(--muted); margin-top: .1rem; }

/* ---------- timeline (crossovers) ---------- */
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; }
.timeline li { padding: 1.25rem 1.35rem; }
.timeline h2 { font-size: 1.1rem; margin-bottom: .6rem; display: flex; align-items: center; gap: .6rem; }
.timeline .num { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; background: var(--primary); color: var(--on-primary); font-size: .85rem; }
.flow { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin-bottom: .85rem; }
.flow .icon { color: var(--muted); width: .95em; height: .95em; }

/* ---------- news ---------- */
.news-list { display: grid; gap: .85rem; }
.news-item { display: grid; grid-template-columns: 64px 1fr; gap: 1rem; padding: 1.1rem 1.25rem; }
.date-box { text-align: center; border-radius: var(--r); background: var(--surface-2); padding: .45rem 0; height: max-content; }
.date-box b { display: block; font-size: 1.35rem; line-height: 1.1; }
.date-box small { color: var(--muted); font-size: .72rem; }
.news-item h3 { font-size: 1.05rem; margin: .35rem 0 .35rem; }
.news-item .prose { font-size: .94rem; }
.news-item.is-sample { border-style: dashed; }

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--line); background: var(--surface); margin-top: 2rem; }
.footer-inner { width: min(var(--wrap), 100% - 2.5rem); margin-inline: auto; padding: 2rem 0 2.5rem; display: grid; grid-template-columns: 1fr auto; gap: 1.5rem; align-items: start; font-size: .88rem; color: var(--muted); }
.footer-inner p { margin: 0 0 .35rem; }
.footer-inner strong { color: var(--text); }
.footer-owner { margin-top: .6rem !important; padding: .6rem .8rem; border-radius: var(--r-sm); background: var(--primary-50); color: var(--text-2); }
.footer-owner strong { color: var(--primary); }
.footer-copy { font-size: .8rem; }
.nw { white-space: nowrap; } /* words the Thai line breaker does not know, e.g. แอดมิน */
.switch { display: inline-flex; align-items: center; gap: .65rem; cursor: pointer; user-select: none; color: var(--text-2); font-weight: 500; white-space: nowrap; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { width: 44px; height: 26px; border-radius: 13px; background: var(--line-strong); position: relative; transition: background-color var(--mid); }
.switch-track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--mid) var(--ease); }
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--primary); outline-offset: 2px; }

/* back to top */
.to-top { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 30; width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); display: grid; place-items: center; cursor: pointer; opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity var(--mid), transform var(--mid) var(--ease); }
.to-top.show { opacity: 1; transform: none; pointer-events: auto; }

/* ---------- search dialog ---------- */
.search-overlay { position: fixed; inset: 0; z-index: 70; padding: 12vh 1rem 1rem; display: flex; justify-content: center; align-items: flex-start; background: rgba(10, 10, 20, .38); backdrop-filter: blur(4px); animation: fade-in var(--fast); }
.search-overlay[hidden] { display: none; }
.search-panel { width: min(640px, 100%); max-height: 72vh; display: flex; flex-direction: column; overflow: hidden; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lg); animation: pop var(--mid) var(--ease); }
.search-field { display: flex; align-items: center; gap: .65rem; padding: .9rem 1rem; border-bottom: 1px solid var(--line); color: var(--muted); }
.search-field input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 1.05rem; }
.search-field input::-webkit-search-cancel-button { display: none; }
.search-close { border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); border-radius: 7px; padding: .2rem .45rem; font-size: .72rem; cursor: pointer; }
.search-results { overflow-y: auto; padding: .4rem; }
.search-group { padding: .6rem .7rem .3rem; font-size: .75rem; font-weight: 600; color: var(--muted); }
.search-hit { display: grid; grid-template-columns: 40px 1fr; gap: .75rem; align-items: center; padding: .5rem .65rem; border-radius: var(--r-sm); color: var(--text); }
.search-hit .avatar { width: 40px; height: 40px; border-radius: 11px; }
.search-hit strong { font-weight: 600; }
.search-hit .zh { color: var(--muted); font-size: .88rem; margin-left: .35rem; }
.hit-sub { display: block; font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-hit[aria-selected='true'], .search-hit:hover { background: var(--primary-50); color: var(--text); }
.search-empty { padding: 2rem 1rem; text-align: center; color: var(--muted); font-size: .95rem; }
.search-empty .icon { width: 28px; height: 28px; display: block; margin: 0 auto .5rem; color: var(--primary); }

/* ---------- loading & 404 ---------- */
.loading { min-height: 50vh; display: grid; place-content: center; justify-items: center; gap: .8rem; color: var(--muted); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--primary-100); border-top-color: var(--primary); animation: spin .8s linear infinite; }
.not-found { min-height: 50vh; display: grid; place-content: center; text-align: center; gap: .6rem; }
.not-found .big { font-size: clamp(4rem, 12vw, 7rem); font-weight: 700; line-height: 1; background: linear-gradient(135deg, var(--primary), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- motion ---------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
.page { animation: page-in .35s var(--ease) both; }
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
/* cards come into view from a soft blur: one-shot, 6px at most */
.reveal { opacity: 0; transform: translateY(14px); filter: blur(6px); }
.reveal.is-in {
  opacity: 1; transform: none; filter: none;
  transition: opacity .5s ease var(--d, 0ms), transform .5s var(--ease) var(--d, 0ms), filter .5s ease var(--d, 0ms);
}

/* opening: the headline arrives letter by letter (fx.js splits it into Thai grapheme clusters, then restores it) */
.split-word { display: inline-block; white-space: nowrap; }
.split-ch { display: inline-block; animation: ch-in .7s var(--ease) calc(.3s + var(--i) * 32ms) both; }
@keyframes ch-in {
  from { opacity: 0; translate: 0 .45em; scale: .7; filter: blur(8px); }
  60% { opacity: 1; filter: blur(0); }
  to { opacity: 1; translate: none; scale: none; filter: none; }
}
/* the gradient word: each letter carries the gradient, because background-clip on the parent misses animated children */
.hero h1.is-splitting .hl { background: none; }
.hero h1.is-splitting .hl .split-ch {
  background: linear-gradient(100deg, var(--primary), color-mix(in srgb, var(--primary) 40%, var(--accent)));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
/* the rest of the hero rises in after it */
.hero.is-intro .hero-badge { animation: rise-in .6s var(--ease) .15s both; }
.hero.is-intro .hero-lede { animation: rise-in .7s var(--ease) calc(.55s + var(--n, 20) * 32ms) both; }
.hero.is-intro .hero-search { animation: rise-in .7s var(--ease) calc(.68s + var(--n, 20) * 32ms) both; }
.hero.is-intro .hero-suggest { animation: rise-in .7s var(--ease) calc(.8s + var(--n, 20) * 32ms) both; }
.hero.is-intro .logo-stack { animation: logo-in-blur 1s var(--ease) both; }
@keyframes rise-in { from { opacity: 0; translate: 0 12px; filter: blur(6px); } to { opacity: 1; translate: none; filter: none; } }
@keyframes logo-in-blur { from { opacity: 0; translate: 0 10px; scale: .94; filter: blur(8px); } to { opacity: 1; translate: none; scale: none; filter: none; } }

/* scrolling down: the hero drifts up, fades and blurs as it leaves (CSS scroll timeline, no scroll listeners) */
@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) {
    .hero-scroll {
      animation: hero-out linear both; animation-timeline: scroll(root block); animation-range: 0 min(520px, 70vh);
    }
    @keyframes hero-out {
      from { opacity: 1; translate: none; filter: none; }
      to { opacity: .15; translate: 0 -40px; scale: .97; filter: blur(6px); }
    }
  }
}

/* ---------- responsive ---------- */
/* ---------- tiers + VS ---------- */
.tier-pill { display: inline-flex; align-items: center; height: 26px; padding: 0 .6rem; border-radius: 8px; background: var(--text); color: var(--bg); font-weight: 700; font-size: .82rem; letter-spacing: .01em; white-space: nowrap; font-variant-numeric: tabular-nums; }
.basis { display: inline-flex; align-items: center; height: 22px; padding: 0 .5rem; border-radius: var(--r-pill); font-size: .72rem; font-weight: 600; white-space: nowrap; }
.basis-official { background: color-mix(in srgb, #1f9e8a 15%, transparent); color: color-mix(in srgb, #1f9e8a 75%, var(--text)); }
.basis-inferred { background: color-mix(in srgb, var(--accent) 16%, transparent); color: color-mix(in srgb, var(--accent) 75%, var(--text)); }
.tier-legend { display: grid; gap: .45rem; margin-bottom: 1.5rem; font-size: .92rem; color: var(--text-2); }
.tier-legend p { margin: 0; }
.tier-legend .basis { margin-right: .4rem; }

.vs-box { padding: 1.25rem; margin-bottom: 2.5rem; }
.vs-box h2 { display: flex; align-items: center; gap: .5rem; font-size: 1.1rem; margin: 0 0 1rem; }
.vs-box h2 svg { color: var(--accent); }
.vs-pick { display: grid; grid-template-columns: 1fr auto 1fr; gap: .75rem; align-items: end; }
.vs-side { display: grid; gap: .35rem; font-size: .82rem; color: var(--muted); min-width: 0; }
.vs-side select { width: 100%; height: 46px; padding: 0 .8rem; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: .95rem; }
.vs-side select:focus { outline: 0; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-50); }
.vs-mark { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; background: var(--primary); color: var(--on-primary); font-weight: 800; font-size: .9rem; }
.vs-result { margin-top: 1.1rem; }
.vs-duel { display: grid; grid-template-columns: 1fr auto 1fr; gap: .75rem; align-items: stretch; }
.vs-fighter { display: grid; justify-items: center; gap: .3rem; padding: .9rem .6rem; border-radius: var(--r-md, 14px); background: var(--surface-2); text-align: center; border: 2px solid transparent; transition: border-color .2s, background .2s; }
.vs-fighter small { color: var(--muted); font-size: .78rem; }
.vs-fighter.is-higher { border-color: var(--primary); background: var(--primary-50); }
.vs-steps { align-self: center; font-size: .8rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.gap-far .vs-steps { color: var(--primary); }
.vs-text { margin: .9rem 0 0; color: var(--text); line-height: 1.7; }
.vs-note { margin: .4rem 0 0; font-size: .85rem; color: color-mix(in srgb, var(--accent) 75%, var(--text)); }
/* red notice: cross-series VS is not a verdict */
.warn-box {
  margin: 0 0 2rem; padding: 1.15rem 1.25rem 1.2rem; border-radius: var(--r-lg);
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent); border-left-width: 5px;
  background: color-mix(in srgb, var(--danger) 9%, var(--surface));
}
.warn-head { display: flex; align-items: center; gap: .55rem; color: var(--danger); }
.warn-head svg { width: 24px; height: 24px; flex: none; }
.warn-head h2 { margin: 0; font-size: 1.15rem; color: var(--danger); }
.warn-lede { margin: .7rem 0 .85rem; line-height: 1.7; }
.warn-points { margin: 0; padding: 0; list-style: none; display: grid; gap: .7rem; counter-reset: warn; }
.warn-points li { display: grid; gap: .2rem; padding-left: 2.1rem; position: relative; line-height: 1.65; counter-increment: warn; }
.warn-points li::before {
  content: counter(warn); position: absolute; left: 0; top: .1rem; width: 1.5rem; height: 1.5rem; border-radius: 50%;
  display: grid; place-items: center; font-size: .8rem; font-weight: 700; background: var(--danger); color: #fff;
}
.warn-points b { color: var(--text); }
.warn-points span { color: var(--text-2); font-size: .95rem; }
.warn-basis { margin: -.3rem 0 .9rem; font-size: .86rem; color: var(--muted); line-height: 1.6; }
.warn-src { display: flex; flex-wrap: wrap; gap: .25rem .5rem; align-items: center; font-size: .8rem; color: var(--muted); margin-top: .15rem; }
.warn-src a { color: var(--danger); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--danger) 40%, transparent); text-underline-offset: 2px; }
.warn-src a:hover { text-decoration-color: currentColor; }
.warn-foot { margin: .95rem 0 0; padding-top: .85rem; border-top: 1px dashed color-mix(in srgb, var(--danger) 40%, transparent); font-size: .92rem; font-weight: 600; color: var(--danger); line-height: 1.65; }
.vs-cross { margin: .6rem 0 0; padding: .55rem .75rem; border-radius: var(--r-sm); font-size: .88rem; line-height: 1.6; color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.vs-caveat { margin: .9rem 0 0; padding-top: .9rem; border-top: 1px dashed var(--line); font-size: .85rem; color: var(--muted); }

.tier-board { display: grid; gap: .5rem; margin-bottom: 2.5rem; }
.tier-row { display: grid; grid-template-columns: 210px 1fr; gap: 1rem; align-items: center; padding: .7rem .9rem; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); }
.tier-row-label { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.tier-row-label small { color: var(--muted); font-size: .8rem; line-height: 1.4; }
.tier-row-people { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip-flag { font-size: .7rem; padding: .05rem .4rem; border-radius: var(--r-pill); background: color-mix(in srgb, var(--accent) 16%, transparent); color: color-mix(in srgb, var(--accent) 75%, var(--text)); }

.tier-list { display: grid; gap: 1rem; }
.tier-card { padding: 1.25rem; scroll-margin-top: calc(var(--header-h) + 16px); }
.tier-card:target { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-50); }
.tier-card-head { display: grid; grid-template-columns: auto 1fr auto; gap: .9rem; align-items: center; }
.tier-card-head h3 { margin: 0; font-size: 1.1rem; }
.tier-card-head h3 a { color: var(--text); }
.tier-card-head h3 a:hover { color: var(--primary); }
.tier-card-head p { margin: .15rem 0 0; font-size: .85rem; }
.tier-peak { display: grid; justify-items: end; gap: .3rem; text-align: right; }
.tier-peak .tier-pill { height: 32px; font-size: .95rem; padding: 0 .8rem; }
.tier-peak small { color: var(--muted); font-size: .78rem; }
.tier-why { margin: 1rem 0; padding: .9rem 1rem; border-radius: var(--r-sm); background: var(--primary-50); }
.tier-why b { display: block; font-size: .8rem; color: var(--primary); margin-bottom: .2rem; }
.tier-why p { margin: 0; color: var(--text-2); line-height: 1.75; }
.tier-stages { list-style: none; margin: 0; padding: 0; display: grid; }
.tier-stages li { display: grid; grid-template-columns: 92px 1fr auto; gap: .75rem; align-items: start; padding: .6rem 0; border-top: 1px solid var(--line); }
.tier-stages li .tier-pill { justify-self: start; background: var(--surface-2); color: var(--text); }
.tier-stage-body { display: grid; gap: .15rem; min-width: 0; }
.tier-stage-name { font-weight: 500; }
.tier-stage-note { font-size: .85rem; color: var(--muted); }
.tier-sources { margin: .75rem 0 0; font-size: .82rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: .3rem .8rem; }
.side-tier { display: flex; align-items: center; gap: .5rem; margin: 0; }

/* /tiers/scale: every tier, strongest first */
.tier-legend .more { justify-self: start; margin-top: .2rem; }
.scale-rules { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .8rem; margin-bottom: 2.5rem; }
.scale-rule { padding: 1rem 1.1rem; display: grid; gap: .4rem; align-content: start; }
.scale-rule h3 { margin: 0; font-size: 1rem; }
.scale-rule p { margin: 0; color: var(--text-2); line-height: 1.7; font-size: .92rem; }
.scale-src { font-size: .78rem; color: var(--muted); }
.scale-src:hover { color: var(--primary); }
.scale-jump { margin-bottom: 1.5rem; }
.scale-group { margin-bottom: 2rem; }
.scale-group-head { display: grid; grid-template-columns: auto 1fr; gap: 1rem; align-items: center; margin-bottom: .75rem; }
.scale-group-head h3 { margin: 0; font-size: 1.15rem; scroll-margin-top: calc(var(--header-h) + 16px); }
.scale-group-head p { margin: .2rem 0 0; font-size: .88rem; line-height: 1.6; }
.scale-major { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 16px; background: var(--primary); color: var(--on-primary); font-weight: 800; font-size: 1.35rem; }
.scale-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column-reverse; gap: .5rem; }
.scale-row { display: grid; grid-template-columns: 110px 1fr; gap: .9rem; padding: .85rem 1rem; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); }
.scale-row.has-people { border-color: color-mix(in srgb, var(--primary) 45%, var(--line)); }
.scale-code .tier-pill { background: var(--surface-2); color: var(--text); }
.scale-row.has-people .scale-code .tier-pill { background: var(--primary); color: var(--on-primary); }
.scale-body { min-width: 0; display: grid; gap: .3rem; }
.scale-body h4 { margin: 0; font-size: .98rem; display: flex; flex-wrap: wrap; align-items: center; gap: .2rem .5rem; }
.scale-body h4 .muted { font-weight: 400; font-size: .82rem; }
.scale-body p { margin: 0; color: var(--text-2); line-height: 1.7; font-size: .92rem; }
.scale-body .scale-energy { display: flex; align-items: center; gap: .35rem; font-size: .85rem; color: var(--muted); }
.scale-energy svg { width: 15px; height: 15px; color: var(--accent); flex: none; }
.scale-flag { font-size: .7rem; font-weight: 500; padding: .05rem .45rem; border-radius: var(--r-pill); border: 1px dashed var(--line-strong); color: var(--muted); cursor: help; }
.scale-body .scale-people { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; font-size: .85rem; }
@media (max-width: 720px) {
  .scale-row { grid-template-columns: 1fr; gap: .5rem; }
  .scale-major { width: 42px; height: 42px; font-size: 1.1rem; }
}

@media (max-width: 720px) {
  .vs-pick { grid-template-columns: 1fr; }
  .vs-mark { justify-self: center; width: 38px; height: 38px; font-size: .8rem; }
  .tier-row { grid-template-columns: 1fr; gap: .5rem; }
  .tier-card-head { grid-template-columns: auto 1fr; }
  .tier-peak { grid-column: 1 / -1; justify-items: start; text-align: left; grid-auto-flow: column; justify-content: start; align-items: center; gap: .5rem; }
  .tier-stages li { grid-template-columns: 1fr auto; }
  .tier-stages li .tier-pill { grid-row: 1; }
  .tier-stages li .tier-stage-body { grid-column: 1 / -1; }
  .tier-stages li .basis { grid-row: 1; grid-column: 2; }
}

/* ---------- universes ---------- */
.universe-bar { margin-bottom: 1rem; }
.universe-bar .chip .icon { width: 1em; height: 1em; }
.see-also { margin-top: 2rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.see-also a { display: inline-flex; align-items: center; gap: .3rem; font-weight: 600; }
.universe-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.universe-card { display: grid; grid-template-columns: 96px 1fr; gap: 1rem; align-items: center; padding: .9rem; color: var(--text); transition: transform var(--mid) var(--ease), box-shadow var(--mid), border-color var(--mid); }
.universe-card:hover { color: var(--text); transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--primary-100); }
.universe-art { position: relative; height: 96px; }
.universe-art > span { position: absolute; top: 0; width: 64px; height: 88px; border-radius: 10px; overflow: hidden; box-shadow: 0 4px 12px rgba(20, 18, 50, .2); border: 2px solid var(--surface); }
.universe-art > span:nth-child(1) { left: 0; z-index: 3; }
.universe-art > span:nth-child(2) { left: 16px; top: 4px; z-index: 2; rotate: 6deg; }
.universe-art > span:nth-child(3) { left: 30px; top: 8px; z-index: 1; rotate: 12deg; }
.universe-art .cover-fallback-text { display: none; }
.universe-art img { width: 100%; height: 100%; object-fit: cover; }
.universe-text { display: grid; gap: .2rem; min-width: 0; }
.universe-text b { font-size: 1rem; }
.universe-text small { color: var(--muted); font-size: .82rem; }
.universe-works { font-size: .85rem; color: var(--text-2); line-height: 1.5; }
.universe-section { scroll-margin-top: calc(var(--header-h) + 16px); }
.universe-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .75rem 1rem; align-items: end; margin-bottom: .75rem; }
.universe-head h2 { margin: 0; font-size: clamp(1.3rem, 2.4vw, 1.6rem); }
.universe-author { margin: .25rem 0 0; color: var(--muted); font-size: .9rem; }
.universe-links { display: flex; flex-wrap: wrap; gap: .4rem; }
.universe-links .icon { width: 1em; height: 1em; }
.universe-summary { margin-bottom: 1.25rem; }
.work-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem; margin: 1.25rem 0 0; }
.work-actions .btn { display: inline-flex; align-items: center; gap: .45rem; }

/* ---------- full plot ---------- */
.plot-head .badge { gap: .35rem; height: 28px; }
.plot-head .badge .icon { width: 1em; height: 1em; }
.plot-head p { margin-top: .35rem; }
.plot-gate { max-width: 560px; margin: 1rem auto 3rem; padding: 2rem 1.5rem; text-align: center; display: grid; justify-items: center; gap: .75rem; }
.plot-gate h2 { margin: 0; font-size: 1.3rem; }
.plot-gate p { margin: 0; color: var(--text-2); line-height: 1.75; }
.plot-gate-icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; background: color-mix(in srgb, var(--accent) 16%, transparent); color: color-mix(in srgb, var(--accent) 80%, var(--text)); }
.plot-gate-icon .icon { width: 26px; height: 26px; }
.plot-body { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 2.5rem; align-items: start; }
.plot-toc { position: sticky; top: calc(var(--header-h) + 1rem); max-height: calc(100vh - var(--header-h) - 2rem); overflow-y: auto; }
.plot-toc summary { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; cursor: pointer; margin-bottom: .5rem; list-style: none; }
.plot-toc summary::-webkit-details-marker { display: none; }
.plot-toc ol { list-style: none; margin: 0; padding: 0; display: grid; gap: .15rem; }
.plot-toc a { display: flex; gap: .55rem; align-items: baseline; padding: .4rem .55rem; border-radius: var(--r-sm); color: var(--text-2); font-size: .9rem; line-height: 1.45; }
.plot-toc a:hover { background: var(--surface-2); color: var(--text); }
.toc-num { flex: none; font-size: .75rem; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; min-width: 1.2em; }
.plot-content { min-width: 0; }
.plot-intro { font-size: 1.05rem; margin-bottom: 2rem; }
.plot-arc { padding-top: 1.5rem; margin-top: 1.5rem; border-top: 1px solid var(--line); scroll-margin-top: calc(var(--header-h) + 16px); }
.plot-arc:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.plot-arc h2 { display: flex; gap: .6rem; align-items: baseline; font-size: clamp(1.2rem, 2.2vw, 1.45rem); margin: 0 0 .35rem; }
.plot-arc h2 .toc-num { font-size: .9rem; }
.plot-chapters { margin: 0 0 1rem; font-size: .85rem; color: var(--muted); }
.plot-arc .prose { max-width: 72ch; }
.plot-sources { margin-top: 2.5rem; }
.plot-note { font-size: .82rem; margin-top: .5rem; }

@media (max-width: 900px) {
  .plot-body { grid-template-columns: 1fr; gap: 1.25rem; }
  .plot-toc { position: static; max-height: none; padding: .9rem 1rem; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
  .plot-toc summary { margin: 0; list-style: revert; }
  .plot-toc details[open] summary { margin-bottom: .5rem; }
}
@media (max-width: 520px) {
  .universe-card { grid-template-columns: 80px 1fr; }
  .universe-art { height: 84px; }
  .universe-art > span { width: 54px; height: 76px; }
}

@media (max-width: 1080px) {
  .main-nav {
    position: fixed; inset: var(--header-h) 0 auto 0; flex-direction: column; gap: .15rem; margin: 0;
    padding: .75rem 1rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); box-shadow: var(--shadow-lg);
    opacity: 0; visibility: hidden; transform: translateY(-6px); transition: all var(--mid) var(--ease);
  }
  .main-nav.open { opacity: 1; visibility: visible; transform: none; }
  .main-nav a { padding: .8rem 1rem; border-radius: var(--r); font-size: 1rem; }
  .menu-btn { display: grid; }
  .search-trigger { min-width: 0; width: 40px; padding: 0; justify-content: center; }
  .search-trigger span, .search-trigger kbd { display: none; }
  .article { grid-template-columns: 1fr; }
  .side { position: static; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
}
@media (max-width: 720px) {
  .brand-sub { display: none; }
  .page { padding-top: 1.25rem; }
  .section { margin-top: 2.5rem; }
  .hero { padding-top: 2rem; }
  .hero-search { height: 54px; padding-left: 1rem; }
  .hero-search .btn { display: none; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: .65rem; }
  .tile { flex-direction: row; align-items: center; padding: .8rem; gap: .7rem; }
  .works-grid { grid-template-columns: repeat(2, 1fr); gap: .85rem; }
  .work-head { grid-template-columns: 120px 1fr; gap: 1rem; }
  .work-head .cover { border-radius: var(--r); }
  .news-item { grid-template-columns: 1fr; gap: .5rem; }
  .date-box { display: inline-flex; gap: .4rem; align-items: baseline; padding: .2rem .6rem; width: max-content; }
  .date-box b { display: inline; font-size: 1rem; }
  .footer-inner { grid-template-columns: 1fr; }
  .to-top { right: .9rem; bottom: .9rem; }
  .section-head { align-items: start; flex-direction: column; gap: .35rem; }
}

@media (prefers-reduced-motion: reduce) {
  .logo-stack, .hero-logo, .hero-emblem .logo-shine, .logo-shine::before, .twinkle { animation: none !important; }
  .twinkle { display: none; }
  .logo-stack { transform: none !important; }
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .reveal { opacity: 1; transform: none; filter: none; }
}

/* narrow phones: the logo already says ERGEN, so drop the Thai name to keep the header on one line */
@media (max-width: 520px) {
  .brand-text { display: none; }
  .brand-logo { height: 34px; }
  .header-tools { gap: .3rem; }
}
