/* ---------- Base ---------- */
* { box-sizing: border-box; }
:root {
  --bg: #0f1220;
  --bg-2: #171a2e;
  --card: #1d2140;
  --card-2: #242a52;
  --border: #2d3366;
  --text: #e6e8ff;
  --muted: #9aa0c7;
  --primary: #6c7cff;
  --primary-2: #8a97ff;
  --accent: #4ad9a5;
  --danger: #ff6b6b;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0,0,0,0.35);

  /* Fixed panel height to keep tabs predictable and stop infinite stretch */
  --panel-h: 640px;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: radial-gradient(1200px 800px at 10% -10%, #222862 0%, var(--bg) 60%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- Header ---------- */
.header { text-align: center; margin-bottom: 20px; }
.header h1 {
  margin: 0;
  font-size: 28px;
  background: linear-gradient(90deg, #8a97ff, #4ad9a5);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle { color: var(--muted); margin: 6px 0 0; font-size: 14px; }

/* ---------- Layout ---------- */
.main {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
}
@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; }
}

.panel-left { display: flex; flex-direction: column; gap: 16px; }

.panel-right {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* CRITICAL: fixed height stops the SVG tab from stretching infinitely */
  height: var(--panel-h);
  max-height: var(--panel-h);
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 12px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  font-weight: 600;
}

/* ---------- Drop zone ---------- */
.drop-zone {
  display: block;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: 0.2s;
  background: var(--card-2);
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--primary);
  background: rgba(108, 124, 255, 0.08);
}
.drop-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}
.drop-inner strong { color: var(--text); }
.drop-inner small { font-size: 11px; opacity: 0.7; }
.paste-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-top: 10px;
  padding: 8px 12px;
}

/* ---------- Controls ---------- */
.control { margin-bottom: 14px; }
.control:last-child { margin-bottom: 0; }
.control label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.control label.row {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.control em {
  font-style: normal;
  color: var(--accent);
  font-weight: 600;
  margin-left: 6px;
}
select, input[type="range"], input[type="number"] {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
input[type="range"] { padding: 0; accent-color: var(--primary); }
input[type="checkbox"] { accent-color: var(--primary); width: 16px; height: 16px; }
input:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Buttons ---------- */
.btn-row { display: flex; gap: 8px; margin-bottom: 8px; }
.btn-row:last-child { margin-bottom: 0; }
.btn {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: 0.15s;
  font-weight: 500;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border-color: var(--primary);
  color: white;
}
.btn-primary:hover { box-shadow: 0 4px 16px rgba(108,124,255,0.4); }
.btn-secondary { background: var(--card-2); }
.btn-ghost { background: transparent; }

/* ---------- Stats ---------- */
.stats ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.stats strong { color: var(--text); float: right; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
}
.tab {
  flex: 1;
  padding: 12px;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text);
  border-bottom-color: var(--primary);
  background: var(--bg-2);
}

/* The tab area now has a definite height (parent has fixed height, tabs have intrinsic height) */
.tab-content {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  min-height: 0;
}
.tab-pane {
  display: none;
  position: absolute;
  inset: 0;          /* fills tab-content exactly — no growth! */
  overflow: hidden;
}
.tab-pane.active { display: block; }

/* ---------- Generic preview box (Original / B/W) ---------- */
.preview-box {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    repeating-conic-gradient(#1a1e38 0% 25%, #1d2142 0% 50%) 50% / 24px 24px;
  overflow: auto;
  padding: 20px;
}
.preview-box canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  image-rendering: pixelated;
  background: white;
  border-radius: 4px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

/* ---------- SVG Output tab layout ---------- */
.svg-split {
  display: flex;
  width: 100%;
  height: 100%;
  min-height: 0;
}

/* CRITICAL: this pane MUST clip its child SVG, otherwise the SVG (which has
   intrinsic width/height attributes) makes the page stretch forever. */
.svg-preview-pane {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    repeating-conic-gradient(#1a1e38 0% 25%, #1d2142 0% 50%) 50% / 24px 24px;
  padding: 20px;
  overflow: auto;
}
.svg-box {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.svg-box svg {
  display: block;
  width: auto !important;
  height: auto !important;
  max-width: 100%;
  max-height: 100%;
  background: white;
  border-radius: 4px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  image-rendering: auto;
}

.svg-nodes-pane {
  width: 280px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--card);
  flex-shrink: 0;
  min-height: 0;
}
.nodes-header {
  padding: 12px 16px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.nodes-scroll {
  flex: 1 1 auto;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0;
  min-height: 0;
}

/* Path nodes — visual canvas view */
.nodes-canvas-wrap {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  background: #0b0e1e;
  border-bottom: 1px solid var(--border);
  min-height: 0;
}
.nodes-canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.nodes-path-list {
  flex-shrink: 0;
  overflow-y: auto;
  max-height: 160px;
  padding: 6px;
}
.nodes-path-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  transition: 0.15s;
}
.nodes-path-item:hover { background: var(--card-2); color: var(--text); }
.nodes-path-item.active { background: rgba(108,124,255,0.15); color: var(--primary-2); }
.nodes-path-icon { font-size: 8px; color: var(--primary); }
.nodes-path-item em { font-style: normal; color: var(--muted); font-size: 11px; }

/* ---------- B/W Editor ---------- */
.bw-editor {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
}
.bw-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.bw-tool-label {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
.btn-brush {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  font-size: 12px;
  flex: none;
}
.btn-brush.active {
  border-color: var(--primary);
  background: rgba(108, 124, 255, 0.2);
  color: var(--text);
}
.brush-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.3);
  display: inline-block;
}
.brush-swatch.black { background: #000; }
.brush-swatch.white { background: #fff; }
.brush-size-input {
  width: 80px;
  accent-color: var(--primary);
}
.btn-sm { padding: 4px 10px; font-size: 11px; flex: none; }
.bw-preview-box {
  position: relative;
  cursor: crosshair;
  flex: 1 1 auto;
  min-height: 0;
}

.empty {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 40px;
}

/* ---------- Code tab ---------- */
.code-pane {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
}
.code-box {
  margin: 0;
  padding: 16px;
  background: #0b0e1e;
  color: #c7d2fe;
  font-family: "SF Mono", Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  border: none;
  outline: none;
  resize: none;
}

.toolbar-sep { flex: 1; }

.footer {
  text-align: center;
  padding: 16px 0 0;
  color: var(--muted);
  font-size: 12px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--card);
  border: 1px solid var(--border);
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 14px;
  opacity: 0;
  transition: 0.3s;
  pointer-events: none;
  z-index: 1000;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { border-color: var(--accent); }
.toast.error { border-color: var(--danger); }
