/* ╔══════════════════════════════════════════════════════════════╗
   ║  Himmelsgeflüster Editor — Deep-Space Observatory Theme     ║
   ╚══════════════════════════════════════════════════════════════╝ */

@import url('https://fonts.googleapis.com/css2?family=Sora:wght@300;400;500;600;700&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');

/* ── Design Tokens ────────────────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg-void:      #05080f;
  --bg-base:      #090e1a;
  --bg-panel:     #0d1424;
  --bg-elevated:  #111827;
  --bg-card:      #141d30;
  --bg-hover:     #1a2540;
  --bg-input:     #080d19;

  /* Borders */
  --border-faint:  rgba(148, 163, 184, 0.06);
  --border:        rgba(148, 163, 184, 0.11);
  --border-strong: rgba(148, 163, 184, 0.18);
  --border-accent: rgba(56, 189, 248, 0.35);

  /* Accents */
  --cyan:          #38bdf8;
  --cyan-dim:      rgba(56, 189, 248, 0.12);
  --cyan-glow:     rgba(56, 189, 248, 0.28);
  --violet:        #a78bfa;
  --violet-dim:    rgba(167, 139, 250, 0.12);
  --emerald:       #34d399;
  --emerald-dim:   rgba(52, 211, 153, 0.12);
  --amber:         #fbbf24;
  --amber-dim:     rgba(251, 191, 36, 0.12);
  --rose:          #fb7185;
  --rose-dim:      rgba(251, 113, 133, 0.12);

  /* Text */
  --text-bright:   #f1f5f9;
  --text-primary:  #cbd5e1;
  --text-secondary:#94a3b8;
  --text-muted:    #64748b;

  /* Radii */
  --r-sm:   8px;
  --r:      11px;
  --r-lg:   14px;
  --r-xl:   18px;

  /* Shadows */
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.4);
  --shadow:    0 4px 16px rgba(0,0,0,0.55);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.7);
  --glow-cyan: 0 0 20px rgba(56, 189, 248, 0.18);

  /* Fonts */
  --font-display: 'Sora', sans-serif;
  --font-body:    'DM Sans', sans-serif;
  --font-mono:    'DM Mono', monospace;

  /* Motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --t:    0.17s;
}

/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: var(--bg-void);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.55;
}

/* ── Scrollbars ──────────────────────────────────────────────── */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(148,163,184,0.12) transparent;
}
::-webkit-scrollbar { width: 3px; height: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(148,163,184,0.15);
  border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(148,163,184,0.28); }

/* ── App Layout ──────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 300px 1fr 380px;
  height: 100vh;
  transition: grid-template-columns var(--t) var(--ease);
}
.app.left-collapsed               { grid-template-columns: 12px 1fr 380px; }
.app.right-collapsed              { grid-template-columns: 300px 1fr 12px; }
.app.left-collapsed.right-collapsed { grid-template-columns: 12px 1fr 12px; }

/* ── Panels ──────────────────────────────────────────────────── */
.panel {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow: auto;
}
.panel.right {
  border-right: none;
  border-left: 1px solid var(--border);
}

.sidebar { position: relative; min-width: 0; }
.sidebar.collapsed { overflow: hidden; }
.sidebar-left.collapsed  > *:not(.pin-btn) { opacity: 0; pointer-events: none; }
.sidebar-right.collapsed > *:not(.pin-btn) { opacity: 0; pointer-events: none; }

/* ── Pin Button ──────────────────────────────────────────────── */
.pin-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  z-index: 20;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t), border-color var(--t), color var(--t), box-shadow var(--t);
}
.pin-btn:hover {
  border-color: var(--border-accent);
  color: var(--cyan);
  background: var(--cyan-dim);
}
.pin-btn.active {
  background: var(--cyan-dim);
  border-color: var(--border-accent);
  color: var(--cyan);
  box-shadow: var(--glow-cyan);
}

/* ── Sidebar Toggle (floating) ───────────────────────────────── */
.sidebar-toggle {
  position: fixed;
  top: 12px;
  z-index: 60;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t), color var(--t), box-shadow var(--t);
}
.sidebar-toggle:hover {
  background: var(--bg-hover);
  color: var(--cyan);
  box-shadow: var(--shadow-lg), var(--glow-cyan);
}
.sidebar-toggle-left  { left: 8px; }
.sidebar-toggle-right { right: 8px; }
.sidebar-toggle.hidden { display: none; }

/* ── Sections ────────────────────────────────────────────────── */
.section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

/* ── Typography ──────────────────────────────────────────────── */
h1, h2, h3 {
  margin: 0 0 10px;
  font-family: var(--font-display);
}

h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-bright);
  letter-spacing: -0.02em;
}

h2 {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 10px;
}

h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

label {
  display: block;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 5px;
}

.muted {
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.55;
  opacity: 0.8;
}

/* ── Form Elements ───────────────────────────────────────────── */
input, textarea, select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.5;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
}
input::placeholder, textarea::placeholder {
  color: var(--text-secondary);
  opacity: 0.5;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--border-accent);
  background: var(--bg-input);
  box-shadow: 0 0 0 3px var(--cyan-dim);
}
input[disabled], textarea[disabled], select[disabled] {
  background: var(--bg-panel);
  color: var(--text-secondary);
  opacity: 0.45;
  cursor: not-allowed;
}
textarea {
  min-height: 90px;
  resize: vertical;
}

/* Custom select arrow */
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}
select option {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* File input */
input[type="file"] {
  padding: 7px 10px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
}
input[type="file"]::-webkit-file-upload-button {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 3px 10px;
  font-family: var(--font-body);
  font-size: 11px;
  cursor: pointer;
  margin-right: 8px;
  transition: background var(--t), border-color var(--t);
}
input[type="file"]::-webkit-file-upload-button:hover {
  background: var(--bg-hover);
  border-color: var(--border-accent);
}

/* Number inputs */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  filter: invert(1) opacity(0.3);
}

/* ── Buttons ─────────────────────────────────────────────────── */
button {
  width: 100%;
  padding: 8px 14px;
  border-radius: var(--r);
  border: 1px solid transparent;
  background: var(--cyan);
  color: #020c18;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  line-height: 1.4;
  transition:
    background var(--t) var(--ease),
    box-shadow var(--t) var(--ease),
    transform 0.1s var(--ease),
    border-color var(--t) var(--ease),
    color var(--t) var(--ease),
    opacity var(--t) var(--ease);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button:hover {
  background: #7dd3fc;
  box-shadow: 0 0 18px var(--cyan-glow);
}
button:active {
  transform: scale(0.96);
}

button.secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
button.secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-accent);
  color: var(--cyan);
  box-shadow: none;
}

button.danger {
  background: var(--rose-dim);
  color: var(--rose);
  border-color: rgba(251, 113, 133, 0.25);
}
button.danger:hover {
  background: rgba(251, 113, 133, 0.20);
  border-color: var(--rose);
  box-shadow: 0 0 14px rgba(251,113,133,0.18);
  color: #fecdd3;
}

button.ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
button.ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
  box-shadow: none;
}

/* ── Layout Utilities ────────────────────────────────────────── */
.row   { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.stack { display: grid; gap: 8px; }

/* ── Story List ──────────────────────────────────────────────── */
.story-list { display: grid; gap: 5px; }
.story-item {
  border: 1px solid var(--border);
  padding: 9px 12px;
  border-radius: var(--r);
  cursor: pointer;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13px;
  transition: border-color var(--t), background var(--t), color var(--t);
}
.story-item:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}
.story-item.active {
  border-color: var(--border-accent);
  background: var(--cyan-dim);
  color: var(--cyan);
}

/* ── Canvas ──────────────────────────────────────────────────── */
.canvas-wrap {
  position: relative;
  overflow: hidden;
  background-color: var(--bg-void);
  background-image:
    linear-gradient(rgba(56, 189, 248, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56, 189, 248, 0.03) 1px, transparent 1px);
  background-size: 24px 24px;
  cursor: grab;
}
.canvas-wrap.panning       { cursor: grabbing; }
.canvas-wrap.node-dragging { cursor: default; }

.canvas-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 6px;
  align-items: center;
  height: 46px;
  padding: 0 48px;
  background: rgba(9, 14, 26, 0.88);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.canvas-stage {
  position: relative;
  width: 100%;
  height: calc(100% - 46px);
  overflow: hidden;
}

.canvas-scale { transform-origin: 0 0; position: absolute; top: 0; left: 0; }
.canvas { position: relative; width: 20000px; height: 20000px; }
svg#connections { position: absolute; inset: 0; pointer-events: none; overflow: visible; }

/* ── Nodes ───────────────────────────────────────────────────── */
.node {
  position: absolute;
  width: 240px;
  min-height: 88px;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: move;
  transition: box-shadow var(--t), border-color var(--t), transform var(--t);
}
.node:hover {
  border-color: rgba(148, 163, 184, 0.26);
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}
.node.selected {
  border-color: var(--border-accent);
  box-shadow: 0 0 0 2px var(--cyan-dim), var(--shadow-lg), var(--glow-cyan);
  transform: none;
}
.node.incomplete {
  border-color: rgba(251, 113, 133, 0.45) !important;
  box-shadow: 0 0 0 2px rgba(251,113,133,0.12), var(--shadow) !important;
}
.node.incomplete .node-header {
  background: rgba(251,113,133,0.10) !important;
  color: var(--rose) !important;
}

/* Node type headers */
.node-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 12px;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-display);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

.node.message .node-header {
  background: var(--cyan-dim);
  color: var(--cyan);
  border-bottom-color: rgba(56,189,248,0.14);
}
.node.choice .node-header {
  background: var(--emerald-dim);
  color: var(--emerald);
  border-bottom-color: rgba(52,211,153,0.14);
}
.node.image .node-header {
  background: var(--violet-dim);
  color: var(--violet);
  border-bottom-color: rgba(167,139,250,0.14);
}
.node.end .node-header {
  background: var(--rose-dim);
  color: var(--rose);
  border-bottom-color: rgba(251,113,133,0.14);
}

.node-body {
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-primary);
  white-space: normal;
}

.node-footer {
  padding: 8px 10px;
  border-top: 1px solid var(--border-faint);
  display: flex;
  gap: 6px;
}

/* ── Mini Buttons (in nodes) ─────────────────────────────────── */
.mini-btn {
  padding: 5px 10px;
  font-size: 10.5px;
  border-radius: var(--r-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  border-color: var(--border);
}
.mini-btn:hover {
  background: var(--bg-hover);
  color: var(--cyan);
  border-color: var(--border-accent);
  box-shadow: none;
}

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--cyan-dim);
  color: var(--cyan);
  border: 1px solid rgba(56,189,248,0.25);
  font-size: 9.5px;
  font-weight: 700;
  font-family: var(--font-display);
  letter-spacing: 0.07em;
  text-transform: uppercase;
}
.badge.warn {
  background: var(--rose-dim);
  color: var(--rose);
  border-color: rgba(251,113,133,0.25);
}

/* ── Choice Chips (node preview) ─────────────────────────────── */
.choice-preview { margin-top: 8px; display: grid; gap: 5px; }
.choice-chip {
  padding: 6px 10px;
  border-radius: var(--r-sm);
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
}
.choice-chip[data-color="0"] { border-left: 3px solid #3b82f6; }
.choice-chip[data-color="1"] { border-left: 3px solid #10b981; }
.choice-chip[data-color="2"] { border-left: 3px solid #f59e0b; }
.choice-chip[data-color="3"] { border-left: 3px solid #ef4444; }

/* ── Choice Editor (right panel) ────────────────────────────── */
.choice-item {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 12px;
  background: var(--bg-card);
  transition: border-color var(--t);
}
.choice-item:hover { border-color: var(--border-strong); }
.choice-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.choice-color-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  display: inline-block;
  box-shadow: 0 0 5px currentColor;
}

/* ── Status & Info ───────────────────────────────────────────── */
.status {
  font-size: 12px;
  font-weight: 500;
  color: var(--emerald);
}

.zoom-label {
  min-width: 52px;
  text-align: center;
  font-size: 12px;
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text-secondary);
}

.helper-note {
  padding: 9px 12px;
  border-radius: var(--r);
  background: rgba(56,189,248,0.05);
  border: 1px solid rgba(56,189,248,0.10);
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.55;
}

/* ── Images ──────────────────────────────────────────────────── */
.image-thumb {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--bg-card);
}
.node-image-preview { margin-top: 8px; }
.node-image-preview img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--bg-card);
}

/* ── Inline Hint ─────────────────────────────────────────────── */
.inline-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.inline-hint button {
  width: auto;
  padding: 4px 10px;
  border-radius: var(--r-sm);
  font-size: 11px;
}

#storyProfileImageEditor { margin-top: 6px; }

/* ── Emoji Picker ────────────────────────────────────────────── */
.textarea-wrap { position: relative; }
.textarea-wrap textarea { width: 100%; box-sizing: border-box; }

.emoji-picker-btn {
  position: absolute;
  bottom: 8px;
  right: 7px;
  background: none;
  border: none;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 3px 5px;
  border-radius: var(--r-sm);
  opacity: 0.45;
  transition: opacity var(--t), background var(--t);
  z-index: 5;
  width: auto;
  min-width: unset;
}
.emoji-picker-btn:hover {
  opacity: 1;
  background: rgba(255,255,255,0.05);
}

.emoji-dropdown {
  position: absolute;
  bottom: calc(100% + 4px);
  right: 0;
  width: 264px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg), 0 0 40px rgba(0,0,0,0.5);
  z-index: 9999;
  padding: 10px;
}

.emoji-search-row { margin-bottom: 8px; }
.emoji-search-row input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  font-size: 12.5px;
  background: var(--bg-input);
  color: var(--text-primary);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  max-height: 200px;
  overflow-y: auto;
}

.emoji-item {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  height: 30px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t);
  user-select: none;
}
.emoji-item:hover { background: rgba(255,255,255,0.06); }

/* ── First section header (app title) ───────────────────────── */
.section:first-child h1::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 99px;
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
  margin-right: 8px;
  vertical-align: middle;
  position: relative;
  top: -1px;
}

/* ── Canvas toolbar buttons override ────────────────────────── */
.canvas-toolbar button {
  width: auto;
  white-space: nowrap;
  padding: 5px 11px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--r-sm);
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-strong);
  min-width: auto;
}
.canvas-toolbar button:hover {
  background: var(--bg-hover);
  border-color: var(--border-accent);
  color: var(--cyan);
  box-shadow: none;
}

/* ── Subtle star-field overlay on canvas ─────────────────────── */
.canvas-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(1px 1px at 12% 15%, rgba(255,255,255,0.35) 0%, transparent 100%),
    radial-gradient(1px 1px at 35% 42%, rgba(255,255,255,0.20) 0%, transparent 100%),
    radial-gradient(1px 1px at 56% 8%,  rgba(255,255,255,0.30) 0%, transparent 100%),
    radial-gradient(1px 1px at 78% 61%, rgba(255,255,255,0.22) 0%, transparent 100%),
    radial-gradient(1px 1px at 91% 30%, rgba(255,255,255,0.18) 0%, transparent 100%),
    radial-gradient(1px 1px at 22% 77%, rgba(255,255,255,0.25) 0%, transparent 100%),
    radial-gradient(1px 1px at 66% 82%, rgba(255,255,255,0.20) 0%, transparent 100%),
    radial-gradient(1px 1px at 48% 55%, rgba(255,255,255,0.15) 0%, transparent 100%);
  opacity: 0.6;
}

/* ── Focus-visible (accessibility) ─────────────────────────── */
:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}
button:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* ═══════════════ UX-Erweiterungen ═══════════════ */

kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  background: rgba(255,255,255,0.05);
  color: var(--text-secondary);
  font-weight: 500;
}
button:not(.secondary):not(.danger):not(.ghost) kbd { color: #07304a; border-color: rgba(2,12,24,.3); background: rgba(255,255,255,.35); }

/* Einklappbare Bereiche */
details.section > summary,
details.subdetails > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
details.section > summary::-webkit-details-marker,
details.subdetails > summary::-webkit-details-marker { display: none; }
details.section > summary h2 { margin: 0; flex: 1; }
details.section > summary::after {
  content: '▾';
  color: var(--text-secondary);
  font-size: 11px;
  transition: transform var(--t);
}
details.section:not([open]) > summary::after { transform: rotate(-90deg); }
details.section[open] > summary { margin-bottom: 10px; }
details.subdetails {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 8px 10px;
  background: var(--bg-card);
}
details.subdetails > summary { font-size: 12px; font-weight: 600; color: var(--text-primary); }
details.subdetails > summary::before { content: '▸'; color: var(--text-secondary); }
details.subdetails[open] > summary::before { content: '▾'; }
details.subdetails[open] > summary { margin-bottom: 8px; }

.pin-btn { top: 12px; }
.sidebar-left .section:first-of-type { padding-right: 52px; }

/* Hinzufügen-Buttons in Typfarben */
.add-btn { justify-content: flex-start; border-left-width: 3px; }
.add-btn.t-message { border-left-color: var(--cyan); }
.add-btn.t-choice  { border-left-color: var(--emerald); }
.add-btn.t-image   { border-left-color: var(--violet); }
.add-btn.t-audio   { border-left-color: var(--amber); }
.add-btn.t-end     { border-left-color: var(--rose); }

/* Upload startet automatisch → Button ausblenden */
.upload-trigger { display: none; }

/* Toolbar */
.tb-title {
  display: flex; align-items: center; gap: 8px;
  flex: none; max-width: 240px; min-width: 0;
  font-family: var(--font-display);
  font-weight: 600; font-size: 13px;
  color: var(--text-bright);
}
.tb-title #topTitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dirty-dot {
  width: 9px; height: 9px; border-radius: 99px; flex: none;
  background: var(--amber); box-shadow: 0 0 8px var(--amber);
}
.dirty-dot[hidden] { display: none; }
.tb-sep { width: 1px; height: 22px; background: var(--border-strong); margin: 0 4px; flex: none; }
.tb-spacer { flex: 1; }
.canvas-toolbar button.primary {
  background: var(--cyan); color: #020c18; border-color: transparent;
}
.canvas-toolbar button.primary:hover { background: #7dd3fc; color: #020c18; box-shadow: 0 0 14px var(--cyan-glow); }
.canvas-toolbar button.toggle.on { background: var(--cyan-dim); border-color: var(--border-accent); color: var(--cyan); }
.canvas-toolbar button:disabled { opacity: .35; cursor: not-allowed; pointer-events: none; }
.canvas-toolbar .badge { margin-left: 4px; }
.canvas-toolbar .badge[hidden] { display: none; }
/* Werkzeugleiste passt sich der Breite der Arbeitsfläche an */
.canvas-wrap { container-type: inline-size; }
@container (max-width: 1150px) {
  .canvas-toolbar .lbl:not(.lbl-save) { display: none; }
  #zoomResetBtn { display: none; }
  .tb-title { max-width: 170px; }
}
@container (max-width: 760px) {
  .canvas-toolbar .lbl-save { display: none; }
  .tb-title { max-width: 110px; }
  .canvas-toolbar { padding: 0 44px 0 44px; gap: 4px; }
}

/* Knoten: Mehrfachauswahl, Handles, Fokus */
.node { overflow: visible; }
.node-header { border-radius: var(--r-xl) var(--r-xl) 0 0; }
.node-footer { border-radius: 0 0 var(--r-xl) var(--r-xl); }
.node.multi {
  border-color: var(--violet);
  box-shadow: 0 0 0 2px var(--violet-dim), var(--shadow-lg);
}
.node:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
.node-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node-inline-edit {
  min-height: 60px; resize: vertical;
  font-size: 13px; padding: 6px 8px;
}
.node-handle {
  position: absolute;
  width: 16px; height: 16px;
  border-radius: 99px;
  border: 2px solid var(--bg-panel);
  background: var(--cyan);
  box-shadow: 0 0 0 1px var(--border-accent);
  cursor: crosshair;
  z-index: 3;
  opacity: .55;
  transition: opacity var(--t), transform var(--t), box-shadow var(--t);
}
.node:hover .node-handle, .node.selected .node-handle, .node-handle:hover { opacity: 1; }
.node-handle:hover { transform: scale(1.3); box-shadow: 0 0 10px var(--cyan-glow); }
.node-handle.main { right: -9px; top: 50%; margin-top: -8px; }
.node-handle.opt { right: -21px; top: 50%; margin-top: -8px; }
.choice-chip { position: relative; }
.node.drop-ok { border-color: var(--emerald); box-shadow: 0 0 0 3px var(--emerald-dim), var(--shadow-lg); }
.node.file-over { border-color: var(--violet); box-shadow: 0 0 0 3px var(--violet-dim), var(--shadow-lg); }
.badge.warn { cursor: help; }

svg#linkPreview { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
svg#linkPreview path { stroke: var(--cyan); stroke-width: 3; stroke-dasharray: 7 6; stroke-linecap: round; }
.canvas-wrap.linking, .canvas-wrap.linking .node { cursor: crosshair; }

/* Auswahlrechteck */
.rubber {
  position: absolute; z-index: 6;
  border: 1px dashed var(--violet);
  background: var(--violet-dim);
  pointer-events: none;
}
.rubber[hidden] { display: none; }

/* Minimap */
.minimap {
  position: absolute; right: 14px; bottom: 14px; z-index: 6;
  width: 200px; height: 130px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  background: rgba(9,14,26,.82);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  cursor: pointer;
}

/* Rechte Leiste */
.panel .section[hidden] { display: none; }
.choice-item select { margin: 2px 0 8px; }
.choice-item-header strong { font-size: 13px; color: var(--text-bright); }

/* Toasts */
.toasts {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  display: grid; gap: 8px; z-index: 200; justify-items: center;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 12px;
  padding: 9px 14px;
  border-radius: var(--r);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--cyan);
  color: var(--text-bright);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  animation: toast-in .18s var(--ease);
  max-width: min(560px, 90vw);
}
.toast.success { border-left-color: var(--emerald); }
.toast.error   { border-left-color: var(--rose); }
.toast.warn    { border-left-color: var(--amber); }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
.toast button { width: auto; padding: 3px 10px; font-size: 12px; background: var(--cyan-dim); color: var(--cyan); border-color: var(--border-accent); }
.toast button:hover { background: var(--cyan-glow); box-shadow: none; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Dialoge */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(2,6,14,.62);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(560px, 100%);
  max-height: 80vh;
  display: flex; flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px 0; }
.modal-head h3 { margin: 0; font-size: 15px; color: var(--text-bright); }
.modal-close { width: 30px; padding: 4px; }
.modal-body { padding: 14px 18px 18px; overflow: auto; }
.keys { width: 100%; border-collapse: collapse; }
.keys td { padding: 6px 0; border-bottom: 1px solid var(--border-faint); vertical-align: top; }
.keys td:first-child { white-space: nowrap; padding-right: 18px; color: var(--text-bright); }

.problem-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.problem-item {
  display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center;
  padding: 9px 12px; border-radius: var(--r);
  border: 1px solid var(--border); background: var(--bg-card);
  cursor: pointer; text-align: left; width: 100%; color: var(--text-primary); font-weight: 400; font-size: 13px;
}
.problem-item:hover { border-color: var(--border-accent); background: var(--bg-hover); box-shadow: none; }
.problem-item .problem-node { font-family: var(--font-mono); font-size: 11px; color: var(--rose); }
.problem-item.warn .problem-node { color: var(--amber); }
.check-ok { color: var(--emerald); font-weight: 600; }

/* Responsiv */
@media (max-width: 1100px) {
  .app { grid-template-columns: 260px 1fr 320px; }
  .app.left-collapsed { grid-template-columns: 12px 1fr 320px; }
  .app.right-collapsed { grid-template-columns: 260px 1fr 12px; }
  .app.left-collapsed.right-collapsed { grid-template-columns: 12px 1fr 12px; }
  .minimap { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

.node { user-select: none; -webkit-user-select: none; }
.node textarea { user-select: text; -webkit-user-select: text; }

/* Suche */
.search-box {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
  width: min(560px, calc(100% - 40px)); z-index: 9;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 8px;
}
.search-box[hidden] { display: none; }
.search-row { display: flex; align-items: center; gap: 6px; }
.search-row input { flex: 1; min-width: 0; }
.search-row button { width: 32px; padding: 6px 0; flex: none; }
.search-count { font-size: 12px; color: var(--text-secondary); white-space: nowrap; font-family: var(--font-mono); }
.search-results { list-style: none; margin: 8px 0 0; padding: 0; max-height: 300px; overflow: auto; display: grid; gap: 3px; }
.search-results:empty { display: none; }
.search-item {
  display: grid; gap: 2px; width: 100%; text-align: left; justify-content: stretch;
  padding: 7px 10px; border-radius: var(--r-sm);
  background: transparent; color: var(--text-primary);
  border: 1px solid transparent; font-weight: 400; font-size: 13px;
}
.search-item:hover, .search-item.active { background: var(--bg-hover); border-color: var(--border-accent); box-shadow: none; }
.search-meta { font-family: var(--font-mono); font-size: 11px; color: var(--cyan); }
.search-snippet { color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; }
.search-item mark, .search-snippet mark { background: var(--amber-dim); color: var(--amber); border-radius: 3px; padding: 0 2px; }
.node.search-hit { border-color: var(--amber); box-shadow: 0 0 0 2px var(--amber-dim), var(--shadow); }
.node.search-current { box-shadow: 0 0 0 3px rgba(251,191,36,.45), 0 0 24px rgba(251,191,36,.3), var(--shadow-lg); }

.toast span { white-space: pre-line; }

/* Benutzerbereich links oben */
.user-box { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); display: grid; gap: 8px; }
.user-name { font-size: 12.5px; font-weight: 600; color: var(--text-bright); display: flex; align-items: center; gap: 6px; }
.user-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.user-actions form { display: contents; }
.user-actions .btn-link {
  width: auto; display: inline-flex; padding: 4px 10px; border-radius: var(--r-sm);
  border: 1px solid var(--border-strong); background: var(--bg-elevated);
  color: var(--text-primary); font-size: 11.5px; font-weight: 600; text-decoration: none; line-height: 1.4;
}
.user-actions .btn-link:hover { background: var(--bg-hover); border-color: var(--border-accent); color: var(--cyan); box-shadow: none; }

[hidden] { display: none !important; }
