:root {
  --bg: #070b16;
  --bg-elev: #0c1224;
  --panel: #10182e;
  --panel-2: #161f3a;
  --line: rgba(148, 163, 255, 0.16);
  --text: #e8edff;
  --muted: #8b96c5;
  --accent: #7c8cff;
  --accent-2: #c084fc;
  --ok: #34d399;
  --danger: #f87171;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 12px;
  --font: Inter, system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 80% -10%, rgba(124, 140, 255, 0.16), transparent 50%), var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app {
  height: 100%;
  display: grid;
  grid-template-rows: 58px 1fr;
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(160px, 1fr) auto auto;
  gap: 16px;
  align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 11, 22, 0.92);
  backdrop-filter: blur(16px);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.logo-mark { display: grid; place-items: center; }
.brand-copy { display: flex; flex-direction: column; line-height: 1.1; }
.brand-copy strong { font-size: 14px; letter-spacing: 0.01em; }
.brand-copy span { font-size: 11px; color: var(--muted); }

.project-meta { display: flex; align-items: center; gap: 10px; min-width: 0; }
.project-title {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font: 600 13px var(--font);
  padding: 6px 8px;
  border-radius: 8px;
  min-width: 0;
  width: 100%;
  max-width: 280px;
}
.project-title:hover, .project-title:focus {
  border-color: var(--line);
  outline: none;
  background: rgba(255,255,255,0.03);
}
.save-state { font-size: 12px; color: var(--ok); white-space: nowrap; }

.mode-toggle {
  display: flex;
  background: #141b33;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}
.mode-toggle button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 600 12px var(--font);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.mode-toggle button.active {
  background: #1f294d;
  color: var(--text);
}

.top-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn, .ghost-btn, .primary-btn, .add-section-btn {
  font: 600 12px var(--font);
  border-radius: 10px;
  cursor: pointer;
}
.icon-btn {
  width: 32px; height: 32px;
  border: 1px solid var(--line);
  background: #141b33;
  color: var(--text);
}
.ghost-btn {
  background: #141b33;
  color: var(--text);
  border: 1px solid var(--line);
  padding: 7px 11px;
}
.ghost-btn.compact { padding: 5px 8px; }
.ghost-btn.linkish { text-decoration: none; display: inline-flex; align-items: center; }
.primary-btn, .add-section-btn {
  background: linear-gradient(180deg, #8b9cff, #6f7fff);
  color: #0b1020;
  border: 0;
  padding: 8px 13px;
  font-weight: 700;
}
.primary-btn:hover, .add-section-btn:hover { filter: brightness(1.06); }

.studio {
  display: grid;
  grid-template-columns: 260px minmax(320px, 1fr) minmax(420px, 1.25fr);
  min-height: 0;
}

.pane {
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--bg-elev);
  display: flex;
  flex-direction: column;
}
.preview-pane { border-right: 0; background: #080d1b; }

.pane-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 14px 14px 10px;
  gap: 8px;
}
.pane-head h2 { margin: 0; font-size: 13px; letter-spacing: 0.04em; text-transform: uppercase; }
.muted { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.count-pill {
  background: #1b2444;
  border-radius: 999px;
  font-size: 11px;
  padding: 2px 8px;
  color: var(--muted);
}

.section-list {
  overflow: auto;
  padding: 0 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sec-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: #121a32;
  cursor: grab;
}
.sec-item.active {
  border-color: rgba(124, 140, 255, 0.55);
  background: #1a2350;
}
.sec-item.hidden-sec { opacity: 0.55; }
.sec-name { font-size: 13px; font-weight: 600; }
.sec-type { font-size: 11px; color: var(--muted); }
.sec-tools { display: flex; gap: 4px; }
.sec-tools button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.add-section-btn { margin: 10px; }

.inspector, .skeleton {
  overflow: auto;
  padding: 0 14px 18px;
  min-height: 0;
}
.inspector.hidden, .skeleton.hidden { display: none; }
.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field input, .field textarea, .field select {
  width: 100%;
  background: #0d1428;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 10px;
  font: 13px var(--font);
}
.field textarea { min-height: 84px; resize: vertical; }
.swatch-row { display: flex; gap: 8px; align-items: center; }
.swatch-row input[type="color"] {
  width: 42px; height: 36px; padding: 0; border: 0; background: transparent;
}
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  width: 16px; height: 16px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.25);
  cursor: pointer;
}

#raw-html {
  width: 100%;
  min-height: calc(100vh - 160px);
  background: #0a1020;
  color: #d7def8;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  font: 12.5px/1.55 var(--mono);
  resize: none;
}

.visibility-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ok);
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.viewport-switch {
  display: flex; gap: 4px;
  background: #121a32;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.viewport-switch button {
  border: 0; background: transparent; color: var(--muted);
  font: 600 11px var(--font); padding: 5px 10px; border-radius: 999px; cursor: pointer;
}
.viewport-switch button.active { background: #1f294d; color: var(--text); }
.preview-status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.12); }
.preview-tools { display: flex; gap: 6px; align-items: center; }
#zoom-select {
  background: #121a32; color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 6px; font: 11px var(--font);
}

.preview-stage {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px;
  display: grid;
  place-items: start center;
}
#preview-frame-wrap {
  width: 1280px;
  transform-origin: top center;
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.08);
}
#preview { width: 100%; height: 1400px; border: 0; background: #fff; display: block; }

.modal-root {
  position: fixed; inset: 0;
  background: rgba(4, 7, 16, 0.72);
  display: grid; place-items: center;
  z-index: 40;
  padding: 24px;
}
.modal-root.hidden { display: none; }
.modal {
  width: min(920px, 100%);
  max-height: 86vh;
  overflow: auto;
  background: #10182e;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px;
}
.modal h3 { margin: 0 0 6px; }
.modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 16px;
}
.card {
  background: #161f3a;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  cursor: pointer;
}
.card:hover { border-color: var(--accent); }
.card h4 { margin: 0 0 6px; font-size: 14px; }
.card p { margin: 0; color: var(--muted); font-size: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toasts {
  position: fixed; right: 16px; bottom: 16px;
  display: flex; flex-direction: column; gap: 8px; z-index: 50;
}
.toast {
  background: #161f3a;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
  min-width: 220px;
  font-size: 13px;
}

@media (max-width: 1180px) {
  .studio { grid-template-columns: 220px 1fr; grid-template-rows: 1fr 48vh; }
  .preview-pane { grid-column: 1 / -1; }
  .topbar { grid-template-columns: auto 1fr auto; }
  .mode-toggle { display: none; }
}
@media (max-width: 760px) {
  .studio { grid-template-columns: 1fr; }
  .left-pane { display: none; }
  .project-title { max-width: 140px; }
}

.hidden { display: none !important; }

.ai-lock {
  position: fixed; inset: 0;
  background: rgba(4, 7, 16, 0.78);
  z-index: 80;
  display: grid; place-items: center;
  pointer-events: all;
}
.ai-lock-card {
  width: min(420px, calc(100vw - 32px));
  background: #10182e;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: var(--shadow);
}
.ai-lock-card h3 { margin: 12px 0 6px; }
.spinner {
  width: 42px; height: 42px; margin: 0 auto;
  border-radius: 50%;
  border: 3px solid rgba(124,140,255,.2);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress-track {
  height: 8px; border-radius: 99px;
  background: #1b2444; overflow: hidden; margin: 16px 0 8px;
}
.progress-bar {
  height: 100%; width: 8%;
  background: linear-gradient(90deg, #7c8cff, #c084fc);
  transition: width .25s ease;
}
#ai-lock-pct { color: var(--muted); font-size: 12px; }

.password-row { display: flex; gap: 8px; }
.password-row input { flex: 1; }
.password-row button {
  background: #141b33; color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 0 12px; cursor: pointer; font: 600 12px var(--font);
}
