:root {
  --bg: #eef1f6;
  --panel: #ffffff;
  --line: #d7dce6;
  --ink: #1f2330;
  --muted: #5b6478;
  --accent: #1565c0;
  --accent-press: #0d47a1;
  --danger: #c62828;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;            /* the main layout never scrolls */
}

/* ---------- App bar ---------- */
.appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  font-size: 22px;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #d6202a, #8e24aa);
  color: #fff; border-radius: 12px;
}
.appbar h1 { font-size: 18px; margin: 0; }
.tag { margin: 0; font-size: 12.5px; color: var(--muted); }
.appbar-actions { display: flex; gap: 8px; }

/* ---------- Main split ---------- */
main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  min-height: 0;
  overflow: hidden;
}

.stage-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  min-height: 0;
  min-width: 0;
}
#stage {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}
#stage svg {
  display: block;
  width: auto;            /* intrinsic 620x400 ratio from the svg attributes */
  height: auto;
  max-width: 100%;
  max-height: 100%;
  border-radius: 16px;
  box-shadow: 0 14px 38px rgba(20, 30, 60, .18);
  touch-action: none;          /* let us own pointer gestures */
  user-select: none;
  cursor: crosshair;
}

/* ---------- Panel ---------- */
.panel {
  border-left: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;            /* panel scrolls internally */
  min-height: 0;
  padding: 8px 16px 24px;
}
.group { border-bottom: 1px solid var(--line); padding: 10px 0; }
.group > summary {
  cursor: pointer;
  font-weight: 650;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 4px 0;
  list-style: none;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before { content: "▸ "; color: var(--muted); }
.group[open] > summary::before { content: "▾ "; }

.field { margin: 10px 0; }
.field.row { display: flex; gap: 8px; align-items: center; }
.field.row > input, .field.row > select { flex: 1; min-width: 0; }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
output { color: var(--ink); font-weight: 600; }

input[type="text"], select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
  background: #fff;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }

.check { display: flex; align-items: center; gap: 8px; color: var(--ink); margin-top: 4px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* color swatches */
.swatches {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 10px;
}
.swatch { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 0; }
.swatch span { font-size: 10.5px; color: var(--muted); }
.swatch input[type="color"] {
  width: 100%;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: none;
  cursor: pointer;
}

/* presets */
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.preset {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.preset:hover { border-color: var(--accent); }
.preset .dot { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  border-radius: var(--radius);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
}
.btn:hover { background: #f3f6fb; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-press); }
.btn-danger { color: var(--danger); }
.btn.wide { display: block; width: 100%; margin-top: 8px; }
.hidden { display: none !important; }

.hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; }
.hint code { background: #eef1f6; padding: 1px 5px; border-radius: 5px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  background: #1f2330;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Narrow fallback (phones) ---------- */
@media (max-width: 820px) {
  body { overflow: auto; }
  main { grid-template-columns: 1fr; }
  .panel { border-left: none; border-top: 1px solid var(--line); }
  #stage svg { max-height: 60vh; }
}
