:root {
  --bg: #0B0B1A;
  --bg-2: #12122A;
  --surface: rgba(255, 255, 255, .03);
  --surface-2: rgba(255, 255, 255, .055);
  --line: rgba(123, 92, 255, .18);
  --line-soft: rgba(255, 255, 255, .07);
  --text: #E4E4F0;
  --muted: #8C8CA8;
  --body: #C4C4D4;
  --purple: #7B5CFF;
  --blue: #3FC8FF;
  --gold: #FFD700;
  --radius: 12px;
  --font: Inter, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--body);
  background:
    radial-gradient(900px 500px at 90% -10%, rgba(123, 92, 255, .16), transparent 70%),
    radial-gradient(700px 500px at -10% 40%, rgba(63, 200, 255, .07), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--muted); }
.pad { padding: 0 20px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  height: 60px; padding: 0 20px;
  background: rgba(11, 11, 26, .8);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 600; letter-spacing: .04em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand em { font-style: normal; color: var(--muted); font-weight: 500; margin-left: 4px; }
.menu-btn { display: none; background: none; border: 1px solid var(--line-soft); color: var(--text); border-radius: 8px; width: 38px; height: 38px; font-size: 18px; cursor: pointer; }

.search {
  flex: 1; min-width: 0; max-width: 460px; margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px; height: 38px;
  border: 1px solid var(--line-soft); border-radius: 10px;
  background: var(--surface); color: var(--muted);
}
.search:focus-within { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(123, 92, 255, .18); }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--text); font: inherit; font-size: 14px; }
.search kbd { font-family: var(--mono); font-size: 11px; padding: 1px 6px; border: 1px solid var(--line-soft); border-radius: 5px; }

.user { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text); white-space: nowrap; }
.user img { border-radius: 50%; }
.user a { color: var(--muted); font-size: 13px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 270px minmax(0, 1fr); max-width: 1280px; margin: 0 auto; }
.sidebar {
  position: sticky; top: 60px; align-self: start;
  height: calc(100vh - 60px); overflow-y: auto;
  padding: 24px 12px 40px 20px;
  border-right: 1px solid var(--line-soft);
}
.cat { margin-bottom: 22px; }
.cat-title { display: block; padding: 4px 10px; margin-bottom: 4px; font-size: 12px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.cat ul { list-style: none; margin: 0; padding: 0; }
.cat li a { display: block; padding: 7px 10px; border-radius: 8px; color: var(--body); font-size: 14px; line-height: 1.4; }
.cat li a:hover { background: var(--surface-2); color: #fff; text-decoration: none; }
.cat a.active { background: rgba(123, 92, 255, .16); color: #fff; box-shadow: inset 2px 0 0 var(--purple); }

.content { padding: 36px clamp(20px, 5vw, 64px) 96px; min-height: calc(100vh - 60px); outline: none; max-width: 900px; }

/* ---------- headings & pages ---------- */
.content > h1 {
  margin: 0 0 8px; font-size: clamp(30px, 4vw, 42px); line-height: 1.1; font-weight: 600;
  letter-spacing: .01em; color: #fff;
}
.lead { font-size: 17px; color: var(--body); margin: 0 0 8px; }
.meta { font-size: 13px; color: var(--muted); margin: 0 0 28px; }
.crumbs { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: 14px; }

.hero h1 {
  margin: 0 0 10px; font-size: clamp(36px, 5vw, 56px); line-height: 1; font-weight: 600;
  font-variant-caps: all-small-caps; letter-spacing: .02em;
  background: linear-gradient(90deg, var(--purple), var(--blue));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p { font-size: 17px; margin: 0 0 32px; max-width: 560px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 14px; }
.card {
  display: flex; flex-direction: column; gap: 8px; padding: 22px;
  border-radius: 16px; border: 1px solid var(--line); background: var(--surface);
  color: var(--body); transition: transform .15s, border-color .15s, box-shadow .15s;
}
.card:hover { text-decoration: none; transform: translateY(-2px); border-color: rgba(123, 92, 255, .5); box-shadow: 0 0 30px rgba(123, 92, 255, .16); }
.card h2 { margin: 0; font-size: 19px; font-weight: 600; color: #fff; }
.card p { margin: 0; font-size: 14px; }
.card .meta { margin: auto 0 0; color: var(--blue); }

.list { display: flex; flex-direction: column; gap: 10px; margin-top: 24px; }
.row {
  display: flex; flex-direction: column; gap: 4px; padding: 16px 18px;
  border-radius: var(--radius); border: 1px solid var(--line-soft); background: var(--surface); color: var(--body);
}
.row:hover { text-decoration: none; border-color: rgba(123, 92, 255, .45); background: var(--surface-2); }
.row strong { color: #fff; font-weight: 600; }
.row span { font-size: 14px; }
.tag { align-self: flex-start; font-size: 11px !important; letter-spacing: .08em; text-transform: uppercase; color: var(--blue); }

/* ---------- markdown ---------- */
.md { font-size: 16px; }
.md h2 { margin: 40px 0 12px; padding-top: 8px; font-size: 24px; font-weight: 600; color: #fff; border-top: 1px solid var(--line-soft); padding-top: 28px; }
.md h2:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.md h3 { margin: 28px 0 8px; font-size: 18px; font-weight: 600; color: #fff; }
.md h4 { margin: 22px 0 6px; font-size: 16px; color: #fff; }
.md p { margin: 0 0 14px; }
.md strong { color: #fff; font-weight: 600; }
.md ul, .md ol { margin: 0 0 16px; padding-left: 24px; }
.md li { margin: 4px 0; }
.md li::marker { color: var(--purple); }
.md hr { border: 0; height: 1px; background: linear-gradient(90deg, transparent, var(--line), transparent); margin: 32px 0; }
.md img { max-width: 100%; border-radius: var(--radius); border: 1px solid var(--line-soft); }

.md code { font-family: var(--mono); font-size: .88em; padding: 2px 6px; border-radius: 6px; background: rgba(63, 200, 255, .1); color: #BFEAFF; }
.md pre {
  position: relative; margin: 0 0 18px; padding: 16px 18px; overflow-x: auto;
  border-radius: var(--radius); border: 1px solid var(--line-soft); background: #0E0E22;
}
.md pre code { padding: 0; background: none; color: #E4E4F0; font-size: 14px; line-height: 1.55; }

.md blockquote {
  position: relative; margin: 0 0 18px; padding: 14px 18px; padding-right: 76px;
  border-radius: var(--radius); border: 1px solid rgba(123, 92, 255, .28); border-left: 3px solid var(--purple);
  background: rgba(123, 92, 255, .07); color: var(--text);
}
.md blockquote p:last-of-type { margin-bottom: 0; }

.copy {
  position: absolute; top: 10px; right: 10px;
  padding: 4px 10px; border-radius: 7px; cursor: pointer;
  font: 500 12px var(--font); color: var(--text);
  background: rgba(255, 255, 255, .06); border: 1px solid var(--line-soft);
}
.copy:hover { background: rgba(123, 92, 255, .25); border-color: var(--purple); }

.md table { width: 100%; border-collapse: collapse; margin: 0 0 20px; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line-soft); }
.md th { color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; border-bottom-color: var(--line); }
.md tr:hover td { background: var(--surface); }

/* ---------- login / error page ---------- */
body.center { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.gate {
  width: min(100%, 420px); text-align: center; padding: 40px 32px;
  border-radius: 20px; border: 1px solid var(--line); background: rgba(18, 18, 42, .7);
  box-shadow: 0 0 60px rgba(123, 92, 255, .14);
}
.gate h1 { margin: 16px 0 8px; font-size: 28px; font-weight: 600; color: #fff; font-variant-caps: all-small-caps; letter-spacing: .03em; }
.gate p { margin: 0 0 24px; }
.gate small { display: block; margin-top: 18px; color: var(--muted); font-size: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px 22px; border-radius: 10px; font-weight: 600; font-size: 15px;
  color: #fff; border: 1px solid var(--purple); background: rgba(123, 92, 255, .18);
}
.btn:hover { text-decoration: none; background: rgba(123, 92, 255, .3); }
.btn-discord { background: #5865F2; border-color: #5865F2; width: 100%; }
.btn-discord:hover { background: #4752C4; border-color: #4752C4; }

/* ---------- mobile ---------- */
.scrim { display: none; }
@media (max-width: 860px) {
  .menu-btn { display: inline-grid; place-items: center; flex: 0 0 auto; }
  .brand span, .user span, .search kbd { display: none; }
  .topbar { gap: 10px; padding: 0 12px; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 60px; left: 0; bottom: 0; width: 280px; height: calc(100dvh - 60px); max-height: none; align-self: auto; z-index: 25;
    background: var(--bg-2); transform: translateX(-100%); transition: transform .2s;
  }
  body.menu-open .sidebar { transform: none; }
  body.menu-open .scrim { display: block; position: fixed; inset: 60px 0 0; background: rgba(0, 0, 0, .5); z-index: 20; }
  .content { padding: 24px 16px 80px; }
}

/* ================= v2: search, cards, editor ================= */
[hidden] { display: none !important; }

.side-home { display: block; padding: 7px 10px; margin: 0 0 18px; border-radius: 8px; color: var(--body); font-size: 14px; }
.side-home:hover { background: var(--surface-2); color: #fff; text-decoration: none; }
.side-home.active { background: rgba(123, 92, 255, .16); color: #fff; box-shadow: inset 2px 0 0 var(--purple); }

/* big search on home */
.search-big { max-width: 640px; height: 54px; margin: 0; padding: 0 18px; gap: 12px; border-radius: 14px; border-color: var(--line); background: rgba(18, 18, 42, .8); box-shadow: 0 0 40px rgba(123, 92, 255, .12); }
.search-big input { font-size: 17px; }
.hero { margin-bottom: 36px; }
.hero p { margin-bottom: 22px; }

.section-head, .page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; margin-bottom: 18px; }
.section-head h2 { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.page-head h1 { margin: 0 0 8px; font-size: clamp(30px, 4vw, 42px); line-height: 1.1; font-weight: 600; color: #fff; }
.page-head .lead { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.card h3 { margin: 0; font-size: 18px; font-weight: 600; color: #fff; }
.card-article { min-height: 150px; }
.card-article .meta { color: var(--muted); }

/* keywords */
.kws { display: flex; flex-wrap: wrap; gap: 6px; }
.kws.top { margin: -16px 0 26px; }
.kw { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; color: #BFEAFF; background: rgba(63, 200, 255, .1); border: 1px solid rgba(63, 200, 255, .18); }

/* search results */
.result-count { font-size: 13px; color: var(--muted); margin: 0 0 12px; }
.results { display: flex; flex-direction: column; gap: 10px; }
.result { display: flex; flex-direction: column; gap: 6px; padding: 16px 18px; border-radius: var(--radius); border: 1px solid var(--line-soft); background: var(--surface); color: var(--body); }
.result:hover { text-decoration: none; border-color: rgba(123, 92, 255, .45); background: var(--surface-2); }
.result strong { color: #fff; font-size: 16px; }
.result .snippet { font-size: 14px; color: var(--muted); }

/* buttons */
.btn { padding: 9px 16px; font-size: 14px; cursor: pointer; font-family: inherit; }
.btn:disabled { opacity: .5; cursor: wait; }
.btn kbd { font: 500 10.5px var(--mono); padding: 1px 5px; border-radius: 4px; background: rgba(255, 255, 255, .1); color: var(--muted); }
.btn-ghost { background: transparent; border-color: var(--line-soft); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; border-color: rgba(255, 107, 107, .5); color: #FF8A8A; }
.btn-danger:hover { background: rgba(255, 107, 107, .12); }
.badge { font-style: normal; font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; padding: 1px 6px; border-radius: 5px; margin-left: 4px; color: var(--gold); border: 1px solid rgba(255, 215, 0, .35); }

/* forms */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field span { display: flex; justify-content: space-between; }
.field em { font-style: normal; font-size: 12px; }
.field input, .field select {
  height: 40px; padding: 0 12px; border-radius: 10px; font: inherit; font-size: 15px; color: var(--text);
  background: rgba(255, 255, 255, .04); border: 1px solid var(--line-soft);
}
.field select { appearance: auto; }
.field input:focus, .field select:focus { outline: none; border-color: var(--purple); box-shadow: 0 0 0 3px rgba(123, 92, 255, .2); }
.form-error { margin: 10px 0 0; padding: 10px 14px; border-radius: 10px; color: #FFB4B4; background: rgba(255, 107, 107, .1); border: 1px solid rgba(255, 107, 107, .3); font-size: 14px; }

/* dialog */
.dialog { width: min(92vw, 460px); padding: 0; border: 1px solid var(--line); border-radius: 18px; background: var(--bg-2); color: var(--body); box-shadow: 0 30px 80px rgba(0, 0, 0, .5); }
.dialog::backdrop { background: rgba(5, 5, 15, .65); backdrop-filter: blur(3px); }
.dialog form { display: flex; flex-direction: column; gap: 14px; padding: 24px; }
.dialog h2 { margin: 0 0 4px; color: #fff; font-size: 20px; font-weight: 600; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* editor (wider than reading view) */
.content:has(.editor) { max-width: 1240px; }
.editor-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.editor-head h1 { margin: 0; font-size: 30px; font-weight: 600; color: #fff; }
.fields { display: grid; grid-template-columns: 2fr 1fr; gap: 14px 16px; margin-bottom: 18px; }
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 6px;
  border: 1px solid var(--line-soft); border-bottom: 0; border-radius: 12px 12px 0 0; background: rgba(255, 255, 255, .03);
}
.tool { height: 32px; min-width: 34px; padding: 0 10px; border-radius: 7px; border: 0; background: transparent; color: var(--body); font: 500 13px var(--font); cursor: pointer; }
.tool:hover { background: rgba(123, 92, 255, .2); color: #fff; }
.tool-sep { width: 1px; height: 20px; margin: 0 4px; background: var(--line-soft); }
.spacer { flex: 1; }
.view-toggle { display: flex; padding: 2px; border-radius: 8px; background: rgba(0, 0, 0, .25); }
.view-toggle button { height: 28px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font: 500 12.5px var(--font); cursor: pointer; }
.view-toggle button.on { background: rgba(123, 92, 255, .3); color: #fff; }

.panes { display: grid; gap: 0; border: 1px solid var(--line-soft); border-radius: 0 0 12px 12px; overflow: hidden; height: min(68vh, 760px); min-height: 380px; }
.panes.view-split { grid-template-columns: 1fr 1fr; }
.panes.view-write, .panes.view-preview { grid-template-columns: 1fr; }
.panes.view-write .preview, .panes.view-preview textarea { display: none; }
.panes textarea {
  width: 100%; height: 100%; resize: none; padding: 18px 20px; border: 0; outline: 0;
  font: 14.5px/1.65 var(--mono); color: var(--text); background: #0D0D20; tab-size: 2;
}
.panes .preview { height: 100%; overflow-y: auto; padding: 18px 24px; background: rgba(255, 255, 255, .015); }
.panes.view-split .preview { border-left: 1px solid var(--line-soft); }
.hint { font-size: 12.5px; color: var(--muted); margin: 12px 0 0; }
.hint code { font-family: var(--mono); font-size: 12px; padding: 1px 5px; border-radius: 4px; background: rgba(63, 200, 255, .08); color: #BFEAFF; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 100; transform: translate(-50%, 20px); opacity: 0;
  padding: 10px 18px; border-radius: 10px; font-size: 14px; color: #fff;
  background: #1C1C3A; border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
  transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { border-color: rgba(85, 255, 85, .35); }
.toast.err { border-color: rgba(255, 107, 107, .5); }

@media (max-width: 860px) {
  .fields { grid-template-columns: 1fr; }
  .panes.view-split { grid-template-columns: 1fr; }
  .panes.view-split .preview { display: none; }
  .search-big { height: 48px; }
  .user .badge { display: none; }
}
.search[hidden] + .user { margin-left: auto; }
