/* ==========================================================================
   unohn — Fontshare-style font library
   ========================================================================== */

:root {
  --bg: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f8f8f8;
  --text: #0a0a0a;
  --text-muted: #737373;
  --text-light: #a3a3a3;
  --border: #eaeaea;
  --border-light: #f0f0f0;
  --accent: #0a0a0a;
  --radius: 4px;
  --radius-pill: 100px;
  --font-ui: "Figtree", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --space-xs: .25rem;
  --space-sm: .5rem;
  --space-md: 1rem;
  --space-lg: 1.25rem;
  --space-xl: 1.5rem;
  --space-2xl: 2.5rem;
  --space-3xl: 4rem;
  --max-width: 1280px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
    --bg-card: #0a0a0a;
    --bg-hover: #141414;
    --text: #fafafa;
    --text-muted: #a3a3a3;
    --text-light: #525252;
    --border: #262626;
    --border-light: #1a1a1a;
    --accent: #fafafa;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  font-weight: 400;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   Main
   ========================================================================== */

.main {
  flex: 1;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-xl) var(--space-2xl);
  width: 100%;
}

/* ==========================================================================
   Toolbar — minimal, single row where possible (Fontshare-style)
   ========================================================================== */

.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  margin-bottom: var(--space-xl);
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--space-xl);
}

/* Explicit top spacing so it stays visible when toolbar is sticky */
.toolbar::before {
  content: '';
  display: block;
  height: 2rem;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  align-items: center;
  margin-bottom: var(--space-sm);
}

.toolbar-row:last-child {
  margin-bottom: 0;
}

.search-wrap {
  flex: 0 1 280px;
  min-width: 0;
  position: relative;
}

.sample-text-wrap {
  flex: 1;
  min-width: 200px;
  max-width: 480px;
}

.toolbar-site {
  margin-left: auto;
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
}

.toolbar-site:hover {
  color: var(--text);
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--text-light);
  pointer-events: none;
}

.search-input,
.sample-text-input {
  width: 100%;
  padding: 10px 14px 10px 34px;
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  font-weight: 400;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  transition: border-color .15s ease, background .15s ease;
}

.sample-text-input {
  padding-left: 14px;
}

.search-input::placeholder,
.sample-text-input::placeholder {
  color: var(--text-light);
}

.search-input:hover,
.sample-text-input:hover {
  border-color: var(--text-light);
}

.search-input:focus,
.sample-text-input:focus {
  outline: none;
  border-color: var(--text);
  background: var(--bg);
}

/* Sample presets — Fontshare-style Cities / Excerpts / Names */
.sample-presets-row {
  margin-bottom: var(--space-sm);
}

.sample-presets-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-right: var(--space-sm);
  font-weight: 500;
}

.sample-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  align-items: center;
}

.sample-preset {
  padding: 4px 12px;
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .15s, background .15s;
}

.sample-preset:hover {
  color: var(--text);
  background: var(--border-light);
}

.sample-preset.active {
  color: var(--text);
  background: var(--border);
}

/* Results bar — count, view toggle, sort (Fontshare-style) */
.results-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-xl);
  margin-bottom: var(--space-lg);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
}

.results-count {
  font-weight: 600;
  color: var(--text);
}

.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
}

.view-btn {
  padding: 6px 14px;
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .15s, background .15s;
}

.view-btn:hover {
  color: var(--text);
}

.view-btn.active {
  background: var(--accent);
  color: var(--bg);
}

.sort-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.sort-label {
  color: var(--text-muted);
}

.sort-options {
  display: flex;
  gap: 2px;
}

.sort-btn {
  padding: 4px 12px;
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .15s, background .15s;
}

.sort-btn:hover {
  color: var(--text);
  background: var(--border-light);
}

.sort-btn.active {
  color: var(--text);
  background: var(--border);
}

/* Mobile only: search icon (hidden on desktop) */
.mobile-search-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0;
  margin-left: var(--space-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: color .15s ease, background .15s ease;
}

.mobile-search-toggle:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.mobile-search-toggle:focus {
  outline: none;
  border-color: var(--text);
  color: var(--text);
}

.mobile-search-toggle svg {
  display: block;
}

/* Touch-friendly targets and layout on small screens */
@media (max-width: 768px) {
  .results-count {
    display: none;
  }

  .filter-pill {
    min-height: 44px;
    padding: 10px 16px;
  }
  .view-btn {
    min-height: 44px;
    padding: 10px 16px;
  }
  .sort-btn {
    min-height: 44px;
    padding: 8px 14px;
  }
  .sample-preset {
    min-height: 44px;
    padding: 10px 14px;
  }

  /* Mobile: sticky results bar + search icon; toolbar collapsed until search opened */
  .mobile-search-toggle {
    display: flex;
    margin-left: auto;
  }

  .results-bar .view-toggle {
    display: none;
  }

  .results-bar .sort-wrap {
    display: none;
  }

  body.mobile-search-open .mobile-search-toggle {
    display: none;
  }

  .results-bar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg);
    border-bottom: none;
    padding-top: calc(var(--space-md) + env(safe-area-inset-top, 0px));
    padding-bottom: var(--space-md);
    padding-left: var(--space-lg);
    padding-right: calc(var(--space-lg) + env(safe-area-inset-right, 0px));
    margin-right: calc(-1 * var(--space-xl));
    margin-bottom: var(--space-lg);
  }

  .toolbar {
    position: static;
    overflow: hidden;
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-bottom: 0;
    border-bottom: none;
    transition: max-height 0.25s ease;
  }

  .toolbar::before {
    height: 0;
  }

  body.mobile-search-open .toolbar {
    max-height: 85vh;
    overflow: visible;
    padding-top: var(--space-md);
    padding-bottom: var(--space-xl);
    margin-bottom: var(--space-xl);
    border-bottom: 1px solid var(--border);
  }

  /* Prevent iOS zoom on focus (inputs need font-size >= 16px) */
  .search-input,
  .sample-text-input {
    font-size: 16px;
  }
}

/* Category filters — text-style pills, no heavy fill (Fontshare) */
.category-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.filter-pill {
  padding: 6px 14px;
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .15s, background .15s;
}

.filter-pill:hover {
  color: var(--text);
  background: var(--border-light);
}

.filter-pill.active {
  color: var(--text);
  background: var(--accent);
  color: var(--bg);
}

@media (prefers-color-scheme: dark) {
  .filter-pill.active {
    background: var(--accent);
    color: var(--bg);
  }
}


/* ==========================================================================
   Font grid — airy, minimal cards (Fontshare-style)
   ========================================================================== */

.font-grid {
  display: grid;
  margin-bottom: var(--space-3xl);
}

.font-grid[data-view="grid"] {
  grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
  gap: 1px;
  background: var(--bg);
}

.font-grid[data-view="list"] {
  grid-template-columns: 1fr;
  gap: 0;
  border-top: 1px solid var(--border);
}

.load-more-sentinel {
  grid-column: 1 / -1;
  height: 1px;
  width: 100%;
  pointer-events: none;
  visibility: hidden;
}

.font-card {
  position: relative;
  background: var(--bg-card);
  border: none;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
  transition: background .15s ease;
}

/* Download icon — bottom-right, visible on card hover */
.font-card-download {
  position: absolute;
  bottom: var(--space-md);
  right: var(--space-md);
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .15s ease, color .15s ease, background .15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.font-card:hover .font-card-download {
  opacity: 1;
}

/* Show download on touch devices (no hover) */
@media (hover: none) {
  .font-card .font-card-download {
    opacity: 1;
  }
}

.font-card-download:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.font-card-download:focus {
  outline: none;
  opacity: 1;
}

.font-card-download svg {
  display: block;
  flex-shrink: 0;
}

/* Download format menu — choose TTF, OTF, woff2, woff */
.download-format-menu {
  position: fixed;
  z-index: 20;
  min-width: 180px;
  padding: var(--space-xs) 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
  font-family: var(--font-ui);
  font-size: 0.8125rem;
}

.download-format-option {
  display: block;
  width: 100%;
  padding: 10px 14px;
  text-align: left;
  border: none;
  background: none;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  font-weight: 500;
  transition: background .1s ease;
}

.download-format-option:hover {
  background: var(--bg-hover);
}

.download-format-option:focus {
  outline: none;
  background: var(--bg-hover);
}

.download-format-option-link {
  text-decoration: none;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 2px;
  padding-top: 10px;
}

.download-format-option-link:hover {
  color: var(--text);
}

@media (max-width: 768px) {
  .download-format-option {
    min-height: 44px;
    padding: 12px 14px;
  }
}

.font-grid[data-view="list"] .font-card {
  border-bottom: 1px solid var(--border);
}

.font-grid[data-view="grid"] .font-card:hover {
  background: var(--bg-hover);
}

.font-grid[data-view="list"] .font-card:hover {
  background: var(--bg-hover);
}

.font-grid[data-view="list"] .font-card {
  display: grid;
  grid-template-columns: minmax(220px, min(55%, min-content)) 1fr;
  align-items: start;
  gap: var(--space-xl);
  border-right: none;
}

@media (max-width: 600px) {
  .font-grid[data-view="list"] .font-card {
    grid-template-columns: 1fr;
  }
}

.font-card-preview {
  padding: var(--space-xl) var(--space-lg);
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.font-grid[data-view="list"] .font-card-preview {
  min-height: 220px;
  padding: var(--space-xl) var(--space-lg);
  justify-content: flex-start;
  text-align: left;
}

.font-card-preview-text {
  font-size: 1.875rem;
  line-height: 1.35;
  color: var(--text);
  word-break: break-word;
  max-width: 100%;
}

.font-grid[data-view="list"] .font-card-preview-text {
  font-size: 1.875rem;
  max-width: 100%;
}

.font-card-meta {
  padding: var(--space-sm) var(--space-lg) var(--space-lg);
  border-top: none;
}

.font-grid[data-view="grid"] .font-card-meta {
  padding: var(--space-md) var(--space-lg) var(--space-xl);
}

.font-grid[data-view="list"] .font-card-meta {
  border-left: none;
  padding-left: var(--space-xl);
}

.font-card-name {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.9375rem;
  margin: 0 0 2px;
  color: var(--text);
}

.font-card-category {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  margin: 0;
}

/* ==========================================================================
   Loading & empty state
   ========================================================================== */

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-3xl);
  color: var(--text-muted);
  font-size: 0.9375rem;
  font-weight: 500;
}

.loading.hidden {
  display: none;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin-bottom: var(--space-md);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: var(--space-3xl);
  color: var(--text-muted);
  font-size: 0.9375rem;
}

.empty-state p {
  margin: 0;
}

/* ==========================================================================
   Footer — minimal (Fontshare-style)
   ========================================================================== */

.site-footer {
  padding: var(--space-xl) var(--space-xl) var(--space-2xl);
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg);
  font-weight: 500;
}

.site-footer p {
  margin: 0;
  max-width: var(--max-width);
  margin-left: auto;
  margin-right: auto;
}

.site-footer-link {
  color: inherit;
  text-decoration: none;
}

.site-footer-link:hover {
  text-decoration: none;
}

/* ==========================================================================
   Back to top — bottom right, visible after scroll
   ========================================================================== */

.back-to-top {
  position: fixed;
  bottom: calc(var(--space-xl) + env(safe-area-inset-bottom, 0px));
  right: calc(var(--space-xl) + env(safe-area-inset-right, 0px));
  z-index: 15;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: opacity 0.2s ease, transform 0.2s ease, color 0.15s ease, background 0.15s ease;
  opacity: 0;
  pointer-events: none;
}

.back-to-top[hidden] {
  display: flex !important;
  visibility: hidden;
}

.back-to-top:not([hidden]) {
  opacity: 1;
  pointer-events: auto;
}

.back-to-top:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.back-to-top:focus {
  outline: none;
  border-color: var(--text);
  color: var(--text);
}

.back-to-top svg {
  display: block;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .back-to-top {
    bottom: calc(var(--space-lg) + env(safe-area-inset-bottom, 0px));
    right: calc(var(--space-lg) + env(safe-area-inset-right, 0px));
  }
}
