/* ============================================
   RITHM - Base Styles
   Global resets, typography, layout primitives,
   buttons, cards, forms, grid, and utility classes.
   ============================================ */

/* ── Resets & Globals ─────────────────────── */

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

html {
  background: var(--bg-primary);
  scroll-behavior: smooth;
  transition: background 0.3s ease;
}

html::after {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.5;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  background: var(--bg-primary);
  min-height: 100vh;
  color: var(--text-primary);
  transition: background 0.3s ease, color 0.3s ease;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-sans);
  font-weight: 600;
  line-height: 1.3;
}

h1 { font-size: 24px; letter-spacing: -0.3px; }
h2 { font-size: 18px; letter-spacing: -0.2px; }
h3 { font-size: 15px; }

::selection {
  background: var(--primary);
  color: #fff;
}

/* ── Layout ──────────────────────────────── */

.container {
  width: 100%;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 1rem;
  padding-right: 1rem;
}

/* Simple responsive grid */
.row {
  display: flex;
  flex-wrap: wrap;
  margin-left: -0.75rem;
  margin-right: -0.75rem;
}

.row > * {
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}

[class*="col-"] {
  width: 100%;
}

@media (min-width: 768px) {
  .col-3 { width: 25%; }
  .col-md-2 { width: 16.6667%; }
  .col-md-4 { width: 33.3333%; }
  .col-md-6 { width: 50%; }
}

/* ── Buttons ──────────────────────────────── */

.btn {
  display: inline-block;
  font-weight: 500;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
  border: none;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  line-height: 1.5;
  font-size: 0.95rem;
  min-height: 36px;
  background: transparent;
  color: var(--text-primary);
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  border-radius: 6px;
}

.btn-lg {
  padding: 0.875rem 1.75rem;
  font-size: 1.05rem;
}

.btn-primary {
  background: var(--color-primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--color-primary-dark);
  box-shadow: var(--shadow-glow);
  color: #ffffff;
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--secondary);
  color: #1a1714;
}

.btn-secondary:hover {
  background: var(--accent-dark);
  box-shadow: 0 2px 8px rgba(212, 197, 160, 0.25);
  color: #1a1714;
}

.btn-success {
  background: var(--color-success);
  color: #ffffff;
}

.btn-success:hover {
  background: var(--color-success-dark);
  box-shadow: 0 2px 8px rgba(34, 197, 94, 0.25);
  color: #ffffff;
}

.btn-warning {
  background: var(--color-warning);
  color: #1a1714;
}

.btn-warning:hover {
  background: var(--color-warning-dark);
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.25);
  color: #1a1714;
}

.btn-info {
  background: var(--color-info);
  color: #ffffff;
}

.btn-info:hover {
  background: var(--color-info);
  filter: brightness(0.9);
  box-shadow: 0 2px 8px rgba(56, 189, 248, 0.25);
  color: #ffffff;
}

.btn-outline-light,
.btn-outline-dark {
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

.btn-outline-light:hover,
.btn-outline-dark:hover {
  background: var(--input-bg);
  border-color: var(--text-muted);
}

.btn-outline-success {
  border: 1px solid var(--success);
  color: var(--success);
}

.btn-outline-success:hover {
  background: var(--surface-success);
  border-color: var(--success);
  color: var(--success);
}

/* ── Forms ────────────────────────────────── */

.form-control {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  min-height: 40px;
  font-family: var(--font-sans);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  appearance: none;
}

.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
}

.form-control::placeholder {
  color: var(--text-muted);
}

.form-group {
  margin-bottom: 1rem;
}

.input-group {
  display: flex;
}

.input-group .form-control {
  flex: 1;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.input-group .btn {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

/* ── Alerts ──────────────────────────────── */

.alert {
  padding: 0.875rem 1rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  position: relative;
  font-size: 0.95rem;
}

.alert-error {
  background: var(--surface-danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: var(--color-danger);
}

.alert-success {
  background: var(--surface-success);
  border: 1px solid rgba(34, 197, 94, 0.2);
  color: var(--color-success);
}

.alert-info {
  background: var(--surface-info);
  border: 1px solid rgba(56, 189, 248, 0.2);
  color: var(--color-info);
}

.alert-warning {
  background: var(--surface-warning);
  border: 1px solid rgba(245, 158, 11, 0.2);
  color: var(--color-warning);
}

.alert-dismissible {
  padding-right: 3rem;
}

.btn-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 1.25rem;
  opacity: 0.7;
  padding: 0.25rem;
  line-height: 1;
}

.btn-close::after {
  content: '\00d7';
}

.btn-close:hover {
  opacity: 1;
}

/* ── Button Groups ───────────────────────── */

.btn-group {
  display: inline-flex;
}

.btn-group .btn {
  border-radius: 0;
}

.btn-group .btn:first-child {
  border-top-left-radius: 8px;
  border-bottom-left-radius: 8px;
}

.btn-group .btn:last-child {
  border-top-right-radius: 8px;
  border-bottom-right-radius: 8px;
}

/* ── Cards ────────────────────────────────── */

.card,
.glass {
  background: var(--surface-alpha);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  transition: border-color var(--transition-fast), transform var(--transition-fast);
}

/* ── Utility Classes ──────────────────────── */

.gradient-text,
.text-brand {
  color: var(--primary);
}

/* Flexbox */
.d-flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.justify-content-center { justify-content: center; }
.align-items-center { align-items: center; }

/* Text */
.text-center { text-align: center; }
.fw-bold { font-weight: 700; }

@media (min-width: 768px) {
  .text-md-end { text-align: right; }
}

/* Spacing */
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }

/* ── Page Sections ───────────────────────── */

.page-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.page-container--narrow {
  max-width: 800px;
}

.page-container--wide {
  max-width: 1400px;
}

@media (max-width: 480px) {
  .page-container {
    padding: 1rem;
  }
}

.page-header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.page-header h1 {
  font-size: 2.25rem;
  margin-bottom: 0.5rem;
}

.page-header p {
  color: var(--text-muted);
  font-size: 1.05rem;
  max-width: 600px;
  margin: 0 auto;
  line-height: 1.6;
}

.content-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 1.75rem;
  margin-bottom: 1.5rem;
}

.content-section h2 {
  font-size: 1.35rem;
  margin-bottom: 1rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.content-section h3 {
  font-size: 1.1rem;
  margin: 1.25rem 0 0.75rem;
  color: var(--text-primary);
}

.content-section p {
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 1rem;
}

.content-section ul {
  color: var(--text-secondary);
  padding-left: 1.5rem;
  margin-bottom: 1rem;
}

.content-section li {
  margin-bottom: 0.5rem;
  line-height: 1.6;
}

.highlight-box {
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 1.75rem;
  text-align: center;
}

.highlight-box h3 {
  color: var(--text-primary);
  margin-bottom: 0.75rem;
}

.highlight-box p {
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

/* ── Spacing Scale ──────────────────────── */

.mt-1 { margin-top: 0.25rem; }
.mt-4 { margin-top: 1.5rem; }
.mt-5 { margin-top: 2rem; }
.mt-6 { margin-top: 3rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-5 { margin-bottom: 2rem; }
.mb-6 { margin-bottom: 3rem; }
.py-4 { padding-top: 1.5rem; padding-bottom: 1.5rem; }
.py-6 { padding-top: 3rem; padding-bottom: 3rem; }
.px-4 { padding-left: 1.5rem; padding-right: 1.5rem; }

/* ── Typography Utilities ───────────────── */

.text-sm { font-size: 0.875rem; }
.text-lg { font-size: 1.05rem; }
.text-xl { font-size: 1.25rem; }

/* ── Card Primitives ────────────────────── */

.card-body {
  padding: 1.25rem;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
}

/* ── Focus Visible ──────────────────────── */

.btn:focus-visible,
.answer-btn:focus-visible,
.nav-link:focus-visible,
.dropdown-item:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

/* ── Reduced Motion ────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Mobile: prevent iOS auto-zoom on input focus ── */

@media (max-width: 768px) {
  .form-control {
    font-size: 1rem;
  }
}

/* ── Accessibility Utilities ───────────── */

.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;
}

.skip-to-main {
  position: absolute;
  top: -100%;
  left: 1rem;
  z-index: 10000;
  padding: 0.75rem 1.25rem;
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius-md);
  font-weight: 600;
  text-decoration: none;
  transition: top 0.2s;
}

.skip-to-main:focus {
  top: 1rem;
}
