:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f0f1f3;
  --border: #e2e4e8;
  --text: #16181d;
  --muted: #6b7079;
  --accent: #2563eb;
  --accent-soft: #dbe6fd;
  --accent-text: #ffffff;
  --tile-bg: #ffffff;
  --tile-hover: #f3f5f9;
  --danger: #b42318;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .06);
  --radius: 10px;
  --icon-color: #000000;
  --checker: repeating-conic-gradient(#e6e7ea 0 25%, #fff 0 50%) 0 0 / 16px 16px;
  color-scheme: light;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #23262e;
    --border: #2e323b;
    --text: #e8eaee;
    --muted: #979ca7;
    --accent: #6d9bff;
    --accent-soft: #1f2d4d;
    --accent-text: #0b1020;
    --tile-bg: #1a1d23;
    --tile-hover: #232833;
    --danger: #ff8a80;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 4px 16px rgb(0 0 0 / .3);
    --checker: repeating-conic-gradient(#2a2d35 0 25%, #1c1f25 0 50%) 0 0 / 16px 16px;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; display: flex; flex-direction: column; }
body.page { display: block; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
code { font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

.banner {
  background: #fff4d6; color: #5c4300; padding: 8px 16px; font-size: 13px; border-bottom: 1px solid #f0d58a;
}
@media (prefers-color-scheme: dark) { .banner { background: #3a2f10; color: #f5dd9b; border-color: #5a4a1a; } }

/* ---------- toolbar ---------- */
.toolbar {
  background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 16px 8px;
  display: flex; flex-direction: column; gap: 8px; position: sticky; top: 0; z-index: 5;
}
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search { flex: 1 1 320px; display: flex; align-items: center; gap: 8px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0 12px; min-width: 0; }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; flex: none; }
.search input { flex: 1; border: 0; background: transparent; padding: 10px 0; font-size: 16px; outline: none; min-width: 0; }
.controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.ctl { display: inline-flex; align-items: center; gap: 6px; }
.lbl { font-size: 12px; color: var(--muted); }
.unit { font-size: 12px; color: var(--muted); }
#color { width: 30px; height: 30px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: none; cursor: pointer; }
#color::-webkit-color-swatch-wrapper { padding: 2px; }
#color::-webkit-color-swatch { border: 0; border-radius: 4px; }
#color-hex { width: 76px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
input[type=text], input[type=number], select {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 5px 7px; height: 30px;
}
input[type=number] { width: 72px; }
#category, #variant { max-width: 220px; }
input[type=range] { width: 90px; accent-color: var(--accent); }
output { font-size: 12px; min-width: 32px; color: var(--muted); font-variant-numeric: tabular-nums; }
.swatches { display: inline-flex; gap: 4px; }
.swatch { width: 20px; height: 20px; border-radius: 5px; border: 1px solid var(--border); cursor: pointer; padding: 0; }
.swatch.active { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon-btn { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2);
  cursor: pointer; line-height: 1; padding: 0; }
.icon-btn:hover { border-color: var(--accent); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: var(--surface-2); padding: 5px 9px; cursor: pointer; font-size: 12px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.count { opacity: .75; }

.providers { gap: 6px; }
.chip { border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 4px 11px; cursor: pointer;
  font-size: 13px; user-select: none; display: inline-flex; gap: 6px; align-items: center; }
.chip .n { font-size: 11px; color: var(--muted); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); }
.chip:not(.on) { opacity: .6; }
.chip:hover { opacity: 1; }
.filters { gap: 14px; }
.status { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ---------- layout ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.grid-wrap { flex: 1; overflow-y: auto; padding: 14px 16px 90px; min-width: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; outline: none; }
.sentinel { height: 1px; }
.empty { text-align: center; color: var(--muted); padding: 60px 16px; }

.tile {
  position: relative; aspect-ratio: 1; border-radius: 8px; background: var(--tile-bg); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; cursor: grab; color: var(--icon-color);
  transition: background .08s;
}
.tile:hover { background: var(--tile-hover); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.tile.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.tile svg { width: 32px; height: 32px; pointer-events: none; }
.tile .badge { position: absolute; left: 4px; bottom: 3px; font-size: 9px; color: var(--muted); letter-spacing: .02em;
  text-transform: uppercase; pointer-events: none; }
.tile .star { position: absolute; right: 4px; top: 2px; font-size: 10px; color: #e0a100; pointer-events: none; }
.tile .name { position: absolute; left: 50%; bottom: calc(100% + 4px); transform: translateX(-50%); white-space: nowrap;
  background: var(--text); color: var(--bg); font-size: 11px; padding: 2px 6px; border-radius: 4px; pointer-events: none;
  opacity: 0; transition: opacity .1s; z-index: 3; }
.tile:hover .name, .tile.sel .name { opacity: 1; }

/* background modes for previews */
.bg-light .tile, .bg-light .preview { background: #fff; }
.bg-dark .tile, .bg-dark .preview { background: #15171c; }
.bg-light .tile:hover { background: #f1f3f7; }
.bg-dark .tile:hover { background: #242833; }
.bg-checker .tile, .bg-checker .preview { background: var(--checker); }
.bg-light .tile .badge { color: #8a8f99; }
.bg-dark .tile .badge { color: #7d828c; }

/* custom stroke width preview: CSS beats presentation attributes */
.custom-stroke .tile svg [stroke-width], .custom-stroke .preview svg [stroke-width],
.custom-stroke .tile svg.stroke, .custom-stroke .preview svg.stroke { stroke-width: var(--sw); }

/* ---------- detail ---------- */
.detail { width: 320px; flex: none; border-left: 1px solid var(--border); background: var(--surface); padding: 18px;
  overflow-y: auto; position: relative; }
.detail .close { position: absolute; right: 12px; top: 12px; font-size: 18px; }
.preview { width: 100%; aspect-ratio: 1; max-height: 260px; border-radius: var(--radius); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; color: var(--icon-color); cursor: grab; background: var(--tile-bg); }
.preview svg { width: 55%; height: 55%; pointer-events: none; }
.preview { position: relative; }
.drag-src { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: grab; }
.drag-hint { text-align: center; font-size: 11px; color: var(--muted); margin: 6px 0 10px; }
.d-name { font-size: 16px; margin: 0 0 2px; word-break: break-all; font-family: ui-monospace, Menlo, monospace; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 10px 0; }
.small-chips .chip { font-size: 12px; padding: 3px 9px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 6px; }
.actions.secondary { margin-top: 0; }
.btn { border: 1px solid var(--border); background: var(--surface-2); border-radius: 7px; padding: 7px 11px; cursor: pointer;
  text-decoration: none; color: var(--text); font-size: 13px; display: inline-flex; align-items: center; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; font-size: 12px; padding: 5px 9px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 7px 0 0 7px; }
.btn-group select { border-radius: 0 7px 7px 0; border-left: 0; height: auto; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 12px 0; }
.tag { font-size: 11px; background: var(--surface-2); border: 1px solid var(--border); padding: 2px 7px; border-radius: 999px;
  cursor: pointer; }
.tag:hover { border-color: var(--accent); }

/* ---------- collection bar ---------- */
.collection-bar { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 12px; padding: 8px 10px;
  display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px); z-index: 8; }
.coll-items { display: flex; gap: 4px; overflow-x: auto; max-width: 40vw; color: var(--icon-color); }
.coll-items button { width: 30px; height: 30px; flex: none; border: 1px solid var(--border); border-radius: 6px;
  background: var(--tile-bg); padding: 4px; cursor: pointer; }
.coll-items svg { width: 100%; height: 100%; pointer-events: none; }
#coll-label { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 6px; z-index: 10; }
.toast { background: var(--text); color: var(--bg); padding: 8px 12px; border-radius: 8px; font-size: 13px;
  box-shadow: var(--shadow); animation: pop .15s ease-out; max-width: 340px; }
.toast.err { background: var(--danger); color: #fff; }
@keyframes pop { from { transform: translateY(6px); opacity: 0; } }

.drag-ghost { position: fixed; left: -1000px; top: -1000px; width: 64px; height: 64px; display: flex;
  align-items: center; justify-content: center; background: var(--surface); border-radius: 10px; }
.drag-ghost svg { width: 44px; height: 44px; }

/* ---------- licenses page ---------- */
.licenses { max-width: 900px; margin: 0 auto; padding: 24px 16px; }
.table-wrap { overflow-x: auto; }
.licenses table { border-collapse: collapse; width: 100%; background: var(--surface); border: 1px solid var(--border); }
.licenses th, .licenses td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }

/* ---------- small screens ---------- */
@media (max-width: 800px) {
  .toolbar { position: static; }
  .controls { gap: 10px; }
  .color-ctl .swatches, #save-swatch { display: none; }
  .detail { position: fixed; left: 0; right: 0; bottom: 0; width: auto; max-height: 72vh; border-left: 0;
    border-top: 1px solid var(--border); box-shadow: var(--shadow); z-index: 9; border-radius: 14px 14px 0 0; }
  .preview { max-height: 160px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
  .status { margin-left: 0; }
  .coll-items { max-width: 30vw; }
}
