:root {
  font-family: ui-monospace, 'SF Mono', Menlo, Monaco, monospace;
  color-scheme: dark;
  --bg: #050507;
  --fg: #e5e5e5;
  --muted: #888;
  --dim: #555;
  --panel: #0a0a10;
  --border: #1f1f26;
  --border-hover: #2a2a33;
  --accent: #4ade80;
  --danger: #f87171;
  --input: #0d0d13;
  --warn: #fbbf24;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: radial-gradient(ellipse at top, #0a0a14 0%, var(--bg) 70%);
  color: var(--fg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: max(1.5rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 100vh;
}

/* Header */
header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand h1 {
  font-size: clamp(1.6rem, 4vw, 2.25rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #fff, #888);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand h1::before {
  content: '> ';
  color: var(--accent);
  -webkit-text-fill-color: var(--accent);
}
.home-link { text-decoration: none; display: inline-block; transition: opacity 0.15s; }
.home-link:hover { opacity: 0.75; }
.tagline { color: var(--muted); font-size: 0.85rem; margin-top: 0.15rem; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Privacy badge */
.privacy-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: inherit;
  font-size: 0.72rem;
  background: rgba(74, 222, 128, 0.06);
  border: 1px solid rgba(74, 222, 128, 0.35);
  color: var(--accent);
  padding: 0.4rem 0.65rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.privacy-badge:hover { background: rgba(74, 222, 128, 0.12); border-color: var(--accent); }
.privacy-badge .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6);
  animation: pulse 2.2s ease-out infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6); }
  70%  { box-shadow: 0 0 0 8px rgba(74, 222, 128, 0); }
  100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}

/* Buttons */
button {
  font-family: inherit;
  font-size: 0.8rem;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 5px;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}
button:hover { background: rgba(74, 222, 128, 0.08); }
button.ghost {
  color: var(--muted);
  border-color: var(--border);
}
button.ghost:hover { color: var(--fg); border-color: var(--border-hover); background: transparent; }

/* Panels */
.panels {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  gap: 1rem;
  flex: 1;
  min-height: 0;
}
.pane {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 0;
  overflow: hidden;
}
.pane-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
}
.pane-title {
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.pane-header .meta { color: var(--muted); font-size: 0.7rem; flex: 1; }
.pane-actions { display: flex; gap: 0.35rem; }
.pane-actions button { padding: 0.25rem 0.6rem; font-size: 0.72rem; }

/* Input pane */
.drop-zone { position: relative; flex: 1; min-height: 0; display: flex; }
.pane-input textarea {
  flex: 1;
  width: 100%;
  font-family: inherit;
  font-size: 0.85rem;
  background: var(--input);
  color: var(--fg);
  border: none;
  padding: 0.85rem;
  resize: none;
  outline: none;
  line-height: 1.55;
  min-height: 420px;
}
.drop-overlay {
  position: absolute;
  inset: 6px;
  border: 2px dashed var(--accent);
  border-radius: 6px;
  background: rgba(74, 222, 128, 0.08);
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 0.9rem;
  pointer-events: none;
  text-align: center;
}
.drop-overlay .sub { display: block; color: var(--muted); font-size: 0.7rem; margin-top: 0.25rem; }
.drop-zone.over .drop-overlay { display: flex; }
[hidden] { display: none !important; }

/* Output pane */
.pane-output pre {
  flex: 1;
  margin: 0;
  padding: 0.85rem;
  background: var(--input);
  color: var(--fg);
  font-family: inherit;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
  line-height: 1.55;
  min-height: 420px;
}
.pane-output pre code { font: inherit; color: inherit; }
#output[data-kind='error'] { color: var(--danger); }

/* Pipeline pane */
.pane-pipeline { display: flex; flex-direction: column; }
.steps {
  list-style: none;
  padding: 0.75rem;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow: auto;
  flex: 1;
  min-height: 0;
}
.step {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.6rem;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: border-color 0.15s, opacity 0.15s;
  flex-wrap: wrap;
}
.step:hover { border-color: var(--border-hover); }
.step[data-status='error'] { border-color: var(--danger); }
.step[data-status='skipped'] { opacity: 0.4; }
.step.dragging { opacity: 0.4; }
.step.drag-over { border-color: var(--accent); }
.step-handle {
  color: var(--dim);
  cursor: grab;
  user-select: none;
  font-size: 0.9rem;
  padding: 0 0.2rem;
}
.step-handle:active { cursor: grabbing; }
.step-type {
  font-family: inherit;
  font-size: 0.8rem;
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.4rem;
  flex: 1;
  min-width: 0;
}
.step-type:focus { outline: none; border-color: var(--accent); }
.step-params {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  flex-basis: 100%;
  padding-left: 1.4rem;
}
.step-params:empty { display: none; }
.step-params label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  color: var(--muted);
}
.step-params input[type='text'],
.step-params select {
  font-family: inherit;
  font-size: 0.72rem;
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.25rem 0.4rem;
  max-width: 10rem;
}
.step-params input[type='checkbox'] { accent-color: var(--accent); }
.step-error {
  flex-basis: 100%;
  color: var(--danger);
  font-size: 0.72rem;
  padding-left: 1.4rem;
}
.step-remove {
  font-family: inherit;
  font-size: 0.9rem;
  background: transparent;
  color: var(--dim);
  border: none;
  cursor: pointer;
  padding: 0 0.3rem;
}
.step-remove:hover { color: var(--danger); background: transparent; }

.add-step-wrap {
  position: relative;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
}
.add-step {
  width: 100%;
  border-style: dashed;
}
.picker {
  position: absolute;
  left: 0.75rem;
  right: 0.75rem;
  bottom: calc(100% + 0.35rem);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem;
  max-height: 22rem;
  overflow: auto;
  z-index: 20;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.picker-group-label {
  font-size: 0.65rem;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0.4rem 0.5rem 0.2rem;
}
.picker-item {
  display: block;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 0.78rem;
  background: transparent;
  color: var(--fg);
  border: none;
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
}
.picker-item:hover { background: rgba(74, 222, 128, 0.1); color: var(--accent); }

/* Footer */
footer {
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  text-align: center;
}
footer a { color: var(--muted); text-decoration: none; font-size: 0.8rem; transition: color 0.15s; }
footer a:hover { color: var(--accent); }
.credits { margin-top: 0.25rem; font-size: 0.7rem; color: var(--dim); }
.credits a { color: var(--dim); font-size: 0.7rem; }
.credits a:hover { color: var(--accent); }

/* Toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--accent);
  color: var(--fg);
  font-size: 0.82rem;
  padding: 0.6rem 1rem;
  border-radius: 6px;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* Privacy dialog */
dialog#privacy-dialog {
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem 1.5rem 1.25rem;
  max-width: 36rem;
  width: calc(100vw - 2rem);
  font-family: inherit;
}
dialog#privacy-dialog::backdrop { background: rgba(0, 0, 0, 0.7); }
dialog#privacy-dialog h2 {
  font-size: 1.1rem;
  color: var(--accent);
  margin-bottom: 0.85rem;
  font-weight: 600;
}
dialog#privacy-dialog ul { padding-left: 1.1rem; display: flex; flex-direction: column; gap: 0.55rem; font-size: 0.85rem; line-height: 1.55; color: #cfcfcf; }
dialog#privacy-dialog code { font-family: inherit; background: var(--input); padding: 0.1rem 0.35rem; border-radius: 3px; font-size: 0.82rem; color: var(--accent); }
dialog#privacy-dialog form { margin-top: 1rem; text-align: right; }

/* Responsive */
@media (max-width: 900px) {
  .panels {
    grid-template-columns: 1fr;
    grid-auto-rows: min-content;
  }
  .pane-input textarea, .pane-output pre { min-height: 240px; }
  .pane-pipeline .steps { max-height: 340px; }
}

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