/* ── Reset & base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Design tokens ───────────────────────────────────────────── */
:root {
  /* Surfaces */
  --bg:          #ffffff;
  --bg-2:        #f8fafc;
  --bg-3:        #f1f5f9;
  /* Borders */
  --border:      #e2e8f0;
  --border-2:    #cbd5e1;
  /* Accent — indigo */
  --accent:      #6366f1;
  --accent-h:    #4f46e5;
  --accent-dim:  #eef2ff;
  /* Text */
  --tx:          #0f172a;
  --tx-2:        #475569;
  --tx-3:        #94a3b8;
  /* Console colours */
  --c-ok:        #059669;
  --c-err:       #dc2626;
  --c-info:      #6366f1;
  /* Run button */
  --run:         #16a34a;
  --run-h:       #15803d;
  /* Layout */
  --navbar-h:    52px;
  --sidebar-w:   220px;
  /* Fonts */
  --font:        'Inter', system-ui, sans-serif;
  --mono:        'JetBrains Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  /* Misc */
  --radius:      6px;
  --t:           150ms ease;
  --shadow:      0 4px 16px rgba(0,0,0,.08);
  --shadow-lg:   0 20px 48px rgba(0,0,0,.18);
}

/* ── Dark theme ──────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:          #0d1117;
  --bg-2:        #161b22;
  --bg-3:        #21262d;
  --border:      #30363d;
  --border-2:    #484f58;
  --accent:      #818cf8;
  --accent-h:    #a5b4fc;
  --accent-dim:  #1e1b4b;
  --tx:          #e6edf3;
  --tx-2:        #8b949e;
  --tx-3:        #6e7681;
  --c-ok:        #3fb950;
  --c-err:       #f85149;
  --c-info:      #818cf8;
  --run:         #238636;
  --run-h:       #2ea043;
  --shadow:      0 4px 16px rgba(0,0,0,.4);
  --shadow-lg:   0 20px 48px rgba(0,0,0,.6);
}

/* ── Global ──────────────────────────────────────────────────── */
html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font);
  font-size: 13px;
  background: var(--bg);
  color: var(--tx);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── App shell ───────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Navbar ──────────────────────────────────────────────────── */
.navbar {
  height: var(--navbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 7px;
  text-decoration: none;
  flex-shrink: 0;
}

.brand-logo {
  height: 28px;
  width: auto;
  align-self: center;
  opacity: 0.9;
}

.brand-name {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -1px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* dark mode gradient stays readable */
[data-theme="dark"] .brand-name {
  background: linear-gradient(135deg, #818cf8, #c4b5fd);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--tx-3);
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  letter-spacing: .3px;
}

/* Weltansicht (Tab "Welt") */
.world-body {
  font-family: var(--sans, inherit);
}
.is-hidden { display: none !important; }

.world-grid {
  display: grid;
  gap: 2px;
  width: max-content;
  max-width: 100%;
}
.world-cell {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-size: 15px;
  line-height: 1;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  position: relative;
}
.world-cell.is-blocked { background: var(--bg-3); }
.world-cell.has-lenny { border-color: var(--accent); }
.world-head {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--tx-3);
  font-family: var(--mono);
}
.world-lenny { color: var(--accent); font-weight: 700; }
.world-count {
  position: absolute;
  right: 2px;
  bottom: 1px;
  font-size: 9px;
  font-family: var(--mono);
  color: var(--tx-3);
}
.world-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 14px;
  font-size: 12px;
  color: var(--tx-3);
}
.world-legend span { white-space: nowrap; }
.world-caption {
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--tx-3);
  font-family: var(--mono);
}

/* Interpreter-Version neben dem Namen */
.brand-version {
  font-size: 11px;
  font-weight: 500;
  color: var(--tx-3);
  letter-spacing: .3px;
}

/* Language pills */
.lang-tabs {
  display: flex;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
}

.lang-btn {
  padding: 3px 10px;
  border: none;
  background: transparent;
  color: var(--tx-3);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .4px;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--t);
}
.lang-btn:hover { background: var(--bg); color: var(--tx-2); }
.lang-btn.active { background: var(--accent); color: #fff; }

/* Nav right */
.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--tx-2);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--t);
}
.nav-btn:hover { background: var(--bg-3); color: var(--tx); border-color: var(--border-2); }
.nav-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}
.icon-btn { font-size: 14px; padding: 5px 9px; }

/* ── Workspace ───────────────────────────────────────────────── */
.workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
}
/* scrollbar-width/color not supported in older Safari — webkit fallback above handles it */
.sidebar-body::-webkit-scrollbar { width: 4px; }
.sidebar-body::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 2px; }

/* Collapsible sections */
.sidebar-section { margin-bottom: 4px; }

.sidebar-section > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  transition: background var(--t);
}
.sidebar-section > summary::-webkit-details-marker { display: none; }

.sidebar-section > summary::before {
  content: '›';
  font-size: 14px;
  color: var(--tx-3);
  width: 12px;
  text-align: center;
  transition: transform var(--t);
  flex-shrink: 0;
}
.sidebar-section[open] > summary::before { transform: rotate(90deg); }

.sidebar-section > summary span {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--tx-3);
}
.sidebar-section > summary:hover { background: var(--bg-3); }
.sidebar-section > summary:hover span { color: var(--tx-2); }

/* Lists inside sections */
.cmd-list {
  list-style: none;
  padding: 3px 4px 6px 20px;
}

.cmd-list li {
  padding: 3px 6px;
  font-size: 12px;
  font-family: var(--mono);
  color: var(--tx-2);
  border-radius: 4px;
  cursor: default;
  transition: all var(--t);
}
.cmd-list li:hover { background: var(--bg-3); color: var(--accent); }

/* Operator list */
.op-list li { display: inline-block; margin: 1px; }

/* Example list */
.ex-list li {
  font-family: var(--font);
  cursor: pointer;
  padding: 4px 8px;
  margin-bottom: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ex-list li.ex-group {
  cursor: default;
  padding: 8px 8px 2px;
  font-size: 0.8em;
  font-weight: bold;
  text-transform: uppercase;
  opacity: 0.7;
}
.ex-list li.ex-group:hover { background: none; color: inherit; }
.ex-list li.ex-hint {
  cursor: default;
  white-space: normal;
  font-size: 0.85em;
  opacity: 0.8;
}
.ex-list li.ex-hint:hover { background: none; color: inherit; }
.ex-list li:hover { background: var(--accent-dim); color: var(--accent); }
.ex-list li.active { background: var(--accent); color: #fff; }

/* Lenny state panel */
.sidebar-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 10px 12px 12px;
}

.state-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--tx-3);
  margin-bottom: 8px;
}

.state-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 8px;
}

.state-grid .state-row {
  display: contents;
}

.state-grid .sk {
  font-size: 11px;
  color: var(--tx-3);
  font-family: var(--mono);
}

.state-grid .sv {
  font-size: 11px;
  color: var(--tx);
  font-family: var(--mono);
  font-weight: 500;
}

/* ── Main area ───────────────────────────────────────────────── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Panel shared ────────────────────────────────────────────── */
.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  height: 40px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}

.panel-left {
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
}

.panel-tab {
  font-size: 12px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  color: var(--tx-3);
  padding-bottom: 2px;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.panel-tab.active {
  color: var(--tx);
  border-bottom-color: var(--accent);
}

.panel-hint {
  font-size: 11px;
  color: var(--tx-3);
  white-space: nowrap;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 13px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t);
  white-space: nowrap;
  background: var(--bg);
  color: var(--tx-2);
}
.btn:active { transform: scale(.97); }

.btn-run {
  background: var(--run);
  color: #fff;
  border-color: transparent;
  padding: 5px 16px;
  font-weight: 600;
}
.btn-run:hover { background: var(--run-h); }

.btn-secondary { background: var(--bg); color: var(--tx-2); }
.btn-secondary:hover { background: var(--bg-3); color: var(--tx); border-color: var(--border-2); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--tx-3); }
.btn-ghost:hover { background: var(--bg-3); color: var(--tx-2); border-color: var(--border); }

.btn-sm { padding: 3px 9px; font-size: 11px; }
.hidden-file-input { display: none; }

/* ── Editor panel ────────────────────────────────────────────── */
.editor-panel {
  flex: 55 55 0;
  min-height: 80px;
}

.editor-body {
  flex: 1;
  overflow: hidden;
  background: var(--bg);
}

#codeEditor {
  display: block;
  width: 100%;
  height: 100%;
  padding: 16px 18px;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.65;
  background: var(--bg);
  color: var(--tx);
  tab-size: 2;
  caret-color: var(--accent);
}
#codeEditor::placeholder { color: var(--tx-3); }

/* ── Resize divider ──────────────────────────────────────────── */
.resize-divider {
  flex-shrink: 0;
  height: 5px;
  background: var(--border);
  cursor: row-resize;
  position: relative;
  transition: background var(--t);
}
.resize-divider::after {
  content: '';
  position: absolute;
  inset: 1px 0;
  background: transparent;
  transition: background var(--t);
}
.resize-divider:hover,
.resize-divider.dragging {
  background: var(--accent);
}

/* ── Console panel ───────────────────────────────────────────── */
.console-panel {
  flex: 45 45 0;
  min-height: 60px;
}

.console-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 18px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.7;
  background: var(--bg);
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
}
.console-body::-webkit-scrollbar { width: 6px; }
.console-body::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }

.console-line { color: var(--c-ok); }
.console-line.error { color: var(--c-err); }
.console-line.info { color: var(--tx-3); font-style: italic; }

/* ── Modals ──────────────────────────────────────────────────── */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 500;
  align-items: center;
  justify-content: center;
}
.modal.open { display: flex; }

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.modal-box {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 840px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-in .15s ease;
}

.modal-box--sm { max-width: 560px; }

@keyframes modal-in {
  from { opacity: 0; transform: scale(.97) translateY(6px); }
  to   { opacity: 1; transform: scale(1)  translateY(0); }
}

.modal-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--tx);
}

.modal-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--tx-2);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: all var(--t);
}
.modal-close:hover { background: var(--c-err); color: #fff; border-color: transparent; }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
}

/* ── Help / markdown content ─────────────────────────────────── */
.modal-body h1, .modal-body h2, .modal-body h3, .modal-body h4 {
  color: var(--tx);
  font-weight: 600;
  margin: 18px 0 8px;
  line-height: 1.3;
}
.modal-body h1 { font-size: 18px; }
.modal-body h2 { font-size: 15px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.modal-body h3 { font-size: 13px; }

.modal-body p  { color: var(--tx-2); font-size: 13px; line-height: 1.65; margin: 8px 0; }
.modal-body hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

.modal-body a { color: var(--accent); text-decoration: none; }
.modal-body a:hover { text-decoration: underline; }

.modal-body code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--accent);
}

.modal-body pre {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  overflow-x: auto;
  margin: 8px 0;
}
.modal-body pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--tx-2);
  font-size: 12px;
}

.modal-body ul, .modal-body ol {
  padding-left: 20px;
  color: var(--tx-2);
  font-size: 13px;
  line-height: 1.7;
  margin: 6px 0;
}

.modal-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin: 8px 0;
}
.modal-body th {
  background: var(--bg-3);
  font-weight: 600;
  color: var(--tx);
  padding: 7px 10px;
  border: 1px solid var(--border);
  text-align: left;
}
.modal-body td {
  color: var(--tx-2);
  padding: 6px 10px;
  border: 1px solid var(--border);
}
.modal-body tr:nth-child(even) td { background: var(--bg-2); }

/* Help collapsible sections */
.help-group-title {
  font-size: 10px !important;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--tx-3) !important;
  border-bottom: 1px solid var(--border) !important;
  padding-bottom: 4px !important;
  margin: 20px 0 10px !important;
}

.help-doc-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}

.help-doc-section > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-2);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--tx);
  transition: background var(--t);
  -webkit-user-select: none;
  user-select: none;
}
.help-doc-section > summary::-webkit-details-marker { display: none; }
.help-doc-section > summary:hover { background: var(--bg-3); }

.help-doc-source {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--tx-3);
  flex-shrink: 0;
}

.help-markdown { padding: 14px 16px; }

.help-status {
  color: var(--tx-3);
  font-size: 13px;
  text-align: center;
  padding: 48px 20px;
  font-style: italic;
}
