@font-face {
  font-family: "Inter";
  src: url("../fonts/Inter.woff") format("woff");
  font-weight: 400 600;
  font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("../fonts/GeistMono.woff") format("woff");
  font-weight: 400 500;
  font-display: swap;
}

:root {
  --bg: #0a0a0c;
  --stage: #050506;
  --surface: #121215;
  --raised: #1b1b20;
  --hover: #24242b;
  --line: #24242a;
  --line-strong: #34343d;
  --text: #ededf2;
  --muted: #8c8c99;
  --faint: #5d5d69;
  --accent: #f8932e;
  --accent-ink: #1a0f02;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  --mono: "SF Mono", ui-monospace, "Geist Mono", Menlo, monospace;
  --r: 9px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 var(--sans);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); font-size: 11.5px; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.grow { flex: 1; }

/* ---------- top bar ---------- */
.top {
  height: 52px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px 0 16px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 600; font-size: 15px; letter-spacing: -0.02em; }
.brand svg { border-radius: 6px; box-shadow: 0 0 0 1px var(--line-strong); }
.top-actions { display: flex; align-items: center; gap: 6px; }
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; }

.btn {
  height: 32px;
  padding: 0 13px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--raised);
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--hover); }
.btn.ghost { background: transparent; }
.btn.ghost:hover, .btn.ghost.on { background: var(--raised); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }

.icon-btn {
  width: 32px; height: 32px;
  display: inline-grid; place-items: center;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted);
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--raised); color: var(--text); }
.icon-btn:disabled { opacity: 0.35; cursor: default; background: transparent; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg.fill { fill: currentColor; stroke: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- layout ---------- */
.work { flex: 1; min-height: 0; display: flex; }
.stage { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--stage); }
.viewport { flex: 1; min-height: 0; position: relative; display: grid; place-items: center; overflow: hidden; touch-action: none; cursor: grab; }
.viewport.dragging { cursor: grabbing; }
.viewport.picking { cursor: crosshair; }
#view { display: block; image-rendering: pixelated; box-shadow: 0 0 0 1px #ffffff12; }
#view.checker { background: repeating-conic-gradient(#1c1c20 0 25%, #131316 0 50%) 0 0 / 16px 16px; }

.pick-note {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: var(--raised); border: 1px solid var(--line-strong); border-radius: 999px; padding: 6px 14px; font-weight: 500;
}
.drop {
  position: absolute; inset: 12px; border: 1.500px dashed var(--accent); border-radius: 14px;
  background: #0a0a0ce6; display: grid; place-items: center; font-size: 17px; font-weight: 600; letter-spacing: -0.02em; pointer-events: none;
}

.transport {
  flex: none; height: 48px; display: flex; align-items: center; gap: 10px; padding: 0 14px 0 8px; border-top: 1px solid var(--line); background: var(--bg);
}
.scrub { flex: 0 1 340px; min-width: 80px; }
.transport .mono { white-space: nowrap; }

.side { flex: none; width: 404px; display: flex; border-left: 1px solid var(--line); background: var(--surface); min-height: 0; }
.rail { flex: none; width: 68px; display: flex; flex-direction: column; gap: 2px; padding: 8px 6px; border-right: 1px solid var(--line); background: var(--bg); overflow-y: auto; scrollbar-width: none; }
.rail button {
  border: 0; background: transparent; color: var(--muted); border-radius: 9px; padding: 8px 0 6px;
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; font-weight: 500; letter-spacing: 0.01em;
  transition: background 0.12s, color 0.12s;
}
.rail button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.rail button:hover { color: var(--text); background: var(--surface); }
.rail button.on { color: var(--text); background: var(--raised); }
.rail button.on svg { color: var(--accent); }

.panel { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.panel-scroll { flex: 1; overflow-y: auto; padding: 4px 16px 24px; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.help { flex: none; min-height: 52px; padding: 10px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; line-height: 1.45; display: flex; align-items: center; }

.tab { display: none; }
.tab.on { display: block; }
.group { padding: 14px 0 6px; border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: 0; }
.group > h3 { margin: 0 0 10px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); }

/* ---------- controls ---------- */
.ctl { margin-bottom: 12px; }
.ctl-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 5px; }
.ctl-head label, .ctl-row label { color: var(--text); font-weight: 450; }
.ctl-head output { font-family: var(--mono); font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ctl.changed .ctl-head output { color: var(--accent); }
.ctl-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 26px; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 18px; margin: 0; background: transparent; cursor: pointer; --p: 0%;
}
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--text) var(--p), var(--line-strong) var(--p)); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--text) var(--p), var(--line-strong) var(--p)); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 1px 4px #000a; }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 1px 4px #000a; }
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.15); }

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  height: 28px; padding: 0 10px; border-radius: 7px; border: 1px solid var(--line-strong); background: transparent; color: var(--muted); font-size: 12px; font-weight: 500; white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.chip:hover { color: var(--text); background: var(--raised); }
.chip.on { background: var(--text); border-color: var(--text); color: #0a0a0c; }
.chip-caption { width: 100%; font-size: 11px; color: var(--faint); margin: 6px 0 1px; }
.chip-caption:first-child { margin-top: 0; }

.switch { width: 36px; height: 21px; border-radius: 11px; border: 0; background: var(--line-strong); position: relative; flex: none; transition: background 0.15s; }
.switch::after { content: ""; position: absolute; top: 2.500px; left: 2.500px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 3px #0008; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(15px); }

.color-row { display: flex; align-items: center; gap: 8px; }
input[type="color"] { -webkit-appearance: none; appearance: none; width: 30px; height: 26px; padding: 0; border: 1px solid var(--line-strong); border-radius: 7px; background: none; cursor: pointer; }
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 4px; }
input[type="color"]::-moz-color-swatch { border: 0; border-radius: 4px; }

.row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.row .btn { flex: 1; }
.note { color: var(--muted); font-size: 12px; margin: 0 0 12px; line-height: 1.45; }
.note.warn { color: var(--accent); margin-top: 14px; }

/* ---------- shape picker ---------- */
.shape-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 5px; }
.shape-btn {
  aspect-ratio: 1; display: grid; place-items: center; padding: 0; border-radius: 8px; border: 1px solid var(--line-strong); background: transparent;
  transition: background 0.12s, border-color 0.12s;
}
.shape-btn canvas { width: 22px; height: 22px; opacity: 0.6; transition: opacity 0.12s; }
.shape-btn:hover { background: var(--raised); }
.shape-btn:hover canvas { opacity: 1; }
.shape-btn.on { background: var(--text); border-color: var(--text); }
.shape-btn.on canvas { opacity: 1; filter: invert(1); }

/* ---------- source card ---------- */
.file-card { display: flex; align-items: center; gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 12px; background: var(--bg); }
.file-card .meta { min-width: 0; flex: 1; }
.file-card .name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-card .sub { color: var(--muted); font-size: 12px; }

/* ---------- looks ---------- */
.looks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.look { border: 1px solid var(--line); background: #000; border-radius: var(--r); padding: 0; overflow: hidden; text-align: left; position: relative; transition: border-color 0.12s, transform 0.12s; }
.look:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.look.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.look canvas { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; image-rendering: pixelated; }
.look span { display: block; padding: 6px 8px 7px; font-size: 11.5px; font-weight: 500; background: var(--surface); border-top: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.look .del { position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: #000b; color: #fff; font-size: 13px; line-height: 1; display: none; }
.look:hover .del { display: block; }

/* ---------- palette ---------- */
.swatches { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.swatch { position: relative; width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--line-strong); overflow: hidden; }
.swatch input { position: absolute; inset: -6px; width: 60px; height: 60px; border: 0; padding: 0; opacity: 0; cursor: pointer; }
.swatch .x { position: absolute; top: 1px; right: 1px; width: 15px; height: 15px; border-radius: 50%; border: 0; background: #000c; color: #fff; font-size: 11px; line-height: 1; padding: 0; display: none; z-index: 2; }
.swatch:hover .x { display: block; }
.swatch.bg::after { content: "backdrop"; position: absolute; left: 0; right: 0; bottom: 0; font-size: 7.500px; text-align: center; background: #000b; color: #fff; padding: 1px 0; pointer-events: none; letter-spacing: 0.02em; }
.swatch.add { display: grid; place-items: center; background: transparent; color: var(--muted); font-size: 20px; border-style: dashed; }
.swatch.add:hover { color: var(--text); background: var(--raised); }

.pal-list { display: flex; flex-direction: column; gap: 4px; }
.pal { display: flex; align-items: center; gap: 10px; padding: 5px 6px; border-radius: 8px; border: 1px solid transparent; background: transparent; text-align: left; }
.pal:hover { background: var(--raised); }
.pal.on { border-color: var(--line-strong); background: var(--raised); }
.pal .strip { display: flex; height: 22px; width: 132px; flex: none; border-radius: 5px; overflow: hidden; box-shadow: 0 0 0 1px var(--line-strong); }
.pal .strip i { flex: 1; }
.pal .pname { font-weight: 500; font-size: 12.500px; }

/* ---------- export ---------- */
.progress { height: 4px; border-radius: 2px; background: var(--line-strong); overflow: hidden; margin: 4px 0 8px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.1s linear; }
.export-status { color: var(--muted); font-size: 12px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }

.toast {
  position: fixed; left: 50%; bottom: 68px; transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  background: var(--raised); border: 1px solid var(--line-strong); padding: 9px 16px; border-radius: 999px; font-weight: 500; box-shadow: 0 8px 30px #000a;
  transition: opacity 0.18s, transform 0.18s; max-width: min(92vw, 520px); text-align: center; z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- small screens ---------- */
@media (max-width: 880px) {
  body { overflow: hidden; }
  .work { flex-direction: column; }
  .stage { flex: none; height: 46dvh; }
  .side { width: 100%; flex: 1; flex-direction: column; border-left: 0; border-top: 1px solid var(--line); }
  .rail { width: 100%; flex-direction: row; padding: 6px 8px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; }
  .rail button { flex: none; width: 62px; }
  .help { display: none; }
  .top { padding: 0 8px 0 12px; }
  .brand span { display: none; }
  #infoLabel { display: none; }
  .panel-scroll { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
}

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