/* Color Font Studio: "candy lab" dark theme */

:root {
  --bg: #15111d;
  --panel: #1b1626;
  --panel-2: #221c30;
  --raised: #2a2339;
  --raised-2: #332a46;
  --line: #342b48;
  --line-soft: #29223a;
  --text: #f3eefb;
  --muted: #a99fc2;
  --faint: #7a7095;
  --pink: #ff4d8d;
  --orange: #ff8a3d;
  --sun: #ffc83d;
  --mint: #45e0a6;
  --danger: #ff5d6c;
  --candy: linear-gradient(100deg, #ff4d8d 0%, #ff8a3d 55%, #ffc83d 100%);
  --ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--sun);
  --r-xl: 18px;
  --r-lg: 14px;
  --r-md: 10px;
  --r-sm: 7px;
  --font: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
  --left-w: clamp(272px, 14vw, 340px);
  --right-w: clamp(352px, 19vw, 440px);
  --top-h: 60px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: grid;
  grid-template-columns: var(--left-w) minmax(0, 1fr) var(--right-w);
  grid-template-rows: var(--top-h) minmax(0, 1fr);
  grid-template-areas: "top top top" "left stage right";
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.45 var(--font);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: none; box-shadow: var(--ring); }

.ico { flex: none; display: block; }

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

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px 0 18px;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, #1d1729, #18131f);
  position: relative;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  text-decoration: none;
  color: var(--muted);
  border-radius: var(--r-sm);
  margin-right: 10px;
}
.brand canvas { display: block; height: auto; filter: drop-shadow(0 4px 14px rgba(255, 77, 141, .25)); }
.brand-sub {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  padding-bottom: 8px;
  color: var(--faint);
}

.topbar-spacer { flex: 1; }

.tool-group {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--r-md);
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px 0 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  transition: background .15s, color .15s;
}
.tool-btn:hover { background: var(--raised); color: var(--text); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  transition: background .15s, color .15s;
}
.icon-btn:hover:not(:disabled) { background: var(--raised); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.danger:hover { color: var(--danger); }

.btn-export {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 42px;
  padding: 0 20px 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--candy);
  background-size: 160% 100%;
  background-position: 0 0;
  color: #1c0f17;
  font-weight: 700;
  font-size: 14.5px;
  letter-spacing: .005em;
  box-shadow: 0 6px 22px -6px rgba(255, 77, 141, .7), inset 0 1px 0 rgba(255, 255, 255, .45), inset 0 -2px 0 rgba(120, 20, 40, .25);
  transition: background-position .4s ease, transform .15s ease, box-shadow .2s;
}
.btn-export:hover { background-position: 100% 0; transform: translateY(-1px); box-shadow: 0 10px 28px -6px rgba(255, 138, 61, .75), inset 0 1px 0 rgba(255, 255, 255, .45), inset 0 -2px 0 rgba(120, 20, 40, .25); }
.btn-export:active { transform: translateY(1px); }
.btn-export.is-busy { opacity: .8; cursor: progress; }
.btn-export.is-busy .ico { animation: bob .6s ease-in-out infinite alternate; }

@keyframes bob { to { transform: translateY(3px); } }

/* ---------- segmented ---------- */

.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: var(--r-md);
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  flex-wrap: wrap;
}
.seg button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.seg button:hover { color: var(--text); }
.seg button.is-on {
  background: var(--raised-2);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .06) inset, 0 2px 8px rgba(0, 0, 0, .25);
}
.seg-sm button { min-height: 26px; padding: 0 9px; font-size: 12px; }
.field .seg { display: flex; }
.field .seg button { flex: 1 1 auto; }

.mode-switch .seg button { padding: 0 14px; }
.mode-switch .seg button.is-on { color: var(--sun); }

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

.panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
}
.panel-left { grid-area: left; border-right: 1px solid var(--line-soft); }
.panel-right { grid-area: right; border-left: 1px solid var(--line-soft); }

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 12px 0;
  border-bottom: 1px solid var(--line-soft);
}
.tabs button {
  position: relative;
  padding: 10px 10px 12px;
  border: 0;
  background: none;
  color: var(--faint);
  font-weight: 600;
  font-size: 13.5px;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
}
.tabs button:hover { color: var(--text); }
.tabs button.is-on { color: var(--text); }
.tabs button.is-on::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--candy);
}

.panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 16px 40px;
  scrollbar-width: thin;
  scrollbar-color: var(--raised-2) transparent;
}

.panel-lead { margin: 2px 2px 14px; color: var(--muted); font-size: 13px; }

.sec { padding: 14px 0 6px; border-top: 1px solid var(--line-soft); }
.sec:first-child { border-top: 0; padding-top: 2px; }
.sec-title {
  margin: 0 0 12px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .01em;
}

.note, .empty-note { margin: 4px 0 10px; color: var(--faint); font-size: 12.5px; }
.empty-note { padding: 18px 14px; border: 1px dashed var(--line); border-radius: var(--r-md); text-align: center; }

/* ---------- fields ---------- */

.field { margin-bottom: 14px; }
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 7px; }
.field-head label, .field-label { color: var(--text); font-size: 13px; font-weight: 500; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field-row .field-label { flex: none; }

.num-wrap {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 0 7px 0 2px;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid transparent;
  transition: border-color .15s;
}
.num-wrap:focus-within { border-color: var(--line); }
.num {
  width: 52px;
  padding: 3px 0 3px 6px;
  border: 0;
  background: none;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  -moz-appearance: textfield;
}
.num::-webkit-inner-spin-button, .num::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.num:focus { outline: none; box-shadow: none; }
.unit { color: var(--faint); font-size: 12px; }

input[type="range"] {
  --p: 50%;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--pink), var(--orange) calc(var(--p) * 1.2), var(--sun)) 0 0 / var(--p) 100% no-repeat, var(--raised);
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 6px; background: var(--raised); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 6px; background: linear-gradient(90deg, var(--pink), var(--orange)); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border-radius: 50%;
  background: #fff;
  border: 0;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, .08), 0 2px 6px rgba(0, 0, 0, .5);
  transition: transform .12s, box-shadow .12s;
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 0;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, .08), 0 2px 6px rgba(0, 0, 0, .5);
}
input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.1); box-shadow: 0 0 0 6px rgba(255, 200, 61, .18), 0 2px 6px rgba(0, 0, 0, .5); }
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.18); }
input[type="range"]:focus-visible { box-shadow: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: var(--ring); }

/* angle dial */
.angle-ctl { display: flex; align-items: center; gap: 10px; }
.dial {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, var(--raised-2), var(--panel-2));
  box-shadow: inset 0 0 0 1px var(--line), 0 2px 8px rgba(0, 0, 0, .35);
  cursor: grab;
  touch-action: none;
  transition: box-shadow .15s;
}
.dial:hover { box-shadow: inset 0 0 0 1px var(--faint), 0 2px 8px rgba(0, 0, 0, .35); }
.dial.is-drag { cursor: grabbing; box-shadow: inset 0 0 0 1px var(--sun), 0 0 0 5px rgba(255, 200, 61, .15); }
.dial-needle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 3px;
  margin-top: -1.5px;
  border-radius: 3px;
  background: var(--candy);
  transform-origin: 0 50%;
}
.dial-needle::after {
  content: "";
  position: absolute;
  right: -3px;
  top: 50%;
  width: 7px;
  height: 7px;
  margin-top: -3.5px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .5);
}
.dial-hub { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: var(--muted); }

/* color */
.color-ctl { display: flex; align-items: center; gap: 8px; }
.chip, .swatch {
  position: relative;
  display: block;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .14), 0 2px 6px rgba(0, 0, 0, .3);
  transition: transform .12s;
}
.chip:hover, .swatch:hover { transform: scale(1.06); }
.chip input, .swatch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }
.chip:focus-within, .swatch:focus-within { box-shadow: var(--ring); }
.hex {
  width: 84px;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-soft);
  background: var(--panel-2);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.hex:focus { border-color: var(--line); }

.grad-preview {
  height: 14px;
  border-radius: 7px;
  margin-bottom: 9px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .1);
}
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch-cell { position: relative; }
.swatch-x {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--raised-2);
  color: var(--text);
  opacity: 0;
  transition: opacity .15s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
.swatch-cell:hover .swatch-x, .swatch-x:focus-visible { opacity: 1; }
.swatch-add {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px dashed var(--line);
  background: transparent;
  color: var(--muted);
}
.swatch-add:hover { color: var(--text); border-color: var(--muted); }

/* select */
.select-wrap { position: relative; min-width: 0; flex: 0 1 190px; }
.select-wrap::after {
  content: "";
  position: absolute;
  right: 11px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 1.6px solid var(--muted);
  border-bottom: 1.6px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
select {
  width: 100%;
  appearance: none;
  padding: 7px 30px 7px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-soft);
  background: var(--panel-2);
  font-size: 13px;
  cursor: pointer;
}
select:hover { border-color: var(--line); }

/* switch */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--raised);
  box-shadow: inset 0 0 0 1px var(--line);
  transition: background .2s;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .2s cubic-bezier(.3, 1.4, .5, 1), background .2s;
}
.switch input:checked + .switch-track { background: var(--candy); box-shadow: none; }
.switch input:checked + .switch-track::after { transform: translateX(16px); background: #fff; }
.switch input:focus-visible + .switch-track { box-shadow: var(--ring); }

.text-input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-soft);
  background: var(--panel-2);
  font-size: 13px;
}
.text-input:focus { border-color: var(--line); }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  transition: background .15s, border-color .15s;
}
.btn-ghost:hover { background: var(--raised); border-color: var(--raised-2); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-block { width: 100%; margin-top: 10px; border-radius: var(--r-md); }

.seed-ctl { display: flex; align-items: center; gap: 10px; }
.seed-val { color: var(--faint); font-variant-numeric: tabular-nums; font-size: 12.5px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip-btn {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-soft);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
}
.chip-btn:hover { color: var(--text); border-color: var(--line); }
.count-badge { color: var(--sun); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.charset {
  width: 100%;
  resize: vertical;
  padding: 9px 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-soft);
  background: var(--panel-2);
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: .08em;
  word-break: break-all;
}

/* ---------- templates ---------- */

.tpl-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.tpl-group + .tpl-group { margin-top: 20px; }
.tpl-group .sec-title { margin: 0 2px 10px; }
.tpl-card { position: relative; }
.tpl-hit {
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  background: var(--panel-2);
  text-align: left;
  overflow: hidden;
  transition: border-color .2s, transform .2s, box-shadow .2s;
}
.tpl-hit:hover { border-color: var(--raised-2); transform: translateY(-2px); box-shadow: 0 12px 26px -12px rgba(0, 0, 0, .7); }
.tpl-hit:active { transform: translateY(0) scale(.99); }
.tpl-hit { position: relative; }
.tpl-thumb {
  display: grid;
  place-items: center;
  height: 96px;
  padding: 10px 12px 22px;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255, 255, 255, .06), transparent 60%),
    repeating-conic-gradient(#251e33 0 25%, #211b2e 0 50%) 0 0 / 14px 14px;
}
.tpl-thumb canvas { display: block; max-width: 100%; max-height: 66px; width: auto; height: auto; object-fit: contain; }
.tpl-hit:hover .tpl-thumb canvas { animation: wiggle .5s ease; }
@keyframes wiggle { 30% { transform: scale(1.05) rotate(-1.5deg); } 65% { transform: scale(1.03) rotate(1deg); } }
.tpl-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 14px 12px 6px;
  background: linear-gradient(transparent, rgba(21, 17, 29, .85));
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
}
.tpl-hit:hover .tpl-name { color: var(--text); }
.tpl-loading { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--raised-2); border-top-color: var(--pink); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.tpl-fail { color: var(--faint); font-size: 12px; }
.tpl-del { position: absolute; right: 6px; bottom: 4px; width: 28px; height: 28px; }
.save-row { display: flex; gap: 8px; margin-bottom: 14px; }

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

.layers-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.layers-head .sec-title { margin: 0; }

.menu-wrap { position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  width: 290px;
  max-height: 62vh;
  overflow-y: auto;
  padding: 6px;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background: rgba(36, 29, 51, .97);
  backdrop-filter: blur(14px);
  box-shadow: 0 24px 50px -12px rgba(0, 0, 0, .75);
  animation: pop .16s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.menu-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 8px;
  border: 0;
  border-radius: var(--r-md);
  background: none;
  text-align: left;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--raised); box-shadow: none; }
.menu-sw { flex: none; width: 30px; height: 30px; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .14); }
.menu-text { display: flex; flex-direction: column; min-width: 0; }
.menu-text strong { font-size: 13px; font-weight: 600; }
.menu-text small { color: var(--faint); font-size: 12px; }

.layer-list { list-style: none; margin: 0 0 6px; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.layer {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px 4px 3px 2px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  background: transparent;
  transition: background .15s, border-color .15s, opacity .15s;
}
.layer:hover { background: var(--panel-2); }
.layer.is-sel { background: var(--raised); border-color: var(--raised-2); }
.layer.is-sel::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--candy);
}
.layer.is-off .layer-main { opacity: .45; }
.layer.is-drag { opacity: .4; }
.layer.drop-before { box-shadow: 0 -2px 0 var(--sun); }
.layer.drop-after { box-shadow: 0 2px 0 var(--sun); }
.layer-grip { color: var(--faint); cursor: grab; padding: 0 2px; opacity: .6; }
.layer:hover .layer-grip { opacity: 1; }
.layer-eye { display: grid; place-items: center; width: 28px; height: 28px; border: 0; border-radius: 6px; background: none; color: var(--muted); }
.layer-eye:hover { color: var(--text); background: var(--raised-2); }
.layer-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 4px;
  border: 0;
  background: none;
  text-align: left;
  border-radius: 6px;
}
.layer-sw {
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16);
}
.layer-sw.lg { width: 40px; height: 40px; border-radius: 11px; }
.layer-name { font-weight: 600; font-size: 13px; white-space: nowrap; }
.layer-meta { margin-left: auto; color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.layer-actions { display: flex; opacity: 0; transition: opacity .15s; }
.layer-actions .icon-btn { width: 28px; height: 28px; }
.layer:hover .layer-actions, .layer.is-sel .layer-actions, .layer-actions:focus-within { opacity: 1; }
.layer-empty { padding: 16px; color: var(--faint); text-align: center; border: 1px dashed var(--line); border-radius: var(--r-md); }

.inspector { margin-top: 12px; padding-top: 16px; border-top: 1px solid var(--line-soft); }
.inspector-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.inspector-title { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.inspector-hint { margin: 1px 0 0; color: var(--faint); font-size: 12.5px; }
.inspector .sec { border-top: 0; padding-top: 6px; }
.inspector .sec + .sec { border-top: 1px solid var(--line-soft); padding-top: 14px; }

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

.items-panel {
  padding: 12px 12px 10px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
}
.items-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.items-head .sec-title { margin: 0; }
.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 148px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--raised-2) transparent;
}
.item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px 4px 2px 0;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.item:hover { background: var(--panel-2); }
.item.is-sel { background: var(--raised); border-color: var(--raised-2); }
.item.is-sel::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 7px;
  bottom: 7px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--candy);
}
.item.is-off .item-main { opacity: .45; }
.item.is-drag { opacity: .4; }
.item.drop-before { box-shadow: 0 -2px 0 var(--sun); }
.item.drop-after { box-shadow: 0 2px 0 var(--sun); }
.item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px;
  border: 0;
  background: none;
  text-align: left;
  border-radius: 6px;
}
.item-sw {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  color: rgba(0, 0, 0, .55);
  font-size: 15px;
  line-height: 1;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16);
}
.item-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 13px; }
.item-meta { margin-left: auto; padding-left: 8px; color: var(--faint); font-size: 11.5px; white-space: nowrap; }
.item .layer-actions { opacity: 0; }
.item:hover .layer-actions, .item.is-sel .layer-actions, .item .layer-actions:focus-within { opacity: 1; }
.item .icon-btn:disabled { opacity: .25; }

/* artboard controls */
.size-ctl { display: flex; align-items: center; gap: 6px; }
.num-input { width: 78px; flex: none; text-align: right; font-variant-numeric: tabular-nums; }
.chip-btn.is-on { color: var(--sun); border-color: rgba(255, 200, 61, .45); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }

/* stage selection */
.sel-box {
  position: absolute;
  pointer-events: none;
  border: 1px dashed rgba(255, 255, 255, .0);
  border-radius: 4px;
  transition: border-color .15s;
}
.stage-view:hover .sel-box { border-color: rgba(255, 255, 255, .22); }
.sel-box.is-sel, .stage-view:hover .sel-box.is-sel { border: 1.5px dashed var(--sun); box-shadow: 0 0 0 1px rgba(0, 0, 0, .35); }
body[data-mode="atlas"] .sel-box { display: none; }
.guide { position: absolute; pointer-events: none; opacity: 0; background: var(--pink); transition: opacity .1s; }
.guide.is-on { opacity: .9; }
.guide-v { left: 50%; top: 0; bottom: 0; width: 1px; }
.guide-h { top: 50%; left: 0; right: 0; height: 1px; }
.stage-view.can-move .stage-frame canvas { cursor: move; }
body.is-dragging-text, body.is-dragging-text * { cursor: grabbing !important; user-select: none; }
body[data-mode="text"] .stage-frame { box-shadow: 0 0 0 1px rgba(255, 255, 255, .08), 0 20px 50px -20px rgba(0, 0, 0, .8); }

/* ---------- font picker ---------- */

.font-search-row { position: relative; margin-bottom: 8px; }
.font-search-ico { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.font-search {
  width: 100%;
  padding: 8px 10px 8px 32px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-soft);
  background: var(--panel-2);
  font-size: 13px;
}
.font-search:focus { border-color: var(--line); }
.font-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 290px;
  overflow-y: auto;
  padding: 4px;
  border-radius: var(--r-md);
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  scrollbar-width: thin;
  scrollbar-color: var(--raised-2) transparent;
}
.font-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  text-align: left;
}
.font-item:hover { background: var(--raised); }
.font-item.is-on { background: var(--raised-2); }
.font-aa { width: 40px; font-size: 24px; line-height: 1.15; text-align: center; color: var(--text); }
.font-item.is-on .font-aa { background: var(--candy); -webkit-background-clip: text; background-clip: text; color: transparent; }
.font-name { font-size: 13px; font-weight: 500; }
.font-tag { margin-left: auto; color: var(--faint); font-size: 11.5px; }

/* ---------- stage ---------- */

.stage {
  grid-area: stage;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: radial-gradient(90% 70% at 50% 40%, #1f1830, var(--bg) 70%);
}

.stage-bar { padding: 16px 20px 0; }
#text-input {
  display: block;
  width: 100%;
  min-height: 52px;
  max-height: 160px;
  resize: none;
  padding: 13px 18px;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background: rgba(27, 22, 38, .8);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -.005em;
  line-height: 1.35;
  text-align: center;
  transition: border-color .2s, box-shadow .2s;
}
#text-input::placeholder { color: var(--faint); font-weight: 500; }
#text-input:focus { border-color: var(--raised-2); box-shadow: 0 0 0 4px rgba(255, 77, 141, .12); }

.stage-view {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 16px 20px 0;
  border-radius: var(--r-xl);
  overflow: auto;
  display: grid;
  border: 1px solid var(--line-soft);
  transition: background-color .3s;
  scrollbar-width: thin;
  scrollbar-color: var(--raised-2) transparent;
}
.stage-view[data-backdrop="checker"] { background: repeating-conic-gradient(#2a2338 0 25%, #221c2f 0 50%) 0 0 / 22px 22px; }
.stage-view[data-backdrop="dark"] { background: #0f0c14; }
.stage-view[data-backdrop="light"] { background: #f4f2f8; }

.stage-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  min-width: 100%;
  min-height: 100%;
  width: max-content;
  padding: 36px;
  margin: auto;
}
.stage-fig { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.stage-fig figcaption {
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(21, 17, 29, .75);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.stage-frame { position: relative; line-height: 0; }
.stage-frame canvas { display: block; }
body[data-mode="atlas"] .stage-frame { outline: 1px dashed rgba(255, 200, 61, .35); outline-offset: 0; }

.stage-error { max-width: 420px; padding: 22px 26px; border-radius: var(--r-lg); background: var(--panel); border: 1px solid var(--line); text-align: center; }
.stage-error strong { display: block; font-size: 15px; margin-bottom: 6px; }
.stage-error p { margin: 0; color: var(--muted); }

.stage-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px 14px;
}
.stage-info { color: var(--faint); font-size: 12.5px; font-variant-numeric: tabular-nums; font-weight: 500; }
.bd { display: block; width: 14px; height: 14px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25); }
.bd-checker { background: repeating-conic-gradient(#8b84a0 0 25%, #4a4360 0 50%) 0 0 / 7px 7px; }
.bd-dark { background: #0f0c14; }
.bd-light { background: #f4f2f8; }

.foot-mid { display: flex; align-items: center; gap: 14px; }
.btn-remix {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 13px 0 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
  font-size: 12.5px;
  transition: border-color .2s, background .2s;
}
.btn-remix .ico { color: var(--sun); }
.btn-remix:hover { border-color: var(--raised-2); background: var(--raised); }
.btn-remix.is-spun .ico { animation: spin-once .6s cubic-bezier(.3, 1.4, .5, 1); }
@keyframes spin-once { from { transform: rotate(-200deg) scale(.6); } }

.stage-view[data-backdrop="checker"] {
  background:
    radial-gradient(60% 55% at 50% 50%, rgba(255, 140, 190, .07), transparent 70%),
    repeating-conic-gradient(#2a2338 0 25%, #221c2f 0 50%) 0 0 / 22px 22px;
}
.preview-badge {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(21, 17, 29, .85);
  border: 1px solid var(--line);
  color: var(--sun);
  font-size: 12px;
  font-weight: 600;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
  z-index: 2;
}
body.is-previewing .preview-badge { opacity: 1; }
body.is-previewing .stage-view { border-color: rgba(255, 200, 61, .45); }
.stage { position: relative; }
.stage-wrap { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }

.icon-btn-solo { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line-soft); background: var(--panel-2); }

.lead-row { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.lead-row .panel-lead { margin: 2px 2px 0; }
.btn-surprise {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  border-radius: var(--r-md);
  border: 1px dashed rgba(255, 200, 61, .5);
  background: rgba(255, 200, 61, .06);
  color: var(--sun);
  font-weight: 700;
  font-size: 13px;
  transition: background .2s, border-color .2s, transform .15s;
}
.btn-surprise:hover { background: rgba(255, 200, 61, .12); border-color: var(--sun); }
.btn-surprise:active { transform: scale(.98); }
.btn-surprise:hover .ico { animation: spin-once .6s cubic-bezier(.3, 1.4, .5, 1); }

.stage-inner.is-pop .stage-frame canvas { animation: pop-in .5s cubic-bezier(.25, 1.5, .5, 1); }
@keyframes pop-in { from { transform: scale(.9); opacity: .4; filter: blur(2px); } }

.drop-veil {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: rgba(21, 17, 29, .72);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
body.is-dropping .drop-veil { opacity: 1; }
.drop-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 36px 56px;
  border-radius: 24px;
  border: 2px dashed var(--sun);
  background: rgba(34, 28, 48, .9);
}
.drop-card strong { font-size: 22px; background: var(--candy); -webkit-background-clip: text; background-clip: text; color: transparent; }
.drop-card span { color: var(--muted); }

/* ---------- toasts & confetti ---------- */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 76px;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  max-width: min(560px, calc(100vw - 32px));
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(42, 35, 57, .96);
  border: 1px solid var(--line);
  box-shadow: 0 16px 36px -10px rgba(0, 0, 0, .7);
  font-weight: 500;
  font-size: 13.5px;
  opacity: 0;
  transform: translateY(10px) scale(.97);
  transition: opacity .25s, transform .3s cubic-bezier(.3, 1.4, .5, 1);
}
.toast.is-in { opacity: 1; transform: none; }
.toast-ok { border-color: rgba(69, 224, 166, .45); }
.toast-ok::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 9px; border-radius: 50%; background: var(--mint); vertical-align: 1px; }
.toast-error { border-color: rgba(255, 93, 108, .6); border-radius: var(--r-lg); }

.confetti {
  position: fixed;
  z-index: 60;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  pointer-events: none;
  animation: confetti 1.1s cubic-bezier(.2, .6, .4, 1) forwards;
}
@keyframes confetti {
  to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; }
}

/* ---------- about ---------- */

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.btn-about {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px 0 12px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  transition: color .15s, border-color .15s, background .15s;
}
.btn-about .ico { color: var(--sun); transition: transform .4s cubic-bezier(.25, 1.5, .5, 1); }
.btn-about:hover { color: var(--text); border-color: rgba(255, 200, 61, .4); background: var(--raised); }
.btn-about:hover .ico { transform: rotate(90deg) scale(1.15); }

.about {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  overflow: visible;
}
.about-card:focus, .about-card:focus-visible { outline: none; box-shadow: 0 40px 120px -30px rgba(255, 77, 141, .45), 0 30px 60px -30px rgba(0, 0, 0, .9); }
.about::backdrop {
  background:
    radial-gradient(60% 50% at 50% 40%, rgba(255, 77, 141, .18), transparent 70%),
    rgba(10, 7, 16, .72);
  backdrop-filter: blur(6px);
}

/* Candy gradient rim: a padded gradient behind the card. */
.about-card {
  position: relative;
  padding: 1px;
  border-radius: 26px;
  background: linear-gradient(140deg, rgba(255, 77, 141, .8), rgba(255, 138, 61, .35) 40%, rgba(155, 107, 255, .25) 70%, rgba(255, 200, 61, .7));
  box-shadow: 0 40px 120px -30px rgba(255, 77, 141, .45), 0 30px 60px -30px rgba(0, 0, 0, .9);
  text-align: center;
}
.about-card > * { position: relative; }
.about-card::before {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: 25px;
  background:
    radial-gradient(90% 60% at 50% 0%, #2c1f45 0%, transparent 70%),
    radial-gradient(1.5px 1.5px at 14% 22%, rgba(255, 255, 255, .7), transparent),
    radial-gradient(1px 1px at 82% 16%, rgba(255, 255, 255, .6), transparent),
    radial-gradient(1.5px 1.5px at 70% 38%, rgba(255, 200, 61, .7), transparent),
    radial-gradient(1px 1px at 24% 44%, rgba(255, 255, 255, .5), transparent),
    radial-gradient(1px 1px at 90% 52%, rgba(255, 255, 255, .45), transparent),
    radial-gradient(1.5px 1.5px at 8% 60%, rgba(255, 77, 141, .7), transparent),
    linear-gradient(180deg, #1e1730, #15111d 70%);
}

.about-close { position: absolute; top: 14px; right: 14px; z-index: 1; border-radius: 50%; }

.about-stage {
  display: grid;
  place-items: center;
  padding: 46px 28px 6px;
}
.about-logo {
  display: block;
  max-width: 100%;
  height: auto;
  filter: drop-shadow(0 18px 30px rgba(255, 77, 141, .28));
}
.about[open] .about-logo { animation: about-logo-in .8s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes about-logo-in {
  from { opacity: 0; transform: translateY(14px) scale(.86) rotate(-2deg); }
  to { opacity: 1; transform: none; }
}

.about-version {
  display: inline-block;
  margin: 10px 0 26px;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 200, 61, .3);
  background: rgba(255, 200, 61, .08);
  color: var(--sun);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}

.about-credits { margin: 0 32px; font-size: 17px; line-height: 1.55; color: var(--text); }
.about-copy, .about-license { margin: 0 32px; font-size: 13.5px; line-height: 1.6; color: var(--muted); }
.about-copy { margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--line-soft); }
.about-license { padding-bottom: 34px; }

.about a {
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  background: linear-gradient(90deg, #ff4d8d, #ffc83d) 0 100% / 100% 2px no-repeat;
  padding-bottom: 1px;
  border-radius: 2px;
  transition: color .15s, background-size .2s;
}
.about a:hover { color: #ffd77a; background-size: 100% 100%; background-image: linear-gradient(90deg, rgba(255, 77, 141, .22), rgba(255, 200, 61, .22)); }

/* ---------- busy state ---------- */

body.is-rendering .stage-info::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 8px; border-radius: 50%; background: var(--sun); vertical-align: 1px; }

/* ---------- responsive ---------- */

@media (max-width: 1180px) {
  :root { --left-w: 220px; --right-w: 320px; }
  .brand-sub { display: none; }
  .tool-btn span { display: none; }
  .tool-btn { padding: 0 9px; }
  .btn-about span { display: none; }
  .btn-about { padding: 0 9px; }
}

@media (max-width: 900px) {
  body {
    overflow: auto;
    height: auto;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
    grid-template-areas: "top" "stage" "right" "left";
  }
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
  .topbar-spacer { display: none; }
  /* Three rows: brand + about/new/copy, history/style + export, mode switch. */
  .brand { order: 0; margin-right: auto; }
  .brand canvas { max-width: 150px; }
  .btn-about, .tool-group[aria-label="Design"], .icon-btn-solo { order: 1; }
  .tool-group[aria-label="History"], .tool-group[aria-label="Style file"] { order: 3; }
  .btn-export { order: 3; margin-left: auto; padding: 0 16px 0 14px; }
  .topbar::before { content: ""; order: 2; flex-basis: 100%; height: 0; }
  .topbar::after { content: ""; order: 4; flex-basis: 100%; height: 0; }
  .mode-switch { order: 5; flex: 1 1 100%; min-width: 0; }
  .mode-switch .seg { display: flex; flex-wrap: nowrap; }
  .mode-switch .seg button { flex: 1; padding: 0 8px; }
  .stage { min-height: 60vh; }
  .stage-bar { padding: 12px 16px 0; }
  .stage-view { margin: 12px 16px 0; min-height: 46vh; }
  .stage-foot { padding: 10px 16px; flex-wrap: wrap; }
  .panel { border: 0; border-top: 1px solid var(--line-soft); }
  .panel-scroll { overflow: visible; }
  .tpl-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

@media (max-width: 380px) {
  .topbar { gap: 8px; padding: 10px 12px; }
  .btn-export { padding: 0 14px 0 12px; gap: 7px; font-size: 13.5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
