*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a0f;
  --bg2: #111118;
  --bg3: #18181f;
  --border: #252530;
  --border2: #30303e;
  --text: #f0f0f8;
  --text2: #9090a8;
  --text3: #60607a;
  --accent: #6c63ff;
  --accent2: #8b85ff;
  --accent-dim: #6c63ff22;
  --green: #22d3a0;
  --green-dim: #22d3a018;
  --red: #ff6b6b;
  --red-dim: #ff6b6b18;
  --amber: #f5a623;
  --amber-dim: #f5a62318;
  --radius: 10px;
  --shadow: 0 4px 24px #00000060;
}

[data-theme="light"] {
  --bg: #f4f4f8;
  --bg2: #ffffff;
  --bg3: #ebebf2;
  --border: #dcdce8;
  --border2: #c8c8d8;
  --text: #0f0f1a;
  --text2: #5a5a72;
  --text3: #9090aa;
  --accent: #5046e5;
  --accent2: #6c63ff;
  --accent-dim: #5046e514;
  --green: #16a37a;
  --green-dim: #16a37a14;
  --red: #e04545;
  --red-dim: #e0454514;
  --amber: #c47d0e;
  --amber-dim: #c47d0e14;
  --shadow: 0 4px 24px #00000018;
}

body {
  font-family: 'Instrument Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.25s, color 0.25s;
}

/* ── TOP BAR ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  height: 58px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  position: sticky; top: 0; z-index: 100;
}
.logo {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: -0.5px;
  display: flex; align-items: center; gap: 8px;
}
.logo-img {
  width: 28px; 
  height: 28px;
  border-radius: 7px;
  object-fit: contain;
}
.header-right { display: flex; align-items: center; gap: 16px; }
.theme-toggle {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; color: var(--text2); font-size: 0.82rem;
}
.toggle-track {
  width: 40px; height: 22px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 999px;
  position: relative; cursor: pointer;
  transition: background 0.2s;
}
.toggle-track.on { background: var(--accent); border-color: var(--accent); }
.toggle-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: left 0.2s;
  box-shadow: 0 1px 4px #0004;
}
.toggle-track.on .toggle-thumb { left: 20px; }

/* ── LAYOUT ── */
.app-shell {
  display: grid;
  grid-template-columns: 380px 1fr;
  min-height: calc(100vh - 58px);
}
.panel {
  padding: 28px;
  overflow-y: auto;
}
.panel-left { border-right: 1px solid var(--border); background: var(--bg2); }
.panel-right { background: var(--bg); }

/* ── SECTION HEADERS ── */
.section { margin-bottom: 28px; }
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.section-title {
  font-family: 'Syne', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text3);
}
.step-badge {
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  font-family: 'Syne', sans-serif;
}

/* ── CARDS ── */
.card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
}

/* ── INPUTS ── */
label { font-size: 0.78rem; color: var(--text2); font-weight: 500; display: block; margin-bottom: 5px; }
input[type="text"], input[type="email"], select, textarea {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 7px;
  padding: 9px 12px;
  font-size: 0.85rem;
  color: var(--text);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
textarea { resize: vertical; min-height: 80px; font-family: 'JetBrains Mono', monospace; font-size: 0.82rem; }
select option { background: var(--bg3); }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 0.84rem;
  font-weight: 600;
  font-family: 'Instrument Sans', sans-serif;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); transform: translateY(-1px); box-shadow: 0 4px 16px var(--accent-dim); }
.btn-ghost { background: transparent; border-color: var(--border2); color: var(--text2); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.btn-danger { background: var(--red-dim); border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { opacity: 0.88; transform: translateY(-1px); }
.btn-sm { padding: 5px 11px; font-size: 0.78rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── VARIABLE FIELD ── */
.field-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  position: relative;
  transition: border-color 0.15s;
}
.field-card:hover { border-color: var(--border2); }
.field-card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.field-type-badge {
  font-size: 0.68rem;
  font-weight: 600;
  font-family: 'Syne', sans-serif;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
}
.badge-number  { background: var(--accent-dim); color: var(--accent2); }
.badge-slider  { background: var(--green-dim); color: var(--green); }
.badge-dropdown{ background: var(--amber-dim); color: var(--amber); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-full { grid-column: 1/-1; }

/* ── FORMULA BOX ── */
.formula-textarea {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  min-height: 90px;
  border-color: var(--accent);
  background: var(--bg2);
}
.formula-hint {
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--text3);
  line-height: 1.5;
}
.var-pill {
  display: inline-block;
  background: var(--accent-dim);
  color: var(--accent2);
  border-radius: 5px;
  padding: 1px 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  margin: 2px 2px;
  cursor: pointer;
  border: 1px solid var(--accent-dim);
  transition: background 0.1s;
}
.var-pill:hover { background: var(--accent); color: #fff; }
.var-pills-row { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 2px; }

/* ── GATE TOGGLE ── */
.gate-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.gate-label { font-size: 0.88rem; font-weight: 500; }
.gate-sub { font-size: 0.75rem; color: var(--text3); margin-top: 2px; }

/* ── RIGHT PANEL ── */
.preview-wrap {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 24px;
}
.preview-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}
.preview-bar-title { font-family: 'Syne', sans-serif; font-size: 0.8rem; font-weight: 700; color: var(--text3); letter-spacing: 1px; text-transform: uppercase; }
.preview-dots { display: flex; gap: 5px; }
.preview-dot { width: 9px; height: 9px; border-radius: 50%; }
.dot-r { background: #ff6057; }
.dot-y { background: #febc2e; }
.dot-g { background: #28c840; }

.preview-body { padding: 24px; }

/* ── LIVE CALC ── */
.calc-title {
  font-family: 'Syne', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.calc-desc { font-size: 0.83rem; color: var(--text2); margin-bottom: 20px; }
.calc-field { margin-bottom: 16px; }
.calc-field label { margin-bottom: 6px; }
.result-box {
  margin-top: 20px;
  padding: 20px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  text-align: center;
}
.result-label { font-size: 0.75rem; color: var(--text2); text-transform: uppercase; letter-spacing: 1px; font-weight: 600; margin-bottom: 4px; }
.result-value {
  font-family: 'Syne', sans-serif;
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--accent2);
  letter-spacing: -1px;
}
.gate-overlay {
  text-align: center; padding: 20px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  margin-top: 20px;
}
.gate-overlay h3 { font-family: 'Syne', sans-serif; font-size: 1rem; margin-bottom: 6px; }
.gate-overlay p { font-size: 0.8rem; color: var(--text2); margin-bottom: 14px; }
.gate-form { display: flex; gap: 8px; }
.gate-form input { flex: 1; }
.error-banner {
  background: var(--red-dim);
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: 7px;
  padding: 10px 14px;
  font-size: 0.82rem;
  margin-top: 12px;
  display: none;
}

/* ── CODE OUTPUT ── */
.code-wrap {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}
.code-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}
.code-bar-title { font-family: 'Syne', sans-serif; font-size: 0.8rem; font-weight: 700; color: var(--text3); letter-spacing: 1px; text-transform: uppercase; }
.code-textarea {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  line-height: 1.6;
  width: 100%;
  background: var(--bg2);
  border: none;
  border-radius: 0;
  padding: 18px;
  color: var(--text2);
  min-height: 200px;
  outline: none;
}
.copy-success {
  color: var(--green);
  font-size: 0.8rem;
  margin-left: 8px;
  display: none;
}

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text3);
}
.empty-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: 0.5; }
.empty-state p { font-size: 0.85rem; line-height: 1.6; }

/* ── MISC ── */
.divider { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.flex-row { display: flex; gap: 10px; align-items: center; }
.flex-row-between { display: flex; justify-content: space-between; align-items: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }

/* ── SLIDER ── */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border2);
  border-radius: 2px;
  outline: none;
  border: none;
  box-shadow: none;
  padding: 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 0 4px var(--accent-dim);
}
.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-val { font-family: 'JetBrains Mono', monospace; font-size: 0.82rem; color: var(--accent2); min-width: 48px; text-align: right; }
/* ── TOAST NOTIFICATION ── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--bg2);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 16px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  transform: translateX(120%); /* Starts off-screen */
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.4s;
  max-width: 350px;
}

.toast.show {
  transform: translateX(0); /* Slides in */
  opacity: 1;
}

.toast-icon { font-size: 1.5rem; }

.toast-content h4 {
  margin: 0 0 4px;
  font-family: 'Syne', sans-serif;
  font-size: 0.95rem;
}

.toast-content p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text2);
  line-height: 1.4;
}

.toast-close {
  background: transparent;
  border: none;
  color: var(--text3);
  font-size: 1.2rem;
  cursor: pointer;
  margin-left: auto;
  transition: color 0.2s;
}

.toast-close:hover { color: var(--red); }

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .panel-left { border-right: none; border-bottom: 1px solid var(--border); }
}
@media (max-width: 600px) {
  header { padding: 0 16px; }
  .panel { padding: 18px; }
  .field-grid { grid-template-columns: 1fr; }
  .gate-form { flex-direction: column; }
}