/* ── Variables ───────────────────────────────────────────────────────── */
:root {
  --bg:        #080A0F;
  --surf:      #0F1117;
  --surf-hi:   #171B26;
  --surf-hi2:  #1E2333;
  --border:    rgba(255,255,255,0.09);
  --border-hi: rgba(255,255,255,0.18);
  --accent:    #F0A830;
  --accent-d:  rgba(240,168,48,0.13);
  --accent-d2: rgba(240,168,48,0.24);
  --text:      #E8ECF8;
  --text-muted:#9BA8C4;
  --text-dim:  #5A6480;
  --danger:    #F05252;
  --danger-d:  rgba(240,82,82,0.13);
  --success:   #3DD68C;
  --icon-fg:   #CDD5EE;
  --r:         5px;
  --r-lg:      9px;
  --lib-w:     264px;
  --topbar-h:  52px;
  --shadow:    0 8px 32px rgba(0,0,0,.6);
}

[hidden] { display: none !important; }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Syne', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
input, button, select, textarea { font-family: inherit; font-size: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: inherit; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 4px; }

#app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ── Top bar ─────────────────────────────────────────────────────────── */
#topbar {
  display: flex; align-items: center; gap: 16px;
  height: var(--topbar-h); padding: 0 16px;
  background: var(--surf);
  border-bottom: 1px solid var(--border-hi);
  flex-shrink: 0; z-index: 100;
}
.brand { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }
.brand-name { font-size: 15px; font-weight: 700; letter-spacing: -.3px; color: var(--text); }

.sets-bar {
  display: flex; align-items: center;
  flex: 1; overflow: hidden; min-width: 0;
  border-left: 1px solid var(--border-hi); margin-left: 8px;
}
#sets-nav {
  display: flex; align-items: stretch; overflow-x: auto; flex: 1; min-width: 0;
  scrollbar-width: none;
}
#sets-nav::-webkit-scrollbar { display: none; }
.set-tab {
  display: flex; align-items: center; gap: 6px;
  padding: 0 16px; height: var(--topbar-h);
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
  color: var(--text-muted); border-right: 1px solid var(--border);
  cursor: pointer; user-select: none; flex-shrink: 0;
  transition: color .15s, background .15s;
}
.set-tab:hover { color: var(--text); background: var(--surf-hi); }
.set-tab.active { color: var(--accent); background: var(--accent-d); border-bottom: 2px solid var(--accent); }
.set-tab-count {
  font-size: 10px; font-weight: 700; border-radius: 10px; padding: 1px 6px;
  font-family: 'DM Mono', monospace;
  background: var(--surf-hi2); color: var(--text-muted);
}
.set-tab.active .set-tab-count { background: var(--accent-d2); color: var(--accent); }
.btn-new-tab {
  display: flex; align-items: center; gap: 6px;
  padding: 0 14px; height: var(--topbar-h);
  font-size: 12px; font-weight: 700; white-space: nowrap; flex-shrink: 0;
  color: var(--text-muted); border-left: 1px solid var(--border);
  transition: color .15s, background .15s;
}
.btn-new-tab:hover { color: var(--accent); background: var(--accent-d); }
.topbar-meta { flex-shrink: 0; font-size: 11px; font-family: 'DM Mono', monospace; color: var(--text-muted); }

/* ── Layout ──────────────────────────────────────────────────────────── */
#layout { display: flex; flex: 1; overflow: hidden; }

/* ── Library ─────────────────────────────────────────────────────────── */
#library {
  width: var(--lib-w); flex-shrink: 0;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border-hi);
  background: var(--surf); overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 6px;
  padding: 0 12px; height: 40px;
  border-bottom: 1px solid var(--border-hi); flex-shrink: 0;
}
.panel-title { font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--text); flex: 1; }
.btn-icon-sm {
  display: flex; align-items: center; gap: 5px;
  padding: 4px 9px; font-size: 11px; font-weight: 700; white-space: nowrap;
  color: var(--text-muted); background: var(--surf-hi);
  border: 1px solid var(--border-hi); border-radius: var(--r); cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.btn-icon-sm:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-d); }
.search-wrap {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-bottom: 1px solid var(--border-hi); flex-shrink: 0;
}
.search-ico { color: var(--text-muted); flex-shrink: 0; }
.search-wrap input, #add-search {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 12px;
}
.search-wrap input::placeholder, #add-search::placeholder { color: var(--text-dim); }

#lib-drop-zone { flex: 1; overflow-y: auto; padding: 8px; position: relative; }
#lib-drop-zone.drag-over::after {
  content: 'Drop SVGs here'; position: absolute; inset: 8px;
  background: var(--accent-d2); border: 2px dashed var(--accent);
  border-radius: var(--r-lg); display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: var(--accent); font-size: 13px; pointer-events: none;
}
#lib-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
#lib-empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 32px 16px; text-align: center; color: var(--text-muted);
}
#lib-empty-state p { font-size: 12px; line-height: 1.6; }
#lib-empty-state strong { color: var(--text); }

/* ── SVG icon colour forcing ─────────────────────────────────────────── */
/* SVGs from Illustrator often have black fills — invisible on dark BG.  */
/* We remap everything to --icon-fg via CSS cascade.                     */
.lib-card-svg, .set-card-svg, .add-card-svg, .edit-preview {
  color: var(--icon-fg);
}
.lib-card-svg svg, .set-card-svg svg, .add-card-svg svg, .edit-preview svg {
  fill: var(--icon-fg);
  color: var(--icon-fg);
}
/* Override inline fill/stroke that Illustrator bakes in */
.lib-card-svg svg *,
.set-card-svg svg *,
.add-card-svg svg *,
.edit-preview svg * {
  fill: inherit;
  stroke: none;
}
/* Preserve elements explicitly set to "none" */
.lib-card-svg svg [fill="none"],
.set-card-svg svg [fill="none"],
.add-card-svg svg [fill="none"],
.edit-preview svg [fill="none"] { fill: none !important; }

/* ── Library card ────────────────────────────────────────────────────── */
.lib-card {
  position: relative; aspect-ratio: 1;
  background: var(--surf-hi); border: 1px solid var(--border-hi);
  border-radius: var(--r);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; overflow: hidden; gap: 4px; padding: 6px 4px 4px;
  transition: border-color .15s, background .15s;
}
.lib-card:hover { border-color: rgba(255,255,255,.3); background: var(--surf-hi2); }
.lib-card.in-set { border-color: var(--accent); }
.lib-card.in-set::after {
  content: ''; position: absolute; top: 4px; right: 4px;
  width: 5px; height: 5px; border-radius: 50%; background: var(--accent);
}
.lib-card-svg { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; }
.lib-card-svg svg { width: 100%; height: 100%; }
.lib-card-name {
  font-size: 9px; font-weight: 600; color: var(--text-muted);
  text-align: center; line-height: 1.2;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  width: 100%; padding: 0 2px;
}
.lib-card-actions {
  position: absolute; inset: 0; background: rgba(8,10,15,.9);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  opacity: 0; transition: opacity .15s;
}
.lib-card:hover .lib-card-actions { opacity: 1; }
.lib-card-btn {
  width: 26px; height: 26px; background: var(--surf-hi2);
  border: 1px solid var(--border-hi); border-radius: var(--r);
  display: flex; align-items: center; justify-content: center; color: var(--text-muted);
  transition: color .1s, border-color .1s, background .1s;
}
.lib-card-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-d); }
.lib-card-btn.danger:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-d); }

/* ── Main panel ──────────────────────────────────────────────────────── */
#main-panel { flex: 1; overflow: hidden; display: flex; flex-direction: column; background: var(--bg); }
.center-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  text-align: center; padding: 40px;
}
.welcome-art { margin-bottom: 8px; }
.center-state h2 { font-size: 22px; font-weight: 800; letter-spacing: -.4px; color: var(--text); }
.center-state p { font-size: 13px; color: var(--text-muted); max-width: 380px; line-height: 1.7; }

/* ── Set config bar ──────────────────────────────────────────────────── */
#set-panel { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
#set-config-bar {
  display: flex; align-items: flex-end; gap: 16px;
  padding: 14px 20px; flex-wrap: wrap;
  background: var(--surf); border-bottom: 1px solid var(--border-hi); flex-shrink: 0;
}
.config-fields { display: flex; gap: 10px; flex-wrap: wrap; flex: 1; }
.field-group { display: flex; flex-direction: column; gap: 4px; min-width: 120px; }
.field-group--ver { min-width: 70px; max-width: 80px; }
.field-group label { font-size: 10.5px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
.field-group .hint { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--text-dim); }
.field-group input {
  height: 32px; padding: 0 10px;
  background: var(--surf-hi2); border: 1px solid var(--border-hi);
  border-radius: var(--r); color: var(--text); font-size: 12.5px; outline: none;
  font-family: 'DM Mono', monospace; transition: border-color .15s;
}
.field-group input:focus { border-color: var(--accent); }
.field-group input::placeholder { color: var(--text-dim); }
.config-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ── Set icons area ──────────────────────────────────────────────────── */
#set-icons-area { flex: 1; overflow-y: auto; padding: 16px 20px; }
.set-icons-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px;
}
.count-badge { font-size: 11px; font-family: 'DM Mono', monospace; color: var(--text-muted); font-weight: 600; }
#set-icons-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
#set-icons-empty { padding: 48px 24px; text-align: center; color: var(--text-muted); font-size: 13px; }
#set-icons-empty strong { color: var(--text); }

/* ── Set icon card ───────────────────────────────────────────────────── */
.set-card {
  position: relative; background: var(--surf);
  border: 1px solid var(--border-hi); border-radius: var(--r-lg);
  padding: 12px 8px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  cursor: default; transition: border-color .15s;
}
.set-card:hover { border-color: rgba(255,255,255,.3); }
.set-card-svg { width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; }
.set-card-svg svg { width: 100%; height: 100%; }
.set-card-name { font-size: 10px; font-weight: 600; color: var(--text-muted); text-align: center; line-height: 1.3; word-break: break-all; max-width: 100%; }
.set-card-unicode {
  font-size: 9px; font-family: 'DM Mono', monospace; color: var(--text-dim);
  background: var(--surf-hi2); padding: 1px 5px; border-radius: 3px;
}
.set-card-remove {
  position: absolute; top: 5px; right: 5px;
  width: 20px; height: 20px; background: var(--surf-hi2);
  border: 1px solid var(--border-hi); border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 10px; line-height: 1;
  opacity: 0; transition: opacity .15s, color .1s, border-color .1s;
}
.set-card:hover .set-card-remove { opacity: 1; }
.set-card-remove:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-d); }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 16px; height: 34px;
  background: var(--accent); color: #120900;
  font-weight: 800; font-size: 12.5px; border-radius: var(--r);
  transition: opacity .15s, transform .1s;
}
.btn-primary:hover { opacity: .88; }
.btn-primary:active { transform: scale(.97); }
.btn-secondary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 14px; height: 34px;
  background: var(--surf-hi); color: var(--text);
  font-weight: 700; font-size: 12.5px;
  border: 1px solid var(--border-hi); border-radius: var(--r);
  transition: border-color .15s, color .15s, background .15s;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 14px; height: 34px;
  color: var(--text-muted); font-weight: 600; font-size: 12.5px; border-radius: var(--r);
  transition: color .15s, background .15s;
}
.btn-ghost:hover { color: var(--text); background: var(--surf-hi); }
.btn-danger-ghost {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 12px; height: 34px;
  color: var(--text-muted); font-weight: 600; font-size: 12.5px;
  border: 1px solid var(--border-hi); border-radius: var(--r);
  transition: color .15s, border-color .15s, background .15s;
}
.btn-danger-ghost:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-d); }

/* ── Modals ──────────────────────────────────────────────────────────── */
#modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.75);
  backdrop-filter: blur(4px); z-index: 200;
}
.modal {
  position: fixed; z-index: 210;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: var(--surf); border: 1px solid var(--border-hi);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
  width: 440px; max-width: calc(100vw - 32px);
  display: flex; flex-direction: column; max-height: calc(100vh - 80px);
  animation: modal-in .18s ease;
}
.modal--wide { width: 680px; }
@keyframes modal-in {
  from { opacity: 0; transform: translate(-50%, -52%) scale(.97); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 20px 14px; border-bottom: 1px solid var(--border-hi); flex-shrink: 0;
}
.modal-head h3 { font-size: 14px; font-weight: 800; flex: 1; letter-spacing: -.2px; color: var(--text); }
.modal-close {
  width: 26px; height: 26px; background: var(--surf-hi);
  border: 1px solid var(--border-hi); border-radius: var(--r);
  color: var(--text-muted); font-size: 11px; flex-shrink: 0;
  transition: color .12s, background .12s;
}
.modal-close:hover { color: var(--text); background: var(--surf-hi2); }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 20px 16px; border-top: 1px solid var(--border-hi); flex-shrink: 0;
}
.modal-foot .btn-ghost { margin-right: auto; }
.modal-search {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; border-bottom: 1px solid var(--border-hi); flex-shrink: 0;
}
.modal-search input { flex: 1; background: none; border: none; outline: none; color: var(--text); font-size: 13px; }
.modal-search input::placeholder { color: var(--text-dim); }
.modal-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 6px; padding: 12px 16px; overflow-y: auto; min-height: 200px; max-height: 380px;
}

/* ── Add icons cards ─────────────────────────────────────────────────── */
.add-card {
  position: relative; aspect-ratio: 1;
  background: var(--surf-hi); border: 1.5px solid var(--border-hi); border-radius: var(--r);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 5px; padding: 6px 4px 4px; cursor: pointer; user-select: none;
  transition: border-color .12s, background .12s;
}
.add-card:hover { border-color: rgba(255,255,255,.3); background: var(--surf-hi2); }
.add-card.selected { border-color: var(--accent); background: var(--accent-d); }
.add-card.already-in { opacity: .3; cursor: not-allowed; }
.add-card-svg { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; }
.add-card-svg svg { width: 100%; height: 100%; }
.add-card-name { font-size: 9px; font-weight: 600; color: var(--text-muted); text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; padding: 0 2px; }
.add-card.selected .add-card-name { color: var(--accent); }
.add-card-check {
  position: absolute; top: 4px; right: 4px;
  width: 14px; height: 14px; background: var(--accent); border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .12s;
}
.add-card.selected .add-card-check { opacity: 1; }
.add-card-check svg { color: #120900; }

/* ── Form elements ───────────────────────────────────────────────────── */
.form-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-row label { font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); }
.form-row .hint { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--text-dim); }
.form-row .req { color: var(--accent); }
.form-row input {
  height: 36px; padding: 0 12px;
  background: var(--surf-hi2); border: 1px solid var(--border-hi);
  border-radius: var(--r); color: var(--text); font-size: 13px; outline: none;
  transition: border-color .15s;
}
.form-row input:focus { border-color: var(--accent); }
.form-row input::placeholder { color: var(--text-dim); }
.two-col { flex-direction: row; gap: 10px; }
.two-col > div { flex: 1; display: flex; flex-direction: column; gap: 5px; }
.two-col > div label { font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); }
.two-col > div input {
  height: 36px; padding: 0 12px;
  background: var(--surf-hi2); border: 1px solid var(--border-hi);
  border-radius: var(--r); color: var(--text); font-size: 13px; outline: none;
  transition: border-color .15s;
}
.two-col > div input:focus { border-color: var(--accent); }
.two-col > div input::placeholder { color: var(--text-dim); }

/* Edit icon preview */
.edit-preview {
  width: 80px; height: 80px; background: var(--surf-hi2);
  border: 1px solid var(--border-hi); border-radius: var(--r-lg);
  display: flex; align-items: center; justify-content: center; margin: 0 auto 16px;
}
.edit-preview svg { width: 52px; height: 52px; }

/* ── Progress overlay ────────────────────────────────────────────────── */
#progress-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(8,10,15,.85);
  display: flex; align-items: center; justify-content: center;
}
.progress-card {
  background: var(--surf); border: 1px solid var(--border-hi);
  border-radius: var(--r-lg); padding: 28px 36px; min-width: 300px;
  box-shadow: var(--shadow);
}
.progress-title { font-weight: 800; font-size: 15px; margin-bottom: 14px; color: var(--text); }
.progress-bar-wrap { height: 4px; background: var(--surf-hi2); border-radius: 2px; overflow: hidden; margin-bottom: 10px; }
#progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: 2px; transition: width .3s ease; }
.progress-label { font-size: 11.5px; color: var(--text-muted); font-family: 'DM Mono', monospace; }

/* ── Toasts ──────────────────────────────────────────────────────────── */
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 400; pointer-events: none; }
.toast {
  background: var(--surf-hi); border: 1px solid var(--border-hi); border-radius: var(--r);
  padding: 10px 14px; font-size: 12.5px; font-weight: 600; color: var(--text);
  box-shadow: var(--shadow); pointer-events: auto; animation: toast-in .2s ease;
  display: flex; align-items: center; gap: 8px; min-width: 200px; max-width: 340px;
}
.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--danger); }
.toast-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.toast.success .toast-dot { background: var(--success); }
.toast.error   .toast-dot { background: var(--danger); }
.toast.info    .toast-dot { background: var(--accent); }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }
