/* AI Enemy System Guide: one stylesheet for every page. Light and dark follow the system setting. */

:root {
  --bg: #ffffff;
  --bg-soft: #f5f6f8;
  --bg-card: #ffffff;
  --text: #1b1f26;
  --text-2: #535c6a;
  --text-3: #8a92a0;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --accent: #2563eb;
  --accent-soft: #edf2ff;
  --good: #15803d;
  --mark: #fde68a;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.07);
  --dg-axis: #98a1ae;
  --dg-accent: #2563eb;
  --dg-accent-fill: rgba(37, 99, 235, 0.1);
  --dg-good: #16a34a;
  --dg-good-fill: rgba(22, 163, 74, 0.12);
  --dg-warn: #d97706;
  --dg-warn-fill: rgba(217, 119, 6, 0.13);
  --dg-crit: #dc2626;
  --dg-crit-fill: rgba(220, 38, 38, 0.11);
  --radius: 12px;
  --topbar-h: 60px;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --bg-soft: #151a21;
    --bg-card: #161b22;
    --text: #e6e9ee;
    --text-2: #a7b0bd;
    --text-3: #7b8494;
    --line: #262c35;
    --line-strong: #343c47;
    --accent: #6ea8fe;
    --accent-soft: #17243b;
    --good: #4ade80;
    --mark: #6b5513;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --dg-axis: #6f7886;
    --dg-accent: #6ea8fe;
    --dg-accent-fill: rgba(110, 168, 254, 0.14);
    --dg-good: #4ade80;
    --dg-good-fill: rgba(74, 222, 128, 0.12);
    --dg-warn: #fbbf24;
    --dg-warn-fill: rgba(251, 191, 36, 0.12);
    --dg-crit: #f87171;
    --dg-crit-fill: rgba(248, 113, 113, 0.12);
  }
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--topbar-h) + 20px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.72 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  padding: 0.05em 0.38em;
  border-radius: 6px;
  white-space: nowrap;
}
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 12px; top: 12px; z-index: 100; background: var(--bg); padding: 6px 10px; border-radius: 8px; }

/* ------------------------------------------------------------------ top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 20px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: radial-gradient(circle at 50% 50%, #fff 0 3px, transparent 3.5px), var(--accent);
}
.mainnav { display: flex; gap: 2px; }
.mainnav a { color: var(--text-2); padding: 6px 10px; border-radius: 8px; font-size: 14px; white-space: nowrap; }
.mainnav a:hover { background: var(--bg-soft); color: var(--text); text-decoration: none; }
.mainnav a[aria-current] { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.lang {
  white-space: nowrap;
  font-size: 13.5px;
  color: var(--text-2);
  border: 1px solid var(--line-strong);
  padding: 4px 10px;
  border-radius: 8px;
}
.lang:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }

/* ------------------------------------------------------------------ search */

.search { position: relative; flex: 1; max-width: 440px; margin-left: auto; }
.search input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line-strong);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 10px;
  padding: 0 34px 0 12px;
  font: inherit;
  font-size: 14px;
}
.search input::placeholder { color: var(--text-3); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--bg); }
.search-kbd {
  position: absolute;
  right: 9px;
  top: 50%;
  transform: translateY(-50%);
  font: 12px/18px var(--mono);
  color: var(--text-3);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  padding: 0 6px;
  background: var(--bg);
  pointer-events: none;
}
.search input:focus + .search-kbd { display: none; }
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  min-width: 320px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.18);
  max-height: min(72vh, 580px);
  overflow: auto;
  padding: 6px;
  z-index: 60;
  text-align: left;
}
.sr-item { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); }
.sr-item:hover, .sr-item.active { background: var(--accent-soft); text-decoration: none; }
.sr-top { display: flex; align-items: center; gap: 8px; }
.sr-kind {
  flex: none;
  font-size: 11px;
  line-height: 18px;
  padding: 0 7px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  color: var(--text-2);
  white-space: nowrap;
}
.sr-kind.k-guide { color: #0f766e; border-color: rgba(15, 118, 110, 0.4); }
.sr-kind.k-recipe { color: #b45309; border-color: rgba(180, 83, 9, 0.4); }
.sr-kind.k-module { color: #7c3aed; border-color: rgba(124, 58, 237, 0.4); }
@media (prefers-color-scheme: dark) {
  .sr-kind.k-guide { color: #5eead4; }
  .sr-kind.k-recipe { color: #fbbf24; }
  .sr-kind.k-module { color: #c4b5fd; }
}
.sr-title { font-weight: 600; font-size: 14px; line-height: 1.4; }
.sr-sec { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.sr-snip {
  font-size: 12.5px;
  color: var(--text-2);
  margin-top: 2px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sr-none { padding: 12px; color: var(--text-3); font-size: 14px; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ------------------------------------------------------------------ layout */

.layout { max-width: 1320px; margin: 0 auto; padding: 0 20px; }
.layout.has-sidebar { display: grid; grid-template-columns: 264px minmax(0, 1fr); gap: 44px; }
.content { min-width: 0; max-width: 900px; padding: 28px 0 64px; }
.layout:not(.has-sidebar) .content { max-width: 1120px; margin: 0 auto; }

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  align-self: start;
  max-height: calc(100vh - var(--topbar-h));
  overflow: auto;
  padding: 26px 6px 40px 0;
  scrollbar-width: thin;
}
.toc-title { font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); margin: 0 0 8px 10px; }
.toc-list, .toc-sub { list-style: none; margin: 0; padding: 0; }
.toc-list a { display: block; padding: 5px 10px; border-radius: 8px; color: var(--text-2); font-size: 14px; line-height: 1.45; }
.toc-list a:hover { background: var(--bg-soft); color: var(--text); text-decoration: none; }
.toc-list a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.toc-list a.active-parent { color: var(--text); font-weight: 600; }
.toc-sub { display: none; margin: 2px 0 6px 12px; padding-left: 8px; border-left: 1px solid var(--line); }
.toc-sec.open > .toc-sub, .toc-sub.open { display: block; }
.toc-sub a { font-size: 13px; padding: 3px 8px; }

.menu-btn { display: none; }

/* ------------------------------------------------------------------ typography */

.page-head { padding: 6px 0 20px; border-bottom: 1px solid var(--line); margin-bottom: 26px; }
h1 { font-size: 30px; line-height: 1.25; margin: 8px 0 10px; letter-spacing: -0.01em; }
h2 { font-size: 22px; line-height: 1.32; margin: 40px 0 12px; }
h3 { font-size: 17px; line-height: 1.42; margin: 28px 0 8px; }
.lead { font-size: 16px; color: var(--text-2); margin: 0 0 8px; }
.meta, .muted { font-size: 13px; color: var(--text-3); margin: 0; }
.content p { margin: 0 0 12px; }
.content ul, .content ol { padding-left: 22px; margin: 0 0 12px; }
.content li { margin: 3px 0; }
.content strong { font-weight: 650; }
.anchor { opacity: 0; margin-left: 8px; color: var(--text-3); font-weight: 400; transition: opacity 0.15s; }
h2:hover .anchor, h3:hover .anchor, .anchor:focus { opacity: 1; text-decoration: none; }
.anchor.copied::after { content: " ✓"; color: var(--good); }

.flash { animation: flash 1.8s ease-out; border-radius: 8px; }
@keyframes flash { 0% { background-color: var(--mark); } 100% { background-color: transparent; } }
section.card.flash { animation: flash-card 1.8s ease-out; }
@keyframes flash-card { 0% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: var(--shadow); } }

/* ------------------------------------------------------------------ tables */

.table-wrap { overflow-x: auto; margin: 12px 0 16px; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; line-height: 1.55; }
th, td { padding: 8px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { background: var(--bg-soft); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
table.settings td:first-child, table.settings td:nth-child(2) { white-space: nowrap; }

/* ------------------------------------------------------------------ cards, guides */

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin: 0 0 20px;
  box-shadow: var(--shadow);
}
.card > h2, .card > h3 { margin-top: 0; }
.summary { color: var(--text-2); margin: -4px 0 14px !important; }
.content .steps { counter-reset: step; list-style: none; padding: 0; margin: 0 0 16px; }
.content .steps li { position: relative; padding: 7px 0 7px 42px; margin: 0; border-top: 1px dashed var(--line); }
.content .steps li:first-child { border-top: none; }
.content .steps li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0;
  top: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
  display: grid;
  place-items: center;
}
.check {
  background: color-mix(in srgb, var(--good) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--good) 32%, transparent);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
}
.check-label { display: block; font-weight: 650; color: var(--good); font-size: 13px; margin-bottom: 2px; }
.related { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
.related-label { font-size: 12px; color: var(--text-3); margin-right: 2px; }
.chip {
  font-size: 13px;
  line-height: 1.5;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  color: var(--text-2);
  background: var(--bg);
}
.chip:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

/* ------------------------------------------------------------------ Blueprint recipes */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  font-size: 13px;
  color: var(--text-2);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
}
.legend-title { font-weight: 650; color: var(--text); margin-right: 4px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 16px; height: 11px; border-radius: 3px; }
.legend-swatch.k-event { background: #9a2828; }
.legend-swatch.k-func { background: #22548f; }
.legend-swatch.k-pure { background: #2f6f3a; }
.legend-swatch.k-flow { background: #575d66; }
.legend-swatch.k-cast { background: #17727c; }
.legend-swatch.k-var { background: #6d3f9e; }
.legend-swatch.k-custom { border: 1.5px dashed var(--text-3); }

.group-title { margin: 44px 0 14px; }
.recipe h3 { font-size: 18px; }
.where { font-size: 14px; color: var(--text-2); margin: -2px 0 12px !important; }
.where-label {
  display: inline-block;
  font-size: 12px;
  font-weight: 650;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 0 8px;
  margin-right: 8px;
}
.bp-chain-wrap { margin: 10px 0 14px; }
.bp-chain-label { font-size: 13px; font-weight: 650; color: var(--text-2); margin: 0 0 6px; }
.bp-graph {
  background-color: #1d1f24;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px);
  background-size: 16px 16px;
  border: 1px solid #2d3038;
  border-radius: 12px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.bp-chain { display: flex; align-items: center; padding: 18px; width: max-content; min-width: 100%; }
.bp-node {
  background: #2a2d34;
  border: 1px solid #3b3f48;
  border-radius: 9px;
  min-width: 168px;
  max-width: 300px;
  color: #e7e9ee;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.bp-hd { position: relative; padding: 7px 12px 7px 26px; }
.bp-ic { position: absolute; left: 10px; top: 13px; width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 255, 255, 0.85); }
.bp-title { display: block; font-weight: 650; }
.bp-sub { font-size: 11px; opacity: 0.72; }
.k-event .bp-hd { background: linear-gradient(90deg, #9a2828, #6f1e1e); }
.k-func .bp-hd { background: linear-gradient(90deg, #22548f, #1a3f6b); }
.k-pure .bp-hd { background: linear-gradient(90deg, #2f6f3a, #24552c); }
.k-flow .bp-hd { background: linear-gradient(90deg, #575d66, #42474f); }
.k-cast .bp-hd { background: linear-gradient(90deg, #17727c, #125a62); }
.k-var .bp-hd { background: linear-gradient(90deg, #6d3f9e, #55307c); }
.bp-body { padding: 8px 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.bp-pin { display: flex; align-items: baseline; gap: 6px; }
.bp-pin.out { justify-content: flex-end; }
.bp-dot { flex: none; width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid #9db8dc; transform: translateY(-1px); }
.bp-pin.out .bp-dot { background: #9db8dc; }
.bp-pn { color: #c8cdd7; white-space: nowrap; }
.bp-op { color: #7d8594; }
.bp-pv { color: #ffd88c; font-family: var(--mono); font-size: 12px; word-break: break-word; }
.bp-pv.from { color: #9fd4ff; font-family: var(--font); font-size: 12.5px; }
.bp-note { font-size: 12px; color: #aab2bf; font-style: italic; }
.bp-node.k-custom { background: rgba(255, 255, 255, 0.03); border: 1.5px dashed #6c7380; box-shadow: none; }
.bp-custom { color: #d6dae2; }
.bp-wire { flex: none; position: relative; width: 38px; height: 2px; background: #e8ebf0; }
.bp-wire span {
  position: absolute;
  right: -2px;
  top: -5px;
  border-left: 8px solid #e8ebf0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
}
.notes { color: var(--text-2); font-size: 14.5px; margin-top: 4px !important; }

/* ------------------------------------------------------------------ modules */

.module .cls { margin: -6px 0 14px !important; }
.module .cls code { white-space: normal; }
.m-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.m-field { margin: 0 0 12px; }
.m-label { font-size: 12px; font-weight: 650; letter-spacing: 0.04em; color: var(--text-3); text-transform: uppercase; margin-bottom: 4px; }
.m-field p { margin: 0; }
.node-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.node-chip { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

/* ------------------------------------------------------------------ home */

.hero { padding: 52px 0 28px; text-align: center; }
.hero h1 { font-size: 40px; margin: 0 0 10px; }
.hero .lead { font-size: 17px; max-width: 660px; margin: 0 auto 24px; }
.search-hero { max-width: 660px; margin: 0 auto; }
.search-hero input { height: 52px; font-size: 16px; border-radius: 14px; padding: 0 18px; }
.home-block { margin: 40px 0; }
.home-block > h2 { margin: 0 0 14px; }
.tasks { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.task {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 40px 16px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-card);
  color: var(--text);
  box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.15s;
}
.task:hover { border-color: var(--accent); transform: translateY(-1px); text-decoration: none; }
.task-title { font-weight: 650; }
.task-desc { font-size: 13.5px; color: var(--text-2); line-height: 1.5; }
.task-go { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--accent); font-size: 18px; }
.mods { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.mod { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: var(--bg-card); }
.mod:hover { border-color: var(--accent); text-decoration: none; }
.mod-name { font-weight: 650; }
.mod-what { font-size: 13px; color: var(--text-2); line-height: 1.5; }
.content .faq-index { columns: 2; column-gap: 36px; padding-left: 0; list-style: none; margin-top: 10px; }
.faq-index li { break-inside: avoid; margin: 0 0 4px; }

/* ------------------------------------------------------------------ FAQ, diagrams */

.faq-sec > h2 { padding-top: 14px; border-top: 1px solid var(--line); }
.faq-sec:first-of-type > h2 { border-top: none; padding-top: 0; }
.diagram { margin: 16px 0 20px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-card); }
.diagram svg { display: block; width: 100%; height: auto; }
.diagram figcaption { font-size: 12.5px; color: var(--text-3); text-align: center; margin-top: 6px; }
.dg text { font-family: var(--font); }
.dg-title { font-size: 15px; font-weight: 600; fill: var(--text); }
.dg-name { font-size: 13px; font-weight: 600; fill: var(--text); }
.dg-text { font-size: 13px; fill: var(--text); }
.dg-quiet { font-size: 11.5px; fill: var(--text-2); }
.dg-line { fill: none; stroke: var(--dg-axis); stroke-width: 1.25; }
.dg-arrowhead { fill: var(--dg-axis); }
.dg-box { fill: none; stroke: var(--dg-axis); stroke-width: 1.25; }
.dg-accent { fill: var(--dg-accent-fill); stroke: var(--dg-accent); stroke-width: 2; }
.dg-good { fill: var(--dg-good-fill); stroke: var(--dg-good); stroke-width: 1.5; }
.dg-warn { fill: var(--dg-warn-fill); stroke: var(--dg-warn); stroke-width: 1.5; }
.dg-crit { fill: var(--dg-crit-fill); stroke: var(--dg-crit); stroke-width: 1.5; }

/* ------------------------------------------------------------------ footer, misc */

.footer { margin-top: 56px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--text-3); }
.footer p { margin: 2px 0 !important; }
.to-top {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--bg-card);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-size: 18px;
  z-index: 30;
}
.to-top:hover { border-color: var(--accent); color: var(--accent); }

/* ------------------------------------------------------------------ narrow screens */

@media (max-width: 1000px) {
  :root { --topbar-h: 104px; }
  .topbar-inner { flex-wrap: wrap; gap: 8px 12px; padding: 8px 16px 0; }
  .search { order: 2; max-width: none; flex: 1 1 200px; }
  .lang { order: 3; }
  .mainnav { order: 4; width: 100%; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
  .mainnav::-webkit-scrollbar { display: none; }
  .layout { padding: 0 16px; }
  .layout.has-sidebar { display: block; }
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    max-height: none;
    background: var(--bg);
    padding: 16px 20px 60px;
    display: none;
  }
  body.nav-open .sidebar { display: block; }
  body.nav-open { overflow: hidden; }
  .menu-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    position: fixed;
    left: 16px;
    bottom: 20px;
    z-index: 45;
    margin: 0;
    padding: 9px 14px;
    font: inherit;
    font-size: 14px;
    color: var(--text);
    background: var(--bg-card);
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    box-shadow: var(--shadow);
    cursor: pointer;
  }
  .content { padding-top: 16px; }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  h1 { font-size: 25px; }
  .hero { padding: 32px 0 16px; }
  .hero h1 { font-size: 29px; }
  .card { padding: 18px 16px; }
  .m-grid { grid-template-columns: 1fr; gap: 0; }
  .content .faq-index { columns: 1; }
  .brand-text { display: none; }
  .search-results { min-width: 0; }
  .sidebar { padding-bottom: 90px; }
}
