/* ============================================================
   shared.css — ใช้ร่วมทุกบทเรียน
   ตรงกับ DESIGN.md ของโปรเจกต์ (Interactive Presentation System)
   ============================================================ */

/* ---------- Design Tokens ---------- */
:root {
  /* Colors */
  --c-primary: #2563EB;
  --c-secondary: #7C3AED;
  --c-tertiary: #F59E0B;
  --c-neutral: #0F172A;
  --c-surface: #FFFFFF;
  --c-surface-2: #F8FAFC;
  --c-on-surface: #0F172A;
  --c-muted: #64748B;
  --c-border: rgba(100, 116, 139, 0.15);
  --c-success: #10B981;
  --c-warning: #F59E0B;
  --c-error: #EF4444;

  /* Radius */
  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-full: 9999px;

  /* Spacing */
  --s-xs: 4px;
  --s-sm: 8px;
  --s-md: 16px;
  --s-lg: 24px;
  --s-xl: 40px;
  --s-2xl: 64px;
  --s-3xl: 96px;

  /* Shadow */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 40px rgba(15, 23, 42, 0.12);
  --shadow-glow: 0 0 40px rgba(37, 99, 235, 0.25);

  /* Motion */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur-fast: 0.2s;
  --dur-base: 0.4s;
  --dur-slow: 0.6s;

  /* Typography */
  --font-sans: "Sarabun", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --c-surface: #0F172A;
    --c-surface-2: #1E293B;
    --c-on-surface: #F1F5F9;
    --c-neutral: #F1F5F9;
    --c-border: rgba(241, 245, 249, 0.1);
  }
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
img, svg, video { max-width: 100%; display: block; }
button { font: inherit; cursor: pointer; }
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

body {
  font-family: var(--font-sans);
  color: var(--c-on-surface);
  background:
    radial-gradient(at 20% 10%, rgba(124, 58, 237, 0.10) 0, transparent 40%),
    radial-gradient(at 80% 90%, rgba(37, 99, 235, 0.12) 0, transparent 40%),
    var(--c-surface);
  min-height: 100vh;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Typography ---------- */
.t-display {
  font-size: clamp(2.5rem, 7vw, 4.5rem);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.03em;
  margin: 0 0 var(--s-lg);
}
.t-h1 {
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0 0 var(--s-md);
}
.t-h2 {
  font-size: clamp(1.3rem, 2.5vw, 1.75rem);
  font-weight: 600;
  line-height: 1.3;
  margin: 0 0 var(--s-sm);
}
.t-lead {
  font-size: clamp(1.05rem, 1.8vw, 1.25rem);
  line-height: 1.6;
  color: var(--c-muted);
  margin: 0 0 var(--s-xl);
}
.t-body { font-size: 1rem; line-height: 1.6; margin: 0 0 var(--s-md); }
.t-label { font-size: 0.875rem; font-weight: 500; letter-spacing: 0.02em; }
.t-mono { font-family: var(--font-mono); font-size: 0.95rem; }
.t-accent { color: var(--c-tertiary); }
.t-gradient {
  background: linear-gradient(135deg, var(--c-primary), var(--c-secondary));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- Layout ---------- */
.container { max-width: 1100px; margin: 0 auto; padding: 0 var(--s-lg); }
.stack > * + * { margin-top: var(--s-md); }
.stack-lg > * + * { margin-top: var(--s-lg); }
.row { display: flex; gap: var(--s-md); flex-wrap: wrap; }
.row-center { display: flex; gap: var(--s-md); justify-content: center; flex-wrap: wrap; }
.grid { display: grid; gap: var(--s-lg); grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

/* ---------- Deck (scroll-snap slides) ---------- */
.deck {
  scroll-snap-type: y mandatory;
  height: 100vh;
  overflow-y: scroll;
  overflow-x: hidden;
}
.slide {
  scroll-snap-align: start;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: var(--s-2xl) var(--s-xl);
  position: relative;
}
.slide-inner { max-width: 1100px; width: 100%; }

/* ---------- Top bar (lesson nav + i18n + progress) ---------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--s-lg);
  background: color-mix(in srgb, var(--c-surface) 80%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--c-border);
  z-index: 100;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: var(--s-sm); }
.topbar-title {
  font-weight: 600;
  font-size: 0.95rem;
}
.topbar-title a { color: inherit; }

.progress-bar {
  position: fixed;
  top: 56px;
  left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, var(--c-primary), var(--c-secondary));
  z-index: 101;
  transition: width 0.2s var(--ease);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--r-full);
  border: 0;
  font: 500 0.95rem/1 var(--font-sans);
  text-decoration: none;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow-glow); }
.btn-ghost {
  background: transparent;
  color: var(--c-on-surface);
  border: 1px solid var(--c-border);
}
.btn-ghost:hover { border-color: var(--c-primary); color: var(--c-primary); }
.btn-sm { padding: 6px 14px; font-size: 0.85rem; }

/* ---------- Cards ---------- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--s-lg);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-base) var(--ease),
              box-shadow var(--dur-base) var(--ease);
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.card .icon { font-size: 2rem; margin-bottom: var(--s-sm); }

.card-link {
  display: block;
  color: inherit;
  text-decoration: none;
}
.card-link:hover { text-decoration: none; }

/* ---------- Callout / Pill ---------- */
.callout {
  display: inline-block;
  background: linear-gradient(135deg, var(--c-tertiary), #FBBF24);
  color: var(--c-neutral);
  padding: 8px 18px;
  border-radius: var(--r-full);
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: var(--shadow-sm);
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: var(--r-full);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  font-size: 0.8rem;
  color: var(--c-muted);
}

/* ---------- Stat ---------- */
.stat .num {
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 800;
  color: var(--c-tertiary);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat .label {
  color: var(--c-muted);
  margin-top: 4px;
  font-size: 0.95rem;
}

/* ---------- Tabs ---------- */
.tabs { max-width: 720px; margin: 0 auto; }
.tab-list {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--c-surface-2);
  border-radius: var(--r-full);
  margin-bottom: var(--s-md);
}
.tab-btn {
  flex: 1;
  padding: 10px 16px;
  border: 0;
  background: transparent;
  border-radius: var(--r-full);
  color: var(--c-muted);
  transition: all var(--dur-fast) var(--ease);
}
.tab-btn[aria-selected="true"] {
  background: var(--c-surface);
  color: var(--c-primary);
  box-shadow: var(--shadow-md);
}
.tab-panel {
  padding: var(--s-md);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  display: none;
}
.tab-panel.active {
  display: block;
  animation: fadeIn var(--dur-base) var(--ease);
}

/* ---------- Quiz ---------- */
.quiz {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--s-lg);
  box-shadow: var(--shadow-md);
  max-width: 640px;
  margin: 0 auto;
}
.quiz fieldset { border: 0; padding: 0; margin: 0 0 var(--s-md); }
.quiz legend { font-weight: 600; margin-bottom: var(--s-sm); }
.quiz label {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--r-md);
  border: 1px solid var(--c-border);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
}
.quiz label:hover {
  border-color: var(--c-primary);
  background: color-mix(in srgb, var(--c-primary) 4%, transparent);
}
.quiz input[type="radio"] { accent-color: var(--c-primary); }
.quiz .feedback {
  font-weight: 600;
  padding: 12px 16px;
  border-radius: var(--r-md);
  display: none;
  margin-top: var(--s-sm);
}
.quiz .feedback.show { display: block; }
.quiz .feedback.ok {
  background: color-mix(in srgb, var(--c-success) 12%, transparent);
  color: var(--c-success);
}
.quiz .feedback.no {
  background: color-mix(in srgb, var(--c-error) 12%, transparent);
  color: var(--c-error);
}

/* ---------- Reveal-on-scroll ---------- */
.reveal {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity var(--dur-slow) var(--ease),
              transform var(--dur-slow) var(--ease);
}
.reveal.is-visible { opacity: 1; transform: none; }
.reveal[data-delay="1"] { transition-delay: 0.1s; }
.reveal[data-delay="2"] { transition-delay: 0.2s; }
.reveal[data-delay="3"] { transition-delay: 0.3s; }
.reveal[data-delay="4"] { transition-delay: 0.4s; }

/* ---------- Spotlight ---------- */
.spotlight {
  position: fixed;
  pointer-events: none;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  left: 0; top: 0;
  z-index: 50;
  background: radial-gradient(circle, color-mix(in srgb, var(--c-primary) 8%, transparent) 0, transparent 60%);
  transform: translate(-50%, -50%);
  mix-blend-mode: screen;
  transition: transform 0.15s ease-out;
}

/* ---------- Chapter dots (TOC indicator) ---------- */
.chapter-dots {
  display: flex;
  gap: 6px;
}
.chapter-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-border);
  transition: all var(--dur-fast) var(--ease);
}
.chapter-dot.is-current { background: var(--c-primary); transform: scale(1.4); }
.chapter-dot.is-done { background: var(--c-success); }

/* ---------- Image with caption ---------- */
figure {
  margin: var(--s-lg) 0;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
}
figure img { width: 100%; height: auto; }
figcaption {
  padding: var(--s-sm) var(--s-md);
  font-size: 0.875rem;
  color: var(--c-muted);
  text-align: center;
}

/* ---------- Animations ---------- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* ---------- Accessibility ---------- */
@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;
  }
  .spotlight { display: none; }
}

:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Print ---------- */
@media print {
  .topbar, .progress-bar, .spotlight, .hint { display: none !important; }
  .deck { height: auto; overflow: visible; scroll-snap-type: none; }
  .slide { min-height: auto; page-break-after: always; padding: var(--s-xl) 0; }
}
