/* ─── Fonts ─────────────────────────────────────────────────────────── */
@font-face {
  font-family: 'Untitled Sans';
  src: url('fonts/UntitledSans-Regular.otf') format('opentype');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Untitled Sans';
  src: url('fonts/UntitledSans-Medium.otf') format('opentype');
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Untitled Sans';
  src: url('fonts/UntitledSans-Bold.otf') format('opentype');
  font-weight: 700; font-style: normal; font-display: swap;
}

/* ─── Reset & Base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #F8FAFC;
  --surface:      #FFFFFF;
  --border:       #E2E8F0;
  --border-light: #F1F5F9;
  --text:         #0F172A;
  --muted:        #475569;
  --dim:          #94A3B8;
  --header-bg:    #0F172A;
  --header-text:  #F8FAFC;
  --ai:           #2563EB;
  --ai-bg:        #EFF6FF;
  --ai-border:    #BFDBFE;
  --src-collins:  #0F172A;
  --src-bn:       #DC2626;
  --src-bpo:      #2563EB;

  --font-ui: 'Untitled Sans', system-ui, sans-serif;
  --radius:    8px;
  --radius-sm: 4px;
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,.05);
  --shadow:    0 1px 3px 0 rgba(0,0,0,.1), 0 1px 2px -1px rgba(0,0,0,.1);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);

  --sidebar-w: 264px;
  --header-h:  52px;
  --search-h:  73px;
}

[data-theme="dark"] {
  --bg:           #0F172A;
  --surface:      #1E293B;
  --border:       #334155;
  --border-light: #1E293B;
  --text:         #F1F5F9;
  --muted:        #94A3B8;
  --dim:          #475569;
  --header-bg:    #020617;
  --header-text:  #F1F5F9;
  --ai-bg:        #1E3A5F;
  --ai-border:    #1D4ED8;
  --src-collins:  #F1F5F9;
}

html { font-size: 14px; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: var(--font-ui); }
input, select { font-family: var(--font-ui); }


/* ─── Header ────────────────────────────────────────────────────────── */
.site-header {
  height: var(--header-h);
  background: var(--header-bg);
  color: var(--header-text);
  display: flex;
  align-items: center;
  padding: 0 20px 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--header-text);
  letter-spacing: -0.01em;
}

.site-title-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ai);
  flex-shrink: 0;
}

.site-tagline {
  font-size: 11.5px;
  color: rgba(255,255,255,0.45);
  letter-spacing: 0.01em;
  flex: 1;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.theme-toggle {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.5);
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  transition: border-color 0.15s, color 0.15s;
}
.theme-toggle:hover { border-color: rgba(255,255,255,0.4); color: #fff; }

.back-link {
  font-size: 11.5px;
  color: rgba(255,255,255,0.45);
  transition: color 0.15s;
}
.back-link:hover { color: rgba(255,255,255,0.8); }


/* ─── Search Section ────────────────────────────────────────────────── */
.search-section {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px 0;
  position: sticky;
  top: var(--header-h);
  z-index: 90;
}

.search-bar-wrap { padding-bottom: 14px; }

.search-bar {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  max-width: 860px;
  transition: border-color 0.15s, box-shadow 0.15s;
  overflow: hidden;
}
.search-bar:focus-within {
  border-color: var(--ai);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.search-icon {
  padding: 0 10px 0 14px;
  color: var(--dim);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

#nl-search {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 10px 10px 0;
  font-size: 13px;
  color: var(--text);
  outline: none;
  min-width: 0;
}
#nl-search::placeholder { color: var(--dim); }

#search-btn {
  flex-shrink: 0;
  border: none;
  border-left: 1px solid var(--border);
  background: var(--ai);
  color: #fff;
  padding: 0 18px;
  height: 38px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.03em;
  transition: background 0.15s;
}
#search-btn:hover { background: #1D4ED8; }
#search-btn:disabled { background: var(--dim); }

.active-filters-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 2px 12px;
  border-top: 1px solid var(--border-light);
  max-width: 860px;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  background: var(--border-light);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 11.5px;
  color: var(--muted);
  transition: all 0.15s;
}
.filter-chip:hover { background: var(--border); color: var(--text); }
.filter-chip.chip-ai { background: var(--ai-bg); border-color: var(--ai-border); color: var(--ai); }

.clear-all-chips {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11.5px;
  padding: 3px 10px;
  border-radius: 20px;
  transition: all 0.15s;
}
.clear-all-chips:hover { border-color: var(--text); color: var(--text); }


/* ─── App Layout ────────────────────────────────────────────────────── */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--header-h) - var(--search-h));
  align-items: start;
}


/* ─── Filter Sidebar ────────────────────────────────────────────────── */
.filter-sidebar {
  border-right: 1px solid var(--border);
  position: sticky;
  top: calc(var(--header-h) + var(--search-h) + 1px);
  max-height: calc(100vh - var(--header-h) - var(--search-h) - 1px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-inner { padding: 12px 0 32px; }

.filter-section {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-light);
}

.filter-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 9px;
  display: block;
}

/* ─── Filter Pills ── */
.filter-pills { display: flex; flex-wrap: wrap; gap: 4px; }

.pill {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  padding: 3px 10px;
  border-radius: 20px;
  transition: all 0.1s;
  line-height: 1.5;
  white-space: nowrap;
}
.pill:hover { border-color: var(--text); color: var(--text); background: var(--border-light); }
.pill.active { background: var(--text); border-color: var(--text); color: #fff; }

.pill-collins.active { background: var(--src-collins); border-color: var(--src-collins); }
.pill-bn.active      { background: var(--src-bn);      border-color: var(--src-bn);      }
.pill-bpo.active     { background: var(--src-bpo);     border-color: var(--src-bpo);     }

/* ─── Specimen Controls ── */
.specimen-controls { background: var(--border-light); }

#specimen-text {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  outline: none;
  margin-bottom: 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#specimen-text:focus {
  border-color: var(--ai);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.size-control { display: flex; align-items: center; gap: 8px; }
.size-label   { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.size-value   { font-size: 11px; color: var(--muted); flex-shrink: 0; min-width: 24px; text-align: right; }
#font-size    { flex: 1; accent-color: var(--ai); }

/* ─── Foundry Panel ── */
.foundry-panel-section { padding-bottom: 6px; }

.foundry-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.foundry-panel-header .filter-label { margin-bottom: 0; }

.foundry-all-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 20px;
  transition: all 0.1s;
}
.foundry-all-btn:hover { border-color: var(--text); color: var(--text); }
.foundry-all-btn.active { background: var(--text); border-color: var(--text); color: #fff; }

.foundry-list { display: flex; flex-direction: column; }

.foundry-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s;
  gap: 8px;
}
.foundry-item:hover { background: var(--border-light); }
.foundry-item.active { background: var(--text); }

.foundry-item-name {
  font-size: 12px;
  color: var(--text);
  flex: 1;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}
.foundry-item.active .foundry-item-name { color: #fff; }

.foundry-item-meta { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.foundry-item-count { font-size: 10px; color: var(--dim); min-width: 14px; text-align: right; }
.foundry-item.active .foundry-item-count { color: rgba(255,255,255,0.5); }

.foundry-item-link {
  font-size: 10px;
  color: var(--dim);
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.1s, color 0.1s;
  line-height: 1;
}
.foundry-item:hover .foundry-item-link { opacity: 1; }
.foundry-item-link:hover { color: var(--ai); }

/* ─── Vibe Tags ── */
.vibe-container { display: flex; flex-wrap: wrap; gap: 4px; }

.vibe-chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 10.5px;
  padding: 3px 8px;
  border-radius: 20px;
  transition: all 0.1s;
  line-height: 1.4;
}
.vibe-chip:hover { border-color: var(--ai); color: var(--ai); background: var(--ai-bg); }
.vibe-chip.active { background: var(--ai); border-color: var(--ai); color: #fff; }

/* ─── Clear Button ── */
.clear-filters-btn {
  display: block;
  margin: 0 18px 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11.5px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  width: calc(100% - 36px);
}
.clear-filters-btn:hover { border-color: var(--text); color: var(--text); background: var(--border-light); }


/* ─── Results Main ──────────────────────────────────────────────────── */
.results-main { min-width: 0; }

.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: calc(var(--header-h) + var(--search-h) + 1px);
  z-index: 80;
}

.results-count { font-size: 12px; color: var(--muted); }

.toolbar-controls { display: flex; align-items: center; gap: 8px; }

.sort-select {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 11.5px;
  padding: 5px 24px 5px 8px;
  border-radius: var(--radius-sm);
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2394A3B8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  cursor: pointer;
  transition: border-color 0.15s;
}
.sort-select:hover { border-color: var(--muted); }

.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.view-btn {
  background: var(--surface);
  border: none;
  color: var(--dim);
  padding: 5px 8px;
  display: flex;
  align-items: center;
  transition: background 0.1s, color 0.1s;
}
.view-btn:hover { color: var(--text); background: var(--border-light); }
.view-btn.active { background: var(--text); color: #fff; }
.view-btn + .view-btn { border-left: 1px solid var(--border); }


/* ─── Typeface Grid ─────────────────────────────────────────────────── */
.typeface-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  padding: 16px;
}

.typeface-grid.list-view {
  grid-template-columns: 1fr;
  gap: 0;
  padding: 0;
}

/* ─── Card (Grid) ── */
.typeface-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: box-shadow 0.15s, transform 0.15s;
  position: relative;
}
.typeface-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.card-specimen {
  height: 140px;
  padding: 16px 20px;
  overflow: hidden;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border-light);
  position: relative;
  background: var(--bg);
}
.card-specimen::after {
  content: '';
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 40px;
  background: linear-gradient(to right, transparent, var(--bg));
  pointer-events: none;
}

.specimen-inner {
  white-space: nowrap;
  line-height: 1;
  color: var(--text);
  display: block;
}

.card-meta {
  padding: 12px 14px 14px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.card-top-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.card-name    { font-size: 13.5px; font-weight: 500; color: var(--text); line-height: 1.2; }
.card-foundry { font-size: 11px; color: var(--muted); margin-top: 1px; }

.card-link {
  flex-shrink: 0;
  font-size: 13px;
  color: var(--dim);
  padding: 2px 0 2px 6px;
  transition: color 0.15s;
}
.card-link:hover { color: var(--ai); }

.card-tags { display: flex; flex-wrap: wrap; gap: 4px; }

.tag {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 20px;
  letter-spacing: 0.01em;
  line-height: 1.6;
  display: inline-flex;
  align-items: center;
}

.tag-class {
  background: var(--border-light);
  color: var(--muted);
  border: 1px solid var(--border);
}
.tag-style {
  background: transparent;
  color: var(--dim);
  border: 1px solid var(--border-light);
}

.vibe-tag-card {
  border: 1px solid var(--border-light);
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  transition: all 0.1s;
}
.vibe-tag-card:hover { border-color: var(--ai); color: var(--ai); background: var(--ai-bg); }
.vibe-tag-card.tag-vibe-active { background: var(--ai); border-color: var(--ai); color: #fff; }

.tag-desc {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-bottom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 4px;
}

.source-badges { display: flex; gap: 3px; }

.src-badge {
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 2px 5px;
  border-radius: 3px;
  color: #fff;
  line-height: 1.4;
}
.src-collins { background: var(--src-collins); }
.src-bn      { background: var(--src-bn); }
.src-bpo     { background: var(--src-bpo); }

.price-badge { font-size: 10px; color: var(--dim); }

/* AI highlight */
.typeface-card.ai-match { outline: 2px solid var(--ai); outline-offset: -2px; }

.ai-rank {
  position: absolute;
  top: 10px; right: 10px;
  background: var(--ai);
  color: #fff;
  font-size: 9px;
  font-weight: 600;
  width: 20px; height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}


/* ─── List View ─────────────────────────────────────────────────────── */
.typeface-card.list-card {
  flex-direction: row;
  align-items: center;
  border-radius: 0;
  border: none;
  border-bottom: 1px solid var(--border-light);
  box-shadow: none;
  padding: 0 20px;
  height: 54px;
  gap: 0;
  transform: none !important;
}
.typeface-card.list-card:hover { background: var(--border-light); box-shadow: none; }

.list-specimen {
  width: 80px; flex-shrink: 0;
  overflow: hidden; white-space: nowrap;
  color: var(--text); line-height: 1;
  padding-right: 16px;
}
.list-name-block { width: 200px; flex-shrink: 0; padding-right: 16px; }
.list-name { font-size: 13px; font-weight: 500; color: var(--text); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-foundry { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-class { width: 160px; flex-shrink: 0; font-size: 11px; color: var(--muted); padding-right: 16px; white-space: nowrap; }
.list-vibes { flex: 1; font-size: 11px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 16px; }
.list-sources { display: flex; gap: 3px; flex-shrink: 0; padding-right: 16px; }
.list-price { font-size: 10px; color: var(--dim); width: 70px; flex-shrink: 0; text-align: right; padding-right: 16px; }
.list-link { font-size: 13px; color: var(--dim); transition: color 0.15s; flex-shrink: 0; }
.list-link:hover { color: var(--ai); }


/* ─── Empty / Loading ── */
.no-results, .searching-state {
  grid-column: 1 / -1;
  padding: 80px 40px;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
}
.dot-pulse::after { content: '...'; animation: dots 1.2s steps(4, end) infinite; }
@keyframes dots { 0%,20%{content:'.'} 40%{content:'..'} 60%,100%{content:'...'} }


/* ─── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --sidebar-w: 220px; }
  .site-tagline { display: none; }
}

@media (max-width: 700px) {
  .app-layout { grid-template-columns: 1fr; }
  .filter-sidebar { position: static; max-height: none; border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar-inner { padding: 10px 0 16px; }
  .filter-section { padding: 10px 14px; }
  .typeface-grid { grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px; }
  .results-toolbar { position: static; }
  .site-tagline { display: none; }
  .typeface-card.list-card .list-class,
  .typeface-card.list-card .list-vibes { display: none; }
}

@media (max-width: 480px) {
  .typeface-grid { grid-template-columns: 1fr; }
}

/* ─── Scrollbar ─────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--border-light); }
::-webkit-scrollbar-thumb { border-radius: 9999px; background: var(--border); }
::-webkit-scrollbar-thumb:hover { background: var(--dim); }
