/* === Reset & Typography === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: var(--font-family);
  font-size: var(--font-size-body);
  line-height: var(--line-height);
  font-weight: var(--font-weight-body);
  color: var(--color-text-primary);
  background: var(--gradient-bg-subtle);
  background-attachment: fixed;
  min-height: 100vh;
  transition: font-family var(--transition), font-size var(--transition);
}

h1, h2, h3 { font-weight: var(--font-weight-heading); line-height: 1.2; }
h1 { font-size: var(--font-size-h1); }
h2 { font-size: var(--font-size-h2); }

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

img { max-width: 100%; height: auto; }

/* === Header === */
.site-header {
  position: sticky;
  top: 0;
  z-index: 200;
  background: var(--gradient-header);
  border-bottom: none;
  padding: 0.875rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: 0 4px 20px rgba(67, 97, 238, 0.2);
}

.site-header__title {
  font-size: 1.3rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  cursor: pointer;
  color: #fff;
  letter-spacing: -0.01em;
  text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.site-header__stats {
  font-size: var(--font-size-small);
  color: rgba(255, 255, 255, 0.8);
  display: flex;
  gap: 0.75rem;
}

/* === Age Switcher === */
.age-switcher {
  position: sticky;
  top: 53px;
  z-index: 100;
  background: var(--color-bg-card);
  border-bottom: 1px solid var(--color-border);
  padding: 0.625rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  box-shadow: var(--shadow-xs);
}

.age-switcher__label {
  font-size: var(--font-size-small);
  color: var(--color-text-secondary);
  font-weight: 600;
  margin-right: 0.25rem;
}

.age-btn {
  padding: 0.375rem 1rem;
  border: 2px solid var(--color-border);
  border-radius: var(--border-radius);
  background: var(--color-bg-card);
  font-family: inherit;
  font-size: var(--font-size-small);
  font-weight: 600;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition-smooth);
  min-height: var(--btn-min-size);
  display: flex;
  align-items: center;
}

.age-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: rgba(67, 97, 238, 0.04);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.age-btn.active {
  background: var(--gradient-primary);
  border-color: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-primary);
  transform: translateY(-1px);
}

/* === Navigation Tabs === */
.nav-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 1.5rem;
  background: var(--color-bg-card);
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
}

.nav-tab {
  padding: 0.625rem 1.125rem;
  border: none;
  border-bottom: 3px solid transparent;
  background: none;
  font-family: inherit;
  font-size: var(--font-size-small);
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-smooth);
  white-space: nowrap;
  position: relative;
  border-radius: 8px 8px 0 0;
}

.nav-tab:hover {
  color: var(--color-primary);
  background: rgba(67, 97, 238, 0.04);
}

.nav-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  background: rgba(67, 97, 238, 0.06);
}

.nav-tab[data-tab="toddler-topics"] { display: none; }
[data-age="4-6"] .nav-tab[data-tab="toddler-topics"] { display: inline-flex; }

/* === Main container === */
.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem 1.5rem 3rem;
}

.tab-content {
  display: none;
  animation: fadeIn 0.3s ease;
}
.tab-content.active { display: block; }

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

/* === Scrollbar === */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.02); border-radius: 4px; }
::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--color-border) 0%, #c8cad0 100%);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, var(--color-text-muted) 0%, #a0a2b0 100%);
  background-clip: padding-box;
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

/* === Utility === */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* === Loading spinner === */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Selection === */
::selection {
  background: rgba(67, 97, 238, 0.15);
  color: var(--color-text-primary);
}

/* === Focus visible === */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* === Responsive === */
@media (max-width: 768px) {
  .site-header { padding: 0.5rem 1rem; }
  .site-header__stats { display: none; }
  .age-switcher { padding: 0.5rem 1rem; }
  .main-content { padding: 0.75rem 1rem 2rem; }
  .nav-tabs { padding: 0.5rem 1rem; }
}

@media (max-width: 480px) {
  .age-btn { padding: 0.25rem 0.625rem; font-size: 0.75rem; min-height: 36px; }
}

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