/* =========================================================
   NameForge - core styles
   Mobile-first, dark-mode-aware, no external dependencies
   ========================================================= */

:root {
  --bg: #0f1115;
  --bg-elev: #161922;
  --bg-elev-2: #1d2230;
  --border: #262b3a;
  --text: #e7e9ef;
  --text-dim: #b8bdc9;
  --text-mute: #7a7f8e;
  --accent: #8a5cf6;        /* royal violet */
  --accent-2: #f59e0b;      /* warm gold */
  --accent-glow: rgba(138, 92, 246, 0.35);
  --success: #10b981;
  --danger: #ef4444;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 8px 30px rgba(0,0,0,0.35);
  --font-display: "Chakra Petch", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-body: "Saira", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --maxw: 1120px;
}

html[data-theme="light"] {
  --bg: #fafaf7;
  --bg-elev: #ffffff;
  --bg-elev-2: #f3f1ec;
  --border: #e3e0d6;
  --text: #1a1d24;
  --text-dim: #3d4354;
  --text-mute: #5b6175;
  --accent: #6d28d9;
  --accent-2: #b45309;
  --accent-glow: rgba(109, 40, 217, 0.18);
}
  --accent-2: #b45309;
  --accent-glow: rgba(109, 40, 217, 0.18);
  --shadow: 0 8px 30px rgba(20, 20, 40, 0.08);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background-color: var(--bg);
  color: var(--text);
  font-size: 1.0625rem;
  line-height: 1.72;
  letter-spacing: 0.005em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1, "liga" 1;
  background-image:
    radial-gradient(ellipse 90% 60% at 50% 0%, rgba(138, 92, 246, 0.16), transparent 60%),
    radial-gradient(ellipse 55% 45% at 100% 20%, rgba(245, 158, 11, 0.08), transparent 70%),
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.05) 1.4px, transparent 1.6px),
    linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 40px 40px, 40px 40px, 40px 40px;
  background-position: 0 0, 0 0, 0 0, 0 0, 0 0;
  background-attachment: fixed;
  background-repeat: no-repeat, no-repeat, repeat, repeat, repeat;
  transition: background-color 0.2s ease, color 0.2s ease;
}
html[data-theme="light"] body {
  background-image:
    radial-gradient(ellipse 90% 60% at 50% 0%, rgba(109, 40, 217, 0.07), transparent 60%),
    radial-gradient(ellipse 55% 45% at 100% 20%, rgba(180, 83, 9, 0.05), transparent 70%),
    radial-gradient(circle at 50% 50%, rgba(0, 0, 0, 0.06) 1.2px, transparent 1.5px),
    linear-gradient(rgba(0, 0, 0, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.07) 1px, transparent 1px);
}

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

img, svg { max-width: 100%; display: block; }

/* ====== Layout ====== */
.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 20px;
}

/* ====== Scanline / CRT overlay ====== */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.055) 0px,
    rgba(255, 255, 255, 0.055) 1.5px,
    transparent 1.5px,
    transparent 3px
  );
  mix-blend-mode: overlay;
  animation: scanline-drift 9s linear infinite;
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9998;
  background:
    radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.45) 100%);
}
html[data-theme="light"] body::before {
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.075) 0px,
    rgba(0, 0, 0, 0.075) 1.5px,
    transparent 1.5px,
    transparent 3px
  );
  mix-blend-mode: multiply;
}
html[data-theme="light"] body::after {
  background: radial-gradient(ellipse at center, transparent 65%, rgba(0, 0, 0, 0.12) 100%);
}
@keyframes scanline-drift {
  0% { background-position: 0 0; }
  100% { background-position: 0 3px; }
}
@media (prefers-reduced-motion: reduce) {
  body::before { animation: none; }
}

/* ====== Header / Nav ====== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.4rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
  text-shadow: 0 0 18px var(--accent-glow);
}
.brand .mark {
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  filter: drop-shadow(0 3px 10px var(--accent-glow));
  transition: transform 0.25s ease;
}
.brand:hover .mark { transform: rotate(-6deg) scale(1.06); }
.brand .mark svg { width: 100%; height: 100%; display: block; overflow: visible; }
.brand .mark .bf { fill: url(#bg); }
.brand .mark .bglint { fill: var(--accent-2); }
.brand .mark .bstop1 { stop-color: var(--accent); }
.brand .mark .bstop2 { stop-color: var(--accent-2); }
.brand:hover { text-decoration: none; }

.nav-links {
  display: none;
  gap: 22px;
  align-items: center;
}
.nav-links a {
  color: var(--text-dim);
  font-weight: 500;
  font-size: 0.95rem;
}
.nav-links a:hover { color: var(--text); text-decoration: none; }

@media (min-width: 820px) {
  .nav-links { display: flex; }
}

.theme-toggle {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.theme-toggle:hover { border-color: var(--accent); }

/* Mobile menu */
.menu-toggle {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 1rem;
}
.mobile-menu {
  display: none;
  border-top: 1px solid var(--border);
  padding: 10px 0 16px;
}
.mobile-menu.open { display: block; }
.mobile-menu a {
  display: block;
  padding: 10px 0;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.mobile-menu a:last-child { border-bottom: 0; }

@media (min-width: 820px) { .menu-toggle { display: none; } }

/* ====== Hero ====== */
.hero {
  padding: 56px 0 28px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: "";
  position: absolute;
  inset: -10% -10% auto -10%;
  height: 420px;
  background:
    radial-gradient(65% 55% at 30% 30%, var(--accent-glow), transparent 70%),
    radial-gradient(55% 55% at 80% 30%, rgba(245, 158, 11, 0.22), transparent 70%);
  filter: blur(20px);
  z-index: -1;
}
.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 5vw, 3.8rem);
  font-weight: 800;
  margin: 0 0 14px;
  letter-spacing: 0.02em;
  line-height: 1.05;
}
.hero p {
  max-width: 640px;
  margin: 0 auto;
  color: var(--text-dim);
  font-size: 1.1rem;
}

/* ====== Generator card ====== */
.gen-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin: 24px 0;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}
.control-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
}
.chip {
  background: transparent;
  color: var(--text-dim);
  border: 0;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9rem;
  min-height: 36px;
}
.chip:hover { color: var(--text); }
.chip.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-glow);
}
.chip:disabled { opacity: 0.5; cursor: not-allowed; }

.count-control {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  color: var(--text-dim);
  font-size: 0.9rem;
}
.count-control input[type=range] { accent-color: var(--accent); width: 110px; }
.count-control output { color: var(--text); font-weight: 600; min-width: 22px; text-align: right; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 65%, var(--accent-2)));
  color: #fff;
  border: 0;
  padding: 14px 26px;
  border-radius: 12px;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  min-height: 52px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 30px var(--accent-glow), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  transition: transform 0.1s ease, box-shadow 0.25s ease;
  animation: pulse-ready 2.4s ease-in-out infinite;
}
.btn-primary::before {
  content: "\25B6";
  margin-right: 10px;
  font-size: 0.78em;
  display: inline-block;
  transition: transform 0.2s ease;
  vertical-align: 0.05em;
}
.btn-primary:hover {
  box-shadow: 0 14px 50px var(--accent-glow), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
  animation-duration: 1.2s;
}
.btn-primary:hover::before { transform: translateX(3px); }
.btn-primary:active { transform: translateY(0) scale(0.98); }
.btn-primary:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 3px;
}
@keyframes pulse-ready {
  0%, 100% {
    box-shadow: 0 10px 30px var(--accent-glow), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  }
  50% {
    box-shadow: 0 12px 44px var(--accent-glow), inset 0 0 0 1px rgba(255, 255, 255, 0.18);
  }
}
@media (prefers-reduced-motion: reduce) {
  .btn-primary { animation: none; }
}
#character-btn::before { content: "\26A1"; font-size: 0.92em; }

.btn-secondary {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  min-height: 44px;
}
.btn-secondary:hover { border-color: var(--accent); }

.generate-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  margin: 4px 0 18px;
}

/* ====== Result grid ====== */
.results {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 600px) { .results { grid-template-columns: 1fr 1fr; } }
@media (min-width: 980px) { .results { grid-template-columns: 1fr 1fr 1fr; } }

.name-card {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.name-card:hover { border-color: var(--accent); }
.name-card.saved { border-color: var(--accent-2); }
.name-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.name-text {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text);
  word-break: break-word;
  line-height: 1.2;
}
.name-meta {
  color: var(--text-mute);
  font-size: 0.85rem;
  font-style: italic;
  line-height: 1.45;
}
.icon-btn {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 36px;
}
.icon-btn:hover { background: var(--bg-elev); color: var(--text); }
.icon-btn.active { color: var(--accent-2); }
.icon-btn .toast {
  position: absolute;
  background: var(--text);
  color: var(--bg);
  font-size: 0.7rem;
  padding: 3px 7px;
  border-radius: 6px;
  margin-top: -28px;
  margin-left: -8px;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.icon-btn .toast.show { opacity: 1; }

/* ====== Saved list ====== */
.saved-section {
  margin-top: 26px;
  padding: 18px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.saved-section h2 {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  gap: 10px;
}
.saved-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 30px;
}
.saved-pill {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.saved-pill button {
  background: transparent;
  border: 0;
  color: var(--text-mute);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}
.saved-pill button:hover { color: var(--danger); }
.saved-empty { color: var(--text-mute); font-size: 0.9rem; font-style: italic; }

/* ====== Ad slots ====== */
.ad-slot {
  margin: 28px 0;
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-mute);
  font-size: 0.8rem;
  text-align: center;
  background: color-mix(in srgb, var(--bg-elev) 70%, transparent);
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ad-slot::before {
  content: "Ad placement \2014 id: " attr(data-id);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* ====== Article content ====== */
.article {
  margin: 40px 0 0;
  max-width: 760px;
}
.article h2 {
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 36px 0 12px;
}
.article h3 {
  font-size: 1.15rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 22px 0 8px;
  color: var(--text);
}
.article p { color: var(--text-dim); margin: 0 0 16px; line-height: 1.75; }
.article ul, .article ol { color: var(--text-dim); padding-left: 22px; line-height: 1.7; }
.article li { margin: 6px 0; }
.article .example-name {
  font-family: var(--font-display);
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.article strong { color: var(--text); }

.faq details {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 8px 0;
}
.faq summary {
  cursor: pointer;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.95rem;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.faq summary::after {
  content: "+";
  color: var(--text-mute);
  font-weight: 400;
  font-size: 1.2rem;
}
.faq details[open] summary::after { content: "\2212"; }
.faq p { margin: 10px 0 0; }

/* ====== Footer ====== */
.site-footer {
  margin-top: 60px;
  border-top: 1px solid var(--border);
  padding: 28px 0 40px;
  color: var(--text-mute);
  font-size: 0.9rem;
}
.footer-row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: center;
  justify-content: space-between;
}
.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}
.footer-links a { color: var(--text-dim); }
.footer-links a:hover { color: var(--text); }

/* ====== Homepage grid ====== */
.search-bar {
  margin: 18px auto 0;
  max-width: 560px;
}
.search-bar input {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px 18px;
  border-radius: 999px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s ease;
}
.search-bar input:focus { border-color: var(--accent); }

.gen-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin: 24px 0;
}
@media (min-width: 600px) { .gen-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 980px) { .gen-grid { grid-template-columns: 1fr 1fr 1fr 1fr; } }

.gen-tile {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: block;
  color: var(--text);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.gen-tile:hover {
  text-decoration: none;
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}
.gen-tile h3 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--text);
}
.gen-tile p { margin: 0; color: var(--text-mute); font-size: 0.9rem; }
.gen-tile .tag {
  display: inline-block;
  margin-top: 10px;
  font-size: 0.72rem;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}

.section-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 28px 0 8px;
  color: var(--text);
}

/* ====== Character card ====== */
.character-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-top: 18px;
  position: relative;
}
.character-card .name-text {
  font-size: 1.8rem;
  margin-bottom: 8px;
}
.character-card .traits {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.character-card .trait {
  font-size: 0.78rem;
  color: var(--text-dim);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
}
.character-card .backstory {
  color: var(--text-dim);
  font-size: 0.95rem;
  margin-top: 10px;
  line-height: 1.65;
}
.char-actions {
  margin-top: 14px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ====== Utility ====== */
.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;
}
.muted { color: var(--text-mute); }
.center { text-align: center; }
.spacer-sm { height: 12px; }
.spacer-md { height: 24px; }
.cross-links {
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.cross-links h3 { font-family: var(--font-display); font-size: 1.1rem; margin: 0 0 10px; }
.cross-links a {
  display: inline-block;
  margin: 4px 8px 4px 0;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  color: var(--text-dim);
  font-size: 0.85rem;
}
.cross-links a:hover { color: var(--text); border-color: var(--accent); text-decoration: none; }
