:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --border: #dde2ea;
  --text: #1c2433;
  --muted: #6b7487;
  --accent: #2b4c7e;
  --accent-soft: #e6edf7;
  --danger: #b4232f;
  --radius: 8px;
  --sidebar: 380px;
  font-family: "Inter", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

button, input, select, textarea { font: inherit; color: inherit; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ------------------------------------------------------------ top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 220px; flex: 1; }

.brand-mark {
  width: 22px; height: 22px; flex: none;
  background:
    linear-gradient(var(--accent), var(--accent)) 0 0 / 100% 5px no-repeat,
    linear-gradient(#7d95bd, #7d95bd) 0 8.5px / 100% 5px no-repeat,
    linear-gradient(#c3d0e4, #c3d0e4) 0 17px / 100% 5px no-repeat;
  transform: skewX(-18deg);
  border-radius: 2px;
}

.project-name {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 8px;
  font-weight: 600;
  font-size: 15px;
  width: min(360px, 100%);
  background: transparent;
}
.project-name:hover, .project-name:focus { border-color: var(--border); background: var(--surface-2); outline: none; }

.toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.toolbar-sep { width: 1px; height: 24px; background: var(--border); margin: 0 6px; }
.export-info { font-size: 12px; color: var(--muted); min-width: 110px; text-align: right; }
.export-info.error { color: var(--danger); }

/* ------------------------------------------------------------ controls */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: #c8cfda; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #22406c; border-color: #22406c; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-small { padding: 4px 9px; font-size: 13px; }

select, input[type="text"], input[type="number"], textarea {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  background: var(--surface);
  min-width: 0;
}
select { padding-right: 4px; }
textarea { resize: vertical; min-height: 34px; line-height: 1.35; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

input[type="color"] {
  width: 34px; height: 26px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
}
input[type="color"]:disabled { opacity: 0.35; cursor: default; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }

.icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 28px; height: 28px;
  border: 0; border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: 0.3; cursor: default; background: transparent; }
.icon-btn.danger:hover { color: var(--danger); }

/* ------------------------------------------------------------ layout */

.workspace { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: var(--sidebar);
  flex: none;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.stage {
  flex: 1;
  min-width: 0;
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
}

#preview {
  display: block;
  background: #fff;
  box-shadow: 0 1px 2px rgba(20, 30, 50, 0.06), 0 8px 28px rgba(20, 30, 50, 0.10);
}
#preview.transparent {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #e8ebf0 25%, transparent 25%, transparent 75%, #e8ebf0 75%),
    linear-gradient(45deg, #e8ebf0 25%, transparent 25%, transparent 75%, #e8ebf0 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
}

.empty-hint {
  position: absolute;
  color: var(--muted);
  margin: 0;
}

/* ------------------------------------------------------------ panels */

.panel { border-bottom: 1px solid var(--border); }
.panel > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 16px;
  font-weight: 600;
  display: flex; align-items: baseline; gap: 8px;
}
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::before {
  content: "";
  width: 6px; height: 6px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg) translateY(-2px);
  transition: transform 0.15s;
  margin-right: 4px;
}
.panel[open] > summary::before { transform: rotate(45deg) translateY(-2px); }
.panel > summary .hint { font-weight: 400; font-size: 12px; color: var(--muted); }

.panel-body { padding: 0 16px 16px; display: grid; gap: 12px; }

.field { display: grid; gap: 4px; }
.field-head { display: flex; justify-content: space-between; gap: 8px; }
.field-head label, .field > span { font-size: 13px; color: var(--muted); }
.field-head output { font-size: 12px; color: var(--text); font-variant-numeric: tabular-nums; }
.field-checkbox, .field-inline { display: flex; align-items: center; gap: 8px; }
.field-checkbox label, .field-inline label { font-size: 13px; }
.field-color { grid-template-columns: 1fr auto; align-items: center; }
.field-color .field-head { grid-column: 1; }

.sidebar-foot { padding: 12px 16px 24px; }

/* ------------------------------------------------------------ layers */

.layer-list, .group-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

.layer-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.layer-card.open { border-color: #c3cddc; box-shadow: 0 2px 8px rgba(20, 30, 50, 0.06); }
.layer-card.dragging { opacity: 0.4; }
.layer-card.drop-target { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.layer-head { display: flex; align-items: center; gap: 6px; padding: 5px 4px 5px 2px; }
.drag-handle { color: #9aa3b4; cursor: grab; display: grid; place-items: center; width: 20px; height: 28px; touch-action: none; }
.drag-handle .icon { stroke-width: 3; }
.thumb {
  width: 34px; height: 34px; flex: none;
  border-radius: 5px;
  background: var(--surface-2);
  display: grid; place-items: center;
  overflow: hidden;
}
.thumb img { max-width: 100%; max-height: 100%; }
.thumb-empty { color: var(--muted); }
.layer-num { font-weight: 700; font-size: 12px; color: var(--accent); width: 18px; font-variant-numeric: tabular-nums; }
.layer-title { flex: 1; border-color: transparent !important; background: transparent !important; padding: 5px 6px; }
.layer-title:hover, .layer-title:focus { border-color: var(--border) !important; background: var(--surface) !important; }
.toggle .icon { transition: transform 0.15s; }
.layer-card.open .toggle .icon { transform: rotate(90deg); }

.layer-body { padding: 4px 12px 12px 30px; display: grid; gap: 10px; }
.sub-label { font-size: 13px; color: var(--muted); }

.legend-editor { display: grid; gap: 6px; }
.swatches { display: flex; flex-wrap: wrap; gap: 4px; }
.swatch { position: relative; }
.swatch input[type="color"] { width: 30px; height: 24px; }
.swatch-remove {
  position: absolute; top: -6px; right: -6px;
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 11px; line-height: 1;
  padding: 0;
  cursor: pointer;
  display: none;
}
.swatch:hover .swatch-remove, .swatch:focus-within .swatch-remove { display: block; }

.row-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.spacer { flex: 1; }

.add-layer { display: grid; gap: 8px; }
.library-pick { display: flex; gap: 6px; }
.library-pick select { flex: 1; }

.empty { color: var(--muted); font-size: 13px; padding: 4px 0; }

/* ------------------------------------------------------------ groups */

.group-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  display: grid;
  gap: 6px;
}
.group-main { display: flex; gap: 6px; align-items: flex-start; }
.group-main select { width: 52px; text-align: center; }
.group-main textarea { flex: 1; }
.group-meta { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.group-meta input[type="number"] { width: 56px; padding: 4px 6px; }
.group-meta label { color: var(--text); }

/* ------------------------------------------------------------ notice */

.notice {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  max-width: min(560px, calc(100vw - 32px));
  z-index: 10;
}
.notice.error { background: var(--danger); }

/* ------------------------------------------------------------ narrow screens */

@media (max-width: 900px) {
  body { height: auto; }
  .workspace { flex-direction: column-reverse; }
  .sidebar { width: 100%; border-right: 0; }
  .stage { min-height: 60vh; }
}
