:root {
  --bg: #0e1014;
  --panel: #15181e;
  --panel2: #1c2028;
  --panel3: #242936;
  --line: #2a2f3b;
  --text: #e4e7ee;
  --muted: #8a92a6;
  --accent: #7c8cff;
  --accent-strong: #5b6cf5;
  --danger: #ff6b6b;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

a { color: var(--accent); }

button, select, input[type="number"], input[type="search"] {
  font: inherit;
  color: var(--text);
  background: var(--panel3);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
}

button { cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { border-color: #3c4356; background: #2b3141; }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
button.primary:hover { background: #6a7af7; }
button.danger { color: var(--danger); }
button.link { background: none; border: none; padding: 0 4px; color: var(--accent); }
button.wide { width: 100%; }

input[type="number"] { padding: 4px 6px; width: 100%; }
input[type="search"] { width: 100%; padding: 7px 10px; }
input[type="color"] {
  width: 34px; height: 26px; padding: 2px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel3); cursor: pointer;
}
input[type="checkbox"] { accent-color: var(--accent); margin: 0; }
input[type="range"] { accent-color: var(--accent); width: 100%; margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; font-size: 14px; letter-spacing: 0.2px; }
.group { display: flex; align-items: center; gap: 6px; }
.group.tight { gap: 4px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

main {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr) 290px;
  min-height: 0;
}

aside {
  background: var(--panel);
  overflow: auto;
  min-height: 0;
}
aside.left { border-right: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; }
aside.right { border-left: 1px solid var(--line); }

section { padding: 12px 14px; border-bottom: 1px solid var(--line); }
section h2 {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 10px; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted);
}
section > * + * { margin-top: 8px; }
section > h2 + * { margin-top: 0; }
p { margin: 0; }

.badge {
  font-size: 11px; text-transform: none; letter-spacing: 0;
  background: var(--panel3); color: var(--text);
  border-radius: 10px; padding: 1px 7px;
}
.badge.accent { background: var(--accent-strong); color: #fff; }

.search { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.search select { width: 100%; }
.search #results { flex: 1; min-height: 0; overflow: auto; align-content: start; padding: 2px; }
.mine { flex: none; max-height: 42%; overflow: auto; }

.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 4px;
}
.icon-grid.small { grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); }

.ico {
  position: relative;
  aspect-ratio: 1;
  padding: 7px;
  display: grid; place-items: center;
  background: var(--panel2);
  border: 1px solid transparent;
  border-radius: 6px;
}
.ico img, .ico svg { width: 100%; height: 100%; display: block; pointer-events: none; }
.ico:hover { border-color: #3c4356; }
.ico.on { border-color: var(--accent); background: #262c4a; }
.ico.on::after {
  content: ""; position: absolute; top: 3px; right: 3px;
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
}
.ico.brush { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.ico.loading { opacity: 0.4; animation: pulse 0.8s ease-in-out infinite alternate; }
@keyframes pulse { to { opacity: 0.9; } }
.ico .x {
  position: absolute; top: -5px; right: -5px;
  width: 17px; height: 17px; padding: 0; line-height: 15px;
  font-size: 12px; border-radius: 50%;
  display: none;
}
.ico:hover .x { display: block; }
#myIcons .ico, #selIcons .ico { color: var(--text); padding: 6px; cursor: pointer; }

.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 0; border: 0; }
.center > * + * { margin-top: 0; }
.stagebar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.zoomlabel { min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; }

.stagewrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #0b0c10;
}
.stagewrap.transparent {
  background-color: #2a2d36;
  background-image:
    linear-gradient(45deg, #1f2128 25%, transparent 25%, transparent 75%, #1f2128 75%),
    linear-gradient(45deg, #1f2128 25%, transparent 25%, transparent 75%, #1f2128 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
}
#stage {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  cursor: default;
}
#stage.panning { cursor: grabbing; }
#dim { fill: rgba(8, 9, 13, 0.62); pointer-events: none; }
#tileBorder { stroke: rgba(255, 255, 255, 0.55); stroke-width: 1; stroke-dasharray: 6 4; pointer-events: none; }
#bgRect, #fillRect { pointer-events: none; }
#overlay * { pointer-events: none; }
#overlay .sel { fill: none; stroke: var(--accent); stroke-width: 1.5; }
#overlay .sel.ghost { stroke-opacity: 0.45; stroke-dasharray: 4 3; }
#overlay .hover { fill: none; stroke: rgba(255, 255, 255, 0.55); stroke-width: 1; stroke-dasharray: 3 3; }
#overlay .handle-line { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 2 3; }
#overlay .handle { fill: #fff; stroke: var(--accent-strong); stroke-width: 2; pointer-events: all; cursor: grab; }

.empty {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  max-width: 320px;
  padding: 14px 18px;
  text-align: center;
  background: rgba(21, 24, 30, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  pointer-events: none;
}

.hint {
  padding: 7px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.row { display: flex; align-items: center; gap: 8px; }
.row.top { align-items: flex-start; }
.row > span:first-child { width: 78px; flex: none; color: var(--muted); }
.row.top > span:first-child { padding-top: 4px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row2 label { display: grid; gap: 3px; color: var(--muted); font-size: 12px; }

.slider {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) 58px;
  align-items: center;
  gap: 8px;
}
.slider > span { color: var(--muted); }

.chips { display: flex; gap: 4px; }
.chips button { flex: 1; padding: 3px 0; font-size: 12px; }
.chips button.on, .seg button.on { background: #2f3760; border-color: var(--accent); }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.seg button { padding: 5px 0; font-size: 12px; }

.palette { display: flex; flex-wrap: wrap; gap: 6px; }
.palette .sw { position: relative; }
.palette .sw .x {
  position: absolute; top: -6px; right: -6px;
  width: 16px; height: 16px; padding: 0; line-height: 14px;
  font-size: 11px; border-radius: 50%; display: none;
}
.palette .sw:hover .x { display: block; }
.palette .add { width: 34px; height: 26px; padding: 0; }

.btns { display: flex; gap: 6px; }
.btns button { flex: 1; }

.credit { padding: 12px 14px; }

.toast {
  position: fixed; left: 50%; bottom: 22px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  padding: 9px 14px;
  background: #242a3a;
  border: 1px solid #39415a;
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  z-index: 10;
}
.toast.error { background: #3a1f24; border-color: #6b2f39; }

@media (max-width: 1000px) {
  body { overflow: auto; grid-template-rows: auto auto; }
  .topbar { flex-wrap: wrap; }
  main { grid-template-columns: 1fr; }
  aside.left { max-height: 70vh; border-right: 0; }
  .center { height: 75vh; }
  aside.right { border-left: 0; }
}
