/* ============================================================
   Form 5 Mathematics (KSSM Malaysia) Interactive Revision Deck
   Modern, Responsive Educational Presentation System
   ============================================================ */

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg-app: #f1f5f9;
  --panel: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f8fafc;
  
  --ch1: #2563eb; /* Variation - Blue */
  --ch2: #7c3aed; /* Matrices - Violet */
  --ch3: #059669; /* Insurance - Emerald */
  --ch4: #d97706; /* Taxation - Amber */
  --ch5: #0891b2; /* Transformations - Cyan */
  --ch6: #e11d48; /* Trigonometry - Rose */
  --ch7: #4f46e5; /* Dispersion - Indigo */
  --ch8: #0d9488; /* Modeling - Teal */

  --danger-bg: #fef2f2;
  --danger-border: #fca5a5;
  --danger-text: #dc2626;

  --success-bg: #f0fdf4;
  --success-border: #86efac;
  --success-text: #16a34a;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.08), 0 2px 6px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.1), 0 4px 10px -2px rgba(0, 0, 0, 0.04);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  height: 100vh;
  width: 100vw;
}

/* ============================================================
   COVER PAGE
   ============================================================ */
.cover {
  min-height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background: radial-gradient(circle at 50% 15%, #eff6ff 0%, #f1f5f9 85%);
  position: relative;
  overflow-y: auto;
}

.cover-inner {
  max-width: 1100px;
  width: 100%;
  text-align: center;
  margin: 0 auto;
}

.cover-badge-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.badge-primary {
  background: #dbeafe;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.badge-accent {
  background: #fef3c7;
  color: #b45309;
  border: 1px solid #fde68a;
}

.badge-dlp {
  background: #f3e8ff;
  color: #6b21a8;
  border: 1px solid #e9d5ff;
}

.cover-title {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.025em;
  line-height: 1.2;
  margin-bottom: 12px;
}

.cover-title span {
  background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.cover-sub {
  font-size: clamp(1rem, 2vw, 1.25rem);
  color: var(--text-muted);
  max-width: 760px;
  margin: 0 auto 32px;
}

.cover-chapters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 36px;
  text-align: left;
}

.cover-ch-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.cover-ch-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: #cbd5e1;
}

.cover-ch-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background-color: var(--ch-color, var(--primary));
}

.cover-ch-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.cover-ch-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--ch-color, var(--primary));
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cover-ch-sections {
  font-size: 11px;
  color: var(--text-light);
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
}

.cover-ch-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 4px;
}

.cover-ch-bm {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
}

.cover-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.cover-start-btn {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
  font-size: 18px;
  font-weight: 700;
  padding: 14px 42px;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.cover-start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.45);
  background: linear-gradient(135deg, #1d4ed8, #1e40af);
}

.cover-hint {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.kbd-badge {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-bottom: 2px solid #94a3b8;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-family: inherit;
  font-weight: 600;
  color: #475569;
}

/* ============================================================
   MAIN APP & TOPBAR
   ============================================================ */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background: #f1f5f9;
}

.hidden {
  display: none !important;
}

/* Topbar */
.topbar {
  height: 52px;
  min-height: 52px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  overflow: hidden;
}

.home-btn {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
  flex-shrink: 0;
}

.home-btn:hover {
  background: #e2e8f0;
}

.crumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crumb-ch {
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
}

.crumb-sep {
  color: #cbd5e1;
  flex-shrink: 0;
}

.crumb-sec {
  font-weight: 600;
  color: var(--text-main);
  flex-shrink: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.btn-icon:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

/* ============================================================
   STAGE & UNIFIED SLIDE ARCHITECTURE
   ============================================================ */
.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 14px 20px 0;
}

/* Unified slide container (Single Card Layout) */
.slide {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 20px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px 24px;
  overflow: hidden;
  animation: slidein 0.28s ease;
}

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

/* Left: Info & Concept Column */
.slide-info {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding-right: 6px;
}

.col-fit {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  transform-origin: top left;
}

/* Right: Visual Column */
.slide-visual {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(180deg, #fbfcfe, #f4f6fb);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  justify-content: flex-start; /* Prevents overflow clipping at top! */
}

.visual-host {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  transform-origin: top center;
  gap: 10px;
}

/* MathJax SVGs must maintain natural sizing */
.visual-host mjx-container svg {
  width: auto !important;
  height: auto !important;
  max-height: none !important;
  display: inline-block;
}

/* Diagrams SVG scale within container */
.visual-host svg {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

/* Slide Info Elements */
.slide-tag-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.slide-sec-pill {
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 12px;
  border-radius: var(--radius-full);
}

.slide-title {
  font-size: clamp(23px, 2.5vw, 30px);
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.25;
  margin-bottom: 12px;
}

.slide-points {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 11px;
  margin-bottom: 14px;
}

.slide-points li {
  position: relative;
  padding-left: 20px;
  font-size: 15.5px;
  color: #1e293b;
  line-height: 1.6;
}

.slide-points li::before {
  content: '•';
  position: absolute;
  left: 3px;
  top: -1px;
  color: var(--primary);
  font-size: 20px;
}

.k {
  font-weight: 700;
  color: var(--primary);
  background: rgba(37, 99, 235, 0.09);
  padding: 1px 6px;
  border-radius: 4px;
}

.k-red {
  font-weight: 700;
  color: #dc2626;
  background: #fef2f2;
  padding: 1px 6px;
  border-radius: 4px;
}

.formula-box {
  background: #f8fafc;
  border: 1.5px solid #cbd5e1;
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 12px 0;
  text-align: center;
  font-size: 16.5px;
}

.formula-box .formula-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 3px;
  letter-spacing: 0.5px;
}

.exam-tip {
  background: #fffbeb;
  border: 1.5px solid #fde68a;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  color: #92400e;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 10px;
}

.exam-tip-icon {
  font-weight: 800;
  font-size: 16px;
}

/* ============================================================
   BAD / GOOD COMPARISON CARDS
   ============================================================ */
.bad-good-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.bad-good-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.bad-card {
  background: var(--danger-bg);
  border: 1.5px solid var(--danger-border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  text-align: center;
}

.bad-card-header {
  font-size: 12px;
  font-weight: 800;
  color: var(--danger-text);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.good-card {
  background: var(--success-bg);
  border: 1.5px solid var(--success-border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  text-align: center;
}

.good-card-header {
  font-size: 12px;
  font-weight: 800;
  color: var(--success-text);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.bad-card-body, .good-card-body {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.45;
}

.bad-good-note {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 5px;
  font-weight: 500;
}

/* ============================================================
   CHAPTER DIVIDER SLIDES
   ============================================================ */
.slide.divider {
  grid-template-columns: 1fr;
  place-items: center;
  text-align: center;
  background: linear-gradient(135deg, var(--ch-bg1, #1e293b), var(--ch-bg2, #0f172a));
  color: #ffffff;
  border: none;
  padding: 36px;
  position: relative;
  overflow: hidden;
}

.divider-num {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--ch-color, #60a5fa);
  margin-bottom: 6px;
}

.divider-title {
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 800;
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}

.divider-bm {
  font-size: 18px;
  color: #cbd5e1;
  font-style: italic;
  margin-bottom: 22px;
}

.divider-sections {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 760px;
  margin-bottom: 28px;
}

.divider-sec-badge {
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 13px;
  color: #f1f5f9;
}

.divider-btn {
  background: var(--ch-color, var(--primary));
  color: #ffffff;
  border: none;
  border-radius: var(--radius-full);
  font-size: 15px;
  font-weight: 700;
  padding: 12px 32px;
  cursor: pointer;
  transition: transform 0.2s;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
}

.divider-btn:hover {
  transform: scale(1.05);
}

/* ============================================================
   BOTTOM BAR & NAVIGATION
   ============================================================ */
.bottombar {
  height: 52px;
  min-height: 52px;
  background: #ffffff;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: relative;
  z-index: 20;
}

.progress-container {
  position: absolute;
  top: -2px;
  left: 0;
  width: 100%;
  height: 3px;
  background: #e2e8f0;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.2s ease;
}

.nav-btn {
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.nav-btn:hover:not(:disabled) {
  background: var(--primary-hover);
}

.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.nav-btn.secondary {
  background: #f1f5f9;
  color: var(--text-main);
  border: 1px solid var(--border);
}

.nav-btn.secondary:hover:not(:disabled) {
  background: #e2e8f0;
}

.slide-counter {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

/* ============================================================
   TABLE OF CONTENTS (DRAWER)
   ============================================================ */
.toc-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(3px);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.toc-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.toc-drawer {
  position: fixed;
  top: 0;
  right: -360px;
  width: 360px;
  height: 100vh;
  background: #ffffff;
  box-shadow: var(--shadow-lg);
  z-index: 101;
  display: flex;
  flex-direction: column;
  transition: right 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.toc-drawer.active {
  right: 0;
}

.toc-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toc-header h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
}

.toc-close-btn {
  background: transparent;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
}

.toc-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
}

.toc-ch-group {
  margin-bottom: 14px;
}

.toc-ch-title {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 5px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toc-ch-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.toc-slide-item {
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: #334155;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.15s;
}

.toc-slide-item:hover {
  background: #f1f5f9;
}

.toc-slide-item.active {
  background: #eff6ff;
  color: var(--primary);
  font-weight: 700;
}

/* ============================================================
   INTERACTIVE WIDGET COMPONENTS
   ============================================================ */
.widget-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 4px;
}

.widget-badge {
  font-size: 12px;
  padding: 3px 9px;
  background: #e2e8f0;
  border-radius: 5px;
  color: #334155;
  font-weight: 700;
}

.control-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.control-label {
  font-size: 13.5px;
  font-weight: 600;
  color: #334155;
  display: flex;
  justify-content: space-between;
}

.control-val {
  font-weight: 800;
  color: var(--primary);
  font-size: 14px;
}

.styled-range {
  width: 100%;
  height: 6px;
  accent-color: var(--primary);
  cursor: pointer;
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab-btn {
  background: #ffffff;
  border: 1.5px solid var(--border);
  padding: 6px 13px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 700;
  color: #334155;
  cursor: pointer;
  transition: all 0.15s;
}

.tab-btn:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

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

.matrix-grid {
  display: inline-grid;
  grid-template-columns: repeat(2, 46px);
  gap: 6px;
  padding: 6px 10px;
  border-left: 2.5px solid #334155;
  border-right: 2.5px solid #334155;
  border-radius: 4px;
  background: #ffffff;
}

.matrix-input {
  width: 44px;
  height: 34px;
  text-align: center;
  font-size: 15px;
  font-weight: bold;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
}

.result-box {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 14px;
  line-height: 1.55;
}

/* ============================================================
   RESPONSIVE LAYOUT (Mobile, Tablet, Small Desktop)
   ============================================================ */
@media (max-width: 1024px) {
  .stage {
    padding: 10px 12px 0;
    overflow-y: auto;
  }
  .slide {
    grid-template-columns: 1fr;
    overflow-y: visible;
    min-height: auto;
    height: auto;
    gap: 16px;
    padding: 16px;
  }
  .slide-info {
    overflow: visible;
    min-height: auto;
  }
  .col-fit {
    transform: none !important;
  }
  .slide-visual {
    overflow: visible;
    min-height: 400px;
    height: auto;
  }
  .visual-host {
    transform: none !important;
    overflow: visible;
  }
}

@media (max-width: 640px) {
  .crumb {
    display: none;
  }
  .cover-title {
    font-size: 1.8rem;
  }
  .topbar {
    padding: 0 12px;
  }
  .bottombar {
    padding: 0 12px;
  }
}
