:root {
  --bg: #f6f7fb; --panel: #ffffff; --line: #e6e8ef; --text: #16181d; --muted: #6b7280;
  --brand: #4f46e5; --card: #ffffff; --card-hover: #f0f1f8; --shadow: 0 10px 30px rgba(20, 24, 40, .08);
  --radius: 14px;
}
:root[data-theme="cream"] {
  --bg: #fdfaf0; --panel: #fffdf6; --line: #e9e2cc; --text: #1f2937; --muted: #6b7280;
  --brand: #1a4d3a; --card: #fffdf6; --card-hover: #faf5e4; --shadow: 0 10px 30px rgba(90, 70, 20, .10);
}
:root[data-theme="dark"] {
  --bg: #0f1115; --panel: #161920; --line: #262a34; --text: #eef0f5; --muted: #8b92a5;
  --card: #161920; --card-hover: #1d212b; --shadow: 0 10px 30px rgba(0, 0, 0, .4);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); transition: background .2s, color .2s;
}
button, input, select { font: inherit; color: inherit; }
.app { display: grid; grid-template-columns: 312px 1fr; min-height: 100vh; }
@media (max-width: 860px) { .app { grid-template-columns: 1fr; } .sidebar { position: static !important; height: auto !important; } }

/* ---------- sidebar ---------- */
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 22px 20px 40px;
  background: var(--panel); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.brand h1 { font-size: 17px; margin: 0; letter-spacing: -.01em; }
.brand p { margin: 0; color: var(--muted); font-size: 12px; }
.field { margin-bottom: 16px; }
.field > label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 600; letter-spacing: .02em; }
.seg { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { min-width: 0; border: 0; background: transparent; padding: 7px 6px; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: 12.5px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.presets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.preset { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); cursor: pointer; text-align: left; font-size: 12.5px; color: var(--text); transition: border-color .15s, box-shadow .15s; }
.preset:hover { border-color: var(--muted); }
.preset.on { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); font-weight: 600; }
.preset.custom { cursor: default; color: var(--muted); border-style: dashed; }
.preset.custom.on { color: var(--text); }
.preset .pname { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preset .dots { display: flex; }
.preset .dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--panel); margin-right: -4px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .18); }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
.swatches { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.swatches button { width: 23px; height: 23px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatches button.on { border-color: var(--text); }
.swatches button.auto { width: auto; height: 24px; border-radius: 12px; padding: 0 8px; font-size: 11px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.swatches button.auto.on { border-color: var(--text); color: var(--text); }
.colorpick { width: 24px; height: 24px; border-radius: 50%; overflow: hidden; border: 1px dashed var(--muted); position: relative; }
.colorpick input { position: absolute; inset: -6px; width: 40px; height: 40px; border: 0; padding: 0; cursor: pointer; background: none; }
input[type=range] { width: 100%; accent-color: var(--brand); }
.row { display: flex; gap: 8px; }
.row .seg { flex: 1; }
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); }
.toggle input { accent-color: var(--brand); width: 18px; height: 18px; }
.sidebar .hint { color: var(--muted); font-size: 12px; margin-top: 18px; line-height: 1.6; }
.sidebar .hint code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 11.5px; }

/* ---------- main ---------- */
.main { padding: 22px 28px 60px; }
.topbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.search { flex: 1; min-width: 200px; display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.search input { flex: 1; border: 0; background: transparent; outline: 0; }
.cats { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 20px; }
.cats button { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: 12.5px; color: var(--muted); }
.cats button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.cats button span { opacity: .6; margin-left: 4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 10px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 10px; cursor: pointer; transition: transform .15s, background .15s, box-shadow .15s;
}
.card:hover { background: var(--card-hover); transform: translateY(-2px); box-shadow: var(--shadow); }
.card .pic { width: 112px; height: 112px; display: grid; place-items: center; }
.card .pic svg { width: 100%; height: 100%; }
.card .name { font-size: 12.5px; color: var(--muted); text-align: center; }
.card .name b { display: block; color: var(--text); font-weight: 600; }
.empty { color: var(--muted); padding: 60px; text-align: center; }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 12, 20, .5); backdrop-filter: blur(4px); display: none; place-items: center; z-index: 50; padding: 20px; }
.modal-bg.open { display: grid; }
.modal { width: min(940px, 100%); max-height: 92vh; overflow: auto; background: var(--panel); border-radius: 18px; box-shadow: var(--shadow); display: grid; grid-template-columns: 340px 1fr; }
@media (max-width: 760px) { .modal { grid-template-columns: 1fr; } }
.modal .preview { padding: 28px; display: flex; flex-direction: column; align-items: center; gap: 14px; border-right: 1px solid var(--line); background: var(--bg); border-radius: 18px 0 0 18px; }
.modal .preview .big { width: 260px; height: 260px; display: grid; place-items: center; }
.modal .preview .big svg { width: 100%; height: 100%; }
.modal .preview h2 { margin: 0; font-size: 18px; }
.modal .preview p { margin: 0; color: var(--muted); font-size: 12.5px; }
.modal .preview p.small { font-size: 11.5px; opacity: .8; }
.modal .body { padding: 24px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.modal .head { display: flex; justify-content: space-between; align-items: center; }
.modal .close { border: 0; background: var(--bg); width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 16px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: var(--panel); padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 13px; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn:active { transform: translateY(1px); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: none; padding: 8px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--text); border-color: var(--brand); font-weight: 600; }
pre.code { margin: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font: 11.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-all; max-height: 300px; overflow: auto; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; z-index: 99; font-weight: 600; }
.toast.show { opacity: 1; transform: translateX(-50%); }
