/* ===================================================================
   PM Wiki — design system
   Fresh neutral encyclopedia identity. Light + dark.
   =================================================================== */
:root {
  --bg: #ffffff;
  --bg-soft: #f6f8fb;
  --bg-sunken: #eef2f7;
  --card: #ffffff;
  --ink: #16202e;
  --ink-soft: #3b4757;
  --muted: #6b7787;
  --faint: #97a2b0;
  --line: #e4e9f0;
  --line-soft: #eef2f7;
  --brand: #2f6df6;      /* primary */
  --brand-ink: #1b4fd0;
  --brand-soft: #eaf1ff;
  --teal: #0f9d8f;
  --amber: #e8a13a;
  --rose: #e0556b;
  --violet: #7a5af5;
  --green: #1a9d6a;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(20,32,52,.06), 0 1px 3px rgba(20,32,52,.05);
  --shadow: 0 2px 6px rgba(20,32,52,.06), 0 12px 30px rgba(20,32,52,.07);
  --maxw: 1180px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1420;
    --bg-soft: #111b2b;
    --bg-sunken: #0a111c;
    --card: #131f31;
    --ink: #e8eef6;
    --ink-soft: #c2ccd9;
    --muted: #93a1b3;
    --faint: #6b7a8d;
    --line: #223347;
    --line-soft: #1a2739;
    --brand: #6494ff;
    --brand-ink: #8fb0ff;
    --brand-soft: #16233c;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
    --shadow: 0 2px 6px rgba(0,0,0,.3), 0 14px 34px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  --bg: #0d1420; --bg-soft: #111b2b; --bg-sunken: #0a111c; --card: #131f31;
  --ink: #e8eef6; --ink-soft: #c2ccd9; --muted: #93a1b3; --faint: #6b7a8d;
  --line: #223347; --line-soft: #1a2739; --brand: #6494ff; --brand-ink: #8fb0ff;
  --brand-soft: #16233c; --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow: 0 2px 6px rgba(0,0,0,.3), 0 14px 34px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--ink);
  line-height: 1.65; font-size: 16.5px; -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { max-width: 100%; display: block; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { line-height: 1.25; color: var(--ink); font-weight: 750; letter-spacing: -.015em; }
h1 { font-size: clamp(1.85rem, 3.4vw, 2.6rem); margin: 0 0 .5rem; }
h2 { font-size: 1.5rem; margin: 2.2rem 0 .8rem; }
h3 { font-size: 1.16rem; margin: 1.6rem 0 .5rem; }
p { margin: 0 0 1rem; }
code { font-family: var(--mono); font-size: .88em; background: var(--bg-sunken); padding: .12em .4em; border-radius: 5px; }
.container { max-width: var(--maxw); margin: 0 auto; padding: 0 22px; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }

/* ── Header ─────────────────────────────────────────────── */
.hdr { position: sticky; top: 0; z-index: 60; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px); border-bottom: 1px solid var(--line); }
.hdr-inner { display: flex; align-items: center; gap: 18px; height: 62px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.16rem;
  letter-spacing: -.03em; color: var(--ink); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand .mark { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--violet)); color: #fff; font-weight: 900; font-size: .95rem; }
.brand em { color: var(--brand); font-style: normal; }
.nav { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.nav > a, .nav > .navitem > button {
  font: inherit; font-size: .93rem; font-weight: 550; color: var(--ink-soft); background: none; border: 0;
  padding: 9px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px;
  white-space: nowrap; }
.nav > a:hover, .nav > .navitem > button:hover { background: var(--bg-soft); color: var(--ink); text-decoration: none; }
.navitem { position: relative; }
.navitem > button::after { content: "▾"; font-size: .62rem; color: var(--faint); }
.mega { position: absolute; top: calc(100% + 8px); left: 50%; transform: translateX(-50%) translateY(6px);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; width: max-content; max-width: 720px; opacity: 0; visibility: hidden; transition: .16s;
  display: grid; grid-template-columns: repeat(3, minmax(150px,1fr)); gap: 4px 20px; }
.navitem:hover .mega { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }
.mega a { display: block; padding: 6px 8px; border-radius: 7px; font-size: .88rem; color: var(--ink-soft); }
.mega a:hover { background: var(--brand-soft); color: var(--brand-ink); text-decoration: none; }
.mega .mega-h { grid-column: 1/-1; font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--faint); padding: 4px 8px 2px; }
.icon-btn { width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--line); background: var(--card);
  color: var(--ink-soft); cursor: pointer; display: grid; place-items: center; font-size: 1rem; }
.icon-btn:hover { background: var(--bg-soft); }
.hdr-search { flex: 0 1 260px; position: relative; }
.hdr-search input { width: 100%; height: 40px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-soft);
  padding: 0 12px 0 36px; font: inherit; font-size: .9rem; color: var(--ink); }
.hdr-search input:focus { outline: 2px solid var(--brand); border-color: transparent; background: var(--card); }
.hdr-search::before { content: "🔍"; position: absolute; left: 11px; top: 50%; transform: translateY(-50%); font-size: .82rem; opacity: .6; }
.menu-toggle { display: none; }

/* search results dropdown */
.search-panel { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); max-height: 60vh; overflow: auto;
  z-index: 80; display: none; }
.search-panel.open { display: block; }
.search-panel a { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); color: var(--ink); }
.search-panel a:hover { background: var(--brand-soft); text-decoration: none; }
.search-panel a small { color: var(--muted); display: block; font-size: .78rem; }
.search-panel .tag { font-size: .68rem; color: var(--brand-ink); background: var(--brand-soft); padding: 1px 7px; border-radius: 20px; float: right; }

/* ── Hero ──────────────────────────────────────────────── */
.hero { background: radial-gradient(1100px 460px at 50% -140px, var(--brand-soft), transparent),
    linear-gradient(180deg, var(--bg-soft), var(--bg)); border-bottom: 1px solid var(--line); padding: 60px 0 52px; text-align: center; }
.hero h1 { max-width: 760px; margin: 0 auto .6rem; }
.hero h1 em { color: var(--brand); font-style: normal; }
.hero .lede { font-size: 1.16rem; color: var(--muted); max-width: 620px; margin: 0 auto 26px; }
.hero-search { max-width: 560px; margin: 0 auto; position: relative; }
.hero-search input { width: 100%; height: 56px; border-radius: 14px; border: 1px solid var(--line); background: var(--card);
  box-shadow: var(--shadow); padding: 0 18px 0 48px; font: inherit; font-size: 1.05rem; color: var(--ink); }
.hero-search input:focus { outline: 2px solid var(--brand); border-color: transparent; }
.hero-search::before { content: "🔍"; position: absolute; left: 18px; top: 50%; transform: translateY(-50%); opacity: .55; }
.hero-stats { display: flex; gap: 30px; justify-content: center; flex-wrap: wrap; margin-top: 30px; }
.hero-stats b { font-size: 1.5rem; color: var(--ink); display: block; letter-spacing: -.02em; }
.hero-stats span { font-size: .82rem; color: var(--muted); }

/* ── Buttons / chips ───────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 11px 20px; border-radius: 11px; font-weight: 650;
  font-size: .95rem; cursor: pointer; border: 1px solid transparent; transition: transform .1s, box-shadow .1s; }
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 6px 16px color-mix(in srgb, var(--brand) 34%, transparent); }
.btn-ghost { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg-soft); }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: .78rem; font-weight: 600; padding: 3px 11px;
  border-radius: 20px; background: var(--bg-sunken); color: var(--ink-soft); }
.chip.brand { background: var(--brand-soft); color: var(--brand-ink); }
.chip.teal { background: color-mix(in srgb, var(--teal) 15%, transparent); color: var(--teal); }
.chip.amber { background: color-mix(in srgb, var(--amber) 18%, transparent); color: #a9711a; }
.chip.violet{ background: color-mix(in srgb, var(--violet) 15%, transparent); color: var(--violet); }
.chip.green { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); }

/* ── Layout: section grid / cards ──────────────────────── */
.section { padding: 52px 0; }
.section.alt { background: var(--bg-soft); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.sec-head { text-align: center; max-width: 640px; margin: 0 auto 34px; }
.sec-head h2 { margin: 0 0 .4rem; font-size: 1.8rem; }
.sec-head p { color: var(--muted); margin: 0; }
.grid { display: grid; gap: 18px; }
.grid.g2 { grid-template-columns: repeat(2, 1fr); }
.grid.g3 { grid-template-columns: repeat(3, 1fr); }
.grid.g4 { grid-template-columns: repeat(4, 1fr); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow-sm); transition: transform .12s, box-shadow .12s, border-color .12s; display: block; color: inherit; }
a.card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); }
.card h3 { margin: 0 0 .35rem; font-size: 1.08rem; }
.card p { margin: 0; color: var(--muted); font-size: .92rem; }
.card .ico { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; font-size: 1.3rem;
  background: var(--brand-soft); margin-bottom: 12px; }
.card .kbd { font-size: .74rem; color: var(--faint); margin-top: 12px; }
.sec-card { border-left: 4px solid var(--brand); }

/* ── Topic / article page ──────────────────────────────── */
.page { display: grid; grid-template-columns: 250px minmax(0,1fr) 220px; gap: 40px; padding: 30px 0 70px; align-items: start; }
.sidebar { position: sticky; top: 78px; align-self: start; font-size: .9rem; max-height: calc(100vh - 90px); overflow: auto; padding-right: 6px; }
.sidebar h4 { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); margin: 16px 0 6px; }
.sidebar a { display: block; padding: 5px 10px; border-radius: 7px; color: var(--ink-soft); font-size: .875rem; }
.sidebar a:hover { background: var(--bg-soft); text-decoration: none; }
.sidebar a.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
.toc { position: sticky; top: 78px; align-self: start; font-size: .84rem; border-left: 1px solid var(--line); padding-left: 16px; }
.toc h4 { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); margin: 0 0 8px; }
.toc a { display: block; padding: 4px 0; color: var(--muted); }
.toc a:hover { color: var(--brand); text-decoration: none; }
.toc a.active { color: var(--brand); font-weight: 600; }
.article { min-width: 0; }
.breadcrumb { font-size: .82rem; color: var(--muted); margin-bottom: 14px; display: flex; gap: 7px; flex-wrap: wrap; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--brand); }
.breadcrumb span { color: var(--faint); }
.article > .lead { font-size: 1.14rem; color: var(--ink-soft); margin-bottom: 1.4rem; }
.article section { scroll-margin-top: 78px; }
.article h2 { border-top: 1px solid var(--line-soft); padding-top: 1.6rem; }
.article h2:first-of-type { border-top: 0; padding-top: 0; }
.article ul, .article ol { margin: 0 0 1rem; padding-left: 1.3rem; }
.article li { margin-bottom: .4rem; }
.article table { width: 100%; border-collapse: collapse; margin: 1rem 0 1.4rem; font-size: .93rem; }
.article th, .article td { border: 1px solid var(--line); padding: 9px 12px; text-align: left; }
.article th { background: var(--bg-soft); font-weight: 650; }
.callout { background: var(--bg-soft); border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: 10px;
  padding: 14px 18px; margin: 1.2rem 0; }
.facts { background: var(--bg-soft); border: 1px solid var(--line); border-radius: 12px; padding: 16px 20px; margin: 1.3rem 0; }
.facts h4 { margin: 0 0 10px; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); }
.facts dl { margin: 0; display: grid; gap: 0; }
.facts dl > div { display: grid; grid-template-columns: 150px 1fr; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line-soft); }
.facts dl > div:first-child { border-top: 0; }
.facts dt { font-weight: 650; color: var(--ink-soft); font-size: .9rem; }
.facts dd { margin: 0; color: var(--ink); font-size: .93rem; }
@media (max-width: 520px) { .facts dl > div { grid-template-columns: 1fr; gap: 2px; } }
.callout.formula { border-left-color: var(--teal); font-family: var(--mono); font-size: .95rem; }
.callout.tip { border-left-color: var(--green); }
.callout.warn { border-left-color: var(--amber); }
.faq { border: 1px solid var(--line); border-radius: 12px; margin: 10px 0; overflow: hidden; background: var(--card); }
.faq summary { padding: 14px 18px; font-weight: 620; cursor: pointer; list-style: none; display: flex; justify-content: space-between; gap: 10px; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--brand); font-weight: 700; }
.faq[open] summary::after { content: "–"; }
.faq .faq-body { padding: 0 18px 14px; color: var(--ink-soft); }
.pill-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.pill { font-size: .85rem; padding: 6px 12px; border-radius: 20px; background: var(--bg-soft); border: 1px solid var(--line); color: var(--ink-soft); }
.pill:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.related-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 10px; }
.related-grid a { padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: .9rem; font-weight: 550; color: var(--ink); }
.related-grid a:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }

/* ── Calculator widget ─────────────────────────────────── */
.calc { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow-sm); margin: 1.2rem 0; }
.calc .row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 12px; }
.calc label { display: block; font-size: .82rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
.calc input, .calc select { width: 100%; height: 42px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg-soft);
  padding: 0 12px; font: inherit; font-size: .95rem; color: var(--ink); }
.calc input:focus { outline: 2px solid var(--brand); border-color: transparent; }
.calc-out { margin-top: 8px; display: grid; grid-template-columns: repeat(auto-fit, minmax(130px,1fr)); gap: 12px; }
.calc-out .metric { background: var(--bg-soft); border: 1px solid var(--line); border-radius: 11px; padding: 13px 15px; }
.calc-out .metric b { display: block; font-size: 1.35rem; letter-spacing: -.02em; }
.calc-out .metric span { font-size: .76rem; color: var(--muted); }
.calc-out .metric.good b { color: var(--green); }
.calc-out .metric.bad b { color: var(--rose); }

/* ── Home hero (slim, grid-led) ── */
.hero-slim { padding: 40px 0 50px; text-align: left; }
.hero-slim .hero-h1 { font-size: .9rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase;
  color: var(--faint); margin: 0 0 20px; text-align: left; }
.hero-slim .hero-h1 em { color: var(--brand); font-style: normal; }
.hero-slim .hero-search { margin-top: 32px; }
.hero-slim .hero-stats { margin-top: 24px; justify-content: flex-start; }

/* ── Home: full 20-section index grid (mega-menu style) ── */
.kicker { font-size: .74rem; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); font-weight: 800; margin-bottom: 18px; }
.sec-index-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px 34px; }
.sec-index-item { display: flex; gap: 12px; align-items: flex-start; padding: 15px 12px; border-radius: 10px;
  color: var(--ink); font-weight: 650; font-size: 1.02rem; letter-spacing: -.01em; border-bottom: 1px solid var(--line-soft);
  transition: background .12s, transform .12s; }
.sec-index-item:hover { background: var(--brand-soft); color: var(--brand-ink); text-decoration: none; transform: translateX(2px); }
.sec-index-item .si-ico { font-size: 1.2rem; line-height: 1.35; flex: none; }
.sec-index-item .si-num { color: var(--faint); font-weight: 700; font-variant-numeric: tabular-nums; margin-right: -4px; }
@media (max-width: 1080px) { .sec-index-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 620px) { .sec-index-grid { grid-template-columns: 1fr; } }

/* ── Index / letter nav ────────────────────────────────── */
.az { display: flex; flex-wrap: wrap; gap: 5px; margin: 8px 0 26px; }
.az a { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--line);
  font-size: .82rem; font-weight: 600; color: var(--ink-soft); background: var(--card); }
.az a:hover { background: var(--brand); color: #fff; text-decoration: none; border-color: var(--brand); }
.topic-list { columns: 3; column-gap: 34px; }
.topic-list a { display: block; padding: 4px 0; break-inside: avoid; font-size: .93rem; color: var(--ink-soft); }
.topic-list a:hover { color: var(--brand); }

/* ── Footer ────────────────────────────────────────────── */
.ftr { background: var(--bg-soft); border-top: 1px solid var(--line); padding: 46px 0 30px; margin-top: 40px; font-size: .9rem; }
.ftr-grid { display: grid; grid-template-columns: 1.6fr repeat(4, 1fr); gap: 30px; }
.ftr h5 { font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); margin: 0 0 12px; }
.ftr a { display: block; color: var(--muted); padding: 3px 0; }
.ftr a:hover { color: var(--brand); }
.ftr .brand { font-size: 1.1rem; margin-bottom: 10px; }
.ftr-bottom { border-top: 1px solid var(--line); margin-top: 30px; padding-top: 18px; color: var(--faint); font-size: .82rem;
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ── Utilities ─────────────────────────────────────────── */
.center { text-align: center; }
.mt0{margin-top:0}.mb0{margin-bottom:0}
.tag-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.disclosure { font-size: .8rem; color: var(--faint); font-style: italic; margin: 8px 0; }
.cta-band { background: linear-gradient(135deg, var(--brand), var(--violet)); color: #fff; border-radius: var(--radius); padding: 34px; text-align: center; margin: 30px 0; }
.cta-band h2 { color: #fff; margin-top: 0; }
.cta-band p { color: rgba(255,255,255,.9); }
.cta-band .btn-ghost { background: rgba(255,255,255,.16); color: #fff; border-color: rgba(255,255,255,.3); }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 1080px) {
  .page { grid-template-columns: minmax(0,1fr); }
  .sidebar, .toc { display: none; }
  .grid.g4 { grid-template-columns: repeat(2,1fr); }
  .ftr-grid { grid-template-columns: 1fr 1fr; }
  .topic-list { columns: 2; }
}
@media (max-width: 760px) {
  .nav { position: fixed; inset: 62px 0 auto 0; background: var(--card); border-bottom: 1px solid var(--line);
    flex-direction: column; align-items: stretch; padding: 10px; gap: 2px; display: none; box-shadow: var(--shadow); }
  .nav.open { display: flex; }
  .nav > a, .nav > .navitem { width: 100%; }
  .navitem > button { width: 100%; justify-content: space-between; }
  .mega { position: static; transform: none; opacity: 1; visibility: visible; box-shadow: none; border: 0; padding: 4px 0 4px 14px;
    grid-template-columns: 1fr 1fr; display: none; }
  .navitem.open .mega { display: grid; }
  .menu-toggle { display: grid; }
  .hdr-search { display: none; }
  .grid.g2, .grid.g3, .grid.g4 { grid-template-columns: 1fr; }
  .topic-list { columns: 1; }
  .ftr-grid { grid-template-columns: 1fr; }
  .calc .row { grid-template-columns: 1fr; }
}
