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

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #f4f8fc;
  color: #334155;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Top bar ── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.5rem;
  background: #ffffff;
  border-bottom: 1px solid #e2eaf3;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand {
  font-size: 1.05rem;
  font-weight: 700;
  color: #3b82f6;
}

.separator {
  color: #cbd5e1;
  font-weight: 300;
}

.subtitle {
  font-size: 0.8rem;
  color: #94a3b8;
  font-weight: 400;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.how-link {
  font-size: 0.78rem;
  font-weight: 500;
  color: #3b82f6;
  text-decoration: none;
  transition: color 0.12s;
}
.how-link:hover { color: #2563eb; text-decoration: underline; }

.lang-switch {
  display: flex;
  gap: 0.25rem;
}

.lang-btn {
  padding: 0.25rem 0.55rem;
  border: 1px solid #e2eaf3;
  border-radius: 6px;
  background: #ffffff;
  color: #64748b;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
}
.lang-btn:hover { background: #f0f6ff; border-color: #bfdbfe; }
.lang-btn.active {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #2563eb;
}

/* ── Pages ── */
.page { display: flex; flex-direction: column; flex: 1; }
.page.hidden { display: none !important; }

/* ── How it works bar (inside output panel) ── */
.how-it-works {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.45rem 0.65rem;
  background: #f0f7ff;
  border: 1px solid #e2eaf3;
  border-radius: 8px;
}

.how-it-works-steps {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1 1 420px;
  min-width: 0;
  flex-wrap: wrap;
}

.step {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.step-number {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #3b82f6;
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.step-text {
  font-size: 0.78rem;
  font-weight: 500;
  color: #475569;
}

.step-arrow {
  color: #93c5fd;
  font-size: 1rem;
}

/* ── Workspace (two columns) ── */
.workspace {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1px;
  flex: 1;
  background: #e2eaf3;
  overflow: hidden;
  min-height: 0;
}

/* ── Panels ── */
.panel {
  background: #ffffff;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
}

.panel-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #f1f5f9;
}

/* ── Form (left panel) ── */
form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.form-fields {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding-bottom: 0.5rem;
}

.form-footer {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: auto;
  position: sticky;
  bottom: 0;
  padding-top: 0.85rem;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0), #ffffff 28px);
  z-index: 1;
}

textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid #e2eaf3;
  border-radius: 8px;
  font-size: 0.88rem;
  resize: vertical;
  background: #fafcff;
  color: #334155;
  transition: border-color 0.12s;
  min-height: 80px;
}
textarea:focus {
  outline: none;
  border-color: #93c5fd;
  box-shadow: 0 0 0 2px rgba(147, 197, 253, 0.25);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.control-group > label {
  font-size: 0.72rem;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

select {
  padding: 0.45rem 0.6rem;
  border: 1px solid #e2eaf3;
  border-radius: 8px;
  font-size: 0.85rem;
  background: #ffffff;
  color: #334155;
  cursor: pointer;
  transition: border-color 0.12s;
}
select:focus {
  outline: none;
  border-color: #93c5fd;
  box-shadow: 0 0 0 2px rgba(147, 197, 253, 0.25);
}

/* ── Theme chips ── */
#theme-selector {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.theme-chip {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.55rem;
  border: 1.5px solid #e2eaf3;
  border-radius: 16px;
  background: #ffffff;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 500;
  color: #64748b;
  transition: all 0.12s;
  white-space: nowrap;
}
.theme-chip:hover {
  border-color: #bfdbfe;
  background: #f8fbff;
}
.theme-chip.active {
  border-color: #93c5fd;
  background: #f0f7ff;
  color: #2563eb;
  font-weight: 600;
}

.palette-dots {
  display: flex;
  gap: 1.5px;
}

.palette-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.08);
}

/* ── Submit button ── */
button[type="submit"] {
  display: block;
  width: 100%;
  padding: 0.55rem 1rem;
  background: #3b82f6;
  color: #ffffff;
  border: none;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
  flex-shrink: 0;
  margin-top: 0.5rem;
}
button[type="submit"]:hover { background: #2563eb; }
button[type="submit"]:disabled { opacity: 0.45; cursor: not-allowed; }

.form-hint {
  font-size: 0.72rem;
  line-height: 1.4;
  color: #cbd5e1;
  text-align: center;
}

/* ── Output panel (right) ── */
.panel-output {
  background: #fafcff;
}

#svg-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
}

#svg-container {
  flex: 1;
  background: #ffffff;
  border: 1px solid #e2eaf3;
  border-radius: 10px;
  padding: 1rem;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#svg-container svg { display: block; width: 100%; height: auto; }

#placeholder-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}

.placeholder-img {
  width: 100%;
  max-width: 480px;
  height: auto;
  opacity: 0.18;
  pointer-events: none;
}

.placeholder-text {
  color: #94a3b8;
  font-size: 0.85rem;
  font-style: italic;
  text-align: center;
}

/* ── Loading overlay ── */
#loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(250, 252, 255, 0.92);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  z-index: 10;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #e2eaf3;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #475569;
}

.loading-subtitle {
  font-size: 0.8rem;
  color: #94a3b8;
}

#download-bar {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  align-items: center;
  margin-left: auto;
  flex-shrink: 0;
}

#download-bar .btn-primary {
  padding: 0.34rem 0.72rem;
  background: #3b82f6;
  color: #ffffff;
  border: none;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}
#download-bar .btn-primary:hover { background: #2563eb; }

#download-bar .btn-secondary {
  padding: 0.34rem 0.72rem;
  background: #ffffff;
  color: #3b82f6;
  border: 1.5px solid #bfdbfe;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}
#download-bar .btn-secondary:hover { background: #f0f7ff; border-color: #93c5fd; }

.svg-note {
  font-size: 0.75rem;
  color: #94a3b8;
  font-style: italic;
  text-align: center;
  margin: 0.25rem 0;
}

/* ── Error ── */
.error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  color: #dc2626;
  font-size: 0.85rem;
}

.hidden { display: none !important; }

/* ── DSL details ── */
details {
  background: #ffffff;
  border: 1px solid #e2eaf3;
  border-radius: 8px;
  overflow: hidden;
}

details summary {
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  color: #94a3b8;
  user-select: none;
}

pre {
  padding: 0.65rem;
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
  border-top: 1px solid #f1f5f9;
  max-height: 250px;
  overflow-y: auto;
  background: #fafcff;
  color: #475569;
}

/* ── How it works page ── */
.how-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.how-back {
  font-size: 0.82rem;
  color: #3b82f6;
  text-decoration: none;
  font-weight: 500;
}
.how-back:hover { text-decoration: underline; }

.how-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1e293b;
}

.how-intro {
  font-size: 0.95rem;
  color: #475569;
  line-height: 1.6;
}

.how-steps-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.how-card {
  background: #ffffff;
  border: 1px solid #e2eaf3;
  border-radius: 10px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.how-card-number {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #3b82f6;
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.how-card h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: #1e293b;
}

.how-card p {
  font-size: 0.82rem;
  color: #64748b;
  line-height: 1.5;
}

.how-faq {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.how-faq h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 0.25rem;
}

.how-faq details p {
  padding: 0.5rem 0.75rem 0.65rem;
  font-size: 0.85rem;
  color: #475569;
  line-height: 1.55;
}

/* ── Responsive: stack on narrow screens ── */
@media (min-width: 769px) {
  .panel-input form {
    justify-content: flex-start;
  }

  .panel-input .form-fields {
    flex: 0 0 auto;
    overflow: visible;
    padding-bottom: 0;
  }

  .panel-input .form-footer {
    flex: 1 1 auto;
    margin-top: 0;
    position: static;
    padding-top: 0.75rem;
    background: none;
  }

  .panel-input button[type="submit"] {
    margin-top: 0;
  }

  .panel-input .form-hint {
    margin-top: auto;
    padding-top: 0.75rem;
  }
}

@media (max-width: 768px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .subtitle { display: none; }
  .separator { display: none; }
  .how-it-works {
    gap: 0.4rem;
    padding: 0.4rem 0.5rem;
    align-items: flex-start;
  }
  .how-it-works-steps {
    gap: 0.4rem;
    flex-basis: 100%;
  }
  .step-text { font-size: 0.7rem; }
  .step-arrow { font-size: 0.8rem; }
  #download-bar {
    width: 100%;
    margin-left: 0;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  #download-bar .btn-primary,
  #download-bar .btn-secondary {
    font-size: 0.72rem;
  }
  .how-steps-grid { grid-template-columns: 1fr; }
}
