:root {
  --bg: #f6f5f2; --panel: #ffffff; --ink: #1a1b22; --muted: #5d6170; --line: #e2e0da;
  --accent: #2f5bd3; --accent-ink: #ffffff; --accent-soft: #e9eefc;
  --ok: #157f3b; --ok-soft: #e7f6ec; --warn: #8a5300; --warn-soft: #fff4e0;
  --chip: #f1f0ec; --chip-hover: #e6e9f6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .07);
  --radius: 12px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1117; --panel: #181b24; --ink: #e8eaf1; --muted: #9ba3b6; --line: #2a2f3d;
  --accent: #8fa8ff; --accent-ink: #0f1430; --accent-soft: #212a4a;
  --ok: #4ade80; --ok-soft: #12301d; --warn: #fbbf24; --warn-soft: #33270b;
  --chip: #20242f; --chip-hover: #283154;
  --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1 { font-size: 30px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 10px; }
code { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
code { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; }
.backlink { text-decoration: none; color: var(--muted); }
.backlink:hover { color: var(--ink); }
.sep { color: var(--line); }
.topactions { display: flex; align-items: center; gap: 10px; }
.freebadge { font-size: 12px; color: var(--ok); background: var(--ok-soft); padding: 3px 10px; border-radius: 99px; white-space: nowrap; }

button, select, input { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 14px;
  cursor: pointer; min-height: 38px;
}
button:hover { border-color: var(--accent); }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
.iconbtn { min-width: 38px; padding: 7px 10px; }
select, input[type="text"], input[type="search"] {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 10px; min-height: 38px;
}

select, input[type="text"], input[type="number"] {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 9px; min-height: 36px; min-width: 0;
}
button:disabled { opacity: .45; cursor: default; }
button:disabled:hover { border-color: var(--line); }

.wrap { max-width: 1320px; margin: 0 auto; padding: 22px 20px 40px; }
.hero { margin-bottom: 12px; }
.lede { color: var(--muted); margin: 0 0 12px; font-size: 16px; }
.presets { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.exlabel { color: var(--muted); font-size: 13px; }
.chip { min-height: 32px; padding: 4px 12px; border-radius: 99px; background: var(--chip); border-color: transparent; font-size: 14px; }
.chip:hover { background: var(--chip-hover); border-color: transparent; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 14px 0 10px; }
.spacer { flex: 1; }
.notice { margin: 0 0 10px; padding: 8px 12px; border-radius: 8px; background: var(--accent-soft); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.studio { display: grid; grid-template-columns: minmax(330px, 400px) minmax(0, 1fr); gap: 16px; align-items: start; }
.controls { display: flex; flex-direction: column; max-height: calc(100vh - 90px); position: sticky; top: 70px; overflow: hidden; }
.grouptabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 10px; border-bottom: 1px solid var(--line); }
.gtab { min-height: 30px; padding: 3px 10px; font-size: 13px; border-radius: 99px; background: var(--chip); border-color: transparent; position: relative; }
.gtab.on { background: var(--accent); color: var(--accent-ink); }
.gtab[data-count]:not([data-count=""])::after {
  content: attr(data-count); font-size: 10px; font-weight: 700; margin-left: 5px; padding: 0 5px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent);
}
.gtab.on[data-count]:not([data-count=""])::after { background: var(--accent-ink); }
.groupbody { overflow-y: auto; padding: 6px 12px 12px; flex: 1; }
.changed { margin: 0; padding: 8px 12px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }

.ctl { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.ctl:last-child { border-bottom: 0; }
.ctl label { display: flex; flex-direction: column; font-size: 13.5px; line-height: 1.25; min-width: 0; }
.ctl .key { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctl.changed label > span::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin: 0 6px 1px 0; }
.widget { display: flex; align-items: center; gap: 4px; min-width: 0; }
.widget > *:first-child { flex: 1; min-width: 0; }
.widget select, .widget input[type="text"] { width: 100%; }
.boolctl .widget { justify-content: flex-end; }
.boolctl .widget > *:first-child { flex: 0 0 auto; }
.resetdot { min-height: 28px; min-width: 28px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 15px; }
.resetdot.invisible { visibility: hidden; }
.numrow { display: flex; gap: 6px; align-items: center; min-width: 0; }
.numrow input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
.num { width: 68px; flex: 0 0 68px; }
.times { color: var(--muted); }
.colorrow { display: flex; gap: 6px; align-items: center; min-width: 0; }
input[type="color"] { width: 36px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); flex: 0 0 36px; cursor: pointer; }
input[type="color"].muted { opacity: .5; }
.colortext { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.bad { border-color: #d33 !important; }
.switch { width: 20px; height: 20px; accent-color: var(--accent); }
.cmaprow { display: flex; flex-direction: column; gap: 4px; }
.cmapbar { display: block; height: 10px; border-radius: 3px; }

.cycle { padding: 8px 0 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.sublabel { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.cycle select { width: 100%; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 6px; }
.sw { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.cn { font: 11px ui-monospace, Menlo, monospace; color: var(--muted); }
.swbtns { display: flex; gap: 2px; }
.mini { min-height: 22px; min-width: 18px; padding: 0 4px; font-size: 12px; line-height: 1; border-radius: 5px; }
.addsw { min-height: 34px; width: 36px; padding: 0; align-self: center; font-size: 18px; }
.cbnote { font-size: 12.5px; margin: 4px 0 8px; }
.cbnote.good { color: var(--ok); }
.cbnote.warn { color: var(--warn); }
.darkrow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.hint { color: var(--muted); font-size: 12.5px; }

.preview { padding: 12px; min-width: 0; }
.previewbar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.segmented { display: inline-flex; flex-wrap: wrap; gap: 2px; background: var(--chip); padding: 3px; border-radius: 10px; }
.seg { min-height: 30px; padding: 3px 11px; font-size: 13px; border: 0; background: transparent; border-radius: 8px; }
.seg.on { background: var(--panel); box-shadow: var(--shadow); font-weight: 600; }
:root[data-theme="dark"] .seg.on { background: var(--accent-soft); }
.inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.charts { display: grid; gap: 10px; }
.charts.all { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.charts.one { grid-template-columns: 1fr; }
.chart { margin: 0; min-width: 0; }
.chart svg { display: block; width: 100%; height: auto; border-radius: 6px; outline: 1px solid var(--line); }
.charts.one svg { max-height: 70vh; width: auto; max-width: 100%; margin: 0 auto; }
.chart figcaption { font-size: 12px; color: var(--muted); text-align: center; margin-top: 3px; }
.err { color: var(--warn); }
.figinfo { font-size: 12.5px; color: var(--muted); margin: 10px 0 0; }
.warnings { margin: 8px 0 0; padding: 8px 12px 8px 28px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 13px; }

.export { margin-top: 16px; padding: 12px; }
.exporthead, .exportopts { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.exportopts { margin: 10px 0; justify-content: flex-start; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; }
#styleName { width: 160px; }
.code {
  margin: 0; padding: 12px 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; max-height: 420px; overflow: auto; white-space: pre;
}
.notes { margin-top: 16px; padding: 12px 16px; font-size: 14px; }
.notes summary { cursor: pointer; font-weight: 600; }
.notes li { margin: 4px 0; color: var(--muted); }

.dlg { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); padding: 0; width: min(640px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(10, 12, 20, .45); }
.dlgbody { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.dlgbody h2 { margin: 0; }
.dlgbody .hint { margin: 0; }
.drop { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px; border: 1px dashed var(--line); border-radius: 8px; font-size: 13px; color: var(--muted); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.dlgbody textarea { width: 100%; font: 12.5px/1.45 ui-monospace, Menlo, Consolas, monospace; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); resize: vertical; }
.dlgbody .warnings { margin: 0; }
.dlgactions { display: flex; justify-content: flex-end; gap: 8px; }
.filters { position: absolute; width: 0; height: 0; overflow: hidden; }

.foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 18px 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; max-width: 1320px; margin: 0 auto; }

@media (max-width: 860px) {
  .studio { grid-template-columns: 1fr; }
  .preview { order: -1; }
  .controls { position: static; max-height: none; }
  .groupbody { overflow: visible; }
  .charts.all { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .wrap { padding: 16px 16px 32px; }
  h1 { font-size: 24px; }
  .freebadge { display: none; }
  .topbar { padding: 10px 16px; }
  .ctl { grid-template-columns: 1fr; gap: 4px; }
  .charts.all { grid-template-columns: 1fr; }
  #styleName { width: 120px; }
  .exporthead { flex-direction: column; align-items: stretch; }
}
