/* ==========================================================================
   SakuraEntropia — Minimal Editorial Design
   Inspired by: Anthropic, Apple, Linear
   ========================================================================== */

:root {
  /* Dark (default) */
  --bg:        #0a0a0b;
  --bg-raised: #111113;
  --bg-card:   #17171a;
  --border:    rgba(255,255,255,0.08);
  --border-em: rgba(255,255,255,0.14);

  --fg:        #f2f2f3;
  --fg-muted:  #888891;
  --fg-dim:    #55555e;

  --accent:    #c9a0dc;        /* soft purple — editorial, not neon */
  --accent-hl: rgba(201,160,220,0.12);

  --mono: "SF Mono", "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --serif: "New York", "Charter", "Georgia", "Cambria", "Noto Serif", serif;

  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;

  --nav-h: 60px;
}

[data-theme="light"] {
  --bg:        #fafaf9;
  --bg-raised: #f4f4f2;
  --bg-card:   #ffffff;
  --border:    rgba(0,0,0,0.07);
  --border-em: rgba(0,0,0,0.13);

  --fg:        #111112;
  --fg-muted:  #666672;
  --fg-dim:    #aaaaaa;

  --accent:    #7c3aed;
  --accent-hl: rgba(124,58,237,0.08);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }

/* ── Progress ── */
#progress-bar {
  position: fixed; top: 0; left: 0;
  height: 2px; width: 0;
  background: var(--accent);
  z-index: 999;
  transition: width .1s linear;
}

/* ── Header ── */
.header {
  position: sticky; top: 0;
  height: var(--nav-h);
  background: rgba(10,10,11,.82);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  border-bottom: 1px solid var(--border);
  z-index: 90;
  transition: background .2s;
}
[data-theme="light"] .header {
  background: rgba(250,250,249,.85);
}
.nav {
  max-width: 1360px; margin: 0 auto;
  height: 100%; padding: 0 28px;
  display: flex; align-items: center; gap: 0;
}

/* Logo */
.logo {
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0; margin-right: 32px;
  color: var(--fg);
}
.logo-mark {
  font-family: var(--serif);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--accent);
  line-height: 1;
}
.logo-mark.small { font-size: 1rem; }
.logo-name {
  font-size: .875rem;
  font-weight: 600;
  color: var(--fg-muted);
  letter-spacing: -.01em;
}

/* Nav tabs */
.nav-tabs {
  display: flex; gap: 2px; flex: 1;
}
.tab-btn, .tab {
  /* disambiguation: .tab is page section, .nav .tab is button */
}
.nav-tabs .tab {   /* this only matches button.tab inside .nav-tabs */
  background: none;
  font-size: .875rem;
  font-weight: 500;
  color: var(--fg-muted);
  padding: 7px 14px;
  border-radius: var(--r-sm);
  transition: color .15s, background .15s;
}
.nav-tabs .tab:hover { color: var(--fg); background: rgba(255,255,255,.05); }
.nav-tabs .tab.active { color: var(--fg); background: rgba(255,255,255,.08); }
[data-theme="light"] .nav-tabs .tab:hover { background: rgba(0,0,0,.05); }
[data-theme="light"] .nav-tabs .tab.active { background: rgba(0,0,0,.07); }

/* Nav actions */
.nav-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.icon-btn {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--fg-muted);
  border-radius: var(--r-sm);
  transition: color .15s, background .15s;
}
.icon-btn:hover { color: var(--fg); background: rgba(255,255,255,.07); }
[data-theme="light"] .icon-btn:hover { background: rgba(0,0,0,.06); }

.pill-btn {
  height: 32px; padding: 0 12px;
  font-size: .78rem; font-weight: 600;
  color: var(--fg-muted);
  border: 1px solid var(--border-em);
  border-radius: 999px;
  transition: color .15s, border-color .15s;
  letter-spacing: .02em;
}
.pill-btn:hover { color: var(--fg); border-color: var(--accent); }

/* ── Search ── */
#search-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 18vh;
}
#search-overlay[hidden] { display: none; }
.search-box {
  width: 100%; max-width: 580px;
  background: var(--bg-card);
  border: 1px solid var(--border-em);
  border-radius: var(--r-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  overflow: hidden;
  animation: pop .18s ease-out;
}
@keyframes pop { from { opacity:0; transform: scale(.96) } to { opacity:1; transform: scale(1) } }
.search-row {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  color: var(--fg-muted);
}
#search-input {
  flex: 1; background: none; border: none; outline: none;
  font: .95rem var(--sans);
  color: var(--fg);
}
#search-results { max-height: 360px; overflow-y: auto; padding: 8px; }
.sr-item {
  padding: 10px 12px; border-radius: var(--r-sm); cursor: pointer;
  transition: background .12s;
}
.sr-item:hover, .sr-item.sel { background: rgba(255,255,255,.06); }
[data-theme="light"] .sr-item:hover { background: rgba(0,0,0,.05); }
.sr-title { font-size: .875rem; font-weight: 600; }
.sr-snip  { font-size: .78rem; color: var(--fg-muted); margin-top: 2px; line-height: 1.4; }

/* ── Layout ── */
.layout {
  max-width: 1360px; margin: 0 auto;
  width: 100%; padding: 36px 28px;
  display: flex; gap: 48px; flex: 1;
  align-items: flex-start;
}
.main { flex: 1; min-width: 0; }

/* ── Sidebar ── */
#sidebar {
  width: 220px; flex-shrink: 0;
  position: sticky; top: calc(var(--nav-h) + 24px);
  max-height: calc(100vh - var(--nav-h) - 48px);
  display: flex; flex-direction: column; gap: 12px;
  overflow: hidden;
}
.toc-header {
  display: flex; justify-content: space-between; align-items: center;
}
.toc-label {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--fg-dim);
}
#pct-badge {
  font-family: var(--mono); font-size: .72rem;
  color: var(--accent); font-weight: 600;
}
#toc-filter {
  width: 100%; padding: 7px 10px;
  font: .78rem var(--sans);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--fg); outline: none;
  transition: border-color .15s;
}
#toc-filter:focus { border-color: var(--accent); }
#toc-nav {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.toc-link {
  display: block;
  font-size: .78rem; color: var(--fg-muted);
  padding: 5px 8px;
  border-radius: 7px;
  line-height: 1.4;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color .12s, background .12s;
  border-left: 2px solid transparent;
}
.toc-link:hover { color: var(--fg); background: rgba(255,255,255,.04); }
.toc-link.active {
  color: var(--accent); font-weight: 600;
  border-left-color: var(--accent);
  background: var(--accent-hl);
}
.toc-link.h3 { padding-left: 18px; font-size: .73rem; color: var(--fg-dim); }
.sidebar-meta {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex; flex-direction: column; gap: 5px;
}
.meta-row {
  display: flex; justify-content: space-between;
  font-size: .73rem;
  color: var(--fg-dim);
}
.meta-row span:last-child { font-family: var(--mono); color: var(--fg-muted); }

/* ── Tab sections ── */
section.tab { display: none; }
section.tab.active { display: block; animation: fadeUp .2s ease-out; }
@keyframes fadeUp { from { opacity:0; transform: translateY(8px) } to { opacity:1; transform: translateY(0) } }

/* ── Hero ── */
.hero {
  display: flex; align-items: center; gap: 36px;
  margin-bottom: 56px; padding-bottom: 48px;
  border-bottom: 1px solid var(--border);
}
.hero-text { flex: 1; min-width: 0; }
.hero-avatar {
  flex-shrink: 0;
  width: 108px; height: 108px;
  border-radius: var(--r-lg);
  overflow: hidden;
  border: 1px solid var(--border-em);
  box-shadow: 0 8px 32px rgba(0,0,0,.35);
}
.avatar-img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.hero-eyebrow {
  font-size: .78rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--fg-dim); margin-bottom: 10px;
}
.hero-h1 {
  font-size: 2rem; font-weight: 700; letter-spacing: -.03em;
  line-height: 1.2; margin-bottom: 12px;
}
.hero-sub {
  font-size: 1rem; color: var(--fg-muted); line-height: 1.6;
  margin-bottom: 24px; max-width: 540px;
}
.hero-cta {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
}
.cta-primary {
  background: var(--fg); color: var(--bg);
  padding: 9px 20px; border-radius: var(--r-sm);
  font-size: .875rem; font-weight: 600;
  transition: opacity .15s;
}
.cta-primary:hover { opacity: .85; }
.cta-ghost {
  background: none;
  border: 1px solid var(--border-em);
  color: var(--fg-muted);
  padding: 9px 18px; border-radius: var(--r-sm);
  font-size: .875rem; font-weight: 500;
  transition: color .15s, border-color .15s;
}
.cta-ghost:hover { color: var(--fg); border-color: var(--border-em); }

/* ── Article / Prose ── */
.prose {
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.82;
  color: var(--fg);
  max-width: 680px;
}
.prose h1,.prose h2,.prose h3,.prose h4 {
  font-family: var(--sans);
  letter-spacing: -.02em; color: var(--fg);
  scroll-margin-top: calc(var(--nav-h) + 24px);
}
.prose h1 { font-size: 1.75rem; font-weight: 700; margin: 2.5rem 0 1rem; }
.prose h2 {
  font-size: 1.35rem; font-weight: 700;
  margin: 3rem 0 1rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}
.prose h3 { font-size: 1.1rem; font-weight: 600; margin: 2rem 0 .75rem; }
.prose p  { margin-bottom: 1.4rem; }
.prose a  { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.prose a:hover { opacity: .8; }
.prose strong { font-weight: 600; }
.prose em { font-style: italic; }
.prose blockquote {
  margin: 1.6rem 0;
  padding: 14px 20px;
  background: var(--bg-raised);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  color: var(--fg-muted); font-style: italic;
}
.prose blockquote p:last-child { margin-bottom: 0; }
.prose hr { border: none; height: 1px; background: var(--border); margin: 2.5rem 0; }
.prose ul,.prose ol { padding-left: 1.6rem; margin-bottom: 1.4rem; }
.prose li { margin-bottom: .4rem; }
.prose code {
  font-family: var(--mono); font-size: .85em;
  background: var(--bg-raised); border: 1px solid var(--border);
  padding: 2px 5px; border-radius: 5px;
}
.prose pre {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 16px; overflow-x: auto;
  font: .85rem/1.5 var(--mono); margin: 1.5rem 0;
}
.prose table {
  width: 100%; border-collapse: collapse; margin: 1.8rem 0;
  font-family: var(--sans); font-size: .88rem;
}
.prose th,.prose td { padding: 9px 13px; border: 1px solid var(--border); text-align: left; }
.prose th { background: var(--bg-raised); font-weight: 600; }
.katex-display {
  margin: 1.6rem 0 !important;
  padding: 14px 18px;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--r-sm); overflow-x: auto;
}

/* Loading */
.loading { display: flex; justify-content: center; padding: 60px 0; }
.spinner {
  width: 32px; height: 32px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

/* ── Page hero (non-essay tabs) ── */
.page-hero {
  margin-bottom: 44px; padding-bottom: 36px;
  border-bottom: 1px solid var(--border);
}
.page-hero h2 {
  font-size: 1.75rem; font-weight: 700; letter-spacing: -.03em;
  margin-bottom: 10px;
}
.page-hero .hero-sub { margin-bottom: 0; }

/* ── Model layout ── */
.model-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 24px; margin-bottom: 32px;
}
.canvas-card, .controls-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 24px;
}
.canvas-top { margin-bottom: 14px; }
.canvas-legend {
  display: flex; align-items: center; gap: 14px;
  font-size: .78rem; color: var(--fg-muted);
}
.dot { width: 10px; height: 3px; border-radius: 2px; display: inline-block; }
.dot.cyan   { background: #38bdf8; }
.dot.pink   { background: var(--accent); }
.dot.yellow { background: #f59e0b; }
.canvas-wrap { background: var(--bg-raised); border-radius: var(--r-sm); overflow: hidden; }
#modelCanvas { display: block; width: 100%; height: auto; }
.status-card {
  margin-top: 16px; padding: 14px 16px;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--r-sm);
  display: flex; align-items: center; gap: 12px;
}
.status-ico { font-size: 1.4rem; }
.status-t { font-size: .875rem; font-weight: 600; }
.status-d { font-size: .78rem; color: var(--fg-muted); margin-top: 2px; }
.controls-card h3 { font-size: 1rem; font-weight: 600; margin-bottom: 20px; }

.ctrl-group { margin-bottom: 20px; }
.ctrl-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.ctrl-row label { font-size: .82rem; font-weight: 500; }
.mono { font-family: var(--mono); font-size: .82rem; color: var(--accent); }
.neg { color: #f87171 !important; }

input[type="range"] {
  width: 100%; height: 4px;
  -webkit-appearance: none; appearance: none;
  background: var(--border-em); border-radius: 2px; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); cursor: pointer;
  box-shadow: 0 0 0 3px var(--accent-hl);
  transition: transform .1s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }

.math-block {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 14px;
  margin-bottom: 20px;
}
.math-label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--fg-dim); margin-bottom: 8px;
}
.diag-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.diag {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 10px;
  display: flex; flex-direction: column; gap: 4px;
}
.diag span:first-child { font-size: .72rem; color: var(--fg-muted); }
.diag span:last-child  { font-family: var(--mono); font-size: 1rem; font-weight: 700; }

.theory-block {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 22px 26px;
}
.theory-block p { font-size: .95rem; color: var(--fg-muted); line-height: 1.7; }
.theory-block p + p { margin-top: .9rem; }

/* ── Wager Matrix ── */
.matrix-wrap { overflow-x: auto; margin-bottom: 32px; }
.matrix {
  width: 100%; border-collapse: separate; border-spacing: 10px;
}
.matrix thead th {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 12px 16px;
  font-size: .875rem; text-align: center;
}
.matrix .dim { font-weight: 400; color: var(--fg-muted); }
.row-head {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 14px; font-size: .875rem;
  font-weight: 600; text-align: center; width: 140px;
}
.cell {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 18px; cursor: pointer;
  vertical-align: top; transition: border-color .15s, transform .15s;
}
.cell:hover { border-color: var(--accent); transform: translateY(-2px); }
.cell.focal { border-color: var(--border-em); background: var(--bg-raised); }
.cell-label {
  display: block; font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--fg-dim); margin-bottom: 8px;
}
.cell-label.accent { color: var(--accent); }
.cell h4 { font-size: .95rem; margin-bottom: 6px; }
.cell p { font-size: .82rem; color: var(--fg-muted); line-height: 1.5; margin-bottom: 10px; }
.cell code { font-family: var(--mono); font-size: .82rem; }

.sim-wrap {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 24px; margin-bottom: 24px;
}
.sim-wrap h3 { font-size: 1rem; font-weight: 600; margin-bottom: 20px; }
.sim-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.sim-results { display: flex; flex-direction: column; gap: 12px; }
.result {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.res-label { font-size: .78rem; color: var(--fg-muted); }
.res-num { font-family: var(--mono); font-size: 2rem; font-weight: 800; letter-spacing: -.03em; }
.verdict {
  background: var(--accent-hl); border: 1px solid rgba(201,160,220,.2);
  border-radius: var(--r-sm); padding: 12px 14px;
  font-size: .82rem; color: var(--fg); line-height: 1.5;
}

/* ── Projects ── */
.profile-hero {
  display: flex; align-items: center; gap: 28px;
}
.profile-avatar {
  width: 80px; height: 80px; border-radius: var(--r-lg);
  object-fit: cover; border: 1px solid var(--border-em);
  flex-shrink: 0;
}
.social-row {
  display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px;
}
.social-row a {
  font-size: .78rem; font-weight: 600; color: var(--fg-muted);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 5px 12px; transition: color .15s, border-color .15s;
}
.social-row a:hover { color: var(--fg); border-color: var(--accent); }

.proj-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.proj-card {
  display: flex; flex-direction: column;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 22px 24px;
  transition: border-color .15s, transform .15s;
}
.proj-card:hover { border-color: var(--border-em); transform: translateY(-2px); }
.proj-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.proj-name { font-size: 1rem; font-weight: 600; }
.proj-arrow { font-size: 1rem; color: var(--fg-dim); }
.proj-card p { font-size: .85rem; color: var(--fg-muted); line-height: 1.55; margin-bottom: 16px; flex: 1; }
.proj-card code { font-size: .82em; }
.proj-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.proj-tags span {
  font-size: .68rem; font-weight: 600; font-family: var(--mono);
  background: var(--bg-raised); border: 1px solid var(--border);
  padding: 3px 8px; border-radius: 5px; color: var(--fg-dim);
}

/* ── Back to top ── */
#back-top {
  position: fixed; bottom: 28px; right: 28px;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--fg-muted); display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .2s, visibility .2s, transform .2s;
  z-index: 80;
}
#back-top.visible { opacity: 1; visibility: visible; pointer-events: auto; }
#back-top:hover { color: var(--fg); transform: translateY(-2px); }

/* ── Footer ── */
.footer {
  border-top: 1px solid var(--border);
  padding: 28px;
  margin-top: 80px;
}
.footer-inner {
  max-width: 1360px; margin: 0 auto;
  display: flex; align-items: center; gap: 16px;
  font-size: .82rem; color: var(--fg-muted); flex-wrap: wrap;
}
.footer-links { display: flex; gap: 16px; margin-left: auto; }
.footer-links a { color: var(--fg-dim); transition: color .15s; }
.footer-links a:hover { color: var(--fg); }

/* ── Responsive ── */
@media (max-width: 1024px) {
  .model-layout { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .layout { gap: 24px; }
  #sidebar { display: none; }
  .hero { flex-direction: column; align-items: flex-start; gap: 24px; }
  .nav { padding: 0 16px; }
  .logo { margin-right: 12px; }
  .logo-name { display: none; }
  .nav-tabs { display: flex; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .nav-tabs::-webkit-scrollbar { display: none; }
  .nav-tabs .tab { flex-shrink: 0; padding: 7px 10px; }
  .sim-layout { grid-template-columns: 1fr; }
  .hero-h1 { font-size: 1.55rem; }
  .profile-hero { flex-direction: column; align-items: flex-start; }
}
