:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #eef5ff;
  --text: #243041;
  --muted: #64748b;
  --primary: #124a86;
  --primary-dark: #0b3662;
  --accent: #0f766e;
  --border: #d9e2ef;
  --success-bg: #e8f7ee;
  --success-text: #166534;
  --warn-bg: #fff7df;
  --warn-text: #92400e;
  --error-bg: #fdecec;
  --error-text: #991b1b;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
}

.site-header {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: white;
  padding: 2.5rem 1rem;
}

.header-inner, main, .top-nav-inner, footer {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
}

.site-header h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3rem);
  letter-spacing: -0.03em;
}

.site-header p {
  max-width: 760px;
  margin: 0.65rem 0 0;
  color: rgba(255,255,255,0.9);
  font-size: 1.08rem;
}

.top-nav {
  background: white;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.top-nav-inner {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  overflow-x: auto;
  padding: 0.6rem 0;
}

.nav-link {
  color: var(--primary-dark);
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
  padding: 0.5rem 0.75rem;
  border-radius: 999px;
}

.nav-link:hover, .nav-link.active {
  background: var(--surface-soft);
}

main { padding: 2rem 0 3rem; }

section, .card, .hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

section {
  padding: clamp(1rem, 2vw, 1.6rem);
  margin-bottom: 1.3rem;
}

h2 {
  color: var(--primary-dark);
  margin: 0 0 0.75rem;
  font-size: 1.45rem;
}

h3 {
  margin: 1rem 0 0.4rem;
  color: var(--primary);
  font-size: 1.1rem;
}

p { margin: 0.4rem 0 0.75rem; }

.muted, .note {
  color: var(--muted);
  font-size: 0.94rem;
}

.note {
  margin-top: 0.2rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1rem;
}

.card {
  padding: 1.1rem;
}

.card h3 { margin-top: 0; }

.card a.button-link, .button-link {
  display: inline-block;
  margin-top: 0.6rem;
  background: var(--primary);
  color: white;
  text-decoration: none;
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  font-weight: 700;
}

.button-link.secondary {
  background: #e2e8f0;
  color: var(--primary-dark);
}

.quick-jump {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.quick-jump a, .tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: 0.35rem 0.65rem;
  background: #f8fafc;
  color: var(--primary-dark);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 700;
}

.formula-block, .problem, .question, .flashcard-shell {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  margin-top: 1rem;
}

.formula-block:first-of-type,
.problem:first-of-type,
.question:first-of-type {
  border-top: none;
  padding-top: 0;
}

.formula {
  font-family: Georgia, 'Times New Roman', serif;
  font-style: italic;
  color: #475569;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  display: inline-block;
  margin: 0.25rem 0 0.55rem;
}

label {
  display: block;
  margin-top: 0.85rem;
  font-weight: 700;
}

input, select {
  display: block;
  width: min(100%, 440px);
  margin-top: 0.3rem;
  padding: 0.6rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: white;
}

select { width: min(100%, 280px); }

button {
  margin-top: 0.9rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 0.65rem 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

button:hover { background: var(--primary-dark); }
button.secondary { background: #e2e8f0; color: var(--primary-dark); }
button.secondary:hover { background: #cbd5e1; }

.result, .output, .feedback, .answer, .score-box {
  margin-top: 0.8rem;
  padding: 0.75rem;
  border-radius: 10px;
  font-weight: 700;
  display: none;
}

.success, .correct {
  display: block;
  background: var(--success-bg);
  color: var(--success-text);
  border: 1px solid #bbf7d0;
}

.warn {
  display: block;
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid #fde68a;
}

.error, .incorrect {
  display: block;
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid #fecaca;
}

.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: end;
  margin: 0.8rem 0 1.2rem;
}

.radio-option {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0.4rem 0;
}

.radio-option input {
  width: auto;
  margin-top: 0.35rem;
}

.radio-option label {
  margin: 0;
  font-weight: 400;
}

.flash-toolbar {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: end;
  margin-bottom: 1rem;
}

.flashcard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1rem;
}

.flashcard {
  min-height: 160px;
  perspective: 900px;
  cursor: pointer;
}

.flashcard-inner {
  position: relative;
  min-height: 160px;
  transform-style: preserve-3d;
  transition: transform 0.35s ease;
}

.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flash-front, .flash-back {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.45rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  background: white;
  backface-visibility: hidden;
}

.flash-front strong, .flash-back strong {
  color: var(--primary-dark);
}

.flash-back {
  transform: rotateY(180deg);
  background: #f8fafc;
}

footer {
  color: var(--muted);
  padding: 0 0 2rem;
  font-size: 0.92rem;
}

footer a { color: var(--primary); }

@media (max-width: 640px) {
  .site-header { padding: 2rem 1rem; }
  .top-nav { position: static; }
  section { border-radius: 14px; }
}

.site-footer {
  margin: 2rem auto 0;
  max-width: 1100px;
  padding: 1rem 1.25rem 2rem;
  color: #5f6f82;
  font-size: 0.9rem;
}
