/* ===========================================================
   Slow Compact · App / style.css
   Design tokens inherited from ../website/style.css.
   Reading-app layouts (library + reader) only.
   =========================================================== */

:root {
  --font-serif-cjk: "Noto Serif SC", "Source Han Serif SC", "Songti SC", serif;
  --font-sans-cjk: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", sans-serif;
  --font-serif-latin: "EB Garamond", "Iowan Old Style", Georgia, serif;
  --font-sans-latin: "Inter", -apple-system, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, monospace;

  /* Neutral shell */
  --ink: #1a1814;
  --paper: #f3efe6;
  --paper-2: #e8e2d3;
  --rule: #1a181433;
  --rule-soft: #1a181418;
  --muted: #6b6458;

  /* Species accents (used in POV badges and library card stripes) */
  --eoani: #b8431e;
  --ketoi: #1b4f72;
  --huvari: #00d9ff;
  --thavari: #00ffc8;
  --human:  #0a0e1a;
}

/* ---- Dark theme (default) ---- */
[data-theme="dark"] {
  --ink: #e8e2d6;
  --paper: #0e0d0b;
  --paper-2: #1a1815;
  --rule: #e8e2d622;
  --rule-soft: #e8e2d612;
  --muted: #9a9488;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-serif-cjk);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body { min-height: 100vh; min-width: 1280px; }

a { color: inherit; text-decoration: none; }
a.underline { border-bottom: 1px solid currentColor; }
a:hover.underline { opacity: 0.7; }

button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; padding: 0; }

::selection { background: var(--ink); color: var(--paper); }

.cjk-en { font-family: var(--font-serif-latin); font-style: italic; opacity: 0.78; font-size: 0.92em; }
.num { font-family: var(--font-mono); font-feature-settings: "tnum"; }

/* -------------------------------------------------------------------
   Global navigation
   ------------------------------------------------------------------- */

.g-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 18px 48px;
  border-bottom: 1px solid var(--rule-soft);
  backdrop-filter: blur(8px);
  background: color-mix(in oklab, var(--paper) 85%, transparent);
}

.g-nav__left { display: flex; align-items: center; }
.g-nav__brand {
  font-family: var(--font-serif-cjk);
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 0.12em;
  display: flex;
  align-items: center;
  gap: 12px;
}
.g-nav__brand-mark {
  width: 22px; height: 22px;
  border: 1px solid currentColor;
}

.g-nav__center { display: flex; gap: 32px; justify-content: center; font-size: 13px; letter-spacing: 0.08em; }
.g-nav__center a { padding: 4px 0; border-bottom: 1px solid transparent; }
.g-nav__center a:hover { border-bottom-color: currentColor; }

.g-nav__right { display: flex; align-items: center; gap: 18px; justify-content: flex-end; }
.g-nav__outlink { font-size: 12px; letter-spacing: 0.08em; opacity: 0.7; }
.g-nav__outlink:hover { opacity: 1; }
.g-nav__user {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}
.g-nav__email-toggle,
.g-nav__signout {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 9px;
  border: 1px solid var(--rule);
  color: var(--muted);
}
.g-nav__email-toggle:hover,
.g-nav__signout:hover { color: var(--ink); border-color: var(--ink); }
.g-nav__lang {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid currentColor;
  opacity: 0.85;
}
.g-nav__lang:hover { opacity: 1; }
.g-nav__theme {
  font-size: 14px;
  padding: 4px 8px;
  opacity: 0.85;
  line-height: 1;
}
.g-nav__theme:hover { opacity: 1; }

/* -------------------------------------------------------------------
   Auth gate
   ------------------------------------------------------------------- */

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 64px 24px;
  position: relative;
}

.auth-chrome {
  position: fixed;
  top: 18px;
  right: 24px;
  display: flex;
  gap: 12px;
  align-items: center;
  z-index: 10;
}

.auth-panel {
  width: min(560px, calc(100vw - 48px));
  border: 1px solid var(--rule-soft);
  padding: 42px 44px 46px;
  background: color-mix(in oklab, var(--paper) 78%, transparent);
}

.auth-kicker {
  margin: 0 0 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.auth-panel h1 {
  margin: 0 0 16px;
  font-weight: 500;
  font-size: 28px;
  line-height: 1.25;
}

.auth-panel p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 15px;
}

.auth-note {
  font-family: var(--font-mono);
  font-size: 11px !important;
}

.auth-email {
  font-family: var(--font-mono);
  color: var(--ink);
}

.auth-email-toggle {
  display: inline;
  border-bottom: 1px solid currentColor;
  color: var(--ink);
  font-size: inherit;
}

.auth-primary {
  margin-top: 10px;
  padding: 10px 16px;
  border: 1px solid var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--paper);
  background: var(--ink);
}

.auth-primary:disabled {
  cursor: wait;
  opacity: 0.6;
}

/* -------------------------------------------------------------------
   Library page (route '/')
   ------------------------------------------------------------------- */

.library {
  max-width: 1100px;
  margin: 0 auto;
  padding: 64px 48px 96px;
}
.library h1 {
  font-weight: 500;
  font-size: 28px;
  letter-spacing: 0.06em;
  margin: 0 0 8px;
}
.library .lib-meta {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 48px;
}

.lib-section { margin-bottom: 56px; }
.lib-section-title {
  font-family: var(--font-serif-cjk);
  font-weight: 500;
  font-size: 18px;
  letter-spacing: 0.08em;
  margin: 0 0 24px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule-soft);
}

.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 28px;
}

.lib-card {
  display: block;
  padding: 24px 24px 28px 32px;
  border: 1px solid var(--rule-soft);
  background: color-mix(in oklab, var(--paper) 70%, transparent);
  transition: border-color 200ms ease;
  cursor: pointer;
  position: relative;
}
.lib-card:hover { border-color: var(--rule); }
.lib-card .lib-accent {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 3px;
}
.lib-card .lib-title-zh {
  font-size: 19px;
  font-weight: 500;
  line-height: 1.3;
  margin: 0 0 4px;
}
.lib-card .lib-title-en {
  font-family: var(--font-serif-latin);
  font-style: italic;
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 16px;
}
.lib-card .lib-summary {
  font-size: 14px;
  color: var(--ink);
  opacity: 0.86;
  margin: 12px 0;
}
.lib-card .lib-foot {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
  margin-top: 18px;
}
.lib-card .lib-foot .num { color: var(--ink); opacity: 0.7; }

.pov-badge {
  font-family: var(--font-sans-latin);
  font-size: 11px;
  letter-spacing: 0.08em;
  padding: 2px 8px;
  border: 1px solid;
  text-transform: uppercase;
  white-space: nowrap;
}

/* -------------------------------------------------------------------
   Reader page (route '/read/:type/:slug')
   ------------------------------------------------------------------- */

.reader {
  max-width: 720px;
  margin: 0 auto;
  padding: 56px 24px 120px;
}
.reader .back-link {
  display: inline-block;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 32px;
}
.reader .back-link:hover { color: var(--ink); }
.reader header {
  margin-bottom: 48px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--rule-soft);
}
.reader h1 {
  font-size: 32px;
  font-weight: 500;
  line-height: 1.3;
  margin: 0 0 6px;
}
.reader .reader-en-title {
  font-family: var(--font-serif-latin);
  font-style: italic;
  color: var(--muted);
  font-size: 16px;
  margin: 0 0 20px;
}
.reader .reader-meta {
  display: flex;
  gap: 16px;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  margin-top: 12px;
}

.reader-body { font-size: 17px; line-height: 1.85; }
.reader-body h1, .reader-body h2, .reader-body h3 {
  font-weight: 500;
  line-height: 1.3;
  margin: 2em 0 0.6em;
}
.reader-body h2 {
  font-size: 22px;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--rule-soft);
  padding-bottom: 0.4em;
}
.reader-body h3 { font-size: 18px; }
.reader-body p { margin: 1.1em 0; }
.reader-body em { font-family: var(--font-serif-latin); font-style: italic; }
.reader-body strong { font-weight: 600; }
.reader-body blockquote {
  margin: 1.4em 0;
  padding: 0.4em 1.4em;
  border-left: 2px solid var(--rule);
  color: var(--muted);
}
.reader-body code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--paper-2);
  padding: 0.1em 0.4em;
}
.reader-body hr {
  border: 0;
  border-top: 1px solid var(--rule-soft);
  margin: 2em 0;
}

.reader .interactive-mount {
  margin: 48px -24px;
  padding: 32px 24px;
  border-top: 1px solid var(--rule-soft);
  border-bottom: 1px solid var(--rule-soft);
  background: color-mix(in oklab, var(--paper) 60%, transparent);
}

/* -------------------------------------------------------------------
   Notice (loading / empty / error)
   ------------------------------------------------------------------- */

.notice {
  max-width: 560px;
  margin: 96px auto;
  padding: 48px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--rule);
  font-size: 14px;
}
.notice p { margin: 0.8em 0; }
.notice code {
  font-family: var(--font-mono);
  background: var(--paper-2);
  padding: 0.15em 0.5em;
}

/* -------------------------------------------------------------------
   Footer
   ------------------------------------------------------------------- */

.site-footer {
  padding: 24px 48px;
  border-top: 1px solid var(--rule-soft);
  color: var(--muted);
  font-size: 12px;
}
.site-footer .sep { margin: 0 8px; opacity: 0.4; }

/* -------------------------------------------------------------------
   Interactive: Species Anatomy Explorer (.sx-*)
   Self-contained dark-themed explorer with per-species color schemes.
   ------------------------------------------------------------------- */

.interactive-mount:has(.sx-root),
.interactive-mount:has(.ssx-root),
.interactive-mount:has(.ssx-shell) {
  padding: 0;
  background: transparent;
  border: none;
  /* Break out of the 720px reader column to full viewport width */
  width: 100vw;
  position: relative;
  left: 50%;
  right: 50%;
  margin-left: -50vw;
  margin-right: -50vw;
  overflow: visible;
}

.sx-root {
  width: min(calc(100vw - 32px), 1400px);
  margin: 28px auto;
  padding: 28px 32px 32px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--rule);
  transition: background 380ms ease, color 380ms ease, border-color 380ms ease;
  position: relative;
  overflow: hidden;
}
.sx-root::before {
  content: "";
  position: absolute; inset: 0;
  background:
    linear-gradient(180deg, var(--bg2) 0%, transparent 30%),
    radial-gradient(60% 50% at 80% 0%, var(--ember) 0%, transparent 70%);
  opacity: 0.55;
  pointer-events: none;
}
.sx-root > * { position: relative; z-index: 1; }

.sx-header {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 32px;
  align-items: end;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--rule);
}
.sx-supertitle {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 6px;
}
.sx-title {
  font-family: var(--font-serif-cjk);
  font-weight: 600;
  font-size: 38px;
  line-height: 1.1;
  margin: 0 0 8px;
  color: var(--fg);
  letter-spacing: 0.02em;
}
.sx-subtitle {
  font-family: var(--font-serif-cjk);
  font-size: 15px;
  color: var(--muted);
}
.sx-header-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  border-left: 1px solid var(--rule);
  padding-left: 24px;
}
.sx-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--rule);
}
.sx-meta-row:last-child { border-bottom: none; }
.sx-meta-k { color: var(--muted); }
.sx-meta-v { color: var(--fg); text-align: right; }

.sx-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--rule);
  margin-top: 4px;
}
.sx-tab {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 18px 16px 16px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  color: var(--muted);
  transition: color 220ms ease, border-color 220ms ease, background 220ms ease;
}
.sx-tab:hover { background: rgba(255,255,255,0.03); color: var(--fg); }
.sx-tab-name {
  font-family: var(--font-serif-cjk);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.sx-tab-en {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  margin-top: 4px;
  opacity: 0.85;
}

.sx-main {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 28px;
  padding-top: 28px;
}
.sx-anatomy {
  border: 1px solid var(--rule);
  background: var(--bg2);
  display: flex;
  flex-direction: column;
  min-height: 720px;
}
.sx-anatomy-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--rule);
}
.sx-anatomy-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.08em;
}
.sx-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg);
  cursor: pointer;
}
.sx-toggle input { accent-color: var(--accent); }
.sx-anatomy-frame {
  flex: 1;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sx-anatomy-foot {
  display: flex;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid var(--rule);
  font-size: 10px;
  color: var(--muted);
}
.sx-mono { font-family: var(--font-mono); }

.sx-side {
  display: flex;
  flex-direction: column;
}
.sx-detail {
  border: 1px solid var(--rule);
  background: var(--bg2);
  flex: 1;
  display: flex;
  flex-direction: column;
}
.sx-detail-empty .sx-detail-prompt {
  padding: 28px;
  border-bottom: 1px solid var(--rule);
  display: flex;
  gap: 18px;
  align-items: flex-start;
}
.sx-detail-prompt-mark {
  font-family: var(--font-serif-cjk);
  font-size: 36px;
  color: var(--accent);
  line-height: 0.6;
}
.sx-detail-prompt-text {
  font-family: var(--font-serif-cjk);
  font-size: 15px;
  color: var(--fg);
  line-height: 1.7;
}
.sx-detail-meta {
  padding: 16px 24px;
  font-family: var(--font-mono);
  font-size: 11px;
}
.sx-detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(180deg, rgba(255,255,255,0.03), transparent);
}
.sx-detail-name {
  font-family: var(--font-serif-cjk);
  font-size: 22px;
  font-weight: 600;
  color: var(--fg);
}
.sx-detail-name-en {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  margin-top: 4px;
  letter-spacing: 0.08em;
}
.sx-close {
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--muted);
  width: 28px; height: 28px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  font-family: var(--font-mono);
}
.sx-close:hover { color: var(--fg); border-color: var(--accent); }

.sx-detail-body { padding: 18px 22px 22px; overflow-y: auto; }
.sx-detail-desc {
  font-family: var(--font-serif-cjk);
  font-size: 14px;
  line-height: 1.75;
  color: var(--fg);
  margin: 0 0 22px;
  text-wrap: pretty;
}
.sx-section-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 18px 0 10px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--rule);
}
.sx-params {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 11px;
}
.sx-params td {
  padding: 6px 0;
  border-bottom: 1px dashed var(--rule);
  vertical-align: top;
}
.sx-param-k { color: var(--muted); width: 38%; }
.sx-param-v { color: var(--fg); text-align: right; }

.sx-ai-block { font-size: 12px; }
.sx-ai-row {
  display: grid;
  grid-template-columns: 60px 1fr;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--rule);
}
.sx-ai-k {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding-top: 2px;
}
.sx-ai-v {
  font-family: var(--font-sans-cjk);
  color: var(--fg);
  line-height: 1.6;
}
.sx-ai-flow { font-family: var(--font-mono); font-size: 11px; }
.sx-ai-note {
  margin-top: 14px;
  padding: 12px 14px;
  border-left: 2px solid var(--accent);
  background: rgba(255,255,255,0.03);
  font-family: var(--font-serif-cjk);
  font-size: 13px;
  line-height: 1.7;
  color: var(--fg);
}

.sx-pipeline {
  margin-top: 28px;
  padding: 22px 24px 18px;
  border: 1px solid var(--rule);
  background: var(--bg2);
}
.sx-pipeline-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 8px;
}
.sx-pipeline-name {
  font-family: var(--font-serif-cjk);
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
}
.sx-pipeline-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}

.sx-footnote {
  display: flex;
  justify-content: space-between;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.06em;
}

/* human (light theme) tweaks */
.sx-root[style*="--bg: #f8f9fa"] .sx-anatomy,
.sx-root[style*="--bg: #f8f9fa"] .sx-detail,
.sx-root[style*="--bg: #f8f9fa"] .sx-pipeline {
  background: rgba(0,0,0,0.02);
}
.sx-root[style*="--bg: #f8f9fa"] .sx-tab:hover { background: rgba(0,0,0,0.04); }
.sx-root[style*="--bg: #f8f9fa"] .sx-detail-head {
  background: linear-gradient(180deg, rgba(0,0,0,0.02), transparent);
}
.sx-root[style*="--bg: #f8f9fa"] .sx-ai-note { background: rgba(0,0,0,0.04); }
