* {
  box-sizing: border-box;
}

:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #1f2937;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --line: #334155;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --danger: #ef4444;
  --canvas: #ffffff;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  background: #020617;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 750;
  letter-spacing: 0.2px;
}

.brand-mark {
  color: var(--accent);
  font-size: 24px;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn,
.tool {
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: var(--panel-2);
  padding: 8px 11px;
  cursor: pointer;
  transition: 0.15s ease;
}

.btn:hover,
.tool:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.btn.primary {
  border-color: var(--accent-2);
  background: var(--accent-2);
  color: #00111f;
  font-weight: 700;
}

.btn.danger {
  border-color: #7f1d1d;
  background: #451a1a;
  color: #fecaca;
}

.btn.full {
  width: 100%;
  margin-top: 10px;
}

.btn.small {
  padding: 6px 8px;
  font-size: 13px;
}

.file-btn {
  display: inline-block;
}

.layout {
  height: calc(100vh - 58px);
  display: grid;
  grid-template-columns: 270px minmax(360px, 1fr) 320px;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px;
  overflow: auto;
}

.right-panel {
  border-right: none;
  border-left: 1px solid var(--line);
}

section + section {
  margin-top: 22px;
}

h2 {
  margin: 0 0 12px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tool.active {
  background: #083344;
  border-color: var(--accent);
  color: #e0f2fe;
}

label {
  display: block;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

input,
textarea {
  width: 100%;
  margin-top: 5px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #020617;
  color: var(--text);
  padding: 8px;
}

input[type="color"] {
  height: 40px;
  padding: 4px;
}

textarea {
  resize: vertical;
}

.form-row.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.status {
  border-bottom: 1px solid var(--line);
  padding: 9px 14px;
  color: var(--muted);
  background: #0b1220;
  font-size: 13px;
}

.stage {
  overflow: auto;
  padding: 28px;
  display: grid;
  place-items: center;
  background:
    linear-gradient(45deg, #111827 25%, transparent 25%),
    linear-gradient(-45deg, #111827 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #111827 75%),
    linear-gradient(-45deg, transparent 75%, #111827 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}

#editorSvg {
  width: min(100%, 1100px);
  height: auto;
  max-height: calc(100vh - 150px);
  background: var(--canvas);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  touch-action: none;
  user-select: none;
}

#contentLayer > * {
  cursor: pointer;
}

#uiLayer {
  pointer-events: none;
}

.selection-box {
  fill: none;
  stroke: #0ea5e9;
  stroke-width: 1.5;
  stroke-dasharray: 7 4;
  vector-effect: non-scaling-stroke;
}

.empty {
  color: var(--muted);
  background: #020617;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
}

.hidden {
  display: none !important;
}

.layer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.layer-list {
  display: grid;
  gap: 6px;
}

.layer-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px;
  background: #020617;
  color: var(--text);
  cursor: pointer;
}

.layer-item.selected {
  border-color: var(--accent);
  background: #082f49;
}

.layer-type {
  color: var(--muted);
  font-size: 12px;
}

.code-box {
  min-height: 220px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre;
}

@media (max-width: 1050px) {
  .layout {
    grid-template-columns: 220px minmax(340px, 1fr);
  }

  .right-panel {
    display: none;
  }
}

@media (max-width: 760px) {
  .topbar {
    height: auto;
    align-items: flex-start;
    flex-direction: column;
    padding: 12px;
  }

  .layout {
    height: auto;
    grid-template-columns: 1fr;
  }

  .panel,
  .right-panel {
    border: none;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    min-height: 70vh;
  }
}


.download-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 9px 14px;
  color: var(--text);
  background: #06202f;
  font-size: 13px;
}

.download-link {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--accent);
  border-radius: 9px;
  padding: 6px 10px;
  color: #e0f2fe;
  background: #075985;
  text-decoration: none;
  font-weight: 700;
}

.download-link.secondary {
  border-color: var(--line);
  background: #0f172a;
  color: var(--muted);
  font-weight: 600;
}

.download-link:hover {
  filter: brightness(1.08);
}
