:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1b1b19;
  --muted: #6c6a64;
  --line: #dedbd3;
  --accent: #1f5fd6;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --ok: #2e7d32;
  --radius: 8px;
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1e1e1c;
    --text: #efede8;
    --muted: #9e9b93;
    --line: #34332f;
    --accent: #6c9cff;
    --accent-text: #0b0b0a;
    --danger: #ff8a80;
    --ok: #81c784;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
.muted { color: var(--muted); }
.top { display: flex; align-items: center; gap: 20px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.top nav { display: flex; gap: 14px; flex: 1; }
.top nav a, .logo { text-decoration: none; color: var(--text); }
.logo { font-weight: 700; }
main { padding: 16px; max-width: 1500px; margin: 0 auto; }
h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 16px; margin: 18px 0 8px; }
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 6px; padding: 6px 12px; cursor: pointer; text-decoration: none; display: inline-block; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); width: 100%; }
textarea { min-height: 70px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 8px 0 3px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 150px; }
.row > button { flex: 0 0 auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.list a.card { text-decoration: none; color: var(--text); display: block; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.tile { position: relative; background: var(--surface); border: 2px solid transparent; border-radius: 6px; overflow: hidden; aspect-ratio: 3/2; display: flex; align-items: center; justify-content: center; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.selected { border-color: var(--accent); }
.tile .status, .tile .flag { position: absolute; left: 4px; bottom: 4px; font-size: 11px; background: rgba(0,0,0,.65); color: #fff; padding: 1px 6px; border-radius: 3px; }
.tile .flag { left: auto; right: 4px; top: 4px; bottom: auto; }
.tile input[type=checkbox] { position: absolute; top: 6px; left: 6px; width: 18px; height: 18px; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); margin: 10px 0; }
.drop.over { border-color: var(--accent); color: var(--accent); }
.progress { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
#toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 6px; display: none; z-index: 20; max-width: calc(100% - 32px); }
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); width: min(520px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.45); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
td, th { text-align: left; padding: 6px; border-bottom: 1px solid var(--line); }

/* Editor */
.editor { display: grid; grid-template-columns: 1fr 340px; gap: 14px; align-items: start; }
@media (max-width: 900px) { .editor { grid-template-columns: 1fr; } }
.stage { position: relative; background: #111; border-radius: var(--radius); min-height: 300px; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; }
.stage canvas { max-width: 100%; max-height: 72vh; display: block; }
.stage .busy { position: absolute; top: 8px; right: 8px; font-size: 12px; color: #fff; background: rgba(0,0,0,.5); padding: 2px 8px; border-radius: 3px; display: none; }
.crop-box { position: absolute; border: 1px solid #fff; box-shadow: 0 0 0 9999px rgba(0,0,0,.5); cursor: move; }
.crop-box .h { position: absolute; width: 14px; height: 14px; background: #fff; border-radius: 2px; }
.crop-box .h.nw { left: -7px; top: -7px; cursor: nwse-resize; }
.crop-box .h.ne { right: -7px; top: -7px; cursor: nesw-resize; }
.crop-box .h.sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.crop-box .h.se { right: -7px; bottom: -7px; cursor: nwse-resize; }
.panel { max-height: calc(100vh - 90px); overflow: auto; }
.panel details { border-bottom: 1px solid var(--line); padding: 6px 0; }
.panel summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.slider { display: grid; grid-template-columns: 96px 1fr 48px; gap: 8px; align-items: center; margin: 4px 0; font-size: 13px; }
.slider input[type=range] { padding: 0; }
.slider output { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.history li { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.history img { width: 64px; height: 44px; object-fit: cover; border-radius: 3px; background: var(--line); }
.history ul { list-style: none; padding: 0; margin: 0; }
.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; border: 1px solid var(--line); margin-right: 4px; }
.chip.ai { border-color: var(--danger); color: var(--danger); }
