:root {
  --ink: #1b1b1b;
  --muted: #4a4a4a;
  --accent: #0b6e6e;
  --accent-strong: #075a5a;
  --accent-warm: #f08a4b;
  --paper: #fff8ed;
  --panel: #ffffff;
  --shadow: rgba(10, 30, 30, 0.12);
  --border: rgba(27, 27, 27, 0.12);
  --bg1: #f3efe6;
  --bg2: #e6f0ef;
  --highlight: #f9d3a7;
  --radius: 16px;
  --radius-small: 10px;
  --space-1: 6px;
  --space-2: 12px;
  --space-3: 18px;
  --space-4: 24px;
  --space-5: 32px;
  --font-body: "Trebuchet MS", "Lucida Grande", sans-serif;
  --font-title: "Georgia", "Times New Roman", serif;
  --font-mono: "Courier New", Courier, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: radial-gradient(circle at 15% 15%, #ffffff, transparent 55%),
    radial-gradient(circle at 85% 10%, #f9e3cc, transparent 50%),
    linear-gradient(160deg, var(--bg1), var(--bg2));
  min-height: 100vh;
}

body::before,
body::after {
  content: "";
  position: fixed;
  z-index: -1;
  border-radius: 50%;
  opacity: 0.35;
}

body::before {
  width: 260px;
  height: 260px;
  background: rgba(11, 110, 110, 0.25);
  top: -70px;
  right: 8%;
}

body::after {
  width: 180px;
  height: 180px;
  background: rgba(240, 138, 75, 0.25);
  bottom: 5%;
  left: 6%;
}

.page {
  max-width: 980px;
  margin: 0 auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  animation: fade-in 0.6s ease-out;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.control-header {
  background: var(--panel);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: 0 12px 30px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  border: 1px solid var(--border);
}

.brand-title {
  font-family: var(--font-title);
  font-size: 1.7rem;
  letter-spacing: 0.5px;
}

.brand-subtitle {
  color: var(--muted);
  margin-top: var(--space-1);
}

.header-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3);
  align-items: end;
}

.header-hint {
  font-size: 0.9rem;
  color: var(--muted);
  background: var(--paper);
  border-radius: var(--radius-small);
  padding: var(--space-2);
}

.toggle {
  padding: var(--space-2) var(--space-3);
  font-weight: 600;
  border-radius: 999px;
  border: 2px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, border 0.2s ease;
  min-height: 44px;
}

.toggle:active {
  transform: translateY(1px);
}

.toggle-off {
  background: #fff;
  color: var(--accent-strong);
  border-color: var(--accent-strong);
}

.control label {
  display: block;
  margin-bottom: var(--space-1);
  font-weight: 600;
}

.control select,
.control input {
  width: 100%;
  padding: var(--space-2);
  border-radius: var(--radius-small);
  border: 1px solid var(--border);
  font-family: var(--font-body);
  font-size: 0.95rem;
}

.insertion-config {
  margin-top: var(--space-2);
}

.pipeline-area,
.editor-area,
.preview-area {
  background: var(--panel);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: 0 10px 24px var(--shadow);
  border: 1px solid var(--border);
}

.section-header h2,
.preview-header h2 {
  font-family: var(--font-title);
  margin: 0 0 var(--space-1) 0;
}

.section-header p {
  margin: 0;
  color: var(--muted);
}

.pipeline-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.pipeline-step {
  border-radius: var(--radius-small);
  border: 1px solid var(--border);
  padding: var(--space-2);
  background: var(--paper);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2);
  align-items: center;
  animation: rise-in 0.3s ease;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.pipeline-step-title {
  font-weight: 700;
}

.pipeline-step-controls {
  display: flex;
  gap: var(--space-1);
}

.pipeline-step-controls button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius-small);
  padding: 8px 12px;
  cursor: pointer;
  min-height: 40px;
}

.pipeline-step-config {
  grid-column: 1 / -1;
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

.pipeline-empty {
  padding: var(--space-2);
  border-radius: var(--radius-small);
  border: 1px dashed var(--border);
  color: var(--muted);
  background: #fff;
}

.template-hint {
  font-size: 0.85rem;
  color: var(--muted);
}

.pipeline-step-config input,
.pipeline-step-config select {
  padding: var(--space-2);
  border-radius: var(--radius-small);
  border: 1px solid var(--border);
}

.pipeline-add {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2);
  margin-top: var(--space-3);
  align-items: end;
}

.pipeline-add button {
  border-radius: var(--radius-small);
  border: 1px solid var(--accent-strong);
  background: var(--accent-strong);
  color: #fff;
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  min-height: 44px;
}

#editor {
  width: 100%;
  border-radius: var(--radius-small);
  border: 1px solid var(--border);
  padding: var(--space-3);
  font-family: var(--font-mono);
  font-size: 1rem;
  min-height: 280px;
  background: #fff;
}

#editor:focus {
  outline: 2px solid var(--accent-warm);
  border-color: transparent;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.preview-toggle {
  background: none;
  border: 1px solid var(--border);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-small);
  cursor: pointer;
}

.preview-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.preview-block {
  background: var(--paper);
  border-radius: var(--radius-small);
  border: 1px solid var(--border);
  padding: var(--space-2);
}

.preview-label {
  font-weight: 700;
  margin-bottom: var(--space-1);
}

.preview-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  min-height: 60px;
}

.status-line {
  margin-top: var(--space-2);
  font-size: 0.9rem;
  color: var(--muted);
  min-height: 18px;
}

.status-line.error {
  color: #9c2f2f;
}

.status-line.warning {
  color: #8a4a12;
}

.preview-collapsed .preview-content {
  display: none;
}

@media (max-width: 720px) {
  .page {
    padding: var(--space-3);
  }

  .control-header,
  .pipeline-area,
  .editor-area,
  .preview-area {
    padding: var(--space-3);
  }

  .header-controls {
    grid-template-columns: 1fr;
  }

  .pipeline-add {
    grid-template-columns: 1fr;
  }

  #editor {
    min-height: 220px;
  }
}
