/* ═══════════════════════════════════════════════════════════
   ETUDE-DZ — DESIGN SYSTEM v3.0
   "الورقة الذكية" — Blueprint-Aligned
   Light-first · Zero CLS · Typography-driven
   ═══════════════════════════════════════════════════════════ */

/* ─── ZERO CLS: Font Fallback Metrics ─── */
@font-face {
  font-family: 'SS Fallback';
  src: local('Segoe UI'), local('Tahoma'), local('Arial');
  size-adjust: 102%;
  ascent-override: 105%;
  descent-override: 35%;
  line-gap-override: 0%;
}

/* ─── DESIGN TOKENS ─── */
:root {
  /* Surfaces */
  --bg-page:       #FFFFFF;
  --bg-surface:    #F8F9FA;
  --bg-elevated:   #F1F3F4;
  --bg-overlay:    #E8EAED;
  --bg-glass:      rgba(255, 255, 255, 0.85);

  /* Text */
  --text-primary:  #202124;
  --text-body:     #3C4043;
  --text-secondary:#5F6368;
  --text-muted:    #6D7175;
  --text-hint:     #BDC1C6;

  /* Math Colors — functional, not decorative */
  --math-a:        #1A73E8;
  --math-b:        #E8710A;
  --math-c:        #0D652D;

  /* Semantic */
  --color-primary:    #1A73E8;
  --color-primary-bg: #E8F0FE;
  --color-success:    #0D652D;
  --color-success-bg: #E6F4EA;
  --color-error:      #C5221F;
  --color-error-bg:   #FCE8E6;
  --color-warn:       #E8710A;
  --color-warn-bg:    #FEF7E0;

  /* Borders */
  --border:         #DADCE0;
  --border-light:   #E8EAED;
  --border-active:  #1A73E8;

  /* Typography */
  --font-main: 'IBM Plex Sans Arabic', 'SS Fallback', 'Segoe UI', 'Tahoma', sans-serif;
  --font-mono: 'JetBrains Mono', 'Consolas', monospace;

  --text-display: clamp(1.75rem, 4vw, 2.25rem);
  --text-title:   clamp(1.25rem, 3vw, 1.5rem);
  --text-body-size: 1rem;
  --text-small:   0.875rem;
  --text-caption: 0.75rem;

  --lh-heading: 1.4;
  --lh-body:    1.85;
  --lh-math:    1.5;

  /* Spacing (8px grid) */
  --sp-xs:  4px;
  --sp-sm:  8px;
  --sp-md:  16px;
  --sp-lg:  24px;
  --sp-xl:  32px;
  --sp-2xl: 48px;
  --sp-3xl: 64px;

  /* Radius */
  --radius-sm:   8px;
  --radius-md:   12px;
  --radius-lg:   16px;
  --radius-pill: 100px;

  /* Shadows — subtle, not heavy */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);

  /* Motion — purposeful only */
  --ease:      cubic-bezier(0.2, 0, 0, 1);
  --ease-out:  cubic-bezier(0.05, 0.7, 0.1, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-micro:   150ms;
  --dur-normal:  250ms;
  --dur-emphasis:350ms;

  /* Layout */
  --content-w: 680px;
  --page-pad:  20px;
}

/* ─── DARK MODE ─── */
[data-theme="dark"] {
  --bg-page:       #1A1A1A;
  --bg-surface:    #242424;
  --bg-elevated:   #2E2E2E;
  --bg-overlay:    #383838;
  --bg-glass:      rgba(26, 26, 26, 0.9);

  --text-primary:  #E8EAED;
  --text-body:     #BDC1C6;
  --text-secondary:#9AA0A6;
  --text-muted:    #6B6E73;
  --text-hint:     #4A4D52;

  --border:        #3C4043;
  --border-light:  #2E2E2E;

  --color-primary-bg: rgba(26, 115, 232, 0.15);
  --color-success-bg: rgba(13, 101, 45, 0.15);
  --color-error-bg:   rgba(197, 34, 31, 0.15);
  --color-warn-bg:    rgba(232, 113, 10, 0.15);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.4);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.5);
}

/* ─── RESET & BASE ─── */
*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-main);
  background: var(--bg-page);
  color: var(--text-body);
  line-height: var(--lh-body);
  direction: rtl;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background-color var(--dur-normal) var(--ease),
              color var(--dur-normal) var(--ease);
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

button {
  font-family: var(--font-main);
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  font-size: inherit;
}

input {
  font-family: var(--font-main);
  color: var(--text-primary);
  background: transparent;
  border: none;
  outline: none;
}

/* ─── LAYOUT ─── */
.page-wrapper {
  position: relative;
  min-height: 100vh;
}

.content-container {
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 0 var(--page-pad);
}

/* ═══════════════════════════════════════
   HEADER — Minimal, sticky
   ═══════════════════════════════════════ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: var(--sp-md) var(--page-pad);
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--content-w);
  margin: 0 auto;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-light);
  /* CLS: fixed height */
  min-height: 56px;
  contain: layout style;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  text-decoration: none;
  color: var(--text-primary);
}

.site-logo:hover { text-decoration: none; }

.site-logo-icon {
  width: 32px;
  height: 32px;
  background: var(--color-primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.site-logo-text {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
}

.theme-toggle {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 1.1rem;
  transition: background var(--dur-micro) var(--ease);
  cursor: pointer;
  background: transparent;
  border: none;
  color: var(--text-secondary);
}

.theme-toggle:hover {
  background: var(--bg-elevated);
}

.header-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-caption);
  color: var(--text-muted);
}

.header-breadcrumb a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--dur-micro);
}

.header-breadcrumb a:hover { color: var(--color-primary); text-decoration: none; }
.header-breadcrumb .sep { opacity: 0.5; font-size: 0.65rem; }

/* ═══════════════════════════════════════
   STEP PAGE — THE CORE EXPERIENCE
   Blueprint Zones 1-4
   ═══════════════════════════════════════ */

/* ─── ZONE 1: STEP HERO (seconds 0-1) ─── */
.step-hero {
  padding: var(--sp-xl) 0 var(--sp-lg);
  contain: layout style;
}

.step-meta {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-md);
}

.step-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 14px;
  background: var(--color-primary-bg);
  border: 1px solid rgba(26, 115, 232, 0.2);
  border-radius: var(--radius-pill);
  font-size: var(--text-caption);
  font-weight: 500;
  color: var(--color-primary);
}

.step-badge-icon { font-size: 0.7rem; }

.step-title {
  font-size: var(--text-display);
  font-weight: 700;
  line-height: var(--lh-heading);
  color: var(--text-primary);
  margin-bottom: var(--sp-sm);
}

/* Formula tag — CLS: reserved height */
.step-formula-tag {
  display: inline-block;
  padding: 8px 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1.15rem;
  direction: ltr;
  min-height: 48px;
  contain: layout style;
}

/* ─── ZONE 1: VISUAL CARD (seconds 1-3) ─── */
.visual-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-lg) var(--sp-lg);
  margin: var(--sp-lg) 0;
  position: relative;
  min-height: 120px;
  contain: layout;
}

.visual-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--math-a), var(--math-b), var(--math-c));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  opacity: 0.7;
}

.visual-equation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 1.8rem;
  direction: ltr;
  padding: var(--sp-md) 0;
  flex-wrap: wrap;
}

.visual-equation .eq-part {
  position: relative;
  padding: 6px 10px;
  border-radius: 6px;
  margin-bottom: var(--sp-lg);
}

.visual-equation .eq-part[data-color="1"] {
  background: rgba(26, 115, 232, 0.1);
  color: var(--math-a);
}

.visual-equation .eq-part[data-color="2"] {
  background: rgba(232, 113, 10, 0.1);
  color: var(--math-b);
}

.visual-equation .eq-part[data-color="3"] {
  background: rgba(13, 101, 45, 0.1);
  color: var(--math-c);
}

.eq-label {
  position: absolute;
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

.eq-label[data-color="1"] { background: rgba(26,115,232,0.12); color: var(--math-a); }
.eq-label[data-color="2"] { background: rgba(232,113,10,0.12); color: var(--math-b); }
.eq-label[data-color="3"] { background: rgba(13,101,45,0.12); color: var(--math-c); }

.visual-equation .eq-plain { color: var(--text-secondary); }

/* ─── ZONE 1: CALCULATION (seconds 3-5) ─── */
.calc-section {
  margin: var(--sp-lg) 0;
  contain: layout style;
}

.calc-section-label {
  font-size: var(--text-caption);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--sp-md);
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
}

.calc-section-label::before {
  content: '';
  display: block;
  width: 3px;
  height: 14px;
  background: var(--color-primary);
  border-radius: 2px;
}

.calc-steps {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.calc-step {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: 12px var(--sp-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  direction: ltr;
  min-height: 50px;
  contain: layout style;
  /* Stagger animation — "الأستاذ يكتب" */
  opacity: 0;
  transform: translateY(6px);
  animation: calcStepIn var(--dur-emphasis) var(--ease) forwards;
}

.calc-step:nth-child(1) { animation-delay: 0ms; }
.calc-step:nth-child(2) { animation-delay: 80ms; }
.calc-step:nth-child(3) { animation-delay: 160ms; }
.calc-step:nth-child(4) { animation-delay: 240ms; }
.calc-step:nth-child(5) { animation-delay: 320ms; }
.calc-step:nth-child(6) { animation-delay: 400ms; }
.calc-step:nth-child(7) { animation-delay: 480ms; }

@keyframes calcStepIn {
  to { opacity: 1; transform: translateY(0); }
}

/* Last step = result — highlighted */
.calc-step:last-child {
  background: var(--color-primary-bg);
  border-color: rgba(26, 115, 232, 0.2);
}

.calc-step-num {
  width: 26px;
  height: 26px;
  min-width: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
}

.calc-step:last-child .calc-step-num {
  background: var(--color-primary);
  color: #fff;
}

.calc-step-math { flex: 1; font-size: 1.1rem; }

.calc-step-note {
  font-size: var(--text-caption);
  color: var(--text-muted);
  direction: rtl;
  white-space: nowrap;
}

/* ─── ZONE 1: SUMMARY (seconds 5-8) ─── */
.summary-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--sp-lg);
  margin: var(--sp-lg) 0;
  contain: layout style;
}

.summary-header {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-md);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.summary-header-icon { font-size: 1.1rem; }

.summary-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
}

.summary-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: var(--text-small);
  color: var(--text-body);
  line-height: 1.7;
}

.summary-list li::before {
  content: '';
  display: block;
  width: 6px;
  height: 6px;
  min-width: 6px;
  background: var(--color-primary);
  border-radius: 50%;
  margin-top: 9px;
}

/* ─── ZONE 1: COMMON MISTAKE (seconds 5-8) ─── */
.mistake-card {
  background: var(--color-error-bg);
  border: 1px solid rgba(197, 34, 31, 0.12);
  border-radius: var(--radius-lg);
  padding: var(--sp-lg);
  margin: var(--sp-md) 0;
  contain: layout style;
}

.mistake-header {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-md);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--color-error);
}

.mistake-wrong, .mistake-right {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: var(--text-small);
  margin-bottom: var(--sp-sm);
  direction: ltr;
}

.mistake-wrong {
  background: rgba(197, 34, 31, 0.06);
  border-right: 3px solid var(--color-error);
  text-decoration: line-through;
  text-decoration-color: var(--color-error);
  color: var(--text-muted);
}

.mistake-right {
  background: var(--color-success-bg);
  border-right: 3px solid var(--color-success);
  color: var(--text-primary);
}

.mistake-tip {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-top: var(--sp-sm);
  padding-right: var(--sp-sm);
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.mistake-tip::before { content: '💡'; font-size: 0.8rem; }

/* ═══════════════════════════════════════
   ZONE 2: TRY IT YOURSELF (seconds 8-10)
   ═══════════════════════════════════════ */
.try-section {
  background: var(--bg-surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-lg);
  margin: var(--sp-xl) 0;
  position: relative;
  overflow: hidden;
  contain: layout style;
  transition: border-color var(--dur-normal) var(--ease);
}

.try-section.active { border-color: var(--color-primary); }

.try-section.success {
  border-color: var(--color-success);
  background: var(--color-success-bg);
}

.try-header {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-md);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--color-warn);
}

.try-header-icon { font-size: 1.1rem; }

.try-equation {
  text-align: center;
  font-size: 1.3rem;
  padding: var(--sp-md);
  margin-bottom: var(--sp-md);
  direction: ltr;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  min-height: 52px;
  contain: layout style;
}

.try-inputs {
  display: flex;
  gap: var(--sp-md);
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: var(--sp-md);
  direction: ltr;
}

.try-field {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.try-field label {
  font-size: var(--text-caption);
  font-weight: 500;
  color: var(--text-muted);
}

.try-field input {
  width: 72px;
  height: 44px;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  background: var(--bg-page);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--dur-normal) var(--ease);
  direction: ltr;
  color: var(--text-primary);
}

.try-field input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-bg);
}

.try-field input.correct {
  border-color: var(--color-success);
  background: var(--color-success-bg);
}

.try-field input.wrong {
  border-color: var(--color-error);
  background: var(--color-error-bg);
  animation: inputShake 400ms var(--ease);
}

@keyframes inputShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

.try-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-sm);
  width: 100%;
  padding: 12px;
  background: var(--color-primary);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  transition: all var(--dur-normal) var(--ease);
}

.try-btn:hover {
  background: #1557B0;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.try-btn:active { transform: translateY(0); }

.try-btn.success-state { background: var(--color-success); }
.try-btn.success-state:hover { background: #0a5224; }

.try-feedback {
  margin-top: var(--sp-md);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: var(--text-small);
  display: none;
  align-items: center;
  gap: var(--sp-sm);
  animation: feedbackIn var(--dur-normal) var(--ease-spring);
}

.try-feedback.show { display: flex; }

.try-feedback.correct-feedback {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.try-feedback.wrong-feedback {
  background: var(--color-warn-bg);
  color: var(--color-warn);
}

@keyframes feedbackIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.try-hint {
  margin-top: var(--sp-sm);
  font-size: var(--text-caption);
  color: var(--text-muted);
  display: none;
}

.try-hint.show { display: block; }

/* ═══════════════════════════════════════
   AD ZONES — Zero CLS Reserved Space
   Blueprint L6: only in "psychological gaps"
   ═══════════════════════════════════════ */
.ad-zone {
  margin: var(--sp-xl) 0;
  width: 100%;
  min-height: 100px;
  max-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-surface);
  overflow: hidden;
  /* CLS: size containment — content cannot change container */
  contain: layout style size;
}

.ad-zone-placeholder {
  font-size: 0.68rem;
  color: var(--text-hint);
  letter-spacing: 0.05em;
}

.ad-zone ins.adsbygoogle {
  display: block;
  width: 100%;
  height: 100%;
}

@media (max-width: 600px) {
  .ad-zone {
    min-height: 100px;
  }
}

/* ═══════════════════════════════════════
   ZONE 3: RELATED STEPS (Engineered Gap)
   Blueprint L4: blur + curiosity
   ═══════════════════════════════════════ */
.related-section {
  margin: var(--sp-xl) 0;
  contain: layout style;
}

.related-header {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-md);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.related-header-icon { color: var(--color-warn); }

.related-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
}

.related-item {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: 14px 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--dur-normal) var(--ease);
  text-decoration: none;
  color: var(--text-primary);
}

.related-item:hover {
  background: var(--bg-elevated);
  border-color: var(--border-active);
  transform: translateX(-4px);
  text-decoration: none;
  color: var(--text-primary);
}

.related-item-icon {
  width: 32px;
  height: 32px;
  min-width: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary-bg);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--color-primary);
}

.related-item-text { font-size: 0.9rem; font-weight: 500; }

/* Engineered Gap — locked/blur items */
.related-item.locked {
  position: relative;
  overflow: hidden;
}

.related-item.locked .related-item-text {
  filter: blur(3px);
  user-select: none;
}

.related-item.locked::after {
  content: 'اكتشف →';
  position: absolute;
  left: 18px;
  font-size: var(--text-caption);
  font-weight: 600;
  color: var(--color-primary);
  opacity: 0;
  transition: opacity var(--dur-normal) var(--ease);
}

.related-item.locked:hover::after { opacity: 1; }
.related-item.locked:hover .related-item-text { filter: blur(1px); }

/* ═══════════════════════════════════════
   ZONE 4: STEP MAP (Connected Network)
   Blueprint L4: "يرى نفسه داخل خريطة"
   ═══════════════════════════════════════ */
.stepmap-section {
  margin: var(--sp-xl) 0;
  padding: var(--sp-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  contain: layout style;
}

.stepmap-header {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-lg);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.stepmap-header-icon { font-size: 1rem; }

.stepmap-list {
  display: flex;
  flex-direction: column;
  position: relative;
}

.stepmap-list::before {
  content: '';
  position: absolute;
  right: 15px;
  top: 16px;
  bottom: 16px;
  width: 2px;
  background: var(--border-light);
}

.stepmap-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 0;
  position: relative;
  z-index: 1;
  text-decoration: none;
  color: var(--text-secondary);
  transition: color var(--dur-micro) var(--ease);
}

.stepmap-item:hover { color: var(--text-primary); text-decoration: none; }

.stepmap-dot {
  width: 12px;
  height: 12px;
  min-width: 12px;
  border-radius: 50%;
  background: var(--bg-page);
  border: 2px solid var(--border);
  transition: all var(--dur-normal) var(--ease);
}

.stepmap-item.current .stepmap-dot {
  background: var(--color-primary);
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px var(--color-primary-bg);
}

.stepmap-item.visited .stepmap-dot {
  background: var(--color-success);
  border-color: var(--color-success);
}

.stepmap-item-text { font-size: var(--text-small); font-weight: 400; }

.stepmap-item.current .stepmap-item-text {
  color: var(--text-primary);
  font-weight: 600;
}

.stepmap-item-current-badge {
  display: none;
  font-size: 0.65rem;
  padding: 2px var(--sp-sm);
  background: var(--color-primary-bg);
  color: var(--color-primary);
  border-radius: var(--radius-pill);
  margin-right: auto;
}

.stepmap-item.current .stepmap-item-current-badge { display: inline-block; }

/* ═══════════════════════════════════════
   AFFILIATE SECTION — Bottom of page
   ═══════════════════════════════════════ */
.affiliate-section {
  margin: var(--sp-xl) 0;
  padding: var(--sp-lg);
  background: var(--color-warn-bg);
  border: 1px solid rgba(232, 113, 10, 0.12);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  gap: var(--sp-md);
}

.affiliate-icon { font-size: 2rem; min-width: 48px; text-align: center; }
.affiliate-text { flex: 1; }
.affiliate-title { font-size: 0.9rem; font-weight: 600; margin-bottom: 4px; color: var(--text-primary); }
.affiliate-desc { font-size: var(--text-caption); color: var(--text-secondary); }

.affiliate-btn {
  padding: var(--sp-sm) var(--sp-lg);
  background: var(--color-warn);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  transition: all var(--dur-normal) var(--ease);
}

.affiliate-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  color: #fff;
  text-decoration: none;
}

/* ═══════════════════════════════════════
   LANDING PAGE
   ═══════════════════════════════════════ */
.landing-hero {
  padding: var(--sp-3xl) 0 var(--sp-2xl);
  text-align: center;
}

.landing-title {
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  font-weight: 700;
  line-height: var(--lh-heading);
  margin-bottom: var(--sp-md);
  color: var(--text-primary);
}

.landing-desc {
  color: var(--text-secondary);
  font-size: 1.05rem;
  max-width: 500px;
  margin: 0 auto var(--sp-xl);
  line-height: 1.8;
}

/* Stats strip */
.landing-stats {
  display: flex;
  justify-content: center;
  gap: var(--sp-xl);
  margin-bottom: var(--sp-2xl);
}

.landing-stat {
  text-align: center;
}

.landing-stat-num {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1.2;
}

.landing-stat-label {
  font-size: var(--text-caption);
  color: var(--text-muted);
}

/* Search */
.search-box {
  position: relative;
  max-width: 480px;
  margin: 0 auto var(--sp-2xl);
}

.search-input {
  width: 100%;
  padding: 14px 48px 14px 20px;
  background: var(--bg-surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 1rem;
  color: var(--text-primary);
  transition: all var(--dur-normal) var(--ease);
}

.search-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-bg);
}

.search-input::placeholder { color: var(--text-hint); }

.search-icon {
  position: absolute;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1.1rem;
  pointer-events: none;
}

/* Search results — position: absolute = Zero CLS */
.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  max-height: 320px;
  overflow-y: auto;
  display: none;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}

.search-results.show { display: block; }

.search-result-item {
  padding: var(--sp-md) 18px;
  cursor: pointer;
  transition: background var(--dur-micro) var(--ease);
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border-light);
}

.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg-surface); }

.search-result-item .sr-lesson {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.search-result-item .sr-title {
  font-size: 0.9rem;
  color: var(--text-primary);
}

/* Lesson Grid */
.lessons-section { margin-bottom: var(--sp-2xl); }

.lessons-section-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: var(--sp-md);
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  color: var(--text-primary);
}

.lessons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--sp-md);
}

.lesson-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--sp-lg);
  cursor: pointer;
  transition: all var(--dur-normal) var(--ease);
  text-decoration: none;
  color: var(--text-primary);
  display: block;
  /* CLS: fixed min-height */
  min-height: 120px;
  contain: layout style;
}

.lesson-card:hover {
  background: var(--bg-elevated);
  border-color: var(--border);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  color: var(--text-primary);
  text-decoration: none;
}

.lesson-card-icon { font-size: 1.6rem; margin-bottom: 10px; }
.lesson-card-title { font-size: 0.9rem; font-weight: 600; margin-bottom: 4px; line-height: 1.4; }
.lesson-card-count { font-size: var(--text-caption); color: var(--text-muted); }

/* Lesson Detail */
.lesson-detail { padding: var(--sp-lg) 0 var(--sp-2xl); }

.lesson-detail-header { margin-bottom: var(--sp-lg); }

.lesson-detail-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: var(--sp-md);
  text-decoration: none;
  transition: color var(--dur-micro);
}

.lesson-detail-back:hover { color: var(--color-primary); text-decoration: none; }

.lesson-detail-title { font-size: var(--text-title); font-weight: 700; color: var(--text-primary); }
.lesson-detail-count { font-size: var(--text-small); color: var(--text-secondary); margin-top: 4px; }

.steps-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
}

.steps-list-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: var(--sp-md) var(--sp-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--dur-normal) var(--ease);
  text-decoration: none;
  color: var(--text-primary);
  min-height: 64px;
  contain: layout style;
}

.steps-list-item:hover {
  background: var(--bg-elevated);
  border-color: var(--border);
  transform: translateX(-4px);
  text-decoration: none;
  color: var(--text-primary);
}

.steps-list-item-num {
  width: 32px;
  height: 32px;
  min-width: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary-bg);
  color: var(--color-primary);
  font-size: var(--text-caption);
  font-weight: 700;
  border-radius: 50%;
}

.steps-list-item-title { flex: 1; font-size: 0.92rem; font-weight: 500; }

.steps-list-item-arrow {
  color: var(--text-hint);
  transition: transform var(--dur-micro) var(--ease);
}

.steps-list-item:hover .steps-list-item-arrow {
  transform: translateX(-4px);
  color: var(--color-primary);
}

/* ─── VIEWS TOGGLE ─── */
.view-landing,
.view-lesson,
.view-step {
  display: none;
}

.view-landing.active,
.view-lesson.active,
.view-step.active {
  display: block;
  animation: viewIn var(--dur-emphasis) var(--ease);
}

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

/* ─── FOOTER — Minimal ─── */
.site-footer {
  padding: var(--sp-xl) var(--page-pad);
  text-align: center;
  font-size: var(--text-caption);
  color: var(--text-muted);
  border-top: 1px solid var(--border-light);
  margin-top: var(--sp-2xl);
}

.site-footer a {
  color: var(--text-muted);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--color-primary);
  text-decoration: none;
}

/* ─── SUCCESS ANIMATION — position: fixed = Zero CLS ─── */
.success-burst {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 200px;
  height: 200px;
  pointer-events: none;
  z-index: 9999;
  display: none;
}

.success-burst.show {
  display: block;
  animation: burstOut 600ms var(--ease) forwards;
}

@keyframes burstOut {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.3); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.5); }
}

/* ─── SCROLL PROGRESS ─── */
.scroll-progress {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  height: 2px;
  background: transparent;
  z-index: 1000;
}

.scroll-progress-bar {
  height: 100%;
  background: var(--color-primary);
  width: 0%;
  transition: width 100ms linear;
}

/* ─── KaTeX — Zero CLS containment ─── */
[data-katex] {
  contain: layout style;
  min-height: 1.4em;
  display: inline-block;
  vertical-align: middle;
  line-height: var(--lh-math);
}

.katex { font-size: 1.1em; }
.calc-step .katex { font-size: 1.15em; }
.try-equation .katex { font-size: 1.3em; }
.step-formula-tag .katex { font-size: 1.1em; }

/* ─── RESPONSIVE ─── */
@media (max-width: 600px) {
  :root {
    --content-w: 100%;
    --page-pad: 16px;
  }

  .site-header {
    flex-wrap: wrap;
    gap: var(--sp-sm);
    min-height: auto;
    padding: var(--sp-sm) var(--page-pad);
  }

  .header-breadcrumb { width: 100%; order: 3; }

  .visual-equation { font-size: 1.3rem; }
  .try-inputs { gap: var(--sp-sm); }
  .try-field input { width: 60px; height: 40px; font-size: 1rem; }

  .affiliate-section { flex-direction: column; text-align: center; }

  .lessons-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }

  .calc-step { padding: 10px 12px; gap: 10px; }
  .calc-step-note { display: none; }
  .eq-label { font-size: 0.58rem; bottom: -18px; }

  .landing-stats { gap: var(--sp-md); }
  .landing-stat-num { font-size: 1.2rem; }
}

@media (max-width: 380px) {
  .visual-equation { font-size: 1.1rem; }
  .step-title { font-size: 1.2rem; }
}

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-hint); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── SELECTION ─── */
::selection { background: var(--color-primary); color: #fff; }

/* ─── SKELETON (CLS-safe) ─── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-elevated) 50%, var(--bg-surface) 75%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeletonShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
