/* Sirocco AI – „Orbit × Atelier“
   Raster und Typografie aus Atelier, Atmosphäre und 3D-Bühne aus Orbit.
   Keine Rundungen, keine Schatten-Karten: Linien, Raster, Schrift. */

/* ===================== Tokens ===================== */
:root {
  --brand: #6C47E8;
  --brand-hover: #7B58F0;
  --mist: #C9BBFF;
  --display: 'Sora', system-ui, sans-serif;
  --body: 'Instrument Sans', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --sidebar-w: 264px;
  --measure: 66ch;
  --pad: clamp(20px, 4vw, 56px);
  --ease: cubic-bezier(.2, .8, .2, 1);
}

/* Orbit: dunkel, violett getönt */
:root, :root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0D0B12;
  --side: #110E17;
  --text: #E7E3F0;
  --strong: #FFFFFF;
  --mute: #8A8499;
  --faint: #575166;
  --rule: #221E2B;
  --rule-strong: #3E3850;
  --accent: #B9A5FF;
  --code-bg: #09080D;
  --danger: #F2B8A8;
  --scrim: rgba(0, 0, 0, .6);
}

/* Atelier: Papier */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #F8F7FB;
  --side: #F8F7FB;
  --text: #1E1A26;
  --strong: #15121C;
  --mute: #6E6879;
  --faint: #ABA6B5;
  --rule: #DCD8E4;
  --rule-strong: #15121C;
  --accent: #5B3BD1;
  --code-bg: #EFEDF4;
  --danger: #A63A21;
  --scrim: rgba(21, 18, 28, .3);
}

/* ===================== Basis ===================== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--body); font-size: 16px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 1px solid var(--accent); outline-offset: 3px; }
::selection { background: rgba(108, 71, 232, .35); }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 11.5px; font-weight: 400; letter-spacing: .06em; text-transform: uppercase; }
svg { flex: 0 0 auto; }

.text-btn {
  min-height: 36px; padding: 0; background: none; border: none;
  color: var(--mute); font-size: 14px;
}
.text-btn:hover { color: var(--strong); }

.btn-square {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-width: 48px; height: 48px; padding: 0 16px;
  background: var(--strong); color: var(--bg);
  border: 1px solid var(--strong); border-radius: 0;
  font-weight: 500; font-size: 14px;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn-square:hover:not(:disabled) { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-square:disabled { background: transparent; border-color: var(--rule-strong); color: var(--faint); cursor: not-allowed; }
.btn-square svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn-square.stop svg { fill: currentColor; stroke: none; }

/* Logo */
.mark path { stroke: var(--strong); }
.mark circle { fill: var(--strong); }
.mark .impulse { fill: var(--accent); }

/* ===================== Layout ===================== */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); height: 100vh; height: 100dvh; }
.sidebar-collapsed .app { grid-template-columns: 0 minmax(0, 1fr); }
.sidebar-collapsed .sidebar { visibility: hidden; }

/* ----- Verzeichnis ----- */
.sidebar {
  display: flex; flex-direction: column; gap: 18px;
  min-width: 0; min-height: 0; overflow: hidden;
  padding: 26px 24px 20px;
  background: var(--side); border-right: 1px solid var(--rule);
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 9px; min-height: 36px; color: var(--strong); text-decoration: none; }
.brand .mark { width: 22px; height: 22px; }
.wordmark { font-family: var(--display); font-weight: 700; font-size: 17px; letter-spacing: -0.04em; }
.ai { font-family: var(--mono); font-size: 9px; color: var(--accent); align-self: flex-start; margin: 6px 0 0 -5px; }
#collapse-sidebar { font-size: 20px; width: 32px; }

.idx-head { display: flex; justify-content: space-between; align-items: baseline; padding-bottom: 8px; border-bottom: 1px solid var(--rule-strong); }
.idx-head .mono { color: var(--mute); }
.text-btn.new { color: var(--strong); font-weight: 500; min-height: 28px; }
.text-btn.new::before { content: '+ '; color: var(--accent); }
.text-btn.new:hover { color: var(--accent); }

.search {
  width: 100%; min-height: 36px; padding: 4px 0;
  background: none; border: none; border-bottom: 1px solid var(--rule);
  font-size: 14px;
}
.search::placeholder { color: var(--faint); }
.search:focus { outline: none; border-bottom-color: var(--accent); }

.history { flex: 1 1 auto; min-height: 0; overflow-y: auto; margin-right: -10px; padding-right: 10px; scrollbar-width: thin; scrollbar-color: var(--rule-strong) transparent; }
.history-group + .history-group { margin-top: 18px; }
.history-label { padding-bottom: 4px; color: var(--faint); font-family: var(--mono); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; }
.history-item { position: relative; display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; align-items: baseline; border-bottom: 1px solid var(--rule); }
.history-item .no { font-family: var(--mono); font-size: 11px; color: var(--faint); }
.history-item .open {
  min-width: 0; min-height: 40px; padding: 9px 0;
  background: none; border: none; text-align: left;
  font-size: 14px; line-height: 1.4;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-item .open:hover { color: var(--strong); }
.history-item.active .open { color: var(--strong); font-weight: 600; }
.history-item.active .no { color: var(--accent); }
.history-item .del { width: 28px; height: 28px; padding: 0; background: none; border: none; color: var(--faint); font-size: 16px; line-height: 1; opacity: 0; }
.history-item:hover .del, .history-item .del:focus-visible { opacity: 1; }
.history-item .del:hover { color: var(--danger); }
.history-empty { margin: 4px 0; font-size: 14px; color: var(--mute); }

.sidebar-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding-top: 14px; border-top: 1px solid var(--rule); }
.foot-note { margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--mute); }
.text-btn.theme { font-size: 13px; min-height: 28px; }
:root[data-theme="dark"] .i-dark, :root[data-theme="light"] .i-light { display: none; }

.scrim { display: none; }

/* ----- Hauptbereich ----- */
.main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.meta-bar {
  display: flex; align-items: center; gap: 20px;
  margin: 0 var(--pad); padding: 22px 0 12px;
  border-bottom: 1px solid var(--rule-strong);
}
#open-sidebar, .only-collapsed { display: none; }
.sidebar-collapsed #open-sidebar, .sidebar-collapsed .only-collapsed { display: inline-flex; align-items: center; }
.chat-title { flex: 1 1 auto; min-width: 0; margin: 0; color: var(--strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.date { color: var(--mute); white-space: nowrap; }
#export { font-size: 11.5px; min-height: 28px; }

.banner {
  display: flex; align-items: center; gap: 20px;
  margin: 16px var(--pad) 0; padding: 14px 0;
  border-top: 1px solid var(--rule-strong); border-bottom: 1px solid var(--rule);
  font-size: 14.5px; line-height: 1.55;
}
.banner-body { flex: 1 1 auto; min-width: 0; }
.banner strong { margin-right: 6px; color: var(--strong); font-weight: 600; }
.banner[data-tone="warn"] strong { color: var(--danger); }
.banner code { font-family: var(--mono); font-size: 12.5px; color: var(--strong); }
.banner .progress { height: 2px; margin-top: 10px; background: var(--rule); }
.banner .progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s var(--ease); }
.banner .btn-square { height: 40px; white-space: nowrap; }

.scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; scrollbar-color: var(--rule-strong) transparent; }

/* ----- Start: Orbit ----- */
.welcome {
  display: flex; flex-direction: column; align-items: center;
  min-height: 100%; padding: 0 var(--pad) 40px;
}
.stage { position: relative; width: 100%; flex: 1 1 auto; min-height: 260px; max-height: 56vh; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
.stage canvas:active { cursor: grabbing; }
.hello {
  margin: 8px 0 26px; text-align: center;
  font-family: var(--display); font-weight: 600;
  font-size: clamp(28px, 3.4vw, 46px); line-height: 1.1; letter-spacing: -0.04em; color: var(--strong);
}
.hello-q { color: var(--mute); }
.welcome-slot { width: min(720px, 100%); }
.dirs { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 34px; margin-top: 18px; }
.dir { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 0; background: none; border: none; color: var(--mute); font-size: 14.5px; }
.dir b { font-family: var(--mono); font-weight: 400; font-size: 11px; color: var(--accent); }
.dir:hover { color: var(--strong); }

.has-turns .welcome { display: none; }
.dock { display: none; }
.has-turns .dock { display: block; }

/* ----- Gespräch: Atelier ----- */
.turns { padding: 8px var(--pad) 24px; }
.turns:empty { padding: 0; }
.turn {
  display: grid; grid-template-columns: 72px minmax(0, 1fr); column-gap: 24px;
  padding: 34px 0 40px; border-bottom: 1px solid var(--rule);
  animation: rise .35s var(--ease);
}
.turn:last-child { border-bottom: none; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { .turn { animation: none; } }
.turn .no { font-family: var(--display); font-weight: 600; font-size: 15px; color: var(--accent); padding-top: 8px; }
.question {
  margin: 0 0 22px; max-width: 26ch;
  font-family: var(--display); font-weight: 600;
  font-size: clamp(22px, 2.4vw, 32px); line-height: 1.18; letter-spacing: -0.03em; color: var(--strong);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.answer, .turn-foot, .notice { grid-column: 2; }
.answer { max-width: var(--measure); font-size: 16.5px; line-height: 1.68; overflow-wrap: anywhere; }
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer p { margin: 0 0 14px; }
.answer h2, .answer h3, .answer h4 { margin: 26px 0 8px; font-family: var(--display); font-weight: 600; letter-spacing: -0.02em; color: var(--strong); line-height: 1.3; }
.answer h2 { font-size: 20px; } .answer h3 { font-size: 17px; } .answer h4 { font-size: 15.5px; }
.answer ul, .answer ol { margin: 0 0 14px; padding-left: 22px; }
.answer li { margin: 5px 0; }
.answer li::marker { color: var(--accent); }
.answer a { color: var(--strong); text-decoration-color: var(--accent); text-underline-offset: 3px; }
.answer strong { font-weight: 600; color: var(--strong); }
.answer blockquote { margin: 0 0 14px; padding-left: 16px; border-left: 1px solid var(--rule-strong); color: var(--mute); }
.answer hr { border: none; border-top: 1px solid var(--rule); margin: 22px 0; }
.answer :not(pre) > code { font-family: var(--mono); font-size: .85em; padding: 1px 5px; background: var(--code-bg); }
.answer.error { color: var(--danger); }
.md-part:empty { display: none; }
.md-part > :last-child { margin-bottom: 14px; }
.md-part:last-child > :last-child { margin-bottom: 0; }

.code-block { margin: 0 0 18px; border: 1px solid var(--rule); background: var(--code-bg); }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 0 0 0 14px; border-bottom: 1px solid var(--rule); font-family: var(--mono); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--mute); }
.code-block pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.code-block code { font-family: var(--mono); font-size: 13px; line-height: 1.6; }

.cursor { display: inline-block; width: 8px; height: 1.05em; margin-left: 2px; vertical-align: -2px; background: var(--accent); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.thinking { display: inline-flex; align-items: center; gap: 12px; font-family: var(--mono); font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--mute); }
.thinking svg { width: 18px; height: 18px; animation: spin 1.2s linear infinite; }
.thinking path { stroke: var(--accent); fill: none; }
.thinking circle { fill: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .thinking svg, .cursor { animation: none; } }

.turn-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 22px; margin-top: 18px; font-size: 13px; }
.action { min-height: 32px; padding: 0; background: none; border: none; color: var(--mute); font-size: 13px; text-decoration: underline; text-decoration-color: var(--rule-strong); text-underline-offset: 3px; }
.action:hover { color: var(--strong); text-decoration-color: var(--accent); }
.code-head .action { min-height: 30px; padding: 0 12px; text-decoration: none; font-family: var(--mono); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.turn-stats { margin-left: auto; font-family: var(--mono); font-size: 11px; letter-spacing: .04em; color: var(--faint); }
.notice { margin-top: 12px; font-size: 13px; color: var(--mute); }

/* ----- Eingabe ----- */
.dock { border-top: 1px solid var(--rule); }
.dock-inner { padding: 14px var(--pad) 16px; }
.has-turns .composer { display: grid; grid-template-columns: 72px minmax(0, 1fr); column-gap: 24px; }
.has-turns .composer .field, .has-turns .composer .composer-row { grid-column: 2; }
.has-turns .entry-label { grid-row: 1; padding-top: 14px; font-family: var(--display); font-weight: 600; font-size: 15px; color: var(--faint); }
.entry-label { display: none; }
.has-turns .entry-label { display: block; }

.field { display: flex; align-items: flex-end; gap: 16px; border-bottom: 1px solid var(--rule-strong); transition: border-color .2s; }
.field:focus-within { border-color: var(--accent); }
.field textarea {
  flex: 1 1 auto; min-width: 0; min-height: 52px; max-height: 240px;
  resize: none; border: none; background: none;
  padding: 12px 0 12px; color: var(--strong);
  font-size: 21px; line-height: 1.35;
}
.has-turns .field textarea { font-size: 18px; min-height: 48px; }
.field textarea::placeholder { color: var(--faint); }
.field textarea:focus { outline: none; }
.field .btn-square { margin-bottom: 8px; }

.composer-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 12px; padding-top: 10px; color: var(--mute); }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.composer-row[data-state="ok"] .status-dot { background: #2FB37F; }
.composer-row[data-state="missing"] .status-dot, .composer-row[data-state="offline"] .status-dot,
.composer-row[data-state="unsupported"] .status-dot, .composer-row[data-state="error"] .status-dot { background: #E0904A; }
.composer-row[data-state="loading"] .status-dot { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.status-model { color: var(--text); }
.composer-row.has-select .status-model { display: none; }
.model-select { min-height: 28px; padding: 0; background: none; border: none; color: var(--text); font: inherit; letter-spacing: inherit; text-transform: inherit; cursor: pointer; }
.model-select:focus { outline: none; }
.model-select option { background: var(--bg); color: var(--text); text-transform: none; }
.status-sub:not(:empty)::before { content: '· '; }
.welcome .disclaimer { display: none; }
.disclaimer { margin-left: auto; color: var(--faint); text-transform: none; letter-spacing: 0; font-family: var(--body); font-size: 12.5px; }

/* ===================== Mobil ===================== */
@media (max-width: 900px) {
  .app, .sidebar-collapsed .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar, .sidebar-collapsed .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 20; width: min(86vw, 300px);
    visibility: visible; transform: translateX(-100%); transition: transform .25s var(--ease);
  }
  .app.sidebar-open .sidebar { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 15; background: var(--scrim); }
  .scrim[hidden] { display: none; }
  #open-sidebar, .only-collapsed { display: inline-flex; align-items: center; }
  #collapse-sidebar { display: none; }
  .date { display: none; }
}
@media (max-width: 600px) {
  :root { --pad: 16px; }
  .meta-bar { gap: 14px; padding-top: 14px; }
  .stage { min-height: 220px; max-height: 42vh; }
  .hello { margin-bottom: 18px; }
  .dirs { gap: 0 22px; }
  .turn, .has-turns .composer { grid-template-columns: minmax(0, 1fr); }
  .turn .no { padding-top: 0; margin-bottom: 4px; }
  .answer, .turn-foot, .notice, .has-turns .composer .field, .has-turns .composer .composer-row { grid-column: 1; }
  .has-turns .entry-label { display: none; }
  .field textarea { font-size: 18px; }
  .disclaimer { display: none; }
  .dock-inner { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}

/* ===================== Bewegung =====================
   Ruhig und präzise: kurze Wege, weiche Kurven, nichts hüpft. */

/* Startseite baut sich gestaffelt auf */
@keyframes fade-up { from { opacity: 0; transform: translateY(10px); } }
@keyframes fade-in { from { opacity: 0; } }
.stage canvas { animation: fade-in 1.2s var(--ease) both; }
.hello { animation: fade-up .7s .15s var(--ease) both; }
.welcome-slot { animation: fade-up .7s .28s var(--ease) both; }
.dirs { animation: fade-up .7s .4s var(--ease) both; }

/* Neue Einträge: Frage, dann Antwort */
.turn { animation: none; }
.turn.enter .no, .turn.enter .question { animation: fade-up .5s var(--ease) both; }
.turn.enter .answer { animation: fade-in .5s .12s var(--ease) both; }
.turn-foot:not([hidden]) { animation: fade-up .4s var(--ease) both; }
.notice { animation: fade-in .4s var(--ease) both; }

/* Verzeichnis */
@keyframes slide-in { from { opacity: 0; transform: translateX(-8px); } }
.history-item.enter { animation: slide-in .45s var(--ease) both; }
.history-item .open, .history-item .no { transition: color .2s; }
.app { transition: grid-template-columns .35s var(--ease); }
.sidebar { transition: visibility .35s, opacity .25s; }
.sidebar-collapsed .sidebar { opacity: 0; }

/* Eingabe: die Linie zieht sich beim Fokus auf */
.field { position: relative; }
.field::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: var(--accent); transform: scaleX(0); transform-origin: left;
  transition: transform .45s var(--ease);
}
.field:focus-within { border-color: var(--rule-strong); }
.field:focus-within::after { transform: scaleX(1); }
.search { transition: border-color .3s; }

/* Kleine Rückmeldungen */
.btn-square svg { transition: transform .25s var(--ease); }
.btn-square:hover:not(:disabled) svg { transform: translate(2px, 2px); }
.btn-square:active:not(:disabled) { transform: scale(.97); }
.dir { transition: color .2s; }
.dir b { transition: transform .25s var(--ease); }
.dir:hover b { transform: translate(2px, 2px); }
.action, .text-btn { transition: color .2s, text-decoration-color .2s; }
.banner { animation: fade-up .45s var(--ease) both; }

/* Denk-Anzeige: der Südost-Ring zeichnet sich, der Impuls pulsiert */
.thinking svg { animation: none; width: 20px; height: 20px; overflow: visible; }
.thinking .arc { stroke: var(--accent); fill: none; stroke-dasharray: 100; animation: draw-arc 1.8s var(--ease) infinite; }
.thinking .core { fill: var(--accent); }
.thinking .impulse { fill: var(--accent); transform-box: fill-box; transform-origin: center; animation: impulse 1.8s var(--ease) infinite; }
@keyframes draw-arc { 0% { stroke-dashoffset: 100; } 50% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: -100; } }
@keyframes impulse { 0%, 40% { opacity: .25; transform: scale(.6); } 60% { opacity: 1; transform: scale(1.15); } 100% { opacity: .25; transform: scale(.6); } }

/* Seitenübergänge (View Transitions) */
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .3s; animation-timing-function: var(--ease); }
#composer { view-transition-name: composer; }
::view-transition-group(composer) { animation-duration: .6s; animation-timing-function: cubic-bezier(.2, .8, .2, 1); }
::view-transition-old(composer), ::view-transition-new(composer) { height: 100%; }
[data-vt="start"]::view-transition-old(root) { animation: .35s var(--ease) both vt-out; }
[data-vt="start"]::view-transition-new(root) { animation: .5s .1s var(--ease) both vt-in; }
@keyframes vt-out { to { opacity: 0; transform: scale(.985); } }
@keyframes vt-in { from { opacity: 0; transform: translateY(12px); } }
/* Hell/Dunkel: der neue Zustand wird per Kreis aufgedeckt (siehe app.js) */
[data-vt="theme"]::view-transition-old(root), [data-vt="theme"]::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
[data-vt="theme"]::view-transition-group(composer) { animation: none; }

/* Weniger Bewegung gewünscht: alles still */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ===================== Violett ===================== */
/* Hauptknöpfe in Markenfarbe */
.btn-square { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-square:hover:not(:disabled) { background: var(--brand-hover); border-color: var(--brand-hover); }
/* Sanfter violetter Schimmer hinter dem 3D-Ring */
.stage::before {
  content: ''; position: absolute; left: 50%; top: 50%; width: min(70vh, 640px); aspect-ratio: 1;
  transform: translate(-50%, -50%); border-radius: 50%; pointer-events: none;
  background: radial-gradient(closest-side, rgba(123, 92, 255, .22), rgba(123, 92, 255, 0));
  animation: fade-in 1.6s var(--ease) both;
}
:root[data-theme="light"] .stage::before { background: radial-gradient(closest-side, rgba(108, 71, 232, .14), rgba(108, 71, 232, 0)); }
