:root {
  --bg: #14111d;
  --panel: #1c1828;
  --line: #2e2942;
  --text: #ece8f6;
  --muted: #9a93b4;
  --accent: #f2c14e;
  --pink: #d63bc4;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, "Segoe UI", sans-serif;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }

.app {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "packs packs" "stage side";
}

.packs {
  grid-area: packs;
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
}
.pack {
  flex: none;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 6px 12px;
  white-space: nowrap;
  color: var(--muted);
  transition: border-color .15s, color .15s, background .15s;
}
.pack:hover { color: var(--text); border-color: #4a4266; }
.pack[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.pack small { opacity: .7; margin-left: 4px; }

.stage {
  grid-area: stage;
  position: relative;
  min-height: 0;
  overflow: hidden;
}
.stage.bg-dark { background: radial-gradient(ellipse at 50% 38%, #2a2340 0%, #14111d 72%); }
.stage.bg-light { background: radial-gradient(ellipse at 50% 38%, #fbf7ef 0%, #e2dccd 80%); }
.stage.bg-grass { background: linear-gradient(#7fb6d6 0 52%, #5c8f3e 52% 100%); }
.stage.bg-check { background: repeating-conic-gradient(#2a2638 0 25%, #211e2d 0 50%) 0 0 / 24px 24px; }
.stage.bg-light .hud, .stage.bg-grass .hud { color: #1d1a26; }

canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }

.hud {
  position: absolute;
  top: 12px;
  left: 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  pointer-events: none;
}
.unit-name { font: 600 15px/1.2 ui-monospace, Consolas, monospace; }
.frame-info { font: 12px/1.2 ui-monospace, Consolas, monospace; opacity: .7; }

.sampler-tag {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #1d1a26;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
}

.bgs { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; }
.swatch {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.25);
  padding: 0;
}
.swatch[aria-pressed="true"] { border-color: var(--accent); }
.swatch.s-dark { background: #2a2340; }
.swatch.s-light { background: #f3eee3; }
.swatch.s-grass { background: linear-gradient(#7fb6d6 0 50%, #5c8f3e 50%); }
.swatch.s-check { background: repeating-conic-gradient(#555 0 25%, #333 0 50%) 0 0 / 8px 8px; }

.controls {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 10px 12px 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: linear-gradient(transparent, rgba(10,8,16,.75));
}
.anims, .tools { display: flex; flex-wrap: wrap; gap: 6px; }
.anim, .tool {
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(20,17,29,.72);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--text);
  backdrop-filter: blur(4px);
}
.anim:hover, .tool:hover { border-color: rgba(255,255,255,.45); }
.anim[aria-pressed="true"] { background: var(--pink); border-color: var(--pink); }
.tool { min-width: 38px; text-align: center; font-variant-numeric: tabular-nums; }

.side {
  grid-area: side;
  border-left: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-title { margin: 12px 14px 8px; font-size: 13px; color: var(--muted); }
.units {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 0 12px;
  align-content: start;
}
.unit {
  position: relative;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #15121f;
  padding: 0;
  overflow: hidden;
}
.unit:hover { border-color: #4a4266; }
.unit[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.unit canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.unit .free {
  position: absolute; left: 4px; bottom: 4px;
  background: var(--accent); color: #1d1a26;
  border-radius: 4px; padding: 0 4px;
  font-size: 10px; font-weight: 700;
}
.more { margin: 10px 14px 14px; color: var(--muted); font-size: 12.5px; }

@media (max-width: 720px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "packs" "stage" "side";
  }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .units { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 64px; overflow-x: auto; overflow-y: hidden; padding-bottom: 8px; }
  .side-title, .more { display: none; }
  .controls { padding: 8px; }
  .anim, .tool { padding: 5px 8px; font-size: 13px; }
}
