:root {
  --bg: #f3f4f8; --panel: #ffffff; --panel-2: #f7f8fb; --ink: #181c2a; --mute: #6b7285; --line: #e3e6ee; --line-2: #d3d8e4;
  --accent: #5468ff; --accent-2: #7a5cff; --accent-ink: #ffffff; --accent-soft: #eceeff;
  --ok: #17803d; --ok-soft: #e4f6ea; --warn: #b45309; --warn-soft: #fff1dc;
  --check1: #e7e9ef; --check2: #f5f6f9;
  --shadow: 0 1px 2px rgba(20, 26, 50, .06), 0 6px 20px rgba(20, 26, 50, .06);
  --shadow-lg: 0 10px 40px rgba(20, 26, 50, .18);
  --art-sky1: #8da2ff; --art-sky2: #ffd2b0; --art-hill1: #5b6bb5; --art-hill2: #3b4887; --art-sun: #fff3d6;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1118; --panel: #161a24; --panel-2: #1b2030; --ink: #eceff7; --mute: #8b93a8; --line: #262c3b; --line-2: #343c50;
    --accent: #7587ff; --accent-2: #9a82ff; --accent-ink: #0b1020; --accent-soft: #212849;
    --ok: #5fd68a; --ok-soft: #14301f; --warn: #f0a74a; --warn-soft: #36270f;
    --check1: #1c2130; --check2: #161a26;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-lg: 0 14px 50px rgba(0, 0, 0, .6);
    --art-sky1: #3b4a9c; --art-sky2: #b5725a; --art-hill1: #28316b; --art-hill2: #1a2150; --art-sun: #ffe1b0;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
svg { display: block; }
[hidden] { display: none !important; }
.spacer { flex: 1; }
.muted { color: var(--mute); font-size: 12.5px; }

#app { height: 100%; display: grid; grid-template-columns: 360px 1fr; grid-template-rows: auto 1fr; grid-template-areas: "top top" "side main"; }

/* ---------- header ---------- */
#top { grid-area: top; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 36px; height: 36px; flex: none; filter: drop-shadow(0 4px 10px rgba(84, 104, 255, .35)); }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: -.01em; line-height: 1.15; }
.brand p { margin: 0; color: var(--mute); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--mute); font-size: 12px; white-space: nowrap; }
.chip.on { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.chip.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.chip svg { width: 14px; height: 14px; }

/* ---------- sidebar ---------- */
#side { grid-area: side; display: flex; flex-direction: column; min-height: 0; background: var(--bg); border-right: 1px solid var(--line); }
.scroll { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; scrollbar-width: thin; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-h h2, summary h2 { margin: 0; font-size: 14.5px; font-weight: 650; }
.step { width: 22px; height: 22px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; flex: none; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, #drop:focus-visible, select:focus-visible, .switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }
.link { background: none; border: 0; padding: 2px 4px; color: var(--accent); font-size: 12.5px; font-weight: 600; border-radius: 6px; }
.link:hover { background: var(--accent-soft); }

#drop { border: 1.5px dashed var(--line-2); border-radius: 12px; padding: 18px 12px; text-align: center; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; background: var(--panel-2); transition: border-color .15s, background .15s, transform .15s; }
#drop svg { width: 26px; height: 26px; color: var(--accent); margin-bottom: 4px; }
#drop strong { font-size: 13.5px; }
#drop span { color: var(--mute); font-size: 12px; }
#drop:hover, #drop.over { border-color: var(--accent); background: var(--accent-soft); }
#drop.over { transform: scale(1.01); }

#thumbs { list-style: none; margin: 12px 0 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
#thumbs:empty { display: none; }
#thumbs li { position: relative; aspect-ratio: 4/3; border-radius: 9px; overflow: hidden; background: var(--check1); box-shadow: 0 0 0 1px var(--line) inset; }
#thumbs canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
#thumbs .num { position: absolute; left: 5px; bottom: 5px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: rgba(10, 14, 26, .62); color: #fff; font-size: 11px; font-weight: 600; display: grid; place-items: center; backdrop-filter: blur(4px); }
#thumbs .x { position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%; background: rgba(10, 14, 26, .62); color: #fff; font-size: 13px; line-height: 20px; opacity: 0; transition: opacity .12s; backdrop-filter: blur(4px); }
#thumbs li:hover .x, #thumbs .x:focus-visible { opacity: 1; }
#thumbs .skipped { box-shadow: 0 0 0 2px var(--warn); }
#thumbs .skipped .num { background: var(--warn); }
.demos { display: flex; align-items: center; gap: 4px; margin-top: 12px; flex-wrap: wrap; }
.demos .muted { margin-right: 2px; }

.group + .group { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.group h3 { margin: 0 0 8px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--mute); font-weight: 650; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--mute); min-width: 0; }
select { width: 100%; font: inherit; font-size: 13px; color: var(--ink); background: var(--panel-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='m3 4.5 3 3 3-3' fill='none' stroke='%238b93a8' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 9px center; border: 1px solid var(--line); border-radius: 9px; padding: 7px 28px 7px 10px; appearance: none; -webkit-appearance: none; cursor: pointer; }
select:hover { border-color: var(--line-2); }

.switch { display: flex; align-items: center; gap: 10px; font-size: 13px; cursor: pointer; user-select: none; margin-top: 2px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch i { position: relative; flex: none; width: 34px; height: 20px; border-radius: 999px; background: var(--line-2); transition: background .15s; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s; }
.switch input:checked + i { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.switch input:checked + i::after { transform: translateX(14px); }
.switch.sm { font-size: 12.5px; gap: 8px; margin: 0; }
.switch.sm i { width: 30px; height: 18px; }
.switch.sm i::after { width: 14px; height: 14px; }
.switch.sm input:checked + i::after { transform: translateX(12px); }

.logcard { padding: 0; }
.logcard summary { list-style: none; display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; cursor: pointer; }
.logcard summary::-webkit-details-marker { display: none; }
.logcard summary::after { content: ""; width: 8px; height: 8px; border-right: 1.7px solid var(--mute); border-bottom: 1.7px solid var(--mute); transform: rotate(45deg); transition: transform .15s; margin-left: 8px; }
.logcard[open] summary::after { transform: rotate(-135deg); }
.logcard summary .muted { margin-left: auto; }
#log { margin: 0; padding: 0 14px 14px; font: 11.5px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace; color: var(--mute); white-space: pre-wrap; max-height: 240px; overflow-y: auto; }
#log .warn { color: var(--warn); }

#foot { padding: 12px 16px 16px; background: linear-gradient(to top, var(--bg) 70%, transparent); display: flex; flex-direction: column; gap: 8px; }
#status { font-size: 12.5px; color: var(--mute); min-height: 18px; text-align: center; }
button.primary { display: flex; align-items: center; justify-content: center; gap: 9px; width: 100%; padding: 12px 16px; border: 0; border-radius: 12px; color: var(--accent-ink); font-weight: 650; font-size: 14.5px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 6px 18px rgba(84, 104, 255, .35); transition: transform .12s, box-shadow .12s, filter .12s; }
button.primary svg { width: 20px; height: 20px; }
button.primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 9px 24px rgba(84, 104, 255, .45); filter: brightness(1.05); }
button.primary:active:not(:disabled) { transform: none; }
button.primary:disabled { box-shadow: none; filter: grayscale(.4); }
button.primary.sm { width: auto; padding: 9px 16px; font-size: 13.5px; }
@media (prefers-color-scheme: dark) { button.primary { color: #fff; } }

/* ---------- main ---------- */
#main { grid-area: main; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#toolbar { display: flex; align-items: center; gap: 14px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 2px; }
.icon { display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; padding: 5px 10px; border-radius: 8px; font-size: 12.5px; font-weight: 550; color: var(--ink); }
.icon svg { width: 16px; height: 16px; }
.icon:hover { background: var(--panel); box-shadow: 0 0 0 1px var(--line); }
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; background: var(--panel); border: 1px solid var(--line-2); border-radius: 9px; font-size: 13px; font-weight: 600; }
.btn svg { width: 16px; height: 16px; }
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.meta { font-size: 12.5px; color: var(--mute); font-variant-numeric: tabular-nums; }

#view { position: relative; flex: 1; min-height: 0; overflow: hidden; cursor: grab; background: repeating-conic-gradient(var(--check1) 0 25%, var(--check2) 0 50%) 0 0 / 22px 22px; touch-action: none; }
#view.drag { cursor: grabbing; }
#view.empty-state { cursor: default; background: radial-gradient(1200px 500px at 50% 0%, var(--accent-soft), transparent 70%), var(--bg); }
#empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px; padding: 24px; }
#empty .art { width: min(420px, 80%); height: auto; margin-bottom: 14px; filter: drop-shadow(0 14px 24px rgba(20, 26, 60, .18)); }
#empty h2 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
#empty p { margin: 0; max-width: 440px; color: var(--mute); }
.cta { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; justify-content: center; }
#stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; box-shadow: var(--shadow-lg); }
#stage canvas { position: absolute; left: 0; top: 0; }
#stage canvas#overlay { pointer-events: none; }

#busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(14, 17, 24, .28); backdrop-filter: blur(3px); z-index: 5; }
.busy-card { width: min(360px, 86%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: var(--shadow-lg); display: grid; grid-template-columns: auto 1fr; gap: 12px 14px; align-items: center; }
.spin { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.busy-text { display: flex; justify-content: space-between; gap: 10px; min-width: 0; }
.busy-text b { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.busy-text span { color: var(--mute); font-variant-numeric: tabular-nums; font-size: 13px; }
#bar { grid-column: 1 / -1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
#barfill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 3px; transition: width .2s; }
#dropveil { position: absolute; inset: 12px; z-index: 6; border: 2px dashed var(--accent); border-radius: 18px; background: color-mix(in srgb, var(--accent) 14%, transparent); display: grid; place-items: center; font-size: 18px; font-weight: 650; color: var(--accent); pointer-events: none; backdrop-filter: blur(2px); }

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

/* ---------- small screens ---------- */
@media (max-width: 820px) {
  #app { display: flex; flex-direction: column; height: auto; min-height: 100%; }
  #top { flex-wrap: wrap; }
  .brand p { white-space: normal; }
  .chips { justify-content: flex-start; }
  #side { border-right: 0; border-bottom: 1px solid var(--line); }
  .scroll { overflow: visible; }
  #foot { position: sticky; bottom: 0; z-index: 4; }
  #main { min-height: 75vh; }
}
