/* ===== Design tokens ===== */
:root {
  --bg: #170F29;
  --bg-elevated: #1F1638;
  --surface: #271D47;
  --surface-hover: #322758;
  --border: rgba(243, 238, 255, 0.09);
  --text-primary: #F3EEFF;
  --text-secondary: #A79BC7;
  --text-tertiary: #776992;
  --accent: #FFB627;
  --accent-strong: #FFC857;
  --accent-soft: rgba(255, 182, 39, 0.14);
  --success: #4ADE80;
  --success-soft: rgba(74, 222, 128, 0.12);

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --shadow-card: 0 12px 32px rgba(8, 4, 20, 0.45);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  position: relative;
  min-height: 100vh;
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Ambient glow background, evokes "connecting two worlds" */
.bg-glow {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(560px 420px at 15% -5%, rgba(255, 182, 39, 0.10), transparent 60%),
    radial-gradient(680px 520px at 100% 10%, rgba(139, 92, 246, 0.16), transparent 55%),
    var(--bg);
}

a { color: inherit; }

/* ===== Header ===== */
.site-header {
  padding: 22px 0;
  border-bottom: 1px solid var(--border);
}
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.brand-mark {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 7px;
  border-radius: 6px;
  letter-spacing: 0.02em;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.header-nav {
  display: flex;
  align-items: center;
  gap: 14px;
}
.pill-badge {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
}

/* ===== Buttons ===== */
.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14.5px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-ghost {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-hover); }
.btn-accent {
  background: var(--accent);
  color: #241503;
  box-shadow: 0 6px 18px rgba(255, 182, 39, 0.28);
}
.btn-accent:hover { background: var(--accent-strong); }
.btn-full { width: 100%; margin-top: 6px; }

/* ===== Hero ===== */
.hero {
  padding: 76px 24px 40px;
  text-align: center;
}
.eyebrow {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 18px;
}
.hero-title {
  font-family: var(--font-display);
  font-size: clamp(34px, 5.4vw, 56px);
  line-height: 1.12;
  font-weight: 600;
  margin: 0 0 18px;
  letter-spacing: -0.01em;
}
.hero-title-accent {
  color: var(--accent);
  font-style: italic;
  font-weight: 400;
}
.hero-sub {
  color: var(--text-secondary);
  font-size: 17px;
  max-width: 480px;
  margin: 0 auto 36px;
}

.search-shell {
  position: relative;
  max-width: 560px;
  margin: 0 auto;
}
.search-icon {
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
}
#searchInput {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 16px;
  padding: 18px 20px 18px 52px;
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#searchInput::placeholder { color: var(--text-tertiary); }
#searchInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.hero-stats {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-tertiary);
  margin: 18px 0 0;
}

/* ===== Categories ===== */
.categories-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: 8px 24px 44px;
}
.chip {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip:hover { background: var(--surface-hover); color: var(--text-primary); }
.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== Results ===== */
.results-section { padding-bottom: 100px; }
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 22px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
}

.card-cat {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}
.card-q {
  font-family: var(--font-display);
  font-size: 18px;
  line-height: 1.35;
  font-weight: 500;
  margin: 0 0 16px;
}

.answer-block {
  background: var(--success-soft);
  border: 1px solid rgba(74, 222, 128, 0.3);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 0 0 14px;
}
.card-a-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--success);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 6px;
}
.card-a {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  color: var(--success);
  margin: 0;
}

.card-flip-btn {
  align-self: flex-start;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12.5px;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  display: inline-block;
  margin-top: auto;
}
.card-flip-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Страница отдельного вопроса (build.py) переиспользует те же классы
   для крупного блока ответа, но без сетки карточек */
.card-face.card-back {
  background: linear-gradient(160deg, var(--success-soft), var(--surface));
  border: 1px solid rgba(74, 222, 128, 0.35);
  border-radius: var(--radius-md);
  padding: 22px;
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 60px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  font-size: 16px;
}

/* ===== Footer ===== */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 28px 0 60px;
}
.footer-row p {
  margin: 0 0 6px;
  color: var(--text-tertiary);
  font-size: 13px;
  max-width: 640px;
}
.footer-sub { font-size: 12px; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 4, 20, 0.65);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-overlay[hidden] {
  display: none;
}
.modal {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-card);
}
.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
}
.modal h2 {
  font-family: var(--font-display);
  font-size: 24px;
  margin: 0 0 8px;
}
.modal-hint {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 0 0 22px;
}
.field {
  display: block;
  margin-bottom: 16px;
}
.field span {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-family: var(--font-mono);
}
.field textarea,
.field input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 15px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  outline: none;
  resize: vertical;
}
.field textarea:focus,
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--success);
  color: #0B2416;
  font-weight: 600;
  font-size: 14px;
  padding: 12px 22px;
  border-radius: 999px;
  box-shadow: var(--shadow-card);
  z-index: 60;
  animation: toast-in 0.25s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
  .card-inner, .btn, .toast { transition: none; animation: none; }
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .hero { padding: 52px 20px 32px; }
  .header-row { flex-wrap: wrap; gap: 10px; }
  .results-grid { grid-template-columns: 1fr; }
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
