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

/* ── light tokens ── */
:root {
  --bg:            #ffffff;
  --fg:            #000000;
  --fg-muted:      #6b6b6b;
  --fg-subtle:     #9b9b9b;
  --border:        #e5e5e5;
  --border-mid:    #d0d0d0;
  --surface:       #f7f7f7;
  --surface-hover: #f0f0f0;

  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Fira Code', monospace;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --header-h:  54px;
}

/* ── dark tokens ── */
[data-theme="dark"] {
  --bg:            #0d0d0d;
  --fg:            #f0f0f0;
  --fg-muted:      #888888;
  --fg-subtle:     #555555;
  --border:        #252525;
  --border-mid:    #333333;
  --surface:       #171717;
  --surface-hover: #1f1f1f;
}

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s, color 0.2s;
}

/* ── header ── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
  height: var(--header-h);
  transition: background 0.2s, border-color 0.2s;
}

.nav {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 28px;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 20px;
}

.nav-brand {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--fg);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.nav-brand:hover { color: var(--fg-muted); }

/* ── search ── */
.search-wrap {
  flex: 1;
  max-width: 420px;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  color: var(--fg-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 34px;
  padding: 0 58px 0 30px;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--fg);
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 0.12s, background 0.12s;
}
.search-input::placeholder { color: var(--fg-subtle); }
.search-input:focus { border-color: var(--border-mid); background: var(--bg); }

.search-clear {
  position: absolute;
  right: 38px;
  font-size: 17px;
  line-height: 1;
  color: var(--fg-subtle);
  cursor: pointer;
  display: none;
  user-select: none;
  padding: 2px 4px;
}
.search-clear:hover { color: var(--fg); }
.search-clear.visible { display: block; }

.search-kbd {
  position: absolute;
  right: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-subtle);
  pointer-events: none;
  transition: opacity 0.12s;
}
.search-kbd.hidden { opacity: 0; }

/* ── theme toggle ── */
.theme-toggle {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  background: none;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--fg-muted);
  margin-left: auto;
  flex-shrink: 0;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.theme-toggle:hover { color: var(--fg); border-color: var(--border-mid); background: var(--surface); }

/* ── main ── */
.main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 28px 80px;
}

/* ── category tabs ── */
.category-tabs {
  display: flex;
  align-items: stretch;
  border-bottom: 0.5px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  padding-top: 4px;
  gap: 0;
}
.category-tabs::-webkit-scrollbar { display: none; }

.tab {
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--fg-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 11px 16px;
  border-bottom: 1.5px solid transparent;
  margin-bottom: -0.5px;
  white-space: nowrap;
  transition: color 0.12s, border-color 0.12s;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--fg); border-bottom-color: var(--fg); }

.tab-sep {
  width: 0.5px;
  background: var(--border);
  margin: 10px 6px;
  flex-shrink: 0;
}

.tab-fav { color: var(--fg-muted); }
.tab-fav .tab-star { opacity: 0.5; transition: opacity 0.12s; }
.tab-fav:hover .tab-star,
.tab-fav.active .tab-star { opacity: 1; }
.tab-fav.active { color: var(--fg); }

.tab-fav-count {
  font-family: var(--font-mono);
  font-size: 10px;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 10px;
  padding: 1px 5px;
  color: var(--fg-muted);
}
.tab-fav.active .tab-fav-count { background: var(--fg); color: var(--bg); border-color: var(--fg); }

/* ── filter bar ── */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  min-height: 54px;
}

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

.chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 0.5px solid var(--border);
  background: var(--bg);
  color: var(--fg-muted);
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}
.chip:hover { border-color: var(--border-mid); color: var(--fg); }
.chip.active { background: var(--fg); color: var(--bg); border-color: var(--fg); }

.results-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-subtle);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── grid ── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

/* ── card ── */
.card {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: background 0.12s;
  position: relative;
}
.card:hover { background: var(--surface); }

.card-preview {
  aspect-ratio: 16 / 9;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
}

.card-body {
  padding: 13px 15px 14px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card-cat {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-subtle);
  letter-spacing: 0.03em;
}

.card-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--fg);
  line-height: 1.35;
}

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

.card-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-subtle);
}
.card-tag::before { content: '#'; }

/* ── card actions (star + library) ── */
.card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 8px;
}

.btn-star,
.btn-lib {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.12s;
  background: none;
  border: none;
  opacity: 0;
}

.card:hover .btn-star,
.card:hover .btn-lib { opacity: 1; }

/* always show if active */
.btn-star.is-fav { opacity: 1; color: var(--fg); }
.btn-lib.in-lib  { opacity: 1; color: var(--fg-muted); }

.btn-star {
  width: 26px;
  justify-content: center;
  color: var(--fg-subtle);
}
.btn-star:hover { color: var(--fg); background: var(--surface-hover); }
.btn-star.is-fav:hover { color: var(--fg-muted); }

.btn-lib {
  padding: 0 9px;
  font-size: 12px;
  color: var(--fg-muted);
  border: 0.5px solid var(--border);
}
.btn-lib:hover { color: var(--fg); border-color: var(--border-mid); background: var(--surface-hover); }
.btn-lib.in-lib { color: var(--fg-subtle); }

/* ── preview: images ── */
.preview-img {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  background: repeating-linear-gradient(
    -45deg,
    var(--surface) 0, var(--surface) 5px,
    var(--surface-hover) 5px, var(--surface-hover) 10px
  );
}

/* ── preview: videos ── */
.preview-vid {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  background: var(--surface);
}

/* ── preview: audio ── */
.preview-aud {
  width: 100%; height: 100%;
  display: flex; align-items: center;
  justify-content: center;
  gap: 2px; padding: 12px 18px;
  background: var(--surface);
}
.wave-bar {
  flex: 1; max-width: 3px;
  border-radius: 2px;
  background: var(--border-mid);
}

/* ── preview: palettes ── */
.preview-pal { width: 100%; height: 100%; display: flex; }
.pal-swatch { flex: 1; height: 100%; }

/* ── preview: fonts ── */
.preview-fnt {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); padding: 10px;
}
.fnt-sample {
  font-size: 46px; font-weight: 600;
  color: var(--fg); letter-spacing: -0.03em;
  line-height: 1; user-select: none;
}
.fnt-sample.mono {
  font-family: var(--font-mono);
  font-size: 30px;
}

/* ── preview: templates ── */
.preview-tpl {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); padding: 12px;
}
.tpl-doc {
  width: 58%; height: 86%;
  background: var(--bg);
  border: 0.5px solid var(--border-mid);
  border-radius: 3px;
  padding: 9px 10px;
  display: flex; flex-direction: column; gap: 5px;
  box-shadow: 2px 3px 10px rgba(0,0,0,0.06);
}
.tpl-line { height: 3px; border-radius: 2px; background: var(--border); }
.tpl-line.dark { background: var(--fg-muted); height: 4px; }
.tpl-gap { flex: 1; max-height: 6px; }

/* ── preview: ui kits ── */
.preview-ui {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface);
}

/* ── empty state ── */
.empty {
  grid-column: 1 / -1;
  display: flex; flex-direction: column;
  align-items: center; gap: 8px;
  padding: 80px 24px;
  background: var(--bg);
}
.empty-title { font-size: 14px; font-weight: 500; color: var(--fg); }
.empty-sub   { font-size: 13px; color: var(--fg-muted); }

/* ── modal backdrop ── */
.modal-backdrop {
  position: fixed; inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: fade-in 0.15s ease;
}
[data-theme="dark"] .modal-backdrop { background: rgba(0,0,0,0.65); }
.modal-backdrop[hidden] { display: none; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── modal panel ── */
.modal-panel {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  position: relative;
  outline: none;
  animation: slide-up 0.18s ease;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
[data-theme="dark"] .modal-panel { box-shadow: 0 20px 60px rgba(0,0,0,0.5); }

/* ── modal close ── */
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--fg-muted);
  z-index: 10;
  transition: all 0.12s;
}
.modal-close:hover { color: var(--fg); border-color: var(--border-mid); }

/* ── modal preview ── */
.modal-preview {
  width: 100%;
  min-height: 240px;
  border-bottom: 0.5px solid var(--border);
  overflow: hidden;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.mprev-img {
  width: 100%; height: 240px;
  display: grid; place-items: center;
  background: repeating-linear-gradient(
    -45deg,
    var(--surface) 0, var(--surface) 5px,
    var(--surface-hover) 5px, var(--surface-hover) 10px
  );
}

.mprev-vid {
  width: 100%; height: 240px;
  display: grid; place-items: center;
  background: var(--surface);
}

.mprev-aud {
  width: 100%; height: 240px;
  display: flex; align-items: center;
  justify-content: center; gap: 2px;
  padding: 20px 32px; background: var(--surface);
}

.mprev-pal {
  width: 100%;
}
.mprev-pal-strip {
  display: flex;
  height: 140px;
}
.mprev-pal-swatch { flex: 1; }
.mprev-pal-codes {
  display: flex;
  border-top: 0.5px solid var(--border);
  background: var(--bg);
}
.mprev-pal-code {
  flex: 1;
  padding: 10px 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-muted);
  text-align: center;
  border-right: 0.5px solid var(--border);
}
.mprev-pal-code:last-child { border-right: none; }

.mprev-fnt {
  width: 100%; height: 240px;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px;
  background: var(--surface); padding: 24px;
}
.mprev-fnt-sample {
  font-size: 72px; font-weight: 600;
  color: var(--fg); letter-spacing: -0.04em;
  line-height: 1; user-select: none;
}
.mprev-fnt-sample.mono {
  font-family: var(--font-mono);
  font-size: 48px;
}
.mprev-fnt-label {
  font-size: 12px; color: var(--fg-subtle);
  font-family: var(--font-mono);
}

.mprev-tpl {
  width: 100%; height: 240px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); padding: 20px;
}
.mprev-tpl-doc {
  width: 55%; height: 90%;
  background: var(--bg);
  border: 0.5px solid var(--border-mid);
  border-radius: 3px;
  padding: 14px 14px;
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: 3px 4px 16px rgba(0,0,0,0.08);
}

.mprev-ui {
  width: 100%; height: 240px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface);
}

/* ── modal body ── */
.modal-body {
  padding: 20px 22px 22px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.modal-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-cat {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-subtle);
  letter-spacing: 0.04em;
}

.modal-title {
  font-size: 18px;
  font-weight: 500;
  color: var(--fg);
  line-height: 1.3;
}

.modal-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.modal-tag {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg-subtle);
}

/* ── modal actions ── */
.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-modal-star {
  display: flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 14px;
  font-size: 13px; color: var(--fg-muted);
  background: none;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.12s;
  flex-shrink: 0;
}
.btn-modal-star:hover { color: var(--fg); border-color: var(--border-mid); background: var(--surface); }
.btn-modal-star.is-fav {
  color: var(--fg);
  border-color: var(--fg);
  background: var(--surface);
}
.btn-modal-star.is-fav .modal-star-icon { fill: currentColor; }

.btn-modal-lib {
  display: flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 16px;
  font-size: 13px; color: var(--fg);
  background: var(--fg);
  border: 0.5px solid var(--fg);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.12s;
  flex: 1;
  justify-content: center;
}
.btn-modal-lib svg { color: var(--bg); }
.btn-modal-lib span { color: var(--bg); }
.btn-modal-lib:hover { opacity: 0.85; }
.btn-modal-lib.in-lib {
  background: var(--surface);
  border-color: var(--border);
  color: var(--fg-muted);
}
.btn-modal-lib.in-lib svg { color: var(--fg-muted); }
.btn-modal-lib.in-lib span { color: var(--fg-muted); }

/* ── toast ── */
.toast {
  position: fixed;
  bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--fg);
  color: var(--bg);
  font-size: 13px;
  padding: 9px 18px;
  border-radius: 20px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
  z-index: 300;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── responsive ── */
@media (max-width: 768px) {
  .nav { padding: 0 16px; gap: 12px; }
  .main { padding: 0 16px 60px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .filter-bar { flex-direction: column; align-items: flex-start; gap: 10px; }
  .results-meta { align-self: flex-end; }
  .btn-star, .btn-lib { opacity: 1; }
}

@media (max-width: 480px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .search-wrap { max-width: 100%; }
  .modal-panel { max-width: 100%; }
  .mprev-fnt-sample { font-size: 52px; }
}
