/* ---------- Design tokens ---------- */
:root {
  --bg: #f7f8fc;
  --surface: #ffffff;
  --surface-2: #f1f3fa;
  --text: #1a1d2e;
  --text-muted: #5a6079;
  --text-subtle: #8a90a8;
  --border: #e3e6f1;
  --accent: #5b4df0;
  --accent-hover: #4a3de0;
  --accent-soft: #ece9ff;
  --success: #14b88a;
  --danger: #e04b5a;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(27, 31, 59, 0.05);
  --shadow-md: 0 6px 20px rgba(27, 31, 59, 0.08);
  --shadow-lg: 0 20px 40px rgba(27, 31, 59, 0.12);
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --transition: 180ms ease;
  --max-w: 960px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1120;
    --surface: #171a2e;
    --surface-2: #1e2138;
    --text: #f1f2fa;
    --text-muted: #aeb3cc;
    --text-subtle: #7a8099;
    --border: #282c46;
    --accent: #8c80ff;
    --accent-hover: #a097ff;
    --accent-soft: #2a2756;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.45);
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 15% -5%, rgba(91, 77, 240, 0.10), transparent 40%),
    radial-gradient(circle at 90% 0%, rgba(20, 184, 138, 0.08), transparent 40%);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01", "ss03";
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: var(--accent-hover); text-decoration: underline; }

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

/* ---------- Header ---------- */
.site-header {
  padding: 28px 24px 10px;
  text-align: center;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.4rem;
  color: var(--text);
  letter-spacing: -0.02em;
}
.brand:hover { text-decoration: none; color: var(--text); }

.brand-mark {
  display: inline-block;
  font-size: 1.4rem;
  transform: translateY(-1px);
}

.brand-tagline {
  margin: 6px 0 0;
  color: var(--text-subtle);
  font-size: 0.95rem;
  letter-spacing: -0.005em;
}

/* ---------- Layout ---------- */
.container {
  flex: 1;
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* ---------- Hero / search ---------- */
.hero {
  margin: 20px auto 28px;
  text-align: center;
}

.hero h1 {
  font-weight: 700;
  font-size: clamp(1.9rem, 4.8vw, 2.75rem);
  letter-spacing: -0.025em;
  margin: 0 0 22px;
  color: var(--text);
}

.hero h1 .hero-word {
  color: var(--accent);
}

.search-form {
  display: flex;
  gap: 10px;
  max-width: 580px;
  margin: 0 auto;
  background: var(--surface);
  padding: 8px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

#word-input {
  flex: 1;
  min-width: 0;
  padding: 14px 16px;
  font-size: 1.05rem;
  font-family: inherit;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  outline: none;
  letter-spacing: -0.01em;
}
#word-input::placeholder {
  color: var(--text-subtle);
  font-weight: 400;
}
#word-input:focus { background: var(--surface-2); }

#search-button {
  appearance: none;
  border: none;
  cursor: pointer;
  padding: 12px 22px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: var(--accent);
  border-radius: var(--radius-md);
  transition: background var(--transition), transform var(--transition);
  white-space: nowrap;
  letter-spacing: -0.005em;
}
#search-button:hover { background: var(--accent-hover); }
#search-button:active { transform: scale(0.98); }
#search-button:disabled { opacity: 0.6; cursor: not-allowed; }

.search-help {
  color: var(--text-subtle);
  font-size: 0.87rem;
  margin: 14px 0 0;
}

/* ---------- Filter bar ---------- */
.filters {
  margin: 22px auto 0;
  max-width: 820px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  text-align: left;
}

.filter-field label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-left: 4px;
}

.filter-select {
  appearance: none;
  -webkit-appearance: none;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 36px 10px 14px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235a6079' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.filter-select:hover {
  border-color: var(--accent);
}
.filter-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- Results ---------- */
.results-section { margin-top: 18px; }

.status {
  text-align: center;
  color: var(--text-muted);
  padding: 10px 6px;
  min-height: 1.5em;
  font-size: 0.95rem;
}
.status.error { color: var(--danger); }

.results-group {
  margin-top: 22px;
}

.results-group + .results-group { margin-top: 26px; }

.group-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 4px 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.group-count {
  font-weight: 500;
  color: var(--text-subtle);
  letter-spacing: 0.02em;
  text-transform: none;
  font-size: 0.85rem;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.rhyme-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 14px 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 1rem;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition),
    border-color var(--transition), background var(--transition);
  word-break: break-word;
  letter-spacing: -0.005em;
}
.rhyme-tile.popular { font-weight: 600; }
.rhyme-tile:hover {
  text-decoration: none;
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  background: var(--accent-soft);
  color: var(--accent);
}
.rhyme-tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Loading skeleton */
.skeleton {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.skeleton-tile {
  height: 48px;
  border-radius: var(--radius-md);
  background: linear-gradient(90deg,
    var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Word detail ---------- */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 18px;
  font-weight: 500;
}
.back-link:hover { color: var(--accent); text-decoration: none; }

.word-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow-md);
}

.word-head {
  border-bottom: 1px solid var(--border);
  padding-bottom: 18px;
  margin-bottom: 22px;
}

.word-title {
  font-size: clamp(2.2rem, 6.5vw, 3.2rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0;
  color: var(--text);
  text-transform: lowercase;
}

.word-phonetic {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: -0.005em;
}

.word-audio-wrap { margin-top: 12px; }

.audio-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 14px;
  font-family: inherit;
  font-weight: 500;
  font-size: 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.audio-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.definitions {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.part-of-speech {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.def-list {
  margin: 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.def-list li { color: var(--text); line-height: 1.6; }

.def-example {
  display: block;
  margin-top: 6px;
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.95rem;
}

.def-synonyms {
  display: block;
  margin-top: 6px;
  color: var(--text-subtle);
  font-size: 0.88rem;
}
.def-synonyms strong { color: var(--text-muted); font-weight: 600; }

.also-rhymes { margin-top: 36px; }

.also-rhymes h2 {
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: -0.015em;
  color: var(--text);
  margin: 0 0 14px;
}

/* ---------- Footer ---------- */
.site-footer {
  padding: 18px 20px 24px;
  text-align: center;
  color: var(--text-subtle);
  font-size: 0.85rem;
}
.site-footer a { color: var(--text-muted); }

/* ---------- Responsive ---------- */
@media (max-width: 540px) {
  .site-header { padding-top: 22px; }
  .search-form {
    flex-direction: column;
    border-radius: var(--radius-md);
    padding: 10px;
  }
  #word-input { padding: 12px 14px; font-size: 1rem; }
  #search-button { padding: 12px 18px; width: 100%; }
  .filters {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 16px;
  }
  .filters .filter-field:first-child { grid-column: 1 / -1; }
  .word-card { padding: 24px 20px; border-radius: var(--radius-md); }
  .results-grid, .skeleton {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }
  .rhyme-tile { padding: 12px 10px; font-size: 0.95rem; }
}

@media (max-width: 360px) {
  .results-grid, .skeleton { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Legal pages (terms / privacy) ---------- */
.legal-page {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 34px;
  box-shadow: var(--shadow-md);
  max-width: 760px;
  margin: 0 auto;
}

.legal-page h1 {
  font-size: clamp(1.8rem, 4vw, 2.2rem);
  font-weight: 700;
  letter-spacing: -0.025em;
  margin: 0 0 6px;
  color: var(--text);
}

.legal-page .legal-meta {
  color: var(--text-subtle);
  font-size: 0.9rem;
  margin: 0 0 24px;
}

.legal-page h2 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  margin: 28px 0 8px;
}

.legal-page p,
.legal-page li {
  color: var(--text);
  line-height: 1.65;
  font-size: 0.98rem;
}

.legal-page p { margin: 0 0 12px; }

.legal-page ul {
  margin: 0 0 12px;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.legal-page a { word-break: break-word; }

/* Footer nav */
.footer-nav {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 0 0 10px;
  flex-wrap: wrap;
}
.footer-nav a {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}
.footer-nav a:hover { color: var(--accent); text-decoration: underline; }
.footer-sep {
  color: var(--text-subtle);
  font-size: 0.85rem;
}

@media (max-width: 540px) {
  .legal-page {
    padding: 26px 20px;
    border-radius: var(--radius-md);
  }
}

/* ---------- Ad slot ---------- */
.ad-slot {
  display: block;
  margin: 2rem auto;
  padding: 0.75rem;
  max-width: 970px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  text-align: center;
}
.ad-slot .adsbygoogle {
  min-height: 90px;
  display: block;
}
.ad-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-subtle);
  margin-bottom: 0.5rem;
}
