:root {
  --bg: #1d1b22;
  --panel: #2a2731;
  --panel-2: #36323f;
  --text: #f1eef6;
  --muted: #a49eb1;
  --accent: #ff7a59;
  --danger: #ff5c7a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
#app { display: flex; flex-direction: column; height: 100dvh; padding-top: var(--safe-top); padding-bottom: var(--safe-bottom); }

.bar { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--panel); }
.top { justify-content: space-between; }
.tools { background: var(--bg); padding: 8px 10px 4px; flex-wrap: nowrap; }

button { font: inherit; color: var(--text); background: var(--panel-2); border: 0; border-radius: 10px; padding: 10px 14px; cursor: pointer; }
button:active { transform: scale(.96); }
button.primary { background: var(--accent); color: #1d1b22; font-weight: 600; }
button:disabled { opacity: .35; }
.icon { width: 42px; height: 42px; padding: 9px; display: inline-grid; place-items: center; flex: none; }
.icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon svg .fill { fill: currentColor; stroke: none; }
.icon svg .dim { opacity: .45; }
.icon.accent { background: var(--accent); color: #1d1b22; }
.icon.danger { color: var(--danger); }
.tool.on, #onionBtn.on { background: var(--text); color: var(--bg); }
#onionBtn:not(.on) { background: var(--panel-2); color: var(--muted); }
#playBtn .pause { display: none; }
body.playing #playBtn .play { display: none; }
body.playing #playBtn .pause { display: block; }

.fps { display: flex; align-items: center; gap: 8px; flex: 1; max-width: 260px; color: var(--muted); font-size: 13px; }
.fps input { flex: 1; }
.fps output { width: 2ch; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
input[type=range] { accent-color: var(--accent); min-width: 0; }
#size { flex: 1; }

.swatch { position: relative; width: 42px; height: 42px; flex: none; }
.swatch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }
.swatch span { display: block; width: 100%; height: 100%; border-radius: 50%; border: 3px solid var(--text); pointer-events: none; }

.palette { display: flex; gap: 8px; padding: 2px 10px 8px; overflow-x: auto; scrollbar-width: none; }
.palette button { width: 26px; height: 26px; padding: 0; border-radius: 50%; flex: none; border: 2px solid transparent; }
.palette button.on { border-color: var(--text); }

#stage { flex: 1; min-height: 0; position: relative; display: grid; place-items: center; padding: 8px; overflow: hidden; }
#view { background: #fff; box-shadow: 0 6px 30px rgba(0,0,0,.45); touch-action: none; border-radius: 4px; max-width: 100%; max-height: 100%; }
#frameBadge { position: absolute; top: 14px; right: 16px; background: rgba(0,0,0,.55); padding: 3px 9px; border-radius: 99px; font-size: 12px; font-variant-numeric: tabular-nums; pointer-events: none; }

#toast { position: absolute; left: 50%; bottom: 18px; transform: translate(-50%, 10px); max-width: calc(100% - 32px);
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 12px; font-size: 14px; text-align: center;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(255,122,89,.35); } }
#addBtn.pulse { animation: pulse .7s ease-in-out 3; }

.strip { gap: 8px; padding: 8px 10px; flex-direction: column; align-items: stretch; }
#frames { display: flex; gap: 6px; overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: 2px; scrollbar-width: thin; }
#frames canvas { height: 64px; flex: none; border-radius: 4px; border: 2px solid transparent; background: #fff; scroll-snap-align: center; }
#frames canvas.on { border-color: var(--accent); }
.frameops { display: flex; gap: 6px; justify-content: center; }

dialog { background: var(--panel); color: var(--text); border: 0; border-radius: 16px; width: min(440px, calc(100vw - 32px)); padding: 18px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { font-size: 15px; margin: 14px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
dialog h2:first-child { margin-top: 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.row.end { justify-content: flex-end; margin-top: 18px; }
.field { display: inline-flex; align-items: center; gap: 8px; }
.field.check { margin: 4px 0; color: var(--muted); }
.field input[type=color] { width: 42px; height: 34px; border: 0; background: none; padding: 0; }
select { font: inherit; background: var(--panel-2); color: var(--text); border: 0; border-radius: 8px; padding: 6px 10px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0; }
#preview img, #preview video { max-width: 100%; max-height: 40vh; display: block; margin: 8px auto; border-radius: 6px; background: #fff; }
