:root {
  --bg: #0f1420;
  --bg-canvas: #131a29;
  --panel: #1a2233;
  --panel-2: #212c42;
  --border: #2c3852;
  --text: #e8edf6;
  --muted: #9aa7bd;
  --accent: #4f9cff;
  --theme: #f0a04b;
  --topic: #4f9cff;
  --leaf: #5fd0a8;
  --cross: #c77dff;
  --shadow: 0 8px 28px rgba(0,0,0,.35);
  font-size: 15px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  overflow: hidden;
}
body { display: flex; flex-direction: column; }

/* ---------- Topbar ---------- */
#topbar {
  height: 60px;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 18px;
  background: linear-gradient(180deg, #18203200, #0e1320), var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 240px; }
.logo {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #7b61ff);
  font-weight: 800; letter-spacing: .5px; color: #fff; text-decoration: none;
}
a.logo:hover { filter: brightness(1.12); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text small { color: var(--muted); font-size: .76rem; }

/* ---------- Fach-Umschalter ---------- */
.subject-switch { display: flex; gap: 6px; align-items: center; }
.subject-switch a {
  display: inline-flex; align-items: center;
  padding: 7px 13px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-canvas); color: var(--text); text-decoration: none;
  font-size: .82rem; font-weight: 700; letter-spacing: .4px; white-space: nowrap;
}
.subject-switch a:hover { border-color: var(--accent); color: #fff; }
.subject-switch a.active {
  background: linear-gradient(135deg, var(--accent), #7b61ff);
  border-color: transparent; color: #fff; cursor: default;
}

.search-wrap { position: relative; flex: 1; max-width: 560px; }
#search {
  width: 100%; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-canvas); color: var(--text);
  font-size: .95rem; outline: none;
}
#search:focus { border-color: var(--accent); }
#search-results {
  position: absolute; top: 46px; left: 0; right: 0; margin: 0; padding: 6px;
  list-style: none; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); max-height: 340px; overflow-y: auto;
  display: none; z-index: 40;
}
#search-results.show { display: block; }
#search-results li {
  padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: .9rem;
}
#search-results li:hover, #search-results li.active { background: var(--accent); color: #fff; }
#search-results li .crumb { display: block; font-size: .74rem; color: var(--muted); }
#search-results li:hover .crumb, #search-results li.active .crumb { color: #e6efff; }

.toolbar { display: flex; gap: 8px; }
.toolbar button {
  padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-canvas); color: var(--text); cursor: pointer; font-size: .85rem;
}
.toolbar button:hover { border-color: var(--accent); color: #fff; }
.toolbar button.active { background: var(--cross); border-color: var(--cross); color: #fff; }

/* ---------- Breadcrumb ---------- */
#breadcrumb {
  height: 34px; display: flex; align-items: center; gap: 6px;
  padding: 0 18px; background: var(--bg-canvas); border-bottom: 1px solid var(--border);
  font-size: .82rem; color: var(--muted); overflow-x: auto; white-space: nowrap;
}
#breadcrumb .bc { cursor: pointer; }
#breadcrumb .bc:hover { color: var(--accent); }
#breadcrumb .sep { opacity: .5; }

/* ---------- Layout ---------- */
#layout { display: flex; flex: 1 1 auto; min-height: 0; }
#canvas-wrap { position: relative; flex: 1; min-width: 0; background:
  radial-gradient(1200px 600px at 30% 20%, #18233a 0%, var(--bg-canvas) 60%); }
#mindmap { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#mindmap:active { cursor: grabbing; }

.legend {
  position: absolute; left: 14px; bottom: 14px;
  background: rgba(20,27,42,.85); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; font-size: .76rem; color: var(--muted);
  display: flex; flex-direction: column; gap: 5px; backdrop-filter: blur(4px);
}
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.legend .d-theme { background: var(--theme); }
.legend .d-topic { background: var(--topic); }
.legend .d-leaf { background: var(--leaf); }
.legend .line-cross { display: inline-block; width: 16px; border-top: 2px dashed var(--cross); margin-right: 6px; vertical-align: middle; }
.legend .hint { margin-top: 4px; max-width: 230px; line-height: 1.4; opacity: .8; }

/* ---------- Nodes & links (SVG) ---------- */
.link { fill: none; stroke: var(--border); stroke-width: 1.5px; }

/* ---------- Querverbindungen ---------- */
.cross-link {
  fill: none; stroke: var(--cross); stroke-dasharray: 6 4;
  stroke-width: 1.6px; pointer-events: none;
  transition: opacity .2s ease, stroke-width .2s ease;
}
.cross-link.faint  { opacity: .22; stroke-width: 1.4px; }   /* Ruhezustand: dezent vorhanden */
.cross-link.shown  { opacity: .5;  stroke-width: 1.7px; }   /* Toggle "Verbindungen" an */
.cross-link.dim    { opacity: .06; stroke-width: 1.2px; }   /* abgeblendet bei Fokus */
.cross-link.active { opacity: 1; stroke-width: 2.6px; stroke: #d49bff;
  filter: drop-shadow(0 0 4px rgba(199,125,255,.6)); }      /* hervorgehoben */
.cross-link.indirect { stroke-dasharray: 2 4; }             /* Ziel in eingeklapptem Ast */
.cross-arrow-head { fill: var(--cross); opacity: .5; }
.cross-arrow-head-active { fill: #d49bff; }

.node { cursor: pointer; }
.node circle {
  stroke-width: 2px; transition: r .15s ease;
}
.node.theme circle { fill: var(--theme); stroke: #ffce9e; }
.node.topic circle { fill: var(--topic); stroke: #a9d0ff; }
.node.leaf  circle { fill: var(--leaf);  stroke: #b6f0db; }
.node._collapsed circle { stroke-width: 3.5px; }
.node.selected circle { stroke: #fff; stroke-width: 3.5px; }
.node.linked circle { stroke: #d49bff; stroke-width: 3.5px; filter: drop-shadow(0 0 5px rgba(199,125,255,.7)); }
.node.linked text.label { fill: #f0dcff; }
.node text {
  fill: var(--text); font-size: 13px; paint-order: stroke;
  stroke: #0f1420; stroke-width: 2px; stroke-linejoin: round;
  text-rendering: geometricPrecision;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.node .badge { fill: var(--muted); font-size: 10px; stroke: none; }
.node .info {
  fill: var(--accent); font-size: 12px; font-weight: 700; stroke: none;
  opacity: 0; transition: opacity .15s;
}
.node:hover .info { opacity: 1; }
.node.has-content:hover circle { filter: brightness(1.15); }

/* ---------- Detail panel ---------- */
#detail {
  width: 460px; min-width: 320px; max-width: 50vw;
  background: var(--panel); border-left: 1px solid var(--border);
  overflow-y: auto; padding: 22px 24px; resize: horizontal; direction: rtl;
}
#detail > * { direction: ltr; }
#detail.empty #detail-content { display: none; }
#detail:not(.empty) #detail-placeholder { display: none; }

#detail-placeholder h2 { margin-top: 0; }
#detail-placeholder ul { padding-left: 18px; color: var(--muted); line-height: 1.7; }
#detail-placeholder .muted { color: var(--muted); font-size: .85rem; margin-top: 18px; }

.detail-kicker { font-size: .76rem; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
#detail-content h1 { font-size: 1.5rem; margin: 4px 0 4px; }
.detail-summary { color: var(--muted); font-style: italic; margin: 0 0 18px; line-height: 1.5; }

#detail-content h3 { margin: 22px 0 8px; font-size: 1.05rem; color: #fff; border-left: 3px solid var(--accent); padding-left: 10px; }
#detail-content h4 { margin: 16px 0 6px; font-size: .95rem; color: #cfe0ff; }
#detail-content p { line-height: 1.6; margin: 8px 0; }
#detail-content ul, #detail-content ol { line-height: 1.6; padding-left: 22px; margin: 8px 0; }
#detail-content li { margin: 3px 0; }
#detail-content li > ul { margin: 4px 0; }
#detail-content strong { color: #fff; }
#detail-content em.term { color: var(--theme); font-style: normal; font-weight: 600; }

#detail-content table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: .88rem; }
#detail-content th, #detail-content td { border: 1px solid var(--border); padding: 7px 9px; text-align: left; vertical-align: top; }
#detail-content th { background: var(--panel-2); }

.callout {
  background: var(--panel-2); border: 1px solid var(--border); border-left: 3px solid var(--theme);
  border-radius: 8px; padding: 10px 14px; margin: 14px 0; font-size: .9rem;
}
.callout.din { border-left-color: var(--leaf); }
.callout .label { display: block; font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }

.crosslinks { margin-top: 26px; border-top: 1px solid var(--border); padding-top: 16px; }
.crosslinks h3 { border: none; padding: 0; margin: 0 0 10px; font-size: .95rem; color: var(--cross); }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; margin: 0 6px 8px 0; border-radius: 20px;
  background: var(--panel-2); border: 1px solid var(--cross); color: var(--text);
  font-size: .82rem; cursor: pointer;
}
.chip:hover { background: var(--cross); color: #fff; }
.chip.missing { border-color: var(--border); color: var(--muted); cursor: help; opacity: .7; }
.chip.missing:hover { background: var(--panel-2); color: var(--muted); }

.sources { margin-top: 22px; font-size: .8rem; color: var(--muted); }
.sources summary { cursor: pointer; color: var(--accent); }
.sources ul { padding-left: 18px; line-height: 1.5; }

.refbadge { color: var(--accent); cursor: pointer; font-weight: 600; }
.refbadge:hover { text-decoration: underline; }

/* Schließen-Button (nur mobil sichtbar) */
.detail-close {
  display: none; position: absolute; top: 12px; right: 14px; z-index: 2;
  padding: 7px 13px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); cursor: pointer; font-size: .85rem; font-weight: 600;
}
.detail-close:hover { border-color: var(--accent); color: #fff; }

/* =====================================================================
   Mobile / Tablet (≤ 820px)
   ===================================================================== */
@media (max-width: 820px) {
  :root { font-size: 14px; }

  #topbar {
    height: auto; flex-wrap: wrap; gap: 8px 10px; padding: 9px 12px;
  }
  .brand { min-width: 0; flex: 1 1 auto; gap: 9px; }
  .logo { width: 34px; height: 34px; border-radius: 9px; }
  .brand-text strong { font-size: .92rem; }
  .brand-text small { font-size: .68rem; }
  .subject-switch { order: 2; }
  .toolbar { order: 3; flex-wrap: wrap; gap: 6px; }
  .toolbar button { padding: 7px 9px; font-size: .78rem; }
  .search-wrap { order: 4; flex: 1 1 100%; max-width: none; }
  #search { padding: 9px 12px; font-size: .9rem; }
  #search-results { top: 44px; max-height: 50vh; }

  #breadcrumb { height: auto; min-height: 30px; padding: 6px 12px; }

  /* Legende kompakt: nur Farbschlüssel, ohne langen Hinweistext */
  .legend { left: 10px; bottom: 10px; padding: 8px 10px; font-size: .7rem; }
  .legend .hint { display: none; }

  /* Node-Schrift schärfer & lesbarer auf hochauflösenden Handy-Displays:
     etwas größere Schrift und dünnerer Kontur-Halo, damit der dunkle
     Umriss bei herausgezoomter Ansicht nicht in die Buchstaben läuft. */
  .node text { font-size: 14px; stroke-width: 1.6px; }
  .node .badge { font-size: 11px; }

  /* Detailpanel wird zum einblendbaren Overlay (Drawer) */
  #detail {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: 100%; min-width: 0; max-width: 100%;
    border-left: none; resize: none; direction: ltr;
    padding: 54px 18px 28px; z-index: 60;
    transform: translateX(100%); transition: transform .28s ease;
    box-shadow: var(--shadow);
  }
  #detail:not(.empty) { transform: translateX(0); }
  #detail-placeholder { display: none; }   /* Begrüßung nur auf Desktop nötig */
  .detail-close { display: inline-flex; align-items: center; }
}

/* Sehr schmale Geräte */
@media (max-width: 440px) {
  .brand-text small { display: none; }
  #detail { padding: 52px 14px 24px; }
}
