:root {
  --bg: #0a0d12;
  --bg-glow: #0d1520;
  --panel: #10151c;
  --panel-2: #141b24;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.12);
  --text: #e8eef6;
  --muted: #8b98a9;
  --dim: #5c6878;
  --accent: #4d9dff;
  --accent-soft: rgba(77, 157, 255, 0.14);
  --good: #3ddc97;
  --bad: #ff6b6b;
  --warn: #ffc857;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Monaco, "Cascadia Code", monospace;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(1200px 700px at 78% -10%, var(--bg-glow), transparent 60%),
    radial-gradient(900px 600px at -10% 100%, #0c1622, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  height: 100vh;
}

/* ---------- sidebar ---------- */

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.015);
  backdrop-filter: blur(20px);
  padding: 18px 12px 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
}

.mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #06121f;
  background: linear-gradient(160deg, #7fc0ff, #4d9dff 55%, #2f7ae0);
  box-shadow: 0 4px 14px rgba(77, 157, 255, 0.35);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.brand-text strong {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.brand-text span {
  font-size: 10.5px;
  color: var(--dim);
}

.tools {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-right: 2px;
}

.tool {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  transition: background 0.14s ease, color 0.14s ease;
}

.tool:hover { background: rgba(255, 255, 255, 0.04); color: var(--text); }

.tool.active {
  background: var(--accent-soft);
  color: #cfe4ff;
}

.tool.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: 2.5px;
  border-radius: 2px;
  background: var(--accent);
}

.tool .glyph {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 5px;
  flex: none;
}

.tool.active .glyph {
  color: var(--accent);
  border-color: rgba(77, 157, 255, 0.4);
  background: rgba(77, 157, 255, 0.08);
}

.sidebar-foot {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 12px 8px 4px;
  font-size: 10.5px;
  color: var(--dim);
  border-top: 1px solid var(--line);
  margin-top: 8px;
}

.sidebar-foot .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--dim);
}

kbd {
  font-family: var(--mono);
  font-size: 9.5px;
  padding: 1px 4px;
  border-radius: 3px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
}

/* ---------- stage ---------- */

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 26px 30px 22px;
  gap: 18px;
  overflow: hidden;
}

.stage-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  flex: none;
}

.stage-head h1 {
  margin: 0 0 4px;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.stage-head p {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}

.stage-tip {
  font-size: 11px;
  color: var(--dim);
  text-align: right;
  line-height: 1.6;
  max-width: 300px;
}

.panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- panes ---------- */

.panes {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.panes.single { grid-template-columns: 1fr; }

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.015);
  flex: none;
}

.pane-title {
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 500;
}

.pane-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn {
  font-family: inherit;
  font-size: 11.5px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 9px;
  cursor: pointer;
  transition: background 0.13s ease, color 0.13s ease, border-color 0.13s ease;
  white-space: nowrap;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.btn:active { transform: translateY(0.5px); }

.btn.primary {
  background: var(--accent-soft);
  color: #a8cfff;
  border-color: rgba(77, 157, 255, 0.3);
}

.btn.primary:hover {
  background: rgba(77, 157, 255, 0.22);
  color: #d6e8ff;
}

.btn.ghost { background: transparent; }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.06); }

textarea.editor, pre.output, .field input, .field textarea {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: none;
  width: 100%;
  flex: 1;
  min-height: 0;
  padding: 12px 14px;
  resize: none;
  tab-size: 2;
}

pre.output {
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

pre.output.mono-nowrap { white-space: pre; word-break: normal; }

textarea.editor::placeholder { color: var(--dim); }

textarea.editor::-webkit-scrollbar, pre.output::-webkit-scrollbar,
.tools::-webkit-scrollbar, .palette-list::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

textarea.editor::-webkit-scrollbar-thumb, pre.output::-webkit-scrollbar-thumb,
.tools::-webkit-scrollbar-thumb, .palette-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.09);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

textarea.editor::-webkit-scrollbar-thumb:hover, pre.output::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.18);
  background-clip: padding-box;
}

/* ---------- status ---------- */

.status {
  font-size: 11px;
  color: var(--dim);
  font-family: var(--mono);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status.ok { color: var(--good); }
.status.err { color: var(--bad); }
.status.warn { color: var(--warn); }

/* ---------- forms ---------- */

.stack {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > label {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--dim);
}

.field input, .field .box {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  flex: none;
}

.field input:focus { border-color: rgba(77, 157, 255, 0.5); }

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.kv {
  display: grid;
  grid-template-columns: 118px 1fr;
  gap: 4px 12px;
  font-size: 12.5px;
  align-items: baseline;
}

.kv dt {
  color: var(--dim);
  font-size: 11.5px;
}

.kv dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text);
  word-break: break-all;
}

.kv dd.strong { color: var(--accent); }
.kv dd.dim { color: var(--muted); }

mark {
  background: rgba(77, 157, 255, 0.32);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-family: var(--mono);
  padding: 2px 7px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.chip.good { background: rgba(61, 220, 151, 0.14); color: var(--good); }
.chip.bad { background: rgba(255, 107, 107, 0.14); color: var(--bad); }

input[type="checkbox"] {
  accent-color: var(--accent);
  width: 13px;
  height: 13px;
  margin: 0;
}

.empty {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--dim);
  font-size: 12.5px;
  text-align: center;
  padding: 30px;
  line-height: 1.8;
}

/* ---------- palette ---------- */

.palette {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 11, 0.55);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: start center;
  padding-top: 16vh;
  z-index: 40;
  animation: fade 0.12s ease;
}

.palette[hidden] { display: none; }

.palette-box {
  width: min(520px, 90vw);
  background: rgba(18, 24, 32, 0.96);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  animation: pop 0.14s ease;
}

#palette-input {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
}

#palette-input::placeholder { color: var(--dim); }

.palette-list {
  max-height: 320px;
  overflow-y: auto;
  padding: 6px;
}

.palette-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
}

.palette-item .glyph {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--dim);
  width: 20px;
  text-align: center;
}

.palette-item .sub {
  margin-left: auto;
  font-size: 11px;
  color: var(--dim);
}

.palette-item.active {
  background: var(--accent-soft);
  color: #d6e8ff;
}

.palette-item.active .glyph { color: var(--accent); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  background: rgba(20, 27, 36, 0.96);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 12.5px;
  padding: 8px 16px;
  border-radius: 9px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 60;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(-6px) scale(0.99); } to { opacity: 1; transform: none; } }

/* ---------- responsive ---------- */

@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .stage { padding: 18px; }
  .panes { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}
