:root {
  /* ---- light theme (default) ---- */
  /* Light palette: warm off-white bg, near-black text, low-contrast borders.
     All colors live here so a [data-theme="dark"] block can override tokens
     without touching any component rule. */
  --bg: #f5f2eb;
  --bg-subtle: #eeebe3;
  --surface: #fbfaf7;
  --surface-hover: #eae6dc;
  --border: #ddd8cd;
  --border-strong: #b8b1a3;
  --text: #23201b;
  --text-muted: #5b564d;
  --text-faint: #6f6859;
  --accent: #6b4c1f;
  --accent-hover: #54390f;
  --danger: #9a3a2a;
  --danger-subtle: #f6e3de;
  --focus-ring: #8a6a2f;
  --shadow: 0 12px 32px rgba(58, 48, 30, 0.12);
  --serif: "Cormorant Garamond", "Times New Roman", Times, serif;
  --sans: "Inter", "Helvetica Neue", Arial, sans-serif;
  --radius: 12px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* The hidden attribute must always win over any display value (e.g. the
   status banner uses display:flex, which would otherwise force it visible). */
[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-weight: 300;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* --- header --- */
.site-head {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 2.5rem;
  border-bottom: 1px solid var(--border);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
  text-decoration: none;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.3rem;
  letter-spacing: 0.01em;
}

.wordmark-icon {
  color: var(--text-faint);
  font-size: 1.4rem;
  line-height: 1;
  transition: transform 0.5s var(--ease);
}

.wordmark:hover .wordmark-icon {
  transform: rotate(18deg);
}

.nav-links {
  display: flex;
  gap: 1.75rem;
}

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: color 0.25s ease;
  cursor: pointer;
  background: none;
  border: none;
}

.nav-link:hover,
.nav-link.active {
  color: var(--text);
}

.stage {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* --- hero --- */
.hero {
  min-height: 62vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding-top: 3rem;
  transition: min-height 0.6s var(--ease), padding 0.6s var(--ease);
}

.hero.compact {
  min-height: 30vh;
  padding-top: 2.5rem;
}

.hero-title {
  font-family: var(--serif);
  font-size: clamp(2.4rem, 6vw, 4rem);
  font-weight: 400;
  line-height: 1.1;
  letter-spacing: -0.01em;
  color: var(--text);
  text-align: center;
}

.subtag {
  margin-top: 1.1rem;
  color: var(--text-muted);
  font-size: clamp(0.95rem, 1.8vw, 1.1rem);
  font-family: var(--serif);
  letter-spacing: 0.01em;
  text-align: center;
}

/* --- search --- */
.search-wrap {
  position: relative;
  margin-top: 2.8rem;
  width: 100%;
  max-width: 640px;
}

.search-frame {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.95rem 1.15rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.3s ease;
}

.search-frame:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.search-icon {
  color: var(--text-faint);
  flex-shrink: 0;
  transition: color 0.3s ease;
}

.search-frame:focus-within .search-icon {
  color: var(--text);
}

.search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--serif);
  font-size: 1.3rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  caret-color: var(--text);
}

.search-input::placeholder {
  color: var(--text-faint);
  opacity: 0.9;
}

.search-input:disabled {
  color: var(--text-faint);
  cursor: not-allowed;
}

.search-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: var(--bg-subtle);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease;
  flex-shrink: 0;
}

.search-clear:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.search-clear:disabled {
  color: var(--text-faint);
  cursor: not-allowed;
  opacity: 0.6;
}

/* subtle inline "fetching suggestions" indicator — absolute so it never
   shifts the layout */
.suggest-status {
  position: absolute;
  right: 3.1rem;
  color: var(--text-faint);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  animation: pulse 1.1s ease-in-out infinite;
}

/* --- suggestion dropdown --- */
.suggest {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  z-index: 30;
  animation: fade-slide 0.15s var(--ease);
  box-shadow: var(--shadow);
}

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

.suggest-item {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.8rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s ease;
}

.suggest-item:last-child {
  border-bottom: none;
}

.suggest-item:hover,
.suggest-item.active {
  background: var(--surface-hover);
}

.suggest-name {
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suggest-desc {
  flex: 1;
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suggest-stars {
  color: var(--text-faint);
  font-size: 0.72rem;
  white-space: nowrap;
}

.suggest-empty {
  padding: 1rem 1.1rem;
  color: var(--text-faint);
  font-size: 0.9rem;
}

/* --- hint --- */
.hint {
  margin-top: 1rem;
  color: var(--text-faint);
  font-size: 0.76rem;
  letter-spacing: 0.04em;
}

kbd {
  display: inline-block;
  padding: 0 0.4rem;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: var(--sans);
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* --- status banner (rate limit / quota warning) --- */
.status-banner {
  width: 100%;
  max-width: 640px;
  margin-top: 1.2rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--danger);
  border-radius: 10px;
  background: var(--danger-subtle);
  color: var(--danger);
  font-size: 0.9rem;
  line-height: 1.5;
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.5rem;
}

.status-banner .rate-countdown {
  font-weight: 500;
}

.status-banner.warn {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
}

/* --- example queries --- */
.examples {
  width: 100%;
  max-width: 640px;
  margin-top: 1.6rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.examples-label {
  color: var(--text-faint);
  font-size: 0.8rem;
  letter-spacing: 0.05em;
}

.example-chip {
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--serif);
  font-size: 0.95rem;
  padding: 0.3rem 0.9rem;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.example-chip:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--accent);
}

.example-chip:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* --- results --- */
.results {
  margin-top: 2rem;
  animation: fade 0.35s var(--ease);
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.results-meta {
  color: var(--text-faint);
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}

.result {
  display: block;
  padding: 1.2rem 0.25rem;
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s ease;
}

.result:hover {
  background: var(--surface-hover);
}

.result:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
  border-radius: 6px;
}

.result-top {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

.result-name {
  font-family: var(--serif);
  font-size: 1.4rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: 0.005em;
  transition: color 0.2s ease;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result:hover .result-name {
  color: var(--accent);
}

.result-stars {
  color: var(--text-faint);
  font-size: 0.78rem;
  white-space: nowrap;
}

.result-desc {
  margin-top: 0.3rem;
  color: var(--text-muted);
  font-size: 0.95rem;
  max-width: 70ch;
  /* truncate long descriptions instead of breaking the card layout */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 0.65rem;
  font-size: 0.72rem;
  color: var(--text-faint);
  letter-spacing: 0.03em;
}

.result-meta .lang {
  color: var(--text-muted);
}

.results-more {
  display: flex;
  justify-content: center;
  padding: 2rem 0;
}

.btn-ghost {
  background: none;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.55rem 1.5rem;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.25s ease, border-color 0.25s ease;
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--text-faint);
}

.btn-ghost:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* --- skeleton loading rows --- */
.skeleton-result {
  padding: 1.2rem 0.25rem;
  border-bottom: 1px solid var(--border);
}

.skeleton-line {
  height: 0.9rem;
  border-radius: 6px;
  background: var(--border);
  margin-bottom: 0.7rem;
  animation: skeleton-pulse 1.2s ease-in-out infinite;
}

.skeleton-line:last-child {
  margin-bottom: 0;
}

.skeleton-line.w40 {
  width: 40%;
  height: 1.3rem;
}

.skeleton-line.w90 {
  width: 90%;
}

.skeleton-line.w60 {
  width: 60%;
}

@keyframes skeleton-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

/* --- empty / error states --- */
.empty-state,
.error-state {
  padding: 2.5rem 0.25rem 3rem;
}

.empty-title,
.error-title {
  font-family: var(--serif);
  font-size: 1.4rem;
  color: var(--text);
  margin-bottom: 0.4rem;
}

.empty-hint {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.error-state .btn-ghost {
  margin-top: 1.1rem;
}

/* --- about --- */
.about {
  max-width: 620px;
  margin: 0 auto;
  padding: 4rem 0 3rem;
  animation: fade 0.4s var(--ease);
}

.about h1 {
  font-family: var(--serif);
  font-size: 2.2rem;
  font-weight: 400;
  margin-bottom: 0.4rem;
}

.about p {
  margin-bottom: 1.1rem;
  color: var(--text-muted);
}

.about strong {
  color: var(--text);
  font-weight: 500;
}

.about a {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border-strong);
}

.about a:hover {
  border-bottom-color: var(--text);
}

/* --- footer --- */
.site-foot {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.6rem;
  padding: 1.8rem 1.5rem;
  color: var(--text-faint);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
}

.foot-dot {
  color: var(--text-faint);
}

/* --- states --- */
.loading .search-icon {
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

body.rate-limited .search-frame {
  border-color: var(--border);
  box-shadow: none;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* --- responsive --- */
@media (max-width: 640px) {
  .site-head {
    padding: 1rem 1.25rem;
  }

  .wordmark-text {
    font-size: 1.05rem;
  }

  .nav-links {
    gap: 1rem;
  }

  .search-input {
    font-size: 1.1rem;
  }

  .suggest-desc {
    display: none;
  }
}
