@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800;900&family=JetBrains+Mono:wght@500;700&display=swap');

:root {
  --ink: #111827;
  --muted: #4b5563;
  --faint: #9ca3af;
  --line: #e5e7eb;
  --paper: #f8fafc;
  --panel: #ffffff;
  --blue: #2563eb;
  --indigo: #4f46e5;
  --green: #059669;
  --amber: #d97706;
  --rose: #e11d48;
  --violet: #7c3aed;
  --teal: #0d9488;
  --cyan: #0284c7;
  --shadow-sm: 0 4px 14px rgba(15, 23, 42, 0.06);
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.10);
  --r: 20px;
  --ct: #2563eb;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 10% -10%, rgba(37, 99, 235, 0.08), transparent 60%),
    radial-gradient(1000px 700px at 100% 0%, rgba(124, 58, 237, 0.08), transparent 55%),
    radial-gradient(900px 700px at 90% 110%, rgba(5, 150, 105, 0.08), transparent 55%),
    var(--paper);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ===================== Cover Section ===================== */
.cover {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 40px 24px;
}

.cover-inner {
  max-width: 1080px;
  width: 100%;
  text-align: center;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.95);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 48px 40px 40px;
}

.cover-eyebrow {
  margin: 0 0 10px;
  color: var(--blue);
  font-weight: 800;
  letter-spacing: 0.18em;
  font-size: 13px;
  text-transform: uppercase;
}

.cover-title {
  margin: 0;
  font-size: clamp(38px, 6vw, 68px);
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: -0.02em;
  background: linear-gradient(125deg, var(--blue), var(--violet) 50%, var(--teal));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.cover-sub {
  margin: 14px 0 28px;
  color: var(--muted);
  font-size: clamp(15px, 2vw, 19px);
  font-weight: 600;
  line-height: 1.5;
}

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

.cover-card {
  border-radius: 16px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  border-top: 4px solid var(--ct);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  cursor: pointer;
}

.cover-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
}

.cover-card .cc-num {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--ct);
}

.cover-card .cc-title {
  font-size: 15px;
  font-weight: 800;
  margin: 4px 0 3px;
  color: var(--ink);
  line-height: 1.25;
}

.cover-card .cc-bm {
  font-size: 11.5px;
  color: var(--muted);
  font-style: italic;
  margin-bottom: 6px;
  line-height: 1.2;
}

.cover-card .cc-list {
  font-size: 11.5px;
  color: var(--faint);
  line-height: 1.45;
}

.cover-start {
  border: none;
  color: #fff;
  background: linear-gradient(125deg, var(--blue), var(--violet));
  padding: 16px 42px;
  font-size: 18px;
  font-weight: 800;
  border-radius: 999px;
  box-shadow: 0 14px 30px rgba(37, 99, 235, 0.32);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.cover-start:hover {
  transform: translateY(-2px);
  box-shadow: 0 20px 38px rgba(37, 99, 235, 0.42);
}

.cover-hint {
  margin: 20px 0 0;
  color: var(--faint);
  font-size: 12.5px;
}

/* ===================== Main Layout ===================== */
.app {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 58px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}

.home-btn {
  border: none;
  background: none;
  font-weight: 900;
  font-size: 16px;
  color: var(--blue);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 8px;
}

.home-btn:hover { background: rgba(37, 99, 235, 0.08); }

.crumb {
  flex: 1;
  color: var(--muted);
  font-weight: 600;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crumb b { color: var(--ink); font-weight: 800; }

.ghost-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  padding: 7px 14px;
  font-weight: 700;
  font-size: 13px;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s;
}

.ghost-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.body {
  flex: 1;
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  min-height: 0;
}

/* ===================== Table of Contents (TOC) ===================== */
.toc {
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  overflow-y: auto;
  padding: 12px 10px 40px;
}

.toc-chapter { margin-bottom: 6px; }

.toc-chead {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  font-weight: 800;
  font-size: 13px;
  color: var(--ct);
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.toc-chead:hover { background: rgba(37, 99, 235, 0.07); }
.toc-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ct); flex: none; }
.toc-items { display: none; padding-left: 6px; }
.toc-chapter.open .toc-items { display: block; }

.toc-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  border-left: 2px solid var(--line);
  padding: 6px 12px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.35;
  transition: all 0.15s;
}

.toc-item:hover { color: var(--ink); background: rgba(37, 99, 235, 0.05); }

.toc-item.active {
  color: var(--ct);
  font-weight: 800;
  border-left: 2px solid var(--ct);
  background: rgba(37, 99, 235, 0.08);
}

.toc-item .ti-sec {
  font-size: 10.5px;
  color: var(--faint);
  font-weight: 700;
  margin-right: 6px;
}

/* ===================== Slide Stage ===================== */
.stage {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px 20px 0;
}

@media (min-width: 1081px) {
  .stage { padding-right: 84px; }
}

.slide {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 22px 28px;
  overflow: hidden;
  animation: slidein 0.28s ease;
}

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

/* Chapter Divider Slides */
.slide.divider {
  grid-template-columns: 1fr;
  place-items: center;
  text-align: center;
  background: linear-gradient(135deg, var(--ct), color-mix(in srgb, var(--ct) 68%, #0f172a));
  color: #fff;
  border: none;
}

.divider .dv-num {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.25em;
  opacity: 0.88;
  text-transform: uppercase;
}

.divider .dv-title {
  font-size: clamp(34px, 5.5vw, 62px);
  font-weight: 900;
  margin: 10px 0 4px;
  line-height: 1.15;
}

.divider .dv-sub {
  font-size: clamp(16px, 2.2vw, 22px);
  font-weight: 500;
  opacity: 0.92;
  font-style: italic;
  margin-bottom: 24px;
}

.divider .dv-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 760px;
}

.divider .dv-chip {
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.35);
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
}

/* Left Column: Concept Info */
.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 center;
  width: 100%;
}

.col-fit > * {
  flex-shrink: 0 !important;
}

.col-fit > .example {
  margin-top: auto;
  flex-shrink: 0 !important;
}

.slide-info::-webkit-scrollbar,
.toc::-webkit-scrollbar,
.slide-visual::-webkit-scrollbar {
  width: 6px;
}

.slide-info::-webkit-scrollbar-thumb,
.toc::-webkit-scrollbar-thumb,
.slide-visual::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 6px;
}

.badge {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #fff;
  background: var(--ct);
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 8px;
}

.slide-title {
  font-size: clamp(20px, 2.3vw, 27px);
  font-weight: 900;
  line-height: 1.25;
  margin: 0 0 10px;
  color: var(--ink);
}

.formula {
  background: color-mix(in srgb, var(--ct) 7%, #fff);
  border: 1.5px solid color-mix(in srgb, var(--ct) 24%, #fff);
  border-radius: 12px;
  padding: 8px 14px 10px;
  margin-bottom: 12px;
  flex: none !important;
  flex-shrink: 0 !important;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden !important;
}

.formula .formula-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--ct);
  letter-spacing: 0.06em;
  margin-bottom: 3px;
  text-transform: uppercase;
}

.formula-tex {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 32px;
  width: 100%;
}

.formula mjx-container[display="true"] {
  margin: 3px 0 !important;
  padding: 0 !important;
  max-width: 100%;
  overflow-x: auto !important;
  overflow-y: hidden !important;
}

.points {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
}

.points li {
  position: relative;
  padding: 3px 0 3px 22px;
  font-size: 14.5px;
  line-height: 1.55;
  color: #334155;
}

.points li::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 10px;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--ct);
  transform: rotate(45deg);
}

.points li b { color: var(--ct); }
.points .k { font-weight: 800; color: var(--ct); }
.points .bm-term { color: var(--muted); font-style: italic; font-size: 0.92em; }

/* Example Box */
.example {
  margin-top: auto;
  border: 1px dashed color-mix(in srgb, var(--ct) 35%, var(--line));
  border-radius: 14px;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--ct) 4%, #fff);
}

.ex-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  color: var(--ct);
  font-size: 13.5px;
  margin-bottom: 6px;
}

.ex-head::before { content: "✎"; }

.ex-q {
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
}

.ex-toggle {
  margin-top: 10px;
  border: 1px solid var(--ct);
  color: var(--ct);
  background: #fff;
  border-radius: 999px;
  padding: 5px 14px;
  font-weight: 700;
  font-size: 12px;
  transition: all 0.15s;
}

.ex-toggle:hover { background: var(--ct); color: #fff; }

.ex-sol { margin-top: 10px; display: none; }
.ex-sol.show { display: block; animation: slidein 0.2s ease; }
.ex-sol ol { margin: 0; padding-left: 18px; }
.ex-sol li { font-size: 13.5px; line-height: 1.6; margin-bottom: 3px; color: #1e293b; }

.ex-ans {
  margin-top: 8px;
  font-weight: 800;
  color: #fff;
  background: var(--ct);
  display: inline-block;
  padding: 5px 14px;
  border-radius: 8px;
  font-size: 13.5px;
}

/* Right Column: Visual Area */
.slide-visual {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(180deg, #ffffff, #f8fafc);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}

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

.visual-host > * { margin: auto; max-width: 100%; }

.visual-host svg {
  width: 100%;
  height: auto;
  max-height: 100%;
  display: block;
}

.slide-visual:has(.ictrl) .visual-host {
  justify-content: flex-start;
}

.slide-visual:has(.ictrl) .visual-host > * {
  margin-top: 0;
}

.slide-visual:has(.ictrl) .visual-host svg {
  max-height: none;
}

.visual-host mjx-container svg {
  width: auto !important;
  height: auto !important;
  max-height: none !important;
  display: inline-block;
}

.visual-caption {
  margin-top: 10px;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.45;
}

/* Interactive Controls */
.ictrl {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.95);
  border: 1.5px solid var(--ct);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

.ictrl label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.ictrl input[type="range"] {
  width: 130px;
  accent-color: var(--ct);
}

.ictrl .step-txt {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.4;
}

.ibtn {
  border: 1px solid var(--ct);
  color: var(--ct);
  background: #fff;
  border-radius: 999px;
  padding: 5px 14px;
  font-weight: 700;
  font-size: 12px;
  transition: all 0.15s;
}

.ibtn:hover, .ibtn.active {
  background: var(--ct);
  color: #fff;
}

.ival {
  font-weight: 800;
  color: var(--ct);
  font-size: 14px;
  min-width: 22px;
  text-align: center;
  font-family: 'JetBrains Mono', monospace;
}

/* Bottom Control Bar */
.controlbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 4px 12px;
}

.nav-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 12px;
  padding: 9px 20px;
  font-weight: 800;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
  color: var(--ink);
  transition: all 0.15s;
}

.nav-btn:hover:not(:disabled) {
  border-color: var(--blue);
  color: var(--blue);
}

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

.progress {
  flex: 1;
  max-width: 440px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.progress-track {
  flex: 1;
  height: 7px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--blue), var(--violet));
  border-radius: 999px;
  transition: width 0.25s ease;
}

.progress-text {
  font-weight: 800;
  font-size: 12.5px;
  color: var(--muted);
  min-width: 58px;
  text-align: right;
  font-family: 'JetBrains Mono', monospace;
}

/* Teacher Dock */
.dock {
  position: fixed;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 6px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.dbtn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  display: grid;
  place-items: center;
  transition: all 0.15s;
}

.dbtn svg { width: 20px; height: 20px; }
.dbtn:hover { background: rgba(37, 99, 235, 0.1); color: var(--blue); }
.dbtn.active { background: var(--blue); color: #fff; }
#dkLaser.active { background: var(--rose); color: #fff; }
#dkPen.active { background: var(--green); color: #fff; }

.dsep { height: 1px; background: var(--line); margin: 2px 4px; }

.dcolors {
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  padding: 3px 0;
}

.dcolor {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line);
  background: var(--sc);
  cursor: pointer;
  padding: 0;
}

.dcolor.active {
  box-shadow: 0 0 0 3px var(--sc);
  transform: scale(1.1);
}

.derase { width: 32px; height: 32px; }
.derase.active { background: var(--amber); color: #fff; }

/* Pen Canvas & Laser Dot */
.pen-canvas {
  position: fixed;
  inset: 0;
  z-index: 800;
  pointer-events: none;
  touch-action: none;
}

.app.pen-on .body { cursor: crosshair; }
.app.laser-on .body { cursor: none; }

.laser-dot {
  position: fixed;
  left: 0;
  top: 0;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 1200;
  background: radial-gradient(circle, rgba(255, 40, 70, 0.98), rgba(255, 0, 0, 0.55) 55%, rgba(255, 0, 0, 0) 75%);
  box-shadow: 0 0 14px 4px rgba(255, 0, 50, 0.6);
}

/* Sidebar Toggle State */
.app.toc-collapsed .toc { display: none; }
.app.toc-collapsed .body { grid-template-columns: 1fr; }

/* Zoom Full-Screen Modal */
.zoom-modal {
  position: fixed;
  inset: 0;
  z-index: 700;
  background: #ffffff;
  overflow: auto;
  padding: 80px clamp(20px, 5vw, 70px) 50px;
}

.zoom-modal.hidden, .zoom-bar.hidden { display: none !important; }

.zoom-body {
  position: relative;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.zoom-q {
  font-size: clamp(20px, 3vw, 36px);
  line-height: 1.65;
  color: var(--ink);
  font-weight: 600;
}

.zoom-sol {
  display: none;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 2px dashed #cbd5e1;
}

.zoom-sol.show { display: block; }
.zoom-sol ol {
  font-size: clamp(17px, 2.4vw, 28px);
  line-height: 1.85;
  padding-left: 1.3em;
  margin: 0;
}

.zoom-sol li { margin-bottom: 8px; }
.zoom-ans {
  margin-top: 18px;
  font-size: clamp(18px, 2.5vw, 30px);
  font-weight: 800;
  color: #fff;
  background: var(--ct);
  display: inline-block;
  padding: 8px 24px;
  border-radius: 12px;
}

.zoom-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1300;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-bottom: 3px solid var(--ct, #2563eb);
}

.zoom-badge {
  flex: 1;
  font-weight: 800;
  color: var(--ct, #2563eb);
  font-size: clamp(13px, 1.8vw, 17px);
}

.zoom-btn {
  border: 1.5px solid var(--ct, #2563eb);
  color: var(--ct, #2563eb);
  background: #fff;
  border-radius: 999px;
  padding: 7px 18px;
  font-weight: 800;
  font-size: 14px;
}

.zoom-btn:hover { background: var(--ct, #2563eb); color: #fff; }
.zoom-x { border-color: #e11d48; color: #e11d48; }
.zoom-x:hover { background: #e11d48; color: #fff; }

.vis-zoom {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 6;
  border: 1.5px solid var(--ct);
  color: var(--ct);
  background: rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 11.5px;
  font-weight: 800;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.vis-zoom:hover { background: var(--ct); color: #fff; }

.ex-zoom {
  margin-left: auto;
  border: 1px solid var(--ct);
  color: var(--ct);
  background: #fff;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 800;
}

.ex-zoom:hover { background: var(--ct); color: #fff; }

/* Responsive Media Queries */
@media (max-width: 1080px) {
  .body { grid-template-columns: 1fr; }
  .toc {
    position: fixed;
    inset: 58px 0 0 0;
    z-index: 40;
    width: min(320px, 86vw);
    border-right: 1px solid var(--line);
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    background: #fff;
  }
  .toc.open { transform: none; box-shadow: var(--shadow); }
  .slide {
    grid-template-columns: 1fr;
    overflow-y: auto !important;
    height: auto;
    min-height: 100%;
  }
  .slide-info { overflow: visible !important; }
  .slide-visual { overflow: visible !important; min-height: 320px; }
  .col-fit { transform: none !important; }
}

@media (max-width: 640px) {
  .stage { padding: 10px 10px 0; }
  .slide { padding: 16px; gap: 16px; }
  .nav-btn { padding: 8px 12px; font-size: 13px; }
}
