/* Anijipedia — brand #006887. System fonts only (no third-party requests). */
:root {
  --brand: #006887;
  --brand-strong: #004d66;
  --brand-soft: #e1f0f5;
  --brand-tint: #f0f7f9;
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-2: #edf2f4;
  --text: #14242b;
  --muted: #566a73;
  --line: #d8e2e7;
  --line-strong: #b6c7cf;
  --link: #00607d;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --ok: #17724a;
  --ok-soft: #e4f4ec;
  --warn: #85560a;
  --warn-soft: #fff3d4;
  --info-soft: #e6f2f6;
  --focus: #1b9cc4;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0, 40, 55, .06), 0 6px 20px rgba(0, 40, 55, .06);
  --header-h: 58px;
  --sidebar-w: 252px;
  --font: "Sarabun", "Noto Sans Thai", "Leelawadee UI", "Sukhumvit Set", "Thonburi", "Tahoma", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --brand-soft: #0f3340; --brand-tint: #0d2831; --bg: #0b161b; --surface: #112229; --surface-2: #17303a;
  --text: #e3edf0; --muted: #9db3bc; --line: #223a45; --line-strong: #33505d; --link: #5cc6e4;
  --danger: #ff8b82; --danger-soft: #3a1b19; --ok: #6fd6a2; --ok-soft: #123225; --warn: #f2c15c; --warn-soft: #382b0c;
  --info-soft: #11303b; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-soft: #0f3340; --brand-tint: #0d2831; --bg: #0b161b; --surface: #112229; --surface-2: #17303a;
    --text: #e3edf0; --muted: #9db3bc; --line: #223a45; --line-strong: #33505d; --link: #5cc6e4;
    --danger: #ff8b82; --danger-soft: #3a1b19; --ok: #6fd6a2; --ok-soft: #123225; --warn: #f2c15c; --warn-soft: #382b0c;
    --info-soft: #11303b; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: auto; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 1rem; line-height: 1.7;
  -webkit-font-smoothing: antialiased; overflow-wrap: anywhere; word-break: normal;
}
body.modal-open { overflow: hidden; }
img, svg { max-width: 100%; }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3, h4 { line-height: 1.35; margin: 0 0 .5em; }
p { margin: 0 0 1em; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.clearfix::after { content: ""; display: table; clear: both; }
.icon { display: inline-flex; flex: none; vertical-align: middle; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--brand); color: #fff; padding: 10px 16px; z-index: 200; border-radius: 8px; }
.skip-link:focus { left: 8px; }
.boot-error { max-width: 520px; margin: 12vh auto; padding: 24px; text-align: center; }
noscript .nojs { padding: 24px; text-align: center; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 8px 16px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  line-height: 1.3; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-soft { background: var(--brand-soft); border-color: transparent; color: var(--brand); }
:root[data-theme="dark"] .btn-soft { color: var(--link); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-light { background: #fff; border-color: #fff; color: #004d66; }
.btn-light:hover { background: #e8f4f8; }
.btn-outline-light { background: transparent; border-color: rgba(255, 255, 255, .7); color: #fff; }
.btn-outline-light:hover { background: rgba(255, 255, 255, .15); }
.btn-sm { min-height: 36px; padding: 5px 12px; font-size: .9rem; border-radius: 8px; }
.btn-lg { min-height: 50px; padding: 10px 22px; font-size: 1.05rem; }
.btn-block { width: 100%; }
.btn, .chip, .badge, .tab-btn, .tabs a { white-space: nowrap; }
.btn[disabled], .btn.is-disabled { opacity: .55; pointer-events: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 42px; height: 42px; border: 0; border-radius: 10px; background: transparent;
  color: inherit; cursor: pointer; flex: none; text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); }
.input {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface);
  color: var(--text); font: inherit; font-size: 1rem; line-height: 1.5;
}
textarea.input { resize: vertical; min-height: 80px; }
select.input { padding-right: 8px; }
.input-lg { min-height: 52px; font-size: 1.1rem; }
.input-sm { min-height: 36px; padding: 4px 8px; width: auto; }
.input::placeholder { color: var(--muted); opacity: .8; }
.input:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; border-color: var(--brand); }
.field { display: block; margin: 0 0 16px; }
.field-label { display: block; font-weight: 600; margin-bottom: 6px; font-size: .95rem; }
.field-top { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.field-top .counter { margin-left: auto; }
.field-hint { display: block; font-size: .875rem; color: var(--muted); margin-top: 4px; min-height: 1.2em; }
.field-hint.ok { color: var(--ok); } .field-hint.bad { color: var(--danger); } .field-hint.warn { color: var(--warn); }
.field-error { color: var(--danger); font-size: .9rem; min-height: 1.2em; }
.field-row { display: grid; gap: 16px; grid-template-columns: 1fr; }
.counter { font-size: .8rem; color: var(--muted); } .counter.bad { color: var(--danger); font-weight: 700; }
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--brand); }
.stack { display: block; }
.row-gap { display: flex; gap: 10px; align-items: center; } .row-gap.wrap { flex-wrap: wrap; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.panel h2 { font-size: 1.15rem; }

/* ---------- badges / chips ---------- */
.badge { display: inline-block; padding: 1px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); line-height: 1.7; white-space: nowrap; }
[class*="badge type-"], .badge[class*="type-"] { background: var(--brand-soft); color: var(--brand); }
:root[data-theme="dark"] .badge[class*="type-"] { color: var(--link); }
.badge-new { background: var(--ok-soft); color: var(--ok); }
.badge-ok, .badge-approved { background: var(--ok-soft); color: var(--ok); }
.badge-pending { background: var(--warn-soft); color: var(--warn); }
.badge-rejected, .badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-withdrawn { background: var(--surface-2); color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; min-height: 34px; padding: 3px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line-strong); color: var(--text); text-decoration: none; font-size: .92rem; }
.chip:hover { background: var(--brand-soft); text-decoration: none; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip small { color: var(--muted); }
.chip-onbrand { background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .45); color: #fff; }
.chip-onbrand:hover { background: rgba(255, 255, 255, .28); }
.avatar { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff; font-weight: 700; font-size: .95rem; flex: none; }
.avatar-lg { width: 72px; height: 72px; font-size: 1.8rem; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 8px; height: calc(var(--header-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.15rem; flex: none; }
.brand:hover { text-decoration: none; }
.brand img { border-radius: 8px; }
.progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; overflow: hidden; opacity: 0; }
.progress.on { opacity: 1; transition: opacity .1s .15s; }
.progress.on::before { content: ""; display: block; height: 100%; width: 40%; background: var(--brand); animation: slide 1s infinite ease-in-out; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(260%); } }
.search { position: relative; flex: 1 1 auto; max-width: 560px; margin: 0 auto 0 12px; display: none; align-items: center; }
.search > .icon { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.search-input { width: 100%; height: 42px; padding: 0 14px 0 40px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); color: var(--text); font: inherit; font-size: 1rem; }
.search-input:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; background: var(--surface); }
.suggest { position: absolute; top: calc(100% + 6px); left: 0; right: 0; margin: 0; padding: 6px; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 70; max-height: 70vh; overflow: auto; }
.suggest a { display: block; padding: 9px 12px; border-radius: 8px; color: var(--text); text-decoration: none; }
.suggest li.active a, .suggest a:hover { background: var(--brand-soft); }
.suggest .suggest-all { color: var(--link); font-weight: 600; }
.user-slot { display: flex; flex: none; }
.search + * { margin-left: auto; }
.user-menu { position: relative; display: flex; gap: 6px; align-items: center; }
.avatar-btn { border: 0; background: transparent; padding: 4px; border-radius: 50%; cursor: pointer; }
.popover { position: absolute; right: 0; top: calc(100% + 8px); min-width: 230px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; z-index: 80; }
.popover a, .popover button { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 42px; padding: 8px 12px; border: 0; background: none; color: var(--text); font: inherit; text-align: left; text-decoration: none; border-radius: 8px; cursor: pointer; }
.popover a:hover, .popover button:hover { background: var(--surface-2); }
.popover-head { display: flex; flex-direction: column; padding: 8px 12px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.only-compact { display: inline-grid; }
.only-phone { display: inline-grid; }
.only-narrow { display: flex; }
.hide-compact { display: none; }
.announce { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 14px; background: var(--brand); color: #fff; font-size: .95rem; }
.announce .icon-btn { color: #fff; width: 34px; height: 34px; }
.announce .icon-btn:hover { background: rgba(255, 255, 255, .2); }

/* ---------- shell ---------- */
.shell { display: block; min-height: calc(100vh - var(--header-h)); min-height: calc(100dvh - var(--header-h)); }
main { display: block; width: 100%; max-width: 1180px; margin: 0 auto; padding: 16px max(14px, env(safe-area-inset-right)) calc(88px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); outline: none; min-width: 0; }
.sidebar {
  position: fixed; z-index: 70; top: 0; bottom: 0; left: 0; width: min(86vw, 310px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-right: 1px solid var(--line); padding: env(safe-area-inset-top) 10px 24px; transform: translateX(-105%);
  transition: transform .22s ease; visibility: hidden;
}
body.drawer-open .sidebar { transform: none; visibility: visible; box-shadow: var(--shadow); }
.scrim { position: fixed; inset: 0; z-index: 65; background: rgba(0, 20, 28, .5); opacity: 0; pointer-events: none; transition: opacity .2s; }
body.drawer-open .scrim { opacity: 1; pointer-events: auto; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; height: var(--header-h); }
.nav-link { display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 6px 12px; border-radius: 10px; color: var(--text); text-decoration: none; }
.nav-link:hover { background: var(--surface-2); text-decoration: none; }
.nav-link[aria-current="page"] { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
:root[data-theme="dark"] .nav-link[aria-current="page"] { color: var(--link); }
.nav-sub { padding-left: 44px; min-height: 36px; font-size: .95rem; }
.nav-title { margin: 16px 12px 4px; font-size: .8rem; font-weight: 700; color: var(--muted); }
.bottomnav {
  position: fixed; z-index: 55; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}
.bn-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 58px; color: var(--muted); text-decoration: none; font-size: .72rem; line-height: 1.2; text-align: center; }
.bn-item[aria-current="page"] { color: var(--brand); font-weight: 700; }
:root[data-theme="dark"] .bn-item[aria-current="page"] { color: var(--link); }
.bn-primary .icon { background: var(--brand); color: #fff; border-radius: 14px; width: 42px; height: 30px; align-items: center; justify-content: center; }
.bn-primary { color: var(--text); }

/* ---------- loading / empty / alerts ---------- */
.loading { display: flex; align-items: center; gap: 10px; padding: 24px; color: var(--muted); }
.spin { width: 20px; height: 20px; border: 3px solid var(--line-strong); border-top-color: var(--brand); border-radius: 50%; animation: rot .8s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty h3 { color: var(--text); margin-top: 10px; }
.alert { padding: 12px 14px; border-radius: var(--radius-sm); margin: 0 0 14px; background: var(--info-soft); border-left: 4px solid var(--brand); }
.alert-danger { background: var(--danger-soft); border-color: var(--danger); color: var(--text); }
.alert-warn { background: var(--warn-soft); border-color: var(--warn); }
.alert .row-gap { margin-top: 8px; }
.note-line { margin-top: 4px; font-size: .95rem; }
.page-pad { padding: 16px 0; }
.toasts { position: fixed; z-index: 120; left: 50%; transform: translateX(-50%); bottom: calc(76px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; width: min(92vw, 460px); pointer-events: none; }
.toast { padding: 12px 16px; background: #10242c; color: #fff; border-radius: 12px; box-shadow: var(--shadow); font-size: .95rem; animation: pop .2s ease; pointer-events: auto; }
.toast.ok { background: #0d5f3f; } .toast.error { background: #8e1d17; } .toast.out { opacity: 0; transition: opacity .3s; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- modal ---------- */
.modal-overlay { position: fixed; inset: 0; z-index: 110; background: rgba(0, 20, 28, .55); display: flex; align-items: flex-end; justify-content: center; padding: 0; }
.modal { width: 100%; max-height: 92vh; max-height: 92dvh; overflow: auto; background: var(--surface); border-radius: 18px 18px 0 0; padding: 4px 18px calc(18px + env(safe-area-inset-bottom)); box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 10px 0 6px; }
.modal-head h2 { margin: 0; font-size: 1.2rem; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
.modal-wide { max-width: 980px; }
.lightbox img { display: block; max-height: 78vh; margin: 0 auto; border-radius: 8px; }

/* ---------- cards / lists ---------- */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); margin-bottom: 18px; }
.card { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; text-decoration: none; color: var(--text); transition: box-shadow .15s, transform .15s; }
a.card:hover { box-shadow: var(--shadow); text-decoration: none; transform: translateY(-1px); }
.card-cover { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--brand-soft); }
.card-cover-empty { display: grid; place-items: center; font-size: 2.6rem; font-weight: 700; color: var(--brand); }
:root[data-theme="dark"] .card-cover-empty { color: var(--link); }
.card-body { padding: 12px 14px 14px; }
.card-body h3 { margin: 6px 0 4px; font-size: 1.1rem; }
.card-body p { margin: 0; color: var(--muted); font-size: .95rem; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.featured { display: grid; }
.featured img { width: 100%; max-height: 260px; object-fit: cover; }
.link-more { color: var(--link); font-weight: 600; }
.list { list-style: none; padding: 0; margin: 0 0 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.list > li { padding: 12px 14px; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.li-main { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.li-title { font-weight: 600; font-size: 1.05rem; }
.li-sub-link { font-size: .85rem; margin-left: auto; }
.li-meta { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.li-note { font-style: italic; }
.li-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.snippet { margin: 4px 0 0; color: var(--muted); font-size: .95rem; }
mark { background: #ffe58a; color: #222; border-radius: 3px; padding: 0 2px; }
.delta { font-family: var(--mono); font-size: .85rem; } .delta.pos { color: var(--ok); } .delta.neg { color: var(--danger); }
.plain-list { margin: 0; padding-left: 1.2rem; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 18px 0; }
.pager-info { color: var(--muted); font-size: .9rem; }
.page-title { font-size: clamp(1.5rem, 1.2rem + 1.4vw, 2.1rem); margin-bottom: 8px; }
.narrow { max-width: 780px; margin: 0 auto; }
.section { margin-bottom: 26px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.section-title { font-size: 1.3rem; margin-bottom: 10px; } .section-title.mt { margin-top: 20px; }
.filters { margin-bottom: 6px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.inline-search { display: flex; gap: 8px; margin-bottom: 12px; max-width: 480px; }
.profile-head { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 18px; }

/* ---------- home ---------- */
.hero { background: var(--brand); color: #fff; border-radius: 18px; padding: clamp(22px, 5vw, 52px) clamp(16px, 4vw, 44px); margin-bottom: 24px; }
.hero h1 { font-size: clamp(2rem, 1.4rem + 3vw, 3.4rem); margin: 0; letter-spacing: -.01em; }
.hero-sub { font-size: clamp(1.05rem, 1rem + .4vw, 1.3rem); margin: 6px 0 20px; color: rgba(255, 255, 255, .92); }
.hero-search { display: flex; flex-direction: column; gap: 10px; max-width: 680px; }
.hero-search .btn { width: 100%; }
.hero-search .input { border: 0; }
.hero-types { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 14px; }
.hero-stats { margin: 0; font-size: .95rem; color: rgba(255, 255, 255, .85); }
.two-col { display: grid; gap: 0 28px; grid-template-columns: 1fr; }
.changes .li-title { font-size: 1rem; }
.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.type-tile { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); text-decoration: none; }
.type-tile:hover { background: var(--brand-soft); text-decoration: none; }
.type-tile b { color: var(--brand); } :root[data-theme="dark"] .type-tile b { color: var(--link); }
.cta { display: grid; gap: 14px; background: var(--brand-soft); border: 1px solid var(--line); border-radius: 18px; padding: 22px; margin-top: 10px; }
.cta h2 { margin-bottom: 4px; } .cta p { margin: 0; color: var(--muted); }
.cta-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.cta .btn-light { border: 1px solid var(--brand); } .cta .btn-outline-light { color: var(--brand); border-color: var(--brand); }
:root[data-theme="dark"] .cta .btn-outline-light { color: var(--link); border-color: var(--link); }
:root[data-theme="dark"] .cta .btn-light { background: var(--brand); color: #fff; }

/* ---------- article ---------- */
.article-layout { display: block; }
.article { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(14px, 3vw, 32px); }
.narrow.article { margin-top: 0; }
.article-head { margin-bottom: 4px; }
.article-head h1 { font-size: clamp(1.8rem, 1.3rem + 2vw, 2.6rem); margin: 8px 0 4px; line-height: 1.3; }
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin: 8px 0 16px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a, .tab-btn { display: inline-flex; align-items: center; gap: 6px; padding: 10px 14px; min-height: 44px; color: var(--muted); text-decoration: none; white-space: nowrap; border: 0; background: none; font: inherit; border-bottom: 3px solid transparent; cursor: pointer; margin-bottom: -1px; }
.tabs a:hover, .tab-btn:hover { color: var(--text); text-decoration: none; }
.tabs a.on, .tab-btn.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 700; }
:root[data-theme="dark"] .tabs a.on, :root[data-theme="dark"] .tab-btn.on { color: var(--link); border-bottom-color: var(--link); }
.tab-btn.danger { color: var(--danger); }
.tabs-extra { display: inline-flex; margin-left: auto; }
.lead { font-size: 1.12rem; color: var(--muted); border-left: 4px solid var(--brand); padding-left: 14px; margin-bottom: 18px; }
.toc-inline { background: var(--brand-tint); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 14px; margin-bottom: 16px; }
.toc-inline summary { cursor: pointer; font-weight: 600; min-height: 36px; display: flex; align-items: center; }
.toc-list { list-style: none; margin: 0; padding: 0 0 6px; }
.toc-list a { display: block; padding: 5px 0; color: var(--text); text-decoration: none; font-size: .95rem; }
.toc-list a:hover { color: var(--link); }
.toc-list .toc-3 { padding-left: 16px; }
.toc-col { display: none; }
.article-tags { margin-top: 20px; }
.article-foot { margin-top: 24px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: .92rem; }
.foot-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.backlinks { margin-top: 16px; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 4px 14px; }
.backlinks summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; font-weight: 600; }
.backlinks-body { padding-bottom: 10px; }

.prose { font-size: 1.0625rem; line-height: 1.85; }
.prose h2 { font-size: 1.55rem; margin: 1.7em 0 .5em; padding-bottom: .25em; border-bottom: 1px solid var(--line); scroll-margin-top: calc(var(--header-h) + 12px); }
.prose h3 { font-size: 1.28rem; margin: 1.5em 0 .4em; scroll-margin-top: calc(var(--header-h) + 12px); }
.prose h4, .prose h5, .prose h6 { font-size: 1.1rem; margin: 1.3em 0 .3em; scroll-margin-top: calc(var(--header-h) + 12px); }
.prose > :first-child { margin-top: 0; }
.prose ul, .prose ol { padding-left: 1.5em; margin: 0 0 1em; } .prose li { margin: .2em 0; } .prose li > ul, .prose li > ol { margin: .2em 0; }
.prose blockquote { margin: 1em 0; padding: .5em 1em; border-left: 4px solid var(--brand); background: var(--brand-tint); border-radius: 0 8px 8px 0; color: var(--muted); }
.prose blockquote p:last-child { margin: 0; }
.prose code { font-family: var(--mono); background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: .92em; }
.prose pre { background: var(--surface-2); padding: 12px 14px; border-radius: 10px; overflow-x: auto; }
.prose pre code { background: none; padding: 0; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 1.6em 0; }
.prose img { height: auto; border-radius: 8px; cursor: zoom-in; }
.prose figure { margin: 1.2em 0; text-align: center; } .prose figcaption { color: var(--muted); font-size: .9rem; margin-top: 4px; }
.prose a.wikilink { text-decoration-style: dotted; } .prose a.wikilink.new { color: var(--danger); }
.prose a.ext::after { content: " ↗"; font-size: .75em; }
.prose sup.fnref a { text-decoration: none; padding: 0 2px; } .prose .references { margin-top: 2em; font-size: .95rem; } .prose .references li { scroll-margin-top: 80px; }
.fnback { text-decoration: none; }
.table-wrap { overflow-x: auto; margin: 1em 0; -webkit-overflow-scrolling: touch; }
.prose table { border-collapse: collapse; min-width: 100%; font-size: .97rem; }
.prose th, .prose td { border: 1px solid var(--line-strong); padding: 7px 12px; text-align: left; vertical-align: top; }
.prose th { background: var(--brand-soft); } .al-center { text-align: center !important; } .al-right { text-align: right !important; }
.infobox { width: 100%; margin: 0 0 18px; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; background: var(--surface); font-size: .95rem; line-height: 1.6; }
.infobox-head { background: var(--brand); color: #fff; text-align: center; font-weight: 700; padding: 10px 12px; font-size: 1.05rem; }
.infobox-img { display: block; width: 100%; max-height: 340px; object-fit: cover; }
.infobox dl { margin: 0; }
.infobox dt { font-weight: 700; padding: 8px 12px 0; color: var(--muted); font-size: .85rem; }
.infobox dd { margin: 0; padding: 0 12px 8px; border-bottom: 1px solid var(--line); }
.infobox dd:last-child { border-bottom: 0; }
.review-head h2 { margin-bottom: 4px; }
.review-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }

/* ---------- editor ---------- */
.editor { max-width: 1240px; margin: 0 auto; }
.editor-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; } .editor-head .save-state { margin-left: auto; }
.tag-input { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); min-height: 44px; align-items: center; cursor: text; }
.tag-input:focus-within { outline: 3px solid var(--focus); border-color: var(--brand); }
.tag-field { flex: 1 1 120px; min-width: 100px; border: 0; background: transparent; font: inherit; color: var(--text); outline: none; min-height: 30px; }
.chip-tag { min-height: 30px; padding: 0 4px 0 12px; background: var(--brand-soft); border-color: transparent; }
.chip-tag button { border: 0; background: none; color: inherit; cursor: pointer; font-size: 1.1rem; width: 28px; height: 28px; border-radius: 50%; }
.fold { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); margin-bottom: 16px; }
.fold > summary { cursor: pointer; padding: 12px 14px; font-weight: 600; min-height: 46px; }
.fold-body { padding: 0 14px 14px; } .fold-body h3 { font-size: 1rem; margin: 10px 0 8px; }
.cover-box { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; } .cover-preview { width: 180px; height: 110px; object-fit: cover; border-radius: 8px; }
.info-rows { display: grid; gap: 8px; margin-bottom: 10px; }
.info-row { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: center; }
.info-row .input:first-child { grid-column: 1 / 2; } .info-row .input:nth-child(2) { grid-column: 1 / 2; } .info-row .icon-btn { grid-column: 2; grid-row: 1 / 3; }
.editor-tabs { gap: 6px; margin-bottom: 8px; }
.editor-tabs .tab-btn { flex: 1; justify-content: center; border: 1px solid var(--line-strong); border-radius: 10px; margin: 0; }
.editor-tabs .tab-btn.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.editor-content { display: block; }
.editor-content[data-tab="write"] .pane-preview, .editor-content[data-tab="preview"] .pane-write { display: none; }
.toolbar { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px; border: 1px solid var(--line-strong); border-bottom: 0; border-radius: 10px 10px 0 0; background: var(--surface-2); position: sticky; top: calc(var(--header-h) + env(safe-area-inset-top)); z-index: 5; }
.tb-btn { display: inline-grid; place-items: center; min-width: 40px; height: 40px; border: 0; border-radius: 8px; background: transparent; color: var(--text); cursor: pointer; font: inherit; font-weight: 700; }
.tb-btn:hover { background: var(--surface); } .tb-text { font-size: .85rem; padding: 0 6px; }
.editor-text { border-radius: 0 0 10px 10px; min-height: 56vh; font-family: var(--mono); font-size: 1rem; line-height: 1.7; resize: vertical; tab-size: 2; }
.pane-preview { border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--bg); max-height: 90vh; overflow: auto; }
.pane-label { font-size: .8rem; color: var(--muted); padding: 4px 8px; }
.preview-box .article { border: 0; padding: 8px; background: transparent; }
.action-bar { position: sticky; bottom: calc(58px + env(safe-area-inset-bottom)); z-index: 6; display: flex; gap: 10px; justify-content: flex-end; padding: 10px 0; background: linear-gradient(to top, var(--bg) 70%, transparent); }
.action-bar .btn-primary { flex: 1; max-width: 320px; }

/* ---------- misc pages ---------- */
.auth-card { max-width: 440px; margin: 4vh auto; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 24px; }
.auth-card h1 { font-size: 1.6rem; }
.search-page-form { display: grid; gap: 10px; grid-template-columns: 1fr; margin-bottom: 14px; }
.results-list .li-title { font-size: 1.12rem; }
.help-grid { display: grid; gap: 18px; grid-template-columns: 1fr; margin: 14px 0; }
.code-sample { background: var(--surface-2); padding: 12px; border-radius: 10px; overflow: auto; font-family: var(--mono); font-size: .9rem; line-height: 1.6; white-space: pre-wrap; margin: 0; }
.prose-page h2 { margin-top: 1.4em; }
.admin-tabs { margin-top: 0; }
.stat-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-bottom: 16px; }
.stat-card { display: flex; flex-direction: column; gap: 2px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--text); }
.stat-card b { font-size: 1.8rem; line-height: 1.2; color: var(--brand); } :root[data-theme="dark"] .stat-card b { color: var(--link); }
.stat-card span { color: var(--muted); font-size: .9rem; } .stat-card.warn { border-color: var(--warn); background: var(--warn-soft); } .stat-card:hover { text-decoration: none; background: var(--brand-soft); }
.media-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); margin-bottom: 16px; }
.media-item { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.media-item img { width: 100%; height: 130px; object-fit: contain; background: var(--surface-2); display: block; }
.media-item figcaption { padding: 8px 10px; font-size: .85rem; display: grid; gap: 4px; justify-items: start; }

/* ---------- diff ---------- */
.diff { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); font-size: .95rem; margin-bottom: 18px; }
.d-line { display: grid; grid-template-columns: 28px 1fr; line-height: 1.6; }
.d-sign { text-align: center; color: var(--muted); font-family: var(--mono); user-select: none; }
.d-text { white-space: pre-wrap; padding: 2px 8px 2px 0; min-width: 0; overflow-wrap: anywhere; }
.d-add { background: var(--ok-soft); } .d-add .d-sign { color: var(--ok); font-weight: 700; } .d-add mark { background: rgba(23, 114, 74, .3); color: inherit; }
.d-del { background: var(--danger-soft); } .d-del .d-sign { color: var(--danger); font-weight: 700; } .d-del mark { background: rgba(179, 38, 30, .28); color: inherit; text-decoration: line-through; }
.d-fold { padding: 4px 12px; text-align: center; color: var(--muted); background: var(--surface-2); font-size: .85rem; }
.meta-changes { margin-bottom: 14px; display: grid; gap: 8px; }
.meta-row { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 12px; background: var(--surface); }
.meta-vals > div { white-space: pre-wrap; padding: 2px 6px; border-radius: 4px; margin-top: 2px; }
.meta-vals .d-del { text-decoration: line-through; opacity: .85; }

/* ---------- tablet 640+ ---------- */
@media (min-width: 640px) {
  .hero-search { flex-direction: row; }
  .hero-search .btn { width: auto; }
  .search { display: flex; }
  .only-phone { display: none; }
  .hide-compact { display: inline-flex; }
  .field-row { grid-template-columns: 220px 1fr; }
  .search-page-form { grid-template-columns: 1fr 200px; }
  .modal-overlay { align-items: center; padding: 20px; }
  .modal { max-width: 520px; border-radius: 18px; padding-bottom: 18px; }
  .modal-wide { max-width: 980px; }
  .cta { grid-template-columns: 1fr auto; align-items: center; }
  .info-row { grid-template-columns: 200px 1fr auto; }
  .info-row .input:first-child, .info-row .input:nth-child(2), .info-row .icon-btn { grid-column: auto; grid-row: auto; }
  .help-grid { grid-template-columns: 1fr 1fr; }
  .toasts { bottom: calc(78px + env(safe-area-inset-bottom)); }
}
@media (min-width: 720px) {
  .infobox { float: right; width: 310px; margin: 4px 0 14px 24px; }
  .two-col { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
  main { padding-left: max(24px, env(safe-area-inset-left)); padding-right: max(24px, env(safe-area-inset-right)); }
}
/* ---------- desktop / landscape iPad 1024+ ---------- */
@media (min-width: 1024px) {
  .shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .sidebar { position: sticky; top: calc(var(--header-h) + env(safe-area-inset-top)); height: calc(100vh - var(--header-h)); height: calc(100dvh - var(--header-h)); width: auto; transform: none; visibility: visible; border-right: 1px solid var(--line); padding-top: 12px; box-shadow: none !important; }
  .scrim { display: none; }
  .only-compact { display: none !important; }
  .bottomnav { display: none; }
  main { padding-bottom: 48px; }
  .action-bar { bottom: 0; }
  .toasts { bottom: 24px; }
  .toast { }
}
@media (min-width: 1100px) {
  .only-narrow { display: none; }
  .editor-content { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; align-items: start; }
  .editor-content[data-tab] .pane { display: block !important; }
  .editor-text { min-height: 62vh; }
  .pane-preview { position: sticky; top: calc(var(--header-h) + 12px); max-height: calc(100vh - var(--header-h) - 28px); }
}
@media (min-width: 1280px) {
  .article-layout { display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 24px; align-items: start; }
  .toc-col { display: block; }
  .toc-sticky { position: sticky; top: calc(var(--header-h) + 16px); max-height: calc(100vh - var(--header-h) - 32px); overflow: auto; }
  .toc-sticky .btn { width: 100%; margin-bottom: 14px; }
  .toc-title { font-size: .95rem; color: var(--muted); }
  .toc-inline { display: none; }
}
@media (pointer: coarse) {
  .btn-sm { min-height: 40px; }
  .chip { min-height: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media print {
  .topbar, .sidebar, .bottomnav, .tabs, .toc-col, .announce, .foot-actions, .backlinks, .scrim, .toasts, .action-bar { display: none !important; }
  .shell { display: block; } body { background: #fff; color: #000; } .article { border: 0; padding: 0; }
  a { color: #000; } .prose a.ext::after { content: " (" attr(href) ")"; font-size: .8em; }
}
