/*
 * PLOTROPOLIS Wiki – Theme "plotropolis"
 * Aufgebaut auf dem Token-Vokabular von Astryx (@astryxdesign/core 0.7.x,
 * Theme-Struktur wie @astryxdesign/theme-neutral): --color-*, --radius-*,
 * --shadow-*, --duration-*, --font-family-*. Schrift: Figtree (OFL), wie im
 * Astryx-Neutral-Theme ausgeliefert.
 */
@layer reset, astryx-base, astryx-theme, app;

/* ------------------------------------------------------------------ Fonts */
@font-face { font-family: 'Figtree'; font-style: normal; font-display: fallback; font-weight: 400; src: url('/fonts/figtree-latin-400-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Figtree'; font-style: normal; font-display: fallback; font-weight: 500; src: url('/fonts/figtree-latin-500-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Figtree'; font-style: normal; font-display: fallback; font-weight: 600; src: url('/fonts/figtree-latin-600-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Figtree'; font-style: normal; font-display: fallback; font-weight: 700; src: url('/fonts/figtree-latin-700-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Figtree'; font-style: normal; font-display: fallback; font-weight: 400; src: url('/fonts/figtree-latin-ext-400-normal.woff2') format('woff2'); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1EFF, U+20A0-20C0, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Figtree'; font-style: normal; font-display: fallback; font-weight: 500; src: url('/fonts/figtree-latin-ext-500-normal.woff2') format('woff2'); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1EFF, U+20A0-20C0, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Figtree'; font-style: normal; font-display: fallback; font-weight: 600; src: url('/fonts/figtree-latin-ext-600-normal.woff2') format('woff2'); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1EFF, U+20A0-20C0, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Figtree'; font-style: normal; font-display: fallback; font-weight: 700; src: url('/fonts/figtree-latin-ext-700-normal.woff2') format('woff2'); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1EFF, U+20A0-20C0, U+2C60-2C7F, U+A720-A7FF; }

/* ------------------------------------------------------------------ Tokens */
@layer astryx-theme {
  :root { color-scheme: light dark; }
  :root[data-theme="light"] { color-scheme: light; }
  :root[data-theme="dark"] { color-scheme: dark; }

  [data-astryx-theme="plotropolis"] {
    /* Fläche */
    --color-background-body: light-dark(#f3f6fa, #101a2b);
    --color-background-surface: light-dark(#ffffff, #16233a);
    --color-background-card: light-dark(#ffffff, #1a2944);
    --color-background-muted: light-dark(#e9eef5, #1d2c47);
    --color-background-popover: light-dark(#ffffff, #1c2b47);
    /* Text */
    --color-text-primary: light-dark(#0d1626, #eef3fa);
    --color-text-secondary: light-dark(#4a586d, #a5b3c8);
    --color-text-disabled: light-dark(#8e99a8, #56647b);
    --color-text-accent: light-dark(#0a6cc2, #6cc4ff);
    --color-icon-secondary: light-dark(#5d6b80, #8d9bb1);
    /* Marke: Diamant-Blau, Gold, Gras */
    --color-accent: light-dark(#0a72cc, #3fb0ff);
    --color-accent-muted: light-dark(#dcecfb, #3fb0ff24);
    --color-on-accent: light-dark(#ffffff, #071322);
    --color-gold: light-dark(#a66d00, #f6bd34);
    --color-gold-muted: light-dark(#fff1cc, #f6bd3424);
    --color-grass: #62bf2c;
    --color-dirt: #74502f;
    /* Status (Astryx-Semantik) */
    --color-info: light-dark(#0a72cc, #6cc4ff);
    --color-info-muted: light-dark(#e1f0fd, #3fb0ff1f);
    --color-success: light-dark(#2b7d2f, #86cf6a);
    --color-success-muted: light-dark(#e2f4dc, #62bf2c24);
    --color-warning: light-dark(#8a6100, #f6bd34);
    --color-warning-muted: light-dark(#fff3d1, #f6bd3424);
    --color-error: light-dark(#c0262c, #ff8a80);
    --color-error-muted: light-dark(#ffe3e0, #ff8a8024);
    /* Linien & Overlays */
    --color-border: light-dark(#0d16261a, #ffffff17);
    --color-border-emphasized: light-dark(#0d16262e, #ffffff2b);
    --color-overlay: light-dark(#0d162680, #050a14bf);
    --color-overlay-hover: light-dark(#0d16260d, #ffffff0f);
    --color-overlay-pressed: light-dark(#0d16261a, #ffffff1a);
    /* Code-Syntax (Astryx-Tokens) */
    --color-syntax-background: light-dark(#f6f8fb, #0d1626);
    --color-syntax-comment: light-dark(#5b6676, #8996aa);
    --color-syntax-keyword: light-dark(#7a1e8c, #e8a6ff);
    --color-syntax-string: light-dark(#0b5f15, #a6dc8f);
    --color-syntax-number: light-dark(#8a3c00, #ffb37e);
    --color-syntax-function: light-dark(#00508f, #8ccfff);
    --color-syntax-variable: light-dark(#0d1626, #e6ecf5);
    --color-syntax-tag: light-dark(#8a0011, #ffaea7);
    /* Form */
    --radius-inner: 0.375rem;
    --radius-element: 0.625rem;
    --radius-container: 0.75rem;
    --radius-full: 9999px;
    --shadow-low: 0 1px 2px light-dark(oklch(0 0 0 / 6%), oklch(0 0 0 / 30%)), inset 0 0 0 1px light-dark(transparent, oklch(1 0 0 / 6%));
    --shadow-med: 0 2px 4px light-dark(oklch(0 0 0 / 5%), oklch(0 0 0 / 35%)), 0 6px 16px light-dark(oklch(0 0 0 / 10%), oklch(0 0 0 / 50%)), inset 0 0 0 1px light-dark(transparent, oklch(1 0 0 / 10%));
    --shadow-high: 0 4px 6px light-dark(oklch(0 0 0 / 10%), oklch(0 0 0 / 50%)), 0 16px 32px light-dark(oklch(0 0 0 / 16%), oklch(0 0 0 / 70%)), inset 0 0 0 1px light-dark(transparent, oklch(1 0 0 / 14%));
    --shadow-focus: 0 0 0 2px var(--color-background-body), 0 0 0 4px var(--color-accent);
    /* Bewegung */
    --duration-fast: 125ms;
    --duration-medium: 300ms;
    --ease: cubic-bezier(.2, .7, .2, 1);
    /* Typo */
    --font-family-body: Figtree, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-family-heading: var(--font-family-body);
    --font-family-code: ui-monospace, "SF Mono", Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    /* Layout */
    --topbar-h: 60px;
    --sidebar-w: 280px;
    --toc-w: 232px;
    --content-max: 46rem;
  }
}

/* ------------------------------------------------------------------ Reset */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html, body { margin: 0; }
  body { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
  img { max-width: 100%; height: auto; display: block; }
  button, input, select, textarea { font: inherit; color: inherit; }
  button { cursor: pointer; }
  [hidden] { display: none !important; }
}

/* ------------------------------------------------------------------ Base */
@layer astryx-base {
  :root { padding-bottom: env(safe-area-inset-bottom, 0px); scroll-padding-top: calc(var(--topbar-h) + 24px + env(safe-area-inset-top, 0px)); }
  body {
    background: var(--color-background-body);
    color: var(--color-text-primary);
    font-family: var(--font-family-body);
    font-size: 1rem;
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
  }
  a { color: var(--color-text-accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
  a:hover { text-decoration-thickness: 2px; }
  :focus-visible { outline: none; box-shadow: var(--shadow-focus); border-radius: var(--radius-inner); }
  ::selection { background: color-mix(in srgb, var(--color-accent) 30%, transparent); }
  kbd { font-family: var(--font-family-body); font-size: .72rem; font-weight: 600; padding: 1px 6px; border-radius: var(--radius-inner); border: 1px solid var(--color-border-emphasized); color: var(--color-text-secondary); background: var(--color-background-surface); }
  code { font-family: var(--font-family-code); font-size: .875em; background: var(--color-background-muted); padding: .1em .35em; border-radius: var(--radius-inner); }
  mark { background: var(--color-gold-muted); color: inherit; padding: 0 .15em; border-radius: 3px; }
  .skip { position: absolute; left: 12px; top: -48px; z-index: 100; padding: 8px 12px; background: var(--color-accent); color: var(--color-on-accent); border-radius: var(--radius-element); }
  .skip:focus { top: 12px; }
  @media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0ms !important; animation-duration: 0ms !important; } }
}

@layer app {
/* ------------------------------------------------------------------ Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px;
  border-radius: var(--radius-element); border: 1px solid var(--color-border-emphasized);
  background: var(--color-background-surface); color: var(--color-text-primary);
  font-size: .875rem; font-weight: 600; white-space: nowrap; text-decoration: none;
  transition: background var(--duration-fast), border-color var(--duration-fast);
}
.btn:hover { background: color-mix(in srgb, var(--color-background-surface), var(--color-text-primary) 6%); }
.btn-primary { background: var(--color-accent); color: var(--color-on-accent); border-color: transparent; }
.btn-primary:hover { background: color-mix(in srgb, var(--color-accent), #000 10%); }
.btn-discord { background: #5865f2; color: #fff; border-color: transparent; }
.btn-discord:hover { background: #4752c4; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--color-text-secondary); }
.btn-ghost:hover { background: var(--color-overlay-hover); color: var(--color-text-primary); }
.btn-danger { color: var(--color-error); }
.btn-sm { height: 30px; padding: 0 10px; font-size: .8125rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none;
  border: 0; border-radius: var(--radius-element); background: transparent; color: var(--color-text-secondary);
}
.icon-btn:hover { background: var(--color-overlay-hover); color: var(--color-text-primary); }
.icon-btn.sm { width: 28px; height: 28px; border-radius: var(--radius-inner); }

/* ------------------------------------------------------------------ Topbar */
.topbar {
  position: sticky; top: 0; z-index: 30; height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: color-mix(in srgb, var(--color-background-surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  padding-top: env(safe-area-inset-top, 0px);
}
.nav-toggle { display: none; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; flex: none; }
.brand-mark { width: 44px; height: auto; }
.brand-wiki { font-weight: 700; font-size: .95rem; color: var(--color-text-secondary); padding-left: 10px; border-left: 1px solid var(--color-border-emphasized); }
.search-trigger {
  display: flex; align-items: center; gap: 10px; height: 38px; width: min(360px, 100%); margin-left: 20px; padding: 0 10px 0 12px;
  border-radius: var(--radius-element); border: 1px solid var(--color-border); background: var(--color-background-muted);
  color: var(--color-text-secondary); font-size: .9rem; text-align: left;
}
.search-trigger span { flex: 1; }
.search-trigger:hover { border-color: var(--color-border-emphasized); }
.top-links { display: flex; gap: 4px; margin-left: auto; }
.top-links a { color: var(--color-text-secondary); text-decoration: none; font-size: .9rem; font-weight: 500; padding: 6px 10px; border-radius: var(--radius-element); }
.top-links a:hover { color: var(--color-text-primary); background: var(--color-overlay-hover); }
.i-sun, .i-moon { display: none; }
:root[data-theme="dark"] .i-moon, :root[data-theme="light"] .i-sun { display: block; }
.auth { display: flex; align-items: center; gap: 8px; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 3px 10px 3px 3px; border-radius: var(--radius-full); border: 1px solid var(--color-border); background: var(--color-background-surface); font-size: .85rem; font-weight: 600; }
.user-chip img { width: 28px; height: 28px; border-radius: 50%; }
.role { font-size: .72rem; font-weight: 600; color: var(--color-text-secondary); }

/* Gras-Kante unter der Kopfzeile – das eine Markenelement */
.grass {
  position: sticky; top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px)); z-index: 29; height: 9px;
  background-color: var(--color-dirt);
  background-image:
    repeating-linear-gradient(90deg, transparent 0 24px, #58b324 24px 32px, transparent 32px 72px, #4ea21f 72px 80px, transparent 80px 104px, #62bf2c 104px 112px, transparent 112px 152px),
    repeating-linear-gradient(90deg, #6fd034 0 8px, #58b324 8px 16px, #64c22c 16px 24px, #4ea21f 24px 32px, #73d63a 32px 40px, #5cba27 40px 48px, #66c72f 48px 56px),
    repeating-linear-gradient(90deg, #74502f 0 8px, #5f4026 8px 16px, #7d5a36 16px 24px, #6a4729 24px 32px, #573a22 32px 40px);
  background-size: auto 3px, auto 5px, auto 9px;
  background-position: 0 5px, 0 0, 0 0;
  background-repeat: repeat-x;
}

/* ------------------------------------------------------------------ Layout */
.layout { flex: 1; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w); max-width: 1440px; width: 100%; margin: 0 auto; }
.main { min-width: 0; padding: 40px 48px 80px; outline: none; }
.main > * { max-width: var(--content-max); margin-left: auto; margin-right: auto; }
.main.is-editing > .editor-shell { max-width: calc(var(--content-max) + 120px); }

/* ------------------------------------------------------------------ Sidebar */
.sidebar {
  position: sticky; top: calc(var(--topbar-h) + 10px + env(safe-area-inset-top, 0px)); align-self: start;
  height: calc(100vh - var(--topbar-h) - 10px - env(safe-area-inset-top, 0px)); overflow-y: auto; overscroll-behavior: contain;
  padding: 24px 12px 32px 20px; border-right: 1px solid var(--color-border);
  scrollbar-width: thin;
}
.side-actions { display: flex; gap: 6px; margin: 0 0 18px; }
.side-actions .btn { flex: 1; justify-content: center; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { padding-left: 14px; margin-left: 10px; border-left: 1px solid var(--color-border); }
.tree-group { margin-top: 22px; }
.tree-group:first-child { margin-top: 0; }
.tree-group > .row .label { font-size: .8rem; font-weight: 700; color: var(--color-text-primary); letter-spacing: .01em; }
.tree-group > ul { border-left: 0; margin-left: 0; padding-left: 0; margin-top: 4px; }
.row { position: relative; display: flex; align-items: center; gap: 2px; border-radius: var(--radius-element); }
.row a, .row .label { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 6px 8px; text-decoration: none; color: var(--color-text-secondary); font-size: .9rem; font-weight: 500; border-radius: var(--radius-element); }
.row a:hover { color: var(--color-text-primary); background: var(--color-overlay-hover); }
.row a[aria-current="page"] { color: var(--color-text-accent); background: var(--color-accent-muted); font-weight: 600; }
.row .ico { width: 1.2em; text-align: center; flex: none; }
.row .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .caret { flex: none; width: 22px; height: 22px; border: 0; background: none; color: var(--color-icon-secondary); border-radius: var(--radius-inner); display: grid; place-items: center; }
.row .caret svg { transition: transform var(--duration-fast); }
.row .caret[aria-expanded="false"] svg { transform: rotate(-90deg); }
.row .row-tools { display: none; gap: 2px; padding-right: 2px; }
.can-edit .row:hover .row-tools, .can-edit .row:focus-within .row-tools { display: flex; }
.row[draggable="true"] { cursor: grab; }
.row.drop-before::before, .row.drop-after::after { content: ""; position: absolute; left: 6px; right: 6px; height: 2px; background: var(--color-accent); border-radius: 2px; }
.row.drop-before::before { top: -1px; }
.row.drop-after::after { bottom: -1px; }
.row.drop-inside { box-shadow: inset 0 0 0 2px var(--color-accent); }
.row.dragging { opacity: .4; }
.side-empty { color: var(--color-text-secondary); font-size: .9rem; }

/* ------------------------------------------------------------------ TOC */
.toc { position: sticky; top: calc(var(--topbar-h) + 10px + env(safe-area-inset-top, 0px)); align-self: start; max-height: calc(100vh - var(--topbar-h) - 10px); overflow-y: auto; padding: 40px 20px 32px 8px; font-size: .85rem; }
.toc h2 { font-size: .8rem; font-weight: 700; margin: 0 0 10px; color: var(--color-text-primary); }
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--color-border); }
.toc a { display: block; padding: 4px 0 4px 12px; margin-left: -1px; border-left: 2px solid transparent; color: var(--color-text-secondary); text-decoration: none; line-height: 1.4; }
.toc a.lvl-3 { padding-left: 24px; }
.toc a:hover { color: var(--color-text-primary); }
.toc a.active { color: var(--color-text-accent); border-left-color: var(--color-accent); font-weight: 600; }

/* ------------------------------------------------------------------ Page */
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; font-size: .85rem; color: var(--color-text-secondary); margin-bottom: 14px; }
.crumbs a { color: inherit; text-decoration: none; }
.crumbs a:hover { color: var(--color-text-primary); }
.crumbs .sep { opacity: .5; }
.page-head { display: flex; gap: 16px; align-items: flex-start; }
.page-head .grow { flex: 1; min-width: 0; }
.page-icon { font-size: 2.4rem; line-height: 1; margin-bottom: 12px; }
.page-title { font-family: var(--font-family-heading); font-size: clamp(1.9rem, 1.4rem + 1.6vw, 2.5rem); font-weight: 700; line-height: 1.15; letter-spacing: -0.022em; margin: 0; text-wrap: balance; }
.page-lead { font-size: 1.15rem; color: var(--color-text-secondary); margin: 12px 0 0; line-height: 1.5; text-wrap: pretty; }
.page-meta { display: flex; align-items: center; gap: 8px; margin: 20px 0 32px; padding-bottom: 20px; border-bottom: 1px solid var(--color-border); font-size: .85rem; color: var(--color-text-secondary); }
.page-meta img { width: 22px; height: 22px; border-radius: 50%; }
.page-tools { display: flex; gap: 6px; flex: none; }

/* Inhalt */
.content { font-size: 1rem; }
.content > * + * { margin-top: 1rem; }
.content p { margin: 0; text-wrap: pretty; }
.content h2, .content h3 { font-family: var(--font-family-heading); letter-spacing: -0.012em; scroll-margin-top: calc(var(--topbar-h) + 30px); }
.content h2 { font-size: 1.5rem; line-height: 1.3; margin: 2.2rem 0 0; }
.content h3 { font-size: 1.2rem; line-height: 1.35; margin: 1.7rem 0 0; }
.content h2 + *, .content h3 + * { margin-top: .6rem; }
.content .anchor { margin-left: 8px; opacity: 0; text-decoration: none; color: var(--color-text-secondary); font-weight: 500; }
.content h2:hover .anchor, .content h3:hover .anchor { opacity: 1; }
.content ul, .content ol { margin: 0; padding-left: 1.5rem; }
.content li + li { margin-top: .3rem; }
.content li::marker { color: var(--color-text-secondary); }
.content blockquote { margin: 0; padding: 2px 0 2px 18px; border-left: 3px solid var(--color-border-emphasized); color: var(--color-text-secondary); font-size: 1.05rem; }
.content hr { border: 0; border-top: 1px solid var(--color-border); margin: 2rem 0; }

.hint { display: flex; gap: 12px; padding: 14px 16px; border-radius: var(--radius-container); background: var(--h-bg); border: 1px solid color-mix(in srgb, var(--h-fg) 22%, transparent); }
.hint .h-ico { flex: none; color: var(--h-fg); margin-top: 3px; }
.hint .h-body { flex: 1; min-width: 0; }
.hint.info { --h-bg: var(--color-info-muted); --h-fg: var(--color-info); }
.hint.success { --h-bg: var(--color-success-muted); --h-fg: var(--color-success); }
.hint.warning { --h-bg: var(--color-warning-muted); --h-fg: var(--color-warning); }
.hint.danger { --h-bg: var(--color-error-muted); --h-fg: var(--color-error); }

.codeblock { position: relative; border-radius: var(--radius-container); background: var(--color-syntax-background); border: 1px solid var(--color-border); overflow: hidden; }
.codeblock .code-bar { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 14px; border-bottom: 1px solid var(--color-border); font-size: .78rem; color: var(--color-text-secondary); font-weight: 600; }
.codeblock pre { margin: 0; padding: 14px 16px; overflow-x: auto; font-family: var(--font-family-code); font-size: .875rem; line-height: 1.6; tab-size: 2; }
.codeblock pre code { background: none; padding: 0; font-size: inherit; }
.hljs-comment, .hljs-quote { color: var(--color-syntax-comment); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-type { color: var(--color-syntax-keyword); }
.hljs-string, .hljs-attr-value, .hljs-regexp { color: var(--color-syntax-string); }
.hljs-number, .hljs-literal { color: var(--color-syntax-number); }
.hljs-title, .hljs-function, .hljs-section { color: var(--color-syntax-function); }
.hljs-attr, .hljs-variable, .hljs-property { color: var(--color-syntax-variable); }
.hljs-tag, .hljs-name { color: var(--color-syntax-tag); }

figure { margin: 0; }
.fig { display: flex; flex-direction: column; }
.fig img { border-radius: var(--radius-container); cursor: zoom-in; }
.fig.w-s { width: min(40%, 100%); } .fig.w-m { width: min(65%, 100%); } .fig.w-l { width: 100%; }
.fig.w-full { width: calc(100% + 96px); margin-left: -48px; margin-right: -48px; max-width: none; }
.fig.w-full img { border-radius: 0; }
.fig.a-center { margin-left: auto; margin-right: auto; } .fig.a-right { margin-left: auto; }
.fig figcaption { font-size: .85rem; color: var(--color-text-secondary); margin-top: 8px; text-align: center; }
.gallery { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); gap: 10px; }
.gallery figure img { aspect-ratio: 4 / 3; object-fit: cover; width: 100%; border-radius: var(--radius-element); cursor: zoom-in; }
.gallery figcaption { font-size: .8rem; color: var(--color-text-secondary); margin-top: 4px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius-container); }
.table-wrap table { border-collapse: collapse; width: 100%; font-size: .925rem; }
.table-wrap th, .table-wrap td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--color-border); }
.table-wrap tr:last-child td { border-bottom: 0; }
.table-wrap th { background: var(--color-background-muted); font-weight: 700; font-size: .85rem; }

details.expand { border: 1px solid var(--color-border); border-radius: var(--radius-container); background: var(--color-background-surface); }
details.expand + details.expand { margin-top: .5rem; }
details.expand summary { list-style: none; cursor: pointer; padding: 12px 16px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
details.expand summary::-webkit-details-marker { display: none; }
details.expand summary svg { transition: transform var(--duration-fast); color: var(--color-icon-secondary); flex: none; }
details.expand[open] summary svg { transform: rotate(90deg); }
details.expand .exp-body { padding: 0 16px 14px 42px; }

.embed { position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius-container); overflow: hidden; background: var(--color-background-muted); }
.embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.link-card { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border: 1px solid var(--color-border); border-radius: var(--radius-container); text-decoration: none; color: var(--color-text-primary); background: var(--color-background-surface); }
.link-card:hover { border-color: var(--color-accent); }
.link-card small { display: block; color: var(--color-text-secondary); overflow: hidden; text-overflow: ellipsis; }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 56px; }
.pager a { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border: 1px solid var(--color-border); border-radius: var(--radius-container); text-decoration: none; color: var(--color-text-primary); font-weight: 600; background: var(--color-background-surface); }
.pager a:hover { border-color: var(--color-accent); }
.pager small { color: var(--color-text-secondary); font-weight: 500; font-size: .8rem; }
.pager .next { text-align: right; grid-column: 2; }

.empty { text-align: center; padding: 72px 16px; color: var(--color-text-secondary); }
.empty img { width: 120px; margin: 0 auto 20px; }
.empty h1 { color: var(--color-text-primary); font-size: 1.5rem; margin: 0 0 8px; }

/* ------------------------------------------------------------------ Editor */
.editor-bar {
  position: sticky; top: calc(var(--topbar-h) + 10px + env(safe-area-inset-top, 0px)); z-index: 20;
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; margin: -24px 0 28px;
  background: color-mix(in srgb, var(--color-background-surface) 92%, transparent); backdrop-filter: blur(10px);
  border: 1px solid var(--color-border); border-radius: var(--radius-container); box-shadow: var(--shadow-low);
}
.editor-bar .status { flex: 1; font-size: .85rem; color: var(--color-text-secondary); display: flex; align-items: center; gap: 8px; min-width: 0; }
.editor-bar .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-success); flex: none; }
.editor-bar .dot.dirty { background: var(--color-gold); }
.editor-shell { padding-left: 60px; }
.ed-icon { font-size: 2.4rem; line-height: 1; background: none; border: 1px dashed transparent; border-radius: var(--radius-element); padding: 4px 6px; margin: 0 0 8px -6px; }
.ed-icon:hover { border-color: var(--color-border-emphasized); }
.ed-icon.empty { font-size: .9rem; color: var(--color-text-secondary); border-color: var(--color-border-emphasized); padding: 6px 10px; }
.ed-title, .ed-lead { outline: none; }
.ed-title { font-size: clamp(1.9rem, 1.4rem + 1.6vw, 2.5rem); font-weight: 700; letter-spacing: -0.022em; line-height: 1.15; }
.ed-lead { font-size: 1.15rem; color: var(--color-text-secondary); margin: 12px 0 28px; }
[contenteditable][data-ph]:empty::before { content: attr(data-ph); color: var(--color-text-disabled); pointer-events: none; }
.blocks { display: flex; flex-direction: column; gap: 6px; padding-bottom: 40vh; }
.blk { position: relative; border-radius: var(--radius-element); }
.blk-gutter { position: absolute; left: -58px; top: 2px; display: flex; gap: 2px; opacity: 0; transition: opacity var(--duration-fast); }
.blk:hover > .blk-gutter, .blk:focus-within > .blk-gutter, .blk-gutter:focus-within { opacity: 1; }
.blk-gutter button { width: 26px; height: 26px; display: grid; place-items: center; border: 0; background: none; border-radius: var(--radius-inner); color: var(--color-icon-secondary); }
.blk-gutter button:hover { background: var(--color-overlay-hover); color: var(--color-text-primary); }
.blk-gutter .drag { cursor: grab; }
.blk.dragging { opacity: .35; }
.blk.drop-before::before, .blk.drop-after::after { content: ""; position: absolute; left: 0; right: 0; height: 3px; background: var(--color-accent); border-radius: 3px; }
.blk.drop-before::before { top: -5px; } .blk.drop-after::after { bottom: -5px; }
.blk .ce { outline: none; min-height: 1.6em; }
.blk .ce.p { padding: 2px 0; }
.blk h2.ce, .blk h3.ce { margin: 0; }
.blk-heading { margin-top: 1rem; }
.blk ul.ce, .blk ol.ce { padding-left: 1.5rem; margin: 0; }
.blk-card { border: 1px solid var(--color-border); border-radius: var(--radius-container); background: var(--color-background-surface); padding: 12px; }
.blk-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 10px; font-size: .8rem; color: var(--color-text-secondary); }
.seg { display: inline-flex; border: 1px solid var(--color-border-emphasized); border-radius: var(--radius-element); overflow: hidden; }
.seg button { border: 0; background: none; padding: 4px 9px; font-size: .78rem; font-weight: 600; color: var(--color-text-secondary); }
.seg button + button { border-left: 1px solid var(--color-border); }
.seg button[aria-pressed="true"] { background: var(--color-accent-muted); color: var(--color-text-accent); }
.field { height: 30px; padding: 0 10px; border-radius: var(--radius-element); border: 1px solid var(--color-border-emphasized); background: var(--color-background-body); font-size: .85rem; min-width: 0; }
.field:focus { outline: none; border-color: var(--color-accent); }
textarea.field { height: auto; padding: 8px 10px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 32px 16px; text-align: center;
  border: 2px dashed var(--color-border-emphasized); border-radius: var(--radius-container); color: var(--color-text-secondary); font-size: .9rem;
}
.dropzone.over { border-color: var(--color-accent); background: var(--color-accent-muted); color: var(--color-text-accent); }
.img-edit { position: relative; }
.img-edit .fig { margin-bottom: 0; }
.img-edit .fig img { cursor: default; }
.img-edit .fig.w-full { width: 100%; margin: 0; }
.img-caption { font-size: .85rem; color: var(--color-text-secondary); text-align: center; margin-top: 8px; outline: none; }
.uploading { display: grid; place-items: center; height: 160px; border-radius: var(--radius-container); background: var(--color-background-muted); color: var(--color-text-secondary); font-size: .9rem; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--color-border-emphasized); border-top-color: var(--color-accent); animation: spin .8s linear infinite; margin: 0 auto 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
.gal-edit .gallery figure { position: relative; cursor: grab; }
.gal-edit .gallery figure.dragging { opacity: .35; }
.gal-edit .gallery figure.over { outline: 2px solid var(--color-accent); outline-offset: 2px; border-radius: var(--radius-element); }
.gal-edit .gallery img { cursor: grab; }
.gal-edit .gal-x { position: absolute; top: 6px; right: 6px; }
.gal-edit .gal-x button { background: color-mix(in srgb, #000 55%, transparent); color: #fff; }
.gal-edit .gallery input { width: 100%; margin-top: 4px; }
.gal-add { aspect-ratio: 4 / 3; display: grid; place-items: center; border: 2px dashed var(--color-border-emphasized); border-radius: var(--radius-element); color: var(--color-text-secondary); background: none; font-weight: 600; font-size: .85rem; }
.gal-add:hover { border-color: var(--color-accent); color: var(--color-text-accent); }
.code-edit pre { min-height: 3em; white-space: pre; }
.tbl-edit td, .tbl-edit th { min-width: 90px; outline: none; }
.tbl-edit td:focus, .tbl-edit th:focus { box-shadow: inset 0 0 0 2px var(--color-accent); }
.exp-edit .exp-title { font-weight: 600; outline: none; padding: 4px 0 8px; border-bottom: 1px solid var(--color-border); margin-bottom: 8px; }
.add-block { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--color-text-secondary); background: none; border: 1px dashed var(--color-border-emphasized); border-radius: var(--radius-element); padding: 10px 14px; width: 100%; font-size: .9rem; }
.add-block:hover { border-color: var(--color-accent); color: var(--color-text-accent); }
.editor-drop-hint { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: color-mix(in srgb, var(--color-accent) 12%, transparent); border: 3px dashed var(--color-accent); pointer-events: none; font-weight: 700; color: var(--color-text-accent); font-size: 1.1rem; }

/* Menüs / Popover */
.popover {
  position: fixed; z-index: 70; min-width: 240px; max-width: 320px; max-height: 360px; overflow-y: auto; padding: 6px;
  background: var(--color-background-popover); border: 1px solid var(--color-border); border-radius: var(--radius-container); box-shadow: var(--shadow-high);
}
.popover .grp { font-size: .72rem; font-weight: 700; color: var(--color-text-secondary); padding: 8px 10px 4px; }
.mi { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; background: none; border-radius: var(--radius-element); text-align: left; font-size: .875rem; color: var(--color-text-primary); }
.mi .mi-ico { width: 30px; height: 30px; flex: none; display: grid; place-items: center; border-radius: var(--radius-inner); border: 1px solid var(--color-border); background: var(--color-background-surface); font-size: .95rem; color: var(--color-text-secondary); }
.mi small { display: block; color: var(--color-text-secondary); font-size: .78rem; }
.mi:hover, .mi.active { background: var(--color-overlay-hover); }
.mi.active { box-shadow: inset 0 0 0 1px var(--color-border-emphasized); }
.mi.danger { color: var(--color-error); }
.mi-empty { padding: 10px; color: var(--color-text-secondary); font-size: .85rem; }
.fmt-bar { position: fixed; z-index: 70; display: flex; gap: 2px; padding: 4px; background: var(--color-background-popover); border: 1px solid var(--color-border); border-radius: var(--radius-element); box-shadow: var(--shadow-high); }
.fmt-bar button { min-width: 30px; height: 30px; border: 0; background: none; border-radius: var(--radius-inner); font-size: .85rem; color: var(--color-text-primary); padding: 0 6px; }
.fmt-bar button:hover { background: var(--color-overlay-hover); }
.fmt-bar .sep { width: 1px; background: var(--color-border); margin: 4px 2px; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; padding: 4px; }
.emoji-grid button { font-size: 1.25rem; height: 36px; border: 0; background: none; border-radius: var(--radius-inner); }
.emoji-grid button:hover { background: var(--color-overlay-hover); }

/* Dialoge */
.modal-back { position: fixed; inset: 0; z-index: 80; background: var(--color-overlay); display: flex; align-items: flex-start; justify-content: center; padding: 10vh 16px 16px; animation: fade var(--duration-fast) var(--ease); }
.modal { width: min(560px, 100%); max-height: 80vh; overflow: auto; background: var(--color-background-popover); border: 1px solid var(--color-border); border-radius: 16px; box-shadow: var(--shadow-high); animation: rise var(--duration-medium) var(--ease); }
.modal.wide { width: min(880px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px 8px; }
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 8px 18px 18px; }
.modal-body p { margin: 0 0 12px; color: var(--color-text-secondary); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; border-top: 1px solid var(--color-border); }
.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-row label { font-size: .85rem; font-weight: 600; }
.form-row .field { height: 38px; font-size: .95rem; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .9rem; }
.check small { display: block; color: var(--color-text-secondary); }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(.99); } }

/* Suche */
.search-box { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--color-border); }
.search-box input { flex: 1; border: 0; background: none; font-size: 1.05rem; outline: none; }
.search-res { padding: 8px; max-height: 60vh; overflow: auto; }
.sr { display: block; padding: 10px 12px; border-radius: var(--radius-element); text-decoration: none; color: var(--color-text-primary); }
.sr.active, .sr:hover { background: var(--color-accent-muted); }
.sr b { font-weight: 600; }
.sr small { display: block; color: var(--color-text-secondary); font-size: .82rem; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr mark { background: var(--color-gold-muted); }
.search-foot { display: flex; gap: 16px; padding: 10px 18px; border-top: 1px solid var(--color-border); font-size: .78rem; color: var(--color-text-secondary); }

/* Verlauf */
.revs { display: grid; grid-template-columns: 240px 1fr; min-height: 360px; }
.rev-list { border-right: 1px solid var(--color-border); padding: 8px; overflow: auto; max-height: 60vh; }
.rev-list .mi { flex-direction: column; align-items: flex-start; gap: 0; }
.rev-prev { padding: 18px 22px; overflow: auto; max-height: 60vh; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; z-index: 90; background: #050a14e6; display: grid; place-items: center; padding: 24px; cursor: zoom-out; animation: fade var(--duration-fast); }
.lightbox img { max-width: 100%; max-height: 90vh; border-radius: var(--radius-container); }

/* Toasts */
.toasts { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 10px 14px; border-radius: var(--radius-element); background: var(--color-text-primary); color: var(--color-background-body); font-size: .9rem; font-weight: 500; box-shadow: var(--shadow-high); animation: rise var(--duration-medium) var(--ease); max-width: 360px; }
.toast.err { background: var(--color-error); color: #fff; }

.demo-banner { max-width: var(--content-max); margin: 0 auto 20px; padding: 10px 14px; border-radius: var(--radius-element); background: var(--color-gold-muted); color: var(--color-text-primary); font-size: .85rem; border: 1px solid color-mix(in srgb, var(--color-gold) 30%, transparent); }

/* ------------------------------------------------------------------ Footer */
.site-footer { border-top: 1px solid var(--color-border); background: var(--color-background-surface); }
.footer-inner { max-width: 1440px; margin: 0 auto; padding: 24px 24px 28px; font-size: .85rem; color: var(--color-text-secondary); }
.footer-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 24px; }
.footer-links { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.footer-links a { color: var(--color-text-secondary); text-decoration: none; }
.footer-links a:hover { color: var(--color-text-primary); text-decoration: underline; }
.footer-legal { margin: 14px 0 0; font-size: .8rem; line-height: 1.6; color: var(--color-text-secondary); }

/* ------------------------------------------------------------------ Responsive */
@media (max-width: 1240px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 960px) {
  .top-links { display: none; }
  .search-trigger { margin-left: auto; width: auto; }
  .search-trigger span, .search-trigger kbd { display: none; }
}
@media (max-width: 860px) {
  .nav-toggle { display: inline-grid; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; height: 100%; width: min(320px, 86vw);
    background: var(--color-background-surface); transform: translateX(-102%); transition: transform var(--duration-medium) var(--ease);
    padding-top: calc(20px + env(safe-area-inset-top, 0px)); box-shadow: var(--shadow-high);
  }
  .sidebar.open { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 45; background: var(--color-overlay); }
  .main { padding: 28px 20px 64px; }
  .fig.w-full { width: calc(100% + 40px); margin-left: -20px; margin-right: -20px; }
  .editor-shell { padding-left: 0; }
  .blk-gutter { position: static; opacity: 1; margin-bottom: 2px; }
  .blk-gutter button { width: 24px; height: 24px; }
  .revs { grid-template-columns: 1fr; }
  .rev-list { border-right: 0; border-bottom: 1px solid var(--color-border); max-height: 30vh; }
  .user-chip .name, .user-chip .role { display: none; }
  .user-chip { padding: 3px; }
}
@media (max-width: 520px) {
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fig.w-s, .fig.w-m { width: 100%; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: 1; }
  .editor-bar .status span.txt { display: none; }
}
}

@layer app {
  [contenteditable]:focus-visible, .search-box input:focus-visible, .ed-title:focus-visible, .ed-lead:focus-visible { box-shadow: none; }
  .blk:focus-within > .blk-gutter { opacity: 1; }
  @media (max-width: 640px) {
    .btn-discord .lbl { display: none; }
    .btn-discord { padding: 0 10px; }
  }
}

@layer app {
  .embed-consent { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 20px; text-align: center; background: var(--color-background-muted); border: 1px solid var(--color-border); border-radius: var(--radius-container); }
  .embed-consent p { margin: 0; max-width: 34rem; font-size: .875rem; color: var(--color-text-secondary); }
  .embed-ext { font-size: .85rem; }
}
