/* ============================================================
   MathBoard — Modern UI/UX Overhaul
   Copyright © 2026 Waseem Akhlaque. MIT License.
   ============================================================ */

/* ---------- Design Tokens ---------- */
:root {
  /* Core palette */
  --bg: #f0f4f8;
  --bg-gradient: linear-gradient(135deg, #f0f4f8 0%, #e2e8f0 50%, #dbe4ee 100%);
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --text: #0f172a;
  --text-2: #334155;
  --text-3: #64748b;
  --text-muted: #94a3b8;

  /* Brand */
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-light: #dbeafe;
  --accent-glow: rgba(59, 130, 246, 0.15);
  --success: #10b981;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --purple: #8b5cf6;
  --purple-light: #ede9fe;
  --orange: #f97316;
  --orange-light: #ffedd5;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
  --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.15);

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 350ms;

  /* Layout */
  --line: var(--border);  /* alias for legacy calc sub-styles */
  --toolbar-height: 48px;
  --section-strip-height: 44px;
  --page-strip-height: 92px;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-gradient);
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
}

.hidden { display: none !important; }
.view { height: 100%; }

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

/* ---------- Buttons ---------- */
button {
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  transition: all var(--duration-fast) var(--ease);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

button:hover {
  background: var(--surface-2);
  border-color: var(--text-muted);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

button:active {
  transform: translateY(0) scale(0.98);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

button.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
  transform: translateY(-1px);
}

button.danger {
  color: var(--danger);
  border-color: var(--danger-light);
  background: var(--danger-light);
}

button.danger:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-3);
}

button.ghost:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-2);
  transform: none;
  box-shadow: none;
}

/* ---------- Library View ---------- */
#library {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-gradient);
}

.lib-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding: max(env(safe-area-inset-top), 20px) 28px 12px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.lib-head-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.lib-logo {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  flex: none;
  box-shadow: var(--shadow-sm);
}

.lib-head h1 {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.lib-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-3);
  padding: 3px;
  border-radius: var(--radius-lg);
}

.lib-tab {
  background: transparent;
  border: none;
  color: var(--text-3);
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-md);
  transition: all var(--duration-fast) var(--ease);
}

.lib-tab:hover {
  background: rgba(255, 255, 255, 0.5);
  color: var(--text-2);
  transform: none;
  box-shadow: none;
}

.lib-tab.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.lib-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.lib-head.lib-lesson .lib-act-paper { display: none; }
.lib-head.lib-paper .lib-act-lesson { display: none; }
/* Keep + New lesson visible on both tabs */
.lib-head.lib-paper .lib-act-lesson.primary { display: inline-flex; }

.lib-file-btn {
  cursor: pointer;
  user-select: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}
.lib-file-btn:hover { background: var(--surface-2, #f4f6f8); }

/* Safari ignores programmatic .click() on display:none file inputs — keep off-screen instead */
.file-offscreen {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

.boot-error {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  padding: 10px 16px;
  background: #7f1d1d;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}
.boot-error.hidden { display: none !important; }

.lib-search {
  display: block;
  margin: 0 28px 4px;
  max-width: 360px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  font: inherit;
  background: var(--surface);
}

/* ---------- Notebook Grid ---------- */
.nb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
  padding: 20px 28px;
  overflow-y: auto;
  flex: 1;
  align-content: start;
  /* iPad Safari computes stretched grid-row heights too short when the card
     contains an aspect-ratio thumb — the body (with Delete/Rename) fell past
     the card's overflow:hidden edge. Size each card to its own content. */
  align-items: start;
}

.nb-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all var(--duration-normal) var(--ease);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
}

.nb-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent-light);
}

.nb-thumb {
  aspect-ratio: 1 / 1.414;
  flex: none;
  background: var(--surface-3);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.nb-thumb::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, transparent 60%, rgba(0,0,0,0.03));
  pointer-events: none;
}

.nb-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.nb-thumb-blank {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.nb-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: none;
}

.nb-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  line-height: 1.3;
}

.nb-meta {
  font-size: 12px;
  color: var(--text-3);
}

.nb-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  margin-bottom: 4px;
  width: fit-content;
}

.nb-badge.paper {
  background: var(--accent-light);
  color: var(--accent);
}

.nb-badge.lesson {
  background: var(--success-light);
  color: var(--success);
}

/* Always visible — hover-reveal hid Delete/Rename on iPad (no hover on touch).
   Wraps to a second row: five buttons overflow the card width otherwise,
   which clipped Delete off the card edge. */
.nb-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.nb-actions button {
  flex: 1 1 auto;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

.nb-actions .open {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.nb-actions .exp {
  font-size: 12px;
}

.muted {
  color: var(--text-3);
}

.footnote {
  padding: 10px 28px 16px;
  font-size: 13px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
}

.sync-status {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}
.sync-foot-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}
.sync-foot-link:hover { color: var(--accent-dark, #1a4fa8); }
.mb-version { font-size: 11px; color: var(--text-3); opacity: 0.7; }

/* ---------- Editor View ---------- */
#editor {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-gradient);
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  z-index: 10;
}

.tbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  padding: 6px 14px;
  padding-left: max(env(safe-area-inset-left), 14px);
}

.tbar-top {
  padding-top: max(env(safe-area-inset-top), 6px);
  min-height: var(--toolbar-height);
}

.tbar-tools {
  border-top: 1px solid var(--border-light);
  background: rgba(248, 250, 252, 0.6);
  padding: 6px 14px;
}

.spacer { flex: 1; }

.tabs {
  display: flex;
  gap: 2px;
  margin-left: 8px;
  background: var(--surface-3);
  padding: 2px;
  border-radius: var(--radius-md);
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-3);
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: all var(--duration-fast) var(--ease);
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.5);
  color: var(--text-2);
  transform: none;
  box-shadow: none;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.tbar-tools .group:not(.show) { display: none; }

.toolbar button {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-2);
  padding: 7px 13px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.toolbar button:hover {
  background: var(--surface-2);
  border-color: var(--text-muted);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.toolbar button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.toolbar button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-3);
}

.toolbar button.ghost:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-2);
}

.toolbar .group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.toolbar .tool {
  position: relative;
}

.toolbar .tool.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.25);
}

.toolbar .tool.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 16px;
  height: 3px;
  background: var(--accent);
  border-radius: var(--radius-full);
}

.nb-name {
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  width: 180px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  transition: border-color var(--duration-fast) var(--ease);
}

.nb-name:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.nb-title-present {
  display: none;
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-label {
  min-width: 52px;
  text-align: center;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* ---------- Classroom layout: app bar + left tool rail + stage ---------- */
.appbar-logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  flex: none;
  box-shadow: var(--shadow-sm);
}

.editor-main {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.tool-rail {
  flex: none;
  width: 178px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 12px 18px;
  border-top: none;
  border-right: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  overflow-y: auto;
  overflow-x: hidden;
  transition: width var(--duration-normal) var(--ease), padding var(--duration-normal) var(--ease);
}

.tool-rail.collapsed {
  width: 0;
  padding: 0;
  border-right: none;
  overflow: hidden;
}

.rail-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}

.rail-head .tabs {
  margin: 0;
  flex: 1;
}

.rail-head .tab-btn {
  flex: 1;
  padding: 6px 4px;
  font-size: 12px;
}

.rail-head .rail-icon {
  flex: none;
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  color: var(--text-3);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.rail-head .rail-icon:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-light);
  transform: none;
  box-shadow: none;
}

.rail-reopen {
  position: absolute;
  left: 8px;
  top: 10px;
  z-index: 6;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 16px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  display: none;
}

.tool-rail.collapsed ~ .rail-reopen { display: inline-flex; }

.tool-rail .group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--border-light);
}

.tool-rail .group:last-child { border-bottom: none; padding-bottom: 0; }

.tool-rail .group > button:not(.swatch) {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 10px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.tool-rail .tool { position: relative; }

.tool-rail .tool.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.25);
}

.tool-rail .ctl-label { flex: 1 1 100%; }
.tool-rail select { flex: 1 1 100%; }

.paper-toggle {
  display: flex;
  flex: 1 1 100%;
  gap: 4px;
}
.paper-toggle-btn {
  flex: 1;
  min-height: 34px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
}
.paper-toggle-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.install-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 16px 12px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--accent-border, rgba(59, 130, 246, 0.35));
  background: var(--accent-soft, rgba(59, 130, 246, 0.1));
  font-size: 14px;
  line-height: 1.45;
}
.install-banner.hidden { display: none; }
.install-banner-actions {
  display: flex;
  flex-shrink: 0;
  gap: 8px;
}
.install-banner-actions button {
  white-space: nowrap;
}

.rail-pagenav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1 1 100%;
}

.rail-pagenav button { flex: none; width: 36px; }
.rail-pagenav .page-label { flex: 1; }

.tool-rail .width-group { flex-wrap: wrap; }
.tool-rail .width-group input[type=range] { flex: 1 1 90px; }

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* ---------- Section Tabs ---------- */
.section-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 6px 14px 6px max(env(safe-area-inset-left), 14px);
  min-height: var(--section-strip-height);
}

.section-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  flex: 1;
  scrollbar-width: none;
}

.section-tabs::-webkit-scrollbar { display: none; }

.section-tab {
  flex: none;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-3);
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all var(--duration-fast) var(--ease);
  cursor: pointer;
}

.section-tab:hover {
  background: var(--surface-2);
  color: var(--text-2);
}

.section-tab.active {
  background: var(--surface);
  border-color: var(--border);
  border-bottom-color: var(--surface);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 -2px 6px rgba(59, 130, 246, 0.08);
}

.section-add {
  flex: none;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-3);
  padding: 6px 12px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  transition: all var(--duration-fast) var(--ease);
}

.section-add:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

/* ---------- Page Thumbnail Strip ---------- */
.page-strip {
  display: flex;
  align-items: stretch;
  gap: 8px;
  background: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 8px 14px 8px max(env(safe-area-inset-left), 14px);
  min-height: var(--page-strip-height);
}

.page-thumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  flex: 1;
  scroll-snap-type: x proximity;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.page-thumb {
  flex: none;
  position: relative;
  width: 56px;
  height: 79px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0;
  overflow: hidden;
  background: var(--surface);
  scroll-snap-align: center;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease);
}

.page-thumb:hover {
  border-color: var(--text-muted);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.page-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

.page-thumb.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.page-thumb.pdf::after {
  content: 'PDF';
  position: absolute;
  top: 3px;
  right: 3px;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.3px;
  background: var(--accent);
  color: #fff;
  padding: 1px 4px;
  border-radius: 3px;
}

.page-thumb-acts {
  position: absolute;
  top: 2px; left: 2px; right: 2px;
  display: flex;
  justify-content: space-between;
  gap: 1px;
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease);
  z-index: 2;
}
.page-thumb:hover .page-thumb-acts { opacity: 1; }
.pt-act {
  width: 12px; height: 14px;
  padding: 0;
  font-size: 9px;
  line-height: 1;
  border: none;
  border-radius: 3px;
  background: rgba(15, 23, 42, 0.82);
  color: #fff;
}
.pt-act:hover { background: var(--accent); transform: none; box-shadow: none; }

.section-tab { position: relative; }
.sec-del {
  margin-left: 8px;
  display: inline-block;
  width: 16px; height: 16px;
  line-height: 14px;
  text-align: center;
  border-radius: 50%;
  font-size: 13px;
  color: var(--text-3);
  background: var(--surface-3);
}
.sec-del:hover { background: var(--danger); color: #fff; }

.page-thumb-num {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  font-size: 10px;
  font-weight: 600;
  text-align: center;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.55));
  padding: 8px 2px 2px;
  pointer-events: none;
}

.strip-add {
  flex: none;
  width: 44px;
  align-self: center;
  background: var(--surface-3);
  border: 1px dashed var(--border);
  color: var(--text-3);
  font-size: 22px;
  line-height: 1;
  border-radius: var(--radius-sm);
  min-height: 56px;
  transition: all var(--duration-fast) var(--ease);
}

.strip-add:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

/* ---------- Live Demo bar ---------- */
.demo-bar {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(31, 39, 51, 0.94);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-xl);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.demo-bar.hidden { display: none; }
.demo-title { font-size: 12px; font-weight: 600; color: #cdd7e3; letter-spacing: 0.3px; }
.demo-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #fff;
  padding: 6px 12px;
  font-size: 13px;
  border-radius: var(--radius-full);
}
.demo-btn:hover { background: rgba(255, 255, 255, 0.18); border-color: rgba(255, 255, 255, 0.3); }
.demo-btn.brand-toggle-active { background: var(--accent) !important; border-color: var(--accent) !important; }
.demo-x { padding: 6px 10px; }

.collab-bar { bottom: 58px; gap: 12px; }
.collab-status { font-size: 12px; font-weight: 700; color: #7dffb3; }
.collab-status[data-state="connecting"] { color: #ffd27d; }
.collab-status[data-state="offline"],
.collab-status[data-state="error"] { color: #ff8a8a; }
.collab-status[data-state="live"] { color: #7dffb3; }
.collab-hint { font-size: 11px; color: #aab4c0; }
.collab-cursors {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 12;
  overflow: hidden;
}
.collab-cursor {
  position: absolute;
  top: 0;
  left: 0;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: #d23b3b;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  transform-origin: 0 0;
}
.demo-slab { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #cdd7e3; }
.demo-slab input[type=range] { width: 180px; }
.demo-slab span { width: 44px; text-align: right; font-variant-numeric: tabular-nums; }
.demo-legacy { margin-left: 8px; padding-left: 10px; border-left: 1px solid rgba(255,255,255,0.2); }

.scene-steps {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: min(320px, 40vw);
  overflow-x: auto;
  padding: 2px 0;
}
.scene-chip {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #e8eef5;
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 999px;
  cursor: pointer;
}
.scene-chip:hover { background: rgba(255, 255, 255, 0.16); }
.scene-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.scene-next-hotspot {
  position: fixed;
  right: 24px;
  bottom: 28px;
  z-index: 30;
  min-width: 120px;
  min-height: 56px;
  padding: 14px 28px;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 999px;
  box-shadow: 0 8px 28px rgba(37, 102, 200, 0.45);
  cursor: pointer;
  touch-action: manipulation;
}
.scene-next-hotspot:hover { filter: brightness(1.08); }
.scene-next-hotspot.hidden { display: none; }
#editor.present-mode .scene-next-hotspot:not(.hidden) { display: block; }

/* ---------- Present Mode (broadcast / screen-share) ---------- */
#editor.present-mode .present-hide { display: none !important; }
#editor.present-mode .present-only { display: flex !important; }

#editor.present-mode .toolbar {
  background: rgba(15, 23, 42, 0.92);
  border-bottom-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

#editor.present-mode .tbar-top {
  min-height: 44px;
  padding-top: max(env(safe-area-inset-top), 8px);
  padding-bottom: 8px;
  gap: 8px;
}

#editor.present-mode .tbar-top button {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
}

#editor.present-mode .tbar-top button:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.2);
  color: #fff;
}

#editor.present-mode .nb-title-present {
  display: block !important;
  flex: 1;
  max-width: none;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  color: #f8fafc;
  letter-spacing: -0.02em;
}

#editor.present-mode #present-toggle {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
  font-weight: 600;
}

#editor.present-mode #brand-toggle.brand-toggle-active {
  background: var(--accent);
  border-color: var(--accent);
}

#editor.present-mode .editor-main { position: relative; }

#editor.present-mode .tool-rail {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 12;
  width: 188px;
  border-right: none;
  box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

#editor.present-mode .tool-rail .group > button:not(.swatch),
#editor.present-mode .tool-rail .geo-btn,
#editor.present-mode .tool-rail .pen-btn {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
}

#editor.present-mode .tool-rail .tool.active,
#editor.present-mode .tool-rail .pen-btn.active,
#editor.present-mode .tool-rail .geo-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#editor.present-mode .tool-rail .ctl-label,
#editor.present-mode .tool-rail label,
#editor.present-mode .tool-rail .width-group {
  color: #94a3b8;
}

#editor.present-mode .tool-rail .rail-head .tab-btn,
#editor.present-mode .tool-rail .rail-head .rail-icon,
#editor.present-mode .tool-rail .paper-toggle-btn,
#editor.present-mode .tool-rail .rail-pagenav button {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
}

#editor.present-mode .tool-rail .rail-head .tab-btn.active,
#editor.present-mode .tool-rail .paper-toggle-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#editor.present-mode .tool-rail select {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
  border-radius: 6px;
  padding: 6px 8px;
}

#editor.present-mode .tool-rail .page-label { color: #e2e8f0; }

#editor.present-mode .tool-rail.collapsed {
  width: 0;
  padding: 0;
  overflow: hidden;
  box-shadow: none;
}

#editor.present-mode .rail-reopen { display: none !important; }

#editor.present-mode .present-rail-toggle {
  display: inline-flex;
}

#editor.present-mode .present-hud {
  display: block;
}

#editor.present-mode .canvas-wrap {
  background: radial-gradient(ellipse at 50% 40%, #1e293b 0%, #0b1120 55%, #020617 100%);
}

#editor.present-mode .page-strip,
#editor.present-mode .section-strip { display: none !important; }

#editor.present-mode .pen-group .pen-btn { padding: 9px 14px; font-size: 13px; }

#editor.present-mode .tbar-tools .swatch { width: 34px; height: 34px; }
#editor.present-mode .tbar-tools .swatch-more { width: 34px; height: 34px; }

#editor.present-mode .brand {
  left: max(env(safe-area-inset-left), 20px);
  bottom: max(env(safe-area-inset-bottom), 72px);
  border-radius: 14px;
  padding: 10px 18px 10px 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

#editor.present-mode .brand-photo { width: 56px; height: 56px; }
#editor.present-mode .brand-name { font-size: 17px; }

.present-hud,
.present-rail-toggle { display: none; }

.present-hud {
  position: absolute;
  left: 50%;
  bottom: max(env(safe-area-inset-bottom), 16px);
  transform: translateX(-50%);
  z-index: 6;
  pointer-events: none;
}

.present-hud-inner {
  display: flex;
  align-items: center;
  gap: 4px;
  pointer-events: auto;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 6px 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.present-hud-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.08);
  color: #f1f5f9;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.present-hud-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  transform: scale(1.05);
}

.present-hud-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 120px;
  padding: 0 8px;
}

.present-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.present-section-label:empty { display: none; }

.present-page-label {
  font-size: 15px;
  font-weight: 700;
  color: #f8fafc;
  font-variant-numeric: tabular-nums;
}

.present-rail-toggle {
  position: absolute;
  left: max(env(safe-area-inset-left), 16px);
  top: 16px;
  z-index: 7;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(15, 23, 42, 0.88);
  color: #f1f5f9;
  font-size: 18px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.present-rail-toggle:hover {
  background: rgba(30, 41, 59, 0.95);
  transform: scale(1.05);
}

/* Keep the close toggle visible and tappable while the rail is open —
   otherwise the idle fade strands the rail with no way to dismiss it.
   The open rail (z-index 12) would cover the toggle's resting spot, so
   slide it past the rail's right edge and stack it above. */
#editor.present-mode.present-rail-open .present-rail-toggle {
  opacity: 0.9;
  pointer-events: auto;
  left: calc(max(env(safe-area-inset-left), 12px) + 210px);
  z-index: 13;
}

/* Rail tabs (Draw / Maths / Page) restyled for the dark present chrome. */
#editor.present-mode .rail-head { border-color: rgba(255, 255, 255, 0.12); }
#editor.present-mode .rail-head .tab-btn {
  background: rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  border-color: rgba(255, 255, 255, 0.12);
}
#editor.present-mode .rail-head .tab-btn.active { background: #2566c8; color: #fff; }
#editor.present-mode .rail-head .rail-icon {
  background: rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  border-color: rgba(255, 255, 255, 0.12);
}

/* Legacy present-mode rules (kept for tool sizing) */
#editor.present-mode .tbar-tools { padding-top: 12px; padding-bottom: 12px; }
#editor.present-mode .tbar-tools .group.show { gap: 8px; }
#editor.present-mode .tool-rail .group > button:not(.swatch) {
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 500;
}

/* P1: Auto-hide chrome in present mode (idle 3s) */
#editor.present-mode.present-idle-active .toolbar {
  opacity: 1;
  pointer-events: auto;
  transition: opacity 0.3s ease-in;
}
#editor.present-mode:not(.present-idle-active) .toolbar,
#editor.present-mode:not(.present-idle-active):not(.present-rail-open) .present-rail-toggle {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease-out 0.1s;
}
#editor.present-mode:not(.present-idle-active) .present-hud {
  opacity: 0.45;
  transition: opacity 0.4s ease-out 0.1s;
}
#editor.present-mode:not(.present-idle-active) .present-hud-inner {
  pointer-events: auto;
}
#editor.present-mode:not(.present-idle-active) .brand {
  opacity: 0.5;
  transition: opacity 0.6s ease-out;
}

/* P1: Hide collab bar in present mode */
#editor.present-mode #collab-bar { display: none !important; }

/* P1: Page transition fade */
.present-mode-fade {
  animation: presentPageIn 0.14s ease-out;
}
@keyframes presentPageIn {
  from { opacity: 0.35; }
  to { opacity: 1; }
}

/* P1: Laser pointer cursor */
.cur-laser { cursor: none !important; }

/* P2: Delete selection — visible in present mode with iPad-friendly size */
#editor.present-mode #delete-selection:not(.hidden) {
  display: inline-flex !important;
  min-width: 52px;
  min-height: 44px;
  padding: 12px 16px;
  font-size: 15px;
  align-items: center;
  justify-content: center;
}

/* ---------- Panel Menu ---------- */
.panel-menu-wrap { position: relative; display: none; }

.panel-drop {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  z-index: 30;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 6px;
  min-width: 180px;
  box-shadow: var(--shadow-xl);
  animation: dropIn var(--duration-fast) var(--ease);
}

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.panel-drop button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text-2);
  padding: 10px 14px;
  font-size: 14px;
  border-radius: var(--radius-sm);
  transition: all var(--duration-fast) var(--ease);
}

.panel-drop button:hover {
  background: var(--surface-2);
  color: var(--accent);
}

.panel-btns {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

/* ---------- Floating Panels ---------- */
#graph.gpanel { top: 88px; right: 20px; }
#mech.panel-mech { top: 88px; right: 20px; }
#cplx.panel-cplx { top: 88px; right: 330px; }
#calculus.panel-calculus { top: 88px; right: 330px; }
#symbolic.panel-symbolic { top: 88px; left: 20px; width: min(320px, calc(100vw - 40px)); }
#algebra.panel-algebra { top: 88px; left: 360px; width: min(320px, calc(100vw - 40px)); }
#rationals.panel-rationals { top: 88px; left: 700px; width: min(300px, calc(100vw - 40px)); }
.sym-btns { display: flex; gap: 8px; margin-top: 8px; }
.sym-btns .ck { flex: 1; }
.cal-row2, .cal-row3 { display: flex; gap: 8px; }
.cal-row2 span, .cal-row3 span { flex: 1; }
.cal-row2 .mech-in, .cal-row3 .mech-in { width: 100%; }
.cal-tabs .mech-tab { padding: 6px 8px; font-size: 12px; }
.stats-panel { left: 20px; bottom: 20px; }
.calc { right: 20px; bottom: 20px; }

/* ---------- MathLive ---------- */
math-field.calc-expr {
  width: 100%;
  box-sizing: border-box;
  background: transparent;
  color: var(--text);
  border: none;
  padding: 2px 0 0;
  font-size: 17px;
  min-height: 28px;
}

math-field.calc-expr:focus-within { outline: none; }

/* ---------- Sync Dialog ---------- */
.sync-dialog {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  animation: fadeIn var(--duration-normal) var(--ease);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

#new-lesson-dialog { z-index: 110; }

.sync-box {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 28px 30px;
  width: min(420px, 92vw);
  box-shadow: var(--shadow-xl);
  animation: slideUp var(--duration-normal) var(--ease-bounce);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.sync-box h3 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.sync-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.sync-auth-btns { margin-top: 8px; margin-bottom: 4px; }
.sync-user { margin: 0 0 8px; font-size: 13px; }

/* in-app dialogs (replace native alert/confirm/prompt — broken in iOS PWAs) */
.mb-modal { z-index: 300; }
.mb-modal-msg { margin: 0 0 2px; font-size: 14px; line-height: 1.5; color: var(--text); }
.mb-modal-input { width: 100%; margin-top: 12px; box-sizing: border-box; }
.mb-toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(16px);
  background: rgba(15, 23, 42, 0.94);
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  max-width: min(440px, 90vw);
  text-align: center;
  box-shadow: var(--shadow-xl);
  z-index: 400;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}
.mb-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .tbar-top .panel-btns { display: none; }
  .panel-menu-wrap { display: block; }
  .tbar-top button { padding: 7px 9px; font-size: 12px; }
  .tbar-tools .tool { padding: 7px 10px; font-size: 12px; }
  .nb-name { width: 110px; }
  #cplx.panel-cplx { right: 12px; top: auto; bottom: 80px; max-height: 45vh; }
  #calculus.panel-calculus { right: 12px; top: auto; bottom: 80px; max-height: 45vh; }
  .calc { width: min(328px, calc(100vw - 24px)); right: 12px; bottom: 12px; }
  .calc.casio { width: min(360px, calc(100vw - 16px)); right: 8px; }
  .stats-panel { width: min(340px, calc(100vw - 24px)); left: 12px; bottom: 12px; }
  .nb-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; padding: 14px 16px; }
  .lib-head { padding: max(env(safe-area-inset-top), 14px) 16px 10px; }
}

/* On narrow screens, the left tool rail becomes a horizontal scrolling bar on top. */
@media (max-width: 760px) {
  .editor-main { flex-direction: column; }
  .tool-rail {
    width: auto;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 8px;
    padding: 8px 12px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    max-height: 42vh;
  }
  .tool-rail.collapsed { width: auto; height: 0; max-height: 0; padding: 0; border-bottom: none; }
  .tool-rail.collapsed ~ .rail-reopen { display: inline-flex; }
  .rail-head {
    flex: none;
    flex-direction: column;
    gap: 6px;
    padding: 0 8px 0 0;
    border-bottom: none;
    border-right: 1px solid var(--border-light);
  }
  .tool-rail .group {
    flex-wrap: nowrap;
    flex: none;
    padding: 0 8px 0 0;
    border-bottom: none;
    border-right: 1px solid var(--border-light);
  }
  .tool-rail .group:last-child { border-right: none; }
  .tool-rail .ctl-label,
  .tool-rail select,
  .rail-pagenav { flex: none; }
  .rail-reopen { top: 8px; }
}

@media (max-width: 600px) {
  .tbar-top .present-hide:not(.panel-menu-wrap) { display: none !important; }
  .geo-group { flex-wrap: nowrap; }
  .nb-grid { grid-template-columns: 1fr; }
  .lib-head { flex-direction: column; align-items: stretch; }
  .lib-head-left { flex-direction: column; align-items: stretch; gap: 10px; }
  .lib-actions { flex-wrap: wrap; }
}

/* ---------- Controls ---------- */
.width-group {
  color: var(--text-3);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.width-group input[type=range] {
  width: 80px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: var(--radius-full);
  outline: none;
}

.width-group input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.width-group span {
  min-width: 18px;
  text-align: right;
  color: var(--text-2);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease);
}

select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.finger {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-3);
  font-size: 13px;
}

/* ---------- Color Swatches ---------- */
.swatches {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  padding: 0;
  border: 2px solid transparent;
  flex: none;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease);
  position: relative;
}

.swatch:hover {
  transform: scale(1.15);
}

.swatch.active {
  border-color: var(--surface);
  box-shadow: 0 0 0 2px var(--accent), 0 2px 8px rgba(0, 0, 0, 0.15);
  transform: scale(1.1);
}

.swatch-more {
  background: conic-gradient(#ef4444, #f97316, #f59e0b, #10b981, #3b82f6, #8b5cf6, #ef4444) !important;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.eq-snippets {
  position: absolute; z-index: 101; display: flex; flex-wrap: wrap; gap: 4px;
  max-width: 220px; padding: 4px; background: #fff; border: 1px solid #c8d4e0;
  border-radius: 6px; box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
.eq-snippet {
  font: 600 12px sans-serif; padding: 3px 7px; border: 1px solid #d0d8e0;
  border-radius: 4px; background: #f4f7fa; cursor: pointer;
}
.eq-snippet:hover { background: #e8eef6; border-color: #2566c8; }
.eq-snippets.hidden { display: none; }

/* ---------- Equation editor dock ---------- */
.eq-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 500;
  background: rgba(255, 255, 255, 0.98);
  border-top: 2px solid var(--accent);
  padding: 10px max(env(safe-area-inset-right), 12px) max(env(safe-area-inset-bottom), 10px) max(env(safe-area-inset-left), 12px);
  box-shadow: 0 -10px 40px rgba(15, 23, 42, 0.18);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.eq-dock.hidden { display: none !important; }

.eq-dock-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.eq-dock-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  flex: 1;
}

.eq-dock-btn {
  font: 600 13px sans-serif;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
}

.eq-dock-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.eq-dock-btn.ghost {
  background: transparent;
  border-color: transparent;
  font-size: 18px;
  padding: 4px 10px;
}

.eq-editor-field {
  display: block;
  width: 100%;
  box-sizing: border-box;
  min-height: 48px;
  font-size: 22px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
}

.eq-editor-field:focus-within {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.eq-dock-hint {
  margin: 6px 0 8px;
  font-size: 12px;
  color: var(--text-3);
}

.eq-symbols {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: min(32vh, 220px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.eq-sym-group { display: flex; flex-direction: column; gap: 4px; }

.eq-sym-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
}

.eq-sym-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.eq-snippet {
  font: 600 13px sans-serif;
  padding: 6px 10px;
  min-width: 36px;
  border: 1px solid #d0d8e0;
  border-radius: 6px;
  background: #f4f7fa;
  cursor: pointer;
  touch-action: manipulation;
}

.eq-snippet:hover, .eq-snippet:active {
  background: #e8eef6;
  border-color: var(--accent);
}

/* MathLive virtual keyboard above equation dock + calculator */
.ML__keyboard, .MLK__backdrop {
  z-index: 10050 !important;
}

/* Fixed action bar — pinned directly above MathLive keyboard (iPad calculator fix) */
.calc-vk-dock {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 10051;
  display: flex;
  gap: 10px;
  padding: 10px max(env(safe-area-inset-right), 12px) 10px max(env(safe-area-inset-left), 12px);
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 2px solid var(--accent);
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.35);
}

.calc-vk-dock.hidden { display: none !important; }

.calc-vk-btn {
  flex: 1;
  min-height: 52px;
  font: 700 15px sans-serif;
  border-radius: var(--radius-sm);
  border: 1px solid #4a515c;
  background: #3a4048;
  color: #eef1f5;
  cursor: pointer;
  touch-action: manipulation;
}

.calc-vk-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.calc-vk-btn:active { filter: brightness(0.9); }

/* Compact calculator while math keyboard is open — hide faceplate, show screen only */
#calc.calc-vk-active .calc-ctl,
#calc.calc-vk-active .calc-keys,
#calc.calc-vk-active .calc-funcs,
#calc.calc-vk-active .calc-mode-menu,
#calc.calc-vk-active .calc-sub {
  display: none !important;
}

#calc.calc-vk-active {
  z-index: 10040;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.55);
}

/* Calculator keyboard bar — Done / toggle stay reachable when MathLive keyboard is open */
.calc-kbd-bar {
  display: flex;
  gap: 8px;
  padding: 6px 12px 8px;
  background: #23262b;
  border-top: 1px solid #3a4048;
}

.calc-kbd-btn {
  flex: 1;
  min-height: 44px;
  font: 600 14px sans-serif;
  border-radius: var(--radius-sm);
  border: 1px solid #4a515c;
  background: #3a4048;
  color: #eef1f5;
  cursor: pointer;
  touch-action: manipulation;
}

.calc-kbd-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.calc-kbd-btn:active { filter: brightness(0.92); }

/* Present mode: park calculator high so the math keyboard can't bury it */
#editor.present-mode #calc:not([data-dragged]) {
  top: max(72px, env(safe-area-inset-top));
  bottom: auto;
  right: max(12px, env(safe-area-inset-right));
  z-index: 10040;
}

#calc.calc-kbd-open {
  z-index: 10040;
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

math-field.eq-editor-field::part(virtual-keyboard-toggle) {
  display: inline-flex !important;
}

.sketch-lab { font-size: 12px; white-space: nowrap; margin-left: 4px; }
.pcr-app { z-index: 3000; }
#color-more.pcr-button,
#color-more {
  width: 28px;
  height: 28px;
  min-width: 28px;
  padding: 0;
  border-radius: 50%;
}

/* ---------- Pen Buttons ---------- */
.pen-group .pen-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-3);
  padding: 7px 11px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: all var(--duration-fast) var(--ease);
}

.pen-group .pen-btn:hover {
  background: var(--surface-2);
  border-color: var(--text-muted);
}

.pen-group .pen-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 2px 6px rgba(59, 130, 246, 0.2);
}

/* Annotate-to-Animate readout highlight (panel styles in annotatedSim.css) */
.annotated-sim-readout-sync { border-color: var(--accent); }

/* ---------- Canvas ---------- */
.canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg-gradient);
}

#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  display: block;
  cursor: crosshair;
}

#board.cur-select { cursor: grab; }
#board.cur-select:active { cursor: grabbing; }

/* ---------- JSXGraph Geometry Overlay ---------- */
.geo-layer {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  width: 1000px;
  height: 1414px;
  transform-origin: 0 0;
  pointer-events: none;
  overflow: visible;
}

.geo-layer.active { pointer-events: auto; }

.geo-inner { width: 1000px; height: 1414px; } /* resized per page in geo.js */

.geo-group .geo-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  padding: 7px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: all var(--duration-fast) var(--ease);
}

.geo-group .geo-btn:hover {
  background: var(--surface-2);
  border-color: var(--text-muted);
}

.geo-group .geo-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 2px 6px rgba(59, 130, 246, 0.2);
}

.geo-group .geo-warn {
  color: var(--danger);
  border-color: var(--danger-light);
}

.geo-group .geo-warn.active {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

/* ---------- Branding Badge ---------- */
.brand {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(31, 39, 51, 0.92);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-lg);
  padding: 8px 16px 8px 8px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.brand.hidden { display: none; }

.brand-photo {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--accent);
  flex: none;
}

.brand-text { line-height: 1.25; }
.brand-name { font-size: 16px; font-weight: 600; letter-spacing: 0.1px; }
.brand-title { font-size: 12.5px; color: #cdd7e3; }
.brand-phone { font-size: 12px; color: var(--accent); font-variant-numeric: tabular-nums; margin-top: 1px; }
.brand-toggle-active { background: var(--accent) !important; border-color: var(--accent) !important; }

/* ---------- Statistics Panel ---------- */
.stats-panel {
  position: fixed;
  left: 20px;
  bottom: 20px;
  z-index: 20;
  width: 340px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xl);
  user-select: none;
}

.stats-panel.hidden { display: none; }

#stats-head {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: var(--surface-2);
  cursor: move;
  border-bottom: 1px solid var(--border);
}

.stats-body { padding: 12px; }

.stats-modes { display: flex; gap: 6px; margin-bottom: 10px; }

.sm-btn {
  flex: 1;
  padding: 8px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text-3);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease);
}

.sm-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.stats-data {
  width: 100%;
  box-sizing: border-box;
  min-height: 60px;
  resize: vertical;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
  margin-bottom: 8px;
}

.stats-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-top: 10px;
}

.stats-summary .st {
  background: var(--surface-3);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}

.stats-summary .st b {
  display: block;
  font-size: 11px;
  color: var(--text-3);
  font-weight: 500;
}

.stats-summary .st span {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.stats-chart { margin-top: 12px; }
.stats-err { color: var(--danger); font-size: 13px; padding: 4px 0; }

/* ---------- Text Editor Overlay ---------- */
.text-editor {
  position: absolute;
  z-index: 6;
  background: rgba(255, 255, 255, 0.9);
  border: 1px dashed var(--accent);
  outline: none;
  border-radius: 4px;
  font-family: sans-serif;
  line-height: 1.25;
  padding: 0 2px;
  margin: 0;
  resize: none;
  overflow: hidden;
  min-width: 60px;
  white-space: pre;
  color: #000;
}

.text-editor.hidden { display: none; }

/* ---------- Scientific Calculator ---------- */
.calc {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  width: 314px;
  background: #2f333a;
  border: 1px solid #15181c;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.42);
  user-select: none;
}

.calc.hidden { display: none; }

.calc-head {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: #23262b;
  cursor: move;
}

.calc-brand {
  flex: 1;
  font-size: 13px;
  letter-spacing: 0.5px;
  color: #c8cdd6;
}

.calc-brand b { color: #e6a23c; font-style: italic; }

.calc-x {
  background: transparent;
  border: none;
  color: #8a93a0;
  font-size: 20px;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
}

.calc-screen {
  margin: 10px;
  padding: 7px 12px 9px;
  background: #b3c0ac;
  border-radius: var(--radius-sm);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.28);
}

.calc-inds {
  display: flex;
  gap: 12px;
  font-size: 10px;
  font-weight: 700;
  color: #4b574a;
  min-height: 12px;
  letter-spacing: 0.6px;
}

#calc-mode { cursor: pointer; }

.ind-shift { visibility: hidden; color: #9c5e10; }
.ind-shift.on { visibility: visible; }

.calc-expr {
  width: 100%;
  box-sizing: border-box;
  background: transparent;
  color: #1c241a;
  border: none;
  padding: 4px 0 0;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 17px;
  text-align: right;
}

.calc-expr:focus { outline: none; }

.calc-result {
  text-align: right;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 23px;
  font-weight: 700;
  min-height: 26px;
  color: #11160f;
  word-break: break-all;
}

.calc-keys {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding: 4px 10px 12px;
}

.ck {
  position: relative;
  padding: 11px 0 9px;
  font-size: 16px;
  border-radius: var(--radius-sm);
  border: none;
  background: #e9ecf1;
  color: #20242b;
  cursor: pointer;
  box-shadow: 0 2px 0 #b9bfc9;
}

.ck:active { transform: translateY(1px); box-shadow: 0 1px 0 #b9bfc9; }
.ck-fn { background: #d8dde6; font-size: 14px; }
.ck-op { background: #c7d0dc; font-weight: 700; }
.ck-ctl { background: #4a515c; color: #eceef2; box-shadow: 0 2px 0 #2c313a; font-size: 13px; }
.ck-shift { background: #e6a23c; color: #2a1c05; font-weight: 700; font-size: 12px; box-shadow: 0 2px 0 #b07c22; }
.ck-warn { background: #d8643f; color: #fff; box-shadow: 0 2px 0 #a64a2c; }
.ck-eq { background: var(--accent); color: #fff; font-weight: 700; font-size: 18px; box-shadow: 0 2px 0 #1a4e9c; }

.sh {
  position: absolute;
  top: 2px;
  left: 0;
  right: 0;
  font-size: 8px;
  color: #9c5e10;
  line-height: 1;
}

/* ---------- fx-991ES PLUS faceplate ---------- */
.calc.casio {
  width: 366px;
  background: linear-gradient(180deg, #2b2f36 0%, #1f2228 100%);
  border: 1px solid #0e1013;
  border-radius: 18px;
  padding-bottom: 6px;
}
.calc.casio .calc-head {
  position: relative;
  background: linear-gradient(180deg, #34373d, #26292e);
  padding: 10px 12px 9px;
  border-radius: 17px 17px 0 0;
}
.casio-logo { font-weight: 800; font-size: 16px; letter-spacing: 1px; color: #f2f4f7; }
.casio-model { margin-left: 8px; font-style: italic; font-weight: 700; font-size: 12.5px; color: #cfd6e0; }
.casio-vpam { margin-left: 8px; font-size: 8px; letter-spacing: 0.4px; color: #18b36b; font-weight: 700; }
.casio-solar {
  position: absolute; right: 34px; top: 11px;
  width: 54px; height: 15px; border-radius: 3px;
  background: repeating-linear-gradient(90deg, #5b4a2a, #5b4a2a 8px, #3a2f1c 8px, #3a2f1c 10px);
  border: 1px solid #1c160c;
}
.calc.casio .calc-x { position: absolute; right: 8px; top: 6px; color: #99a2ad; }

.calc.casio .calc-screen {
  margin: 10px 12px;
  background: linear-gradient(180deg, #aebfa6, #9eb397);
  border: 2px solid #6f7d68;
}
.ind-alpha { visibility: hidden; color: #b23b2e; }
.ind-alpha.on { visibility: visible; }
.ind-modename { margin-left: auto; color: #36432f; font-weight: 800; }

.calc-ctl {
  display: grid;
  grid-template-columns: 1fr 1fr 84px 1fr 1fr;
  align-items: center;
  gap: 6px;
  padding: 2px 12px 8px;
}
.ck-alpha { background: #b23b2e; color: #fff; font-weight: 700; font-size: 12px; box-shadow: 0 2px 0 #7e271d; }

.calc-replay {
  position: relative;
  width: 78px; height: 58px;
  margin: 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, #4a515c, #2b3038);
  box-shadow: inset 0 0 0 2px #15181c, 0 2px 0 #15181c;
}
.calc-replay .rep {
  position: absolute; background: transparent; border: none; color: #cfd6e0;
  font-size: 9px; padding: 0; cursor: pointer; width: 22px; height: 18px; line-height: 1;
}
.calc-replay .rep:active { color: #fff; }
.rep-up { top: 1px; left: 50%; transform: translateX(-50%); }
.rep-down { bottom: 1px; left: 50%; transform: translateX(-50%); }
.rep-left { left: 1px; top: 50%; transform: translateY(-50%); }
.rep-right { right: 1px; top: 50%; transform: translateY(-50%); }
.rep-hub {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, #5b636f, #343b44);
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.15), 0 1px 2px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.calc.casio .calc-keys { padding: 2px 12px 8px; gap: 5px; }
.calc.casio .ck { position: relative; background: #3a4048; color: #eef1f5; box-shadow: 0 2px 0 #1b1f25; font-size: 13px; padding: 13px 0 6px; }
.calc.casio .ck .sh { left: 4px; right: auto; text-align: left; }
.calc.casio .ck .al { position: absolute; top: 2px; right: 4px; font-size: 8px; line-height: 1; color: #e07a6b; }
.calc.casio .ck-num { background: #eef1f5; color: #14181d; box-shadow: 0 2px 0 #aeb6c0; font-weight: 600; font-size: 15px; }
.calc.casio .ck-op { background: #cdd6e0; color: #14181d; box-shadow: 0 2px 0 #98a2ad; font-weight: 700; }
.calc.casio .ck-eq { background: var(--accent); color: #fff; box-shadow: 0 2px 0 #1a4e9c; font-weight: 700; font-size: 17px; }
.calc.casio .ck-warn { background: #d8643f; color: #fff; box-shadow: 0 2px 0 #a64a2c; font-size: 12px; }
.calc.casio .ck-shift { background: #e6b422; color: #2a1c05; box-shadow: 0 2px 0 #ab8316; font-weight: 700; font-size: 12px; }
.calc.casio .ck-ctl { background: #4a515c; color: #eceef2; box-shadow: 0 2px 0 #2c313a; font-size: 12px; }
.sh.sh-y { color: #f0c33a; }
.sh.sh-r { color: #e0796b; }

.calc-funcs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; padding: 0 12px 8px; }

.calc-mode-menu {
  margin: 0 12px 10px; padding: 10px; border-radius: 10px;
  background: #161a20; border: 1px solid #2c313a;
}
.calc-mode-menu.hidden { display: none; }
.cmm-title { color: #9aa3af; font-size: 11px; margin-bottom: 8px; letter-spacing: 0.4px; }
.cmm-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.cmm-grid button { background: #2a2f37; color: #e7eaef; border: 1px solid #3a414b; border-radius: 6px; padding: 8px; font-size: 12px; }
.cmm-grid button:hover { background: #343b44; }

.intg-modes { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.gp-trig { border-top: 1px solid var(--border); margin-top: 8px; padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.gp-trig-head { display: flex; align-items: center; gap: 8px; }
.gp-read { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; flex: 1; }
.gp-trig-sub { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.gp-slab { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.gp-slab input[type=range] { flex: 1; }
.gp-slab span { width: 38px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text-3); }
.stats-place { width: 100%; margin-top: 10px; }
.stats-chart-types { display: flex; gap: 6px; margin: 8px 0 4px; }
.stats-chart-types .sc-btn { flex: 1; padding: 6px 4px; font-size: 12px; background: var(--surface-3); border: 1px solid var(--border); color: var(--text-3); border-radius: var(--radius-sm); }
.stats-chart-types .sc-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.eqn-fields { display: grid; gap: 6px; margin: 8px 0; }
.eqn-fields .eqn-row { display: flex; gap: 6px; }
.eqn-fields .ct-in { margin-bottom: 0; text-align: center; }

/* hide MathLive's built-in menu / virtual-keyboard toggle inside the calc display */
.calc-expr::part(menu-toggle),
.calc-expr::part(virtual-keyboard-toggle) { display: none; }

/* ---------- Calculator TABLE / Matrix ---------- */
.calc-sub { padding: 12px; }
.calc-sub.hidden { display: none; }

.ct-lab {
  font-size: 12px;
  color: var(--text-3);
  display: block;
  margin: 0 0 3px;
}

.ct-in {
  width: 100%;
  box-sizing: border-box;
  background: #11161d;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 14px;
  margin-bottom: 8px;
}

.ct-row3 { display: flex; gap: 8px; }
.ct-row3 span { flex: 1; }
.ct-btns { display: flex; gap: 8px; margin-top: 2px; }

.ck-eq2 {
  flex: 2;
  padding: 11px 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.ct-out { max-height: 220px; overflow: auto; margin-top: 10px; }

.ct-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
}

.ct-table th, .ct-table td {
  border: 1px solid var(--border);
  padding: 4px 9px;
  text-align: right;
}

.ct-table th {
  color: var(--text-3);
  position: sticky;
  top: 0;
  background: var(--surface);
}

.ct-err { color: var(--danger); font-size: 13px; padding: 6px 0; }

/* ---------- Matrix / Vector ---------- */
.mx-tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.mx-tab { padding: 6px 14px; font-size: 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-3); color: var(--text-3); cursor: pointer; }
.mx-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.mx-block { margin-bottom: 10px; }
.mx-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.mx-row3 { display: flex; gap: 4px; }
.mx-in { width: 100%; box-sizing: border-box; background: #11161d; color: var(--text); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 7px 9px; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 14px; text-align: center; }
.mx-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.mx-btns .ck { flex: 1; min-width: 50px; padding: 9px 0; font-size: 13px; }
.mx-mat { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 14px; white-space: pre; line-height: 1.6; }

/* ---------- Function Grapher Panel ---------- */
.gpanel {
  position: fixed;
  right: 20px;
  top: 96px;
  z-index: 20;
  width: 290px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xl);
  user-select: none;
}

.gpanel.hidden { display: none; }

.gp-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
  cursor: move;
  border-bottom: 1px solid var(--border);
}

.gp-list {
  padding: 10px 10px 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gp-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.gp-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex: none;
}

.gp-eq { font-size: 13px; color: var(--text-3); }

.gp-in {
  flex: 1;
  min-width: 0;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 14px;
}

.gp-del {
  background: transparent;
  border: none;
  color: var(--text-3);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
}

.gp-tools {
  display: flex;
  gap: 6px;
  padding: 6px 10px;
}

.gp-tools .ck { flex: 1; padding: 9px 0; }

.gp-actions {
  display: flex;
  gap: 6px;
  padding: 6px 10px 10px;
}

.gp-actions .ck { flex: 1; padding: 9px 0; }

.gp-hint {
  font-size: 11px;
  color: var(--text-3);
  padding: 0 12px 12px;
  line-height: 1.4;
}

/* ---------- RAG search (Course Library) + animated tools ---------- */
.rag-search { margin: 0 0 16px; }
.rag-form { display: flex; gap: 8px; }
.rag-form #rag-q { flex: 1; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--text); font-size: 14px; }
.rag-form #rag-course { padding: 8px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--text); font-size: 13px; }
.rag-results { margin-top: 10px; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.rag-msg { grid-column: 1 / -1; }
.rag-card { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 10px 12px; background: var(--surface); font-size: 13px; line-height: 1.45; }
.rag-card header { font-weight: 600; font-size: 11px; color: var(--text-3); margin-bottom: 4px; }
.rag-card p { margin: 0 0 8px; color: var(--text); }
.rag-card-actions { display: flex; gap: 8px; }
.rag-card-actions button { font-size: 12px; padding: 4px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); cursor: pointer; }
.rag-card-actions .rag-anim { background: var(--accent-light); }
.anim-dialog { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(900px, 94vw); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-lg, 0 12px 40px rgba(0,0,0,.35)); z-index: 300; display: flex; flex-direction: column; max-height: 90vh; }
.anim-dialog:fullscreen { top: 0; left: 0; transform: none; width: 100vw; max-height: 100vh; border-radius: 0; }

/* Fullscreen fallback for browsers without the Fullscreen API (iPad PWA,
   iPhone Safari) — js/fullscreen.js toggles this class instead. */
.mb-fs-fallback {
  position: fixed !important;
  inset: 0 !important;
  top: 0 !important;
  left: 0 !important;
  transform: none !important;
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  border-radius: 0 !important;
  margin: 0 !important;
  z-index: 100001 !important;
}
.anim-dialog .gp-head { display: flex; align-items: center; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.anim-main { display: flex; flex: 1; min-height: 0; overflow: hidden; }
.anim-dialog #anim-host { flex: 1; padding: 12px; overflow: auto; }
.anim-params { width: 240px; padding: 12px; border-left: 1px solid var(--border); overflow-y: auto; background: var(--surface-2); }
.anim-params:not(.hidden) { display: block; }
.anim-param-group { margin-bottom: 16px; }
.anim-param-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.anim-param-group input[type="number"] { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); font-size: 12px; }
.anim-param-group input[type="range"] { width: 100%; margin: 4px 0; }
.anim-param-value { font-size: 11px; color: var(--text-3); margin-top: 2px; }
#anim-pin { margin-left: auto; }
mb-suvat-anim, mb-vector-lines-anim { display: block; }
.mb-anim-svg { width: 100%; height: auto; }
.mb-anim-controls { display: flex; gap: 10px; align-items: center; margin-top: 6px; }
.mb-anim-controls button { width: 36px; height: 30px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); cursor: pointer; }
.mb-anim-controls input[type="range"] { flex: 1; }
.mb-anim-caption { min-height: 20px; margin-top: 8px; font-size: 13px; color: var(--text-2); }
mb-incline-lab, mb-pulley-lab, mb-suvat-lab, mb-forces-particle-lab, mb-projectile-lab, mb-quadratic-lab, mb-tangent-lab { display: block; }
.mb-lab-readout { margin-top: 8px; padding: 6px 10px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.5; color: var(--text); background: var(--surface-2); border-radius: var(--radius-sm); min-height: 20px; }
.mb-drag-handle { cursor: grab; touch-action: none; }
.mb-drag-handle.is-dragging { cursor: grabbing; }
.mb-lab-picker { display: flex; flex-direction: column; gap: 10px; padding: 12px 4px; }
.mb-lab-picker-heading { font-size: 11px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 6px; }
.mb-lab-picker-row { display: flex; flex-direction: column; gap: 8px; }
.mb-lab-chip { padding: 12px 16px; font-size: 14px; text-align: left; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); color: var(--text); cursor: pointer; }
.mb-lab-chip:hover { background: var(--accent-light); }
.mb-lab-massrow { display: flex; gap: 6px; align-items: center; justify-content: center; margin-top: 6px; }
.mb-lab-massrow button { width: 28px; height: 26px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); cursor: pointer; }
.mb-lab-masslbl { font-size: 13px; color: var(--text-2); min-width: 84px; text-align: center; }
.rag-labs-btn { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); color: var(--text); font-size: 13px; cursor: pointer; }

/* ---------- Snip-to-Sim overlay + picker ---------- */
.snip-overlay { position: absolute; inset: 0; z-index: 40; cursor: crosshair; touch-action: none; background: rgba(15, 23, 42, 0.08); }
.snip-rect { position: absolute; border: 2px dashed var(--accent, #4a7dff); background: var(--accent-light, rgba(74,125,255,.12)); box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.25); pointer-events: none; }
.snip-rect.hidden { display: none; }
.sim-picker { display: flex; flex-direction: column; gap: 12px; padding: 8px 4px 4px; max-height: min(72vh, 640px); overflow-y: auto; }
.sim-picker-hint { margin: 0; font-size: 13px; }
.sim-thumb { display: block; max-width: 100%; max-height: 180px; width: auto; margin: 0 auto; border: 1px solid var(--border); border-radius: var(--radius-md); background: #fff; object-fit: contain; }
.sim-picker-grid { display: flex; flex-direction: column; gap: 8px; }
.sim-chip-suggested { border-color: var(--accent, #4a7dff); background: var(--accent-light); }

/* ---------- Mechanics Panel ---------- */
.panel-mech {
  width: 300px;
  max-height: 80vh;
  overflow-y: auto;
}

.mech-panel .mech-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 10px 0;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.mech-tab {
  flex: 1;
  padding: 7px 8px;
  font-size: 12px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  text-align: center;
  transition: all var(--duration-fast) var(--ease);
}

.mech-tab.active {
  background: var(--surface);
  border-color: var(--border);
  border-bottom-color: var(--surface);
  color: var(--accent);
  font-weight: 600;
}

.mech-pane { padding: 10px; }

.mech-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }

.mech-in {
  width: 100%;
  box-sizing: border-box;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 14px;
  margin-bottom: 6px;
}

.mech-in.full { width: 100%; }

.mech-chk {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-3);
  margin: 6px 0;
}

.mech-add { width: 100%; }

.mech-place { width: 100%; margin-top: 6px; }

.mech-foot { padding: 8px 10px 10px; border-top: 1px solid var(--border); }

.mech-hint {
  font-size: 12px;
  color: var(--text-3);
  margin: 6px 0 0;
  line-height: 1.35;
}

/* ---------- Complex Panel ---------- */
.cplx-pane { padding: 10px; }
.cplx-hint { font-size: 12px; color: var(--text-3); margin: 0 0 10px; line-height: 1.4; }
.cw-row { margin-bottom: 8px; }
.cw-pair { display: flex; align-items: center; gap: 6px; }
.cw-pair .mech-in { flex: 1; margin-bottom: 0; }
.cw-plus { color: var(--text-3); font-size: 16px; }
.cw-i { color: var(--text-3); font-size: 14px; font-style: italic; }
.cplx-presets { display: flex; gap: 6px; margin: 8px 0; }
.cplx-presets .ck { flex: 1; padding: 9px 0; font-size: 13px; }

/* ---------- Busy Overlay ---------- */
.busy {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 26, 34, 0.45);
  z-index: 5;
}

.busy-box {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-xl);
}

.busy-msg { font-size: 14px; }

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Fraction / Surd Display ---------- */
.c-frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  line-height: 1;
}

.c-num, .c-den {
  font-size: 0.7em;
  padding: 0 4px;
}

.c-bar {
  display: block;
  width: 100%;
  height: 1.5px;
  background: currentColor;
  margin: 1px 0;
}

.c-surd { display: inline-flex; align-items: center; }
.c-sqrt { font-size: 1.2em; margin-right: 2px; }

/* ---------- Empty State ---------- */
.lib-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  font-size: 15px;
  color: var(--text-3);
}

/* ---------- Controls ---------- */
.ctl-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-3);
  font-size: 13px;
}

/* ---------- Parametric Row ---------- */
.gp-row-param { flex-wrap: wrap; }
.gp-param-line { display: flex; align-items: center; gap: 4px; width: 100%; }
.gp-param-line .gp-in { flex: 1; }
.gp-param-line .gp-eq { font-size: 12px; }

/* ---------- Calc Title ---------- */
.calc-title { flex: 1; font-size: 14px; font-weight: 600; color: var(--text-2); }

/* ---------- Indent ---------- */
.ind-fmt { cursor: pointer; }

/* ---------- Layers panel ---------- */
.layers-panel { width: 280px; max-height: 420px; }
.layers-list { max-height: 320px; overflow-y: auto; padding: 8px; }
.layer-row {
  display: flex; align-items: center; gap: 4px; padding: 6px 4px;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.layer-row.layer-hidden { opacity: 0.45; }
.layer-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 4px;
  padding: 2px 6px; cursor: pointer; font-size: 12px;
}
.nb-pdf-tag { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--text-3); font-size: 11px; }

/* ---------- Graph view (fullscreen) ---------- */
.graph-view {
  position: fixed; inset: 0; z-index: 9000; background: #eef1f6;
  display: flex; flex-direction: column;
}
.graph-view.hidden { display: none !important; }
.gv-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.gv-title { flex: 1; font-weight: 600; }
#gv-canvas { flex: 1; width: 100%; display: block; }
.gv-hint { text-align: center; font-size: 12px; color: var(--text-3); padding: 6px; }

/* ---------- AR Studio ---------- */
.studio {
  position: fixed; inset: 0; z-index: 9500; background: #000;
  display: flex; flex-direction: column;
}
.studio.hidden { display: none !important; }
.studio-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 10px;
  background: rgba(20,24,32,0.92); color: #fff;
}
.studio-title { font-weight: 600; margin-right: 8px; }
.studio-spec { flex: 1; min-width: 140px; padding: 4px 8px; border-radius: 4px; border: none; }
.studio-chk { font-size: 12px; color: #ccc; display: inline-flex; align-items: center; gap: 4px; }
.studio-wrap { position: relative; flex: 1; overflow: hidden; }
.studio-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#studio-annot { pointer-events: auto; z-index: 2; }
#studio-output-canvas { z-index: 1; pointer-events: none; }
.studio-err {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 18px; background: rgba(0,0,0,0.7); z-index: 10;
}
.studio-err.hidden { display: none; }

/* ===== Course Library tab ===================================================== */
.lib-head.lib-course .lib-act-lesson,
.lib-head.lib-course .lib-act-paper { display: none; }

#nb-list .course-node {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  margin-bottom: 12px;
  overflow: hidden;
}
.course-sum {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; cursor: pointer; list-style: none;
  background: linear-gradient(135deg, var(--accent), var(--purple, #7c3aed));
  color: #fff; font-weight: 700; font-size: 16px;
}
.course-sum::-webkit-details-marker { display: none; }
.course-sum::before { content: '▸'; transition: transform .15s ease; opacity: .9; }
.course-node[open] > .course-sum::before { transform: rotate(90deg); }
.course-count { margin-left: auto; font-size: 12px; font-weight: 600; opacity: .9; }
.course-body { padding: 8px 12px 12px; }

.topic-node { border-top: 1px solid var(--border-light); }
.topic-node:first-child { border-top: none; }
.topic-sum {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 6px; cursor: pointer; list-style: none;
  font-weight: 600; color: var(--text); font-size: 14px;
}
.topic-sum::-webkit-details-marker { display: none; }
.topic-sum::before { content: '▸'; transition: transform .15s ease; color: var(--text-3); }
.topic-node[open] > .topic-sum::before { transform: rotate(90deg); }
.topic-count {
  margin-left: auto; min-width: 22px; text-align: center;
  background: var(--surface-3); color: var(--text-3);
  border-radius: 999px; font-size: 12px; font-weight: 700; padding: 1px 8px;
}
.topic-body { padding: 0 4px 8px 18px; }

.exercise-node { margin: 6px 0 10px; }
.exercise-name { font-size: 13px; color: var(--text-2); font-weight: 600; margin-bottom: 6px; }
.example-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.example-empty { font-size: 13px; padding: 6px 2px; }

.example-card {
  display: flex; flex-direction: column; text-align: left;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); padding: 0; overflow: hidden; cursor: pointer;
  transition: border-color .12s ease, box-shadow .12s ease, transform .12s ease;
}
.example-card:hover { border-color: var(--accent); box-shadow: 0 4px 14px var(--accent-glow); transform: translateY(-1px); }
.example-thumb { height: 96px; background: var(--surface-2); overflow: hidden; display: flex; align-items: center; justify-content: center; }
.example-thumb .nb-thumb { width: 100%; height: 100%; }
.example-thumb img { width: 100%; height: 100%; object-fit: cover; }
.example-meta { padding: 8px 10px; }
.example-title {
  font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.3;
  overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3;
}
.example-play { font-size: 11px; color: var(--accent); font-weight: 600; margin-top: 3px; }

.course-empty { padding: 24px 8px; }
.course-empty p { margin: 4px 0; }

/* Catalog tagging dialog */
.cat-box { max-width: 420px; }
.cat-lbl { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; font-size: 13px; font-weight: 600; color: var(--text-2); text-align: left; }
.cat-lbl .ct-in { font-weight: 400; }
.nb-actions .cat { white-space: nowrap; }

/* ============================================================
   Product polish — v92: self-hosted Inter, dark theme, a11y
   ============================================================ */

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../vendor/fonts/inter/inter-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../vendor/fonts/inter/inter-500.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../vendor/fonts/inter/inter-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../vendor/fonts/inter/inter-700.woff2') format('woff2');
}

/* Dark theme tokens */
[data-theme="dark"] {
  --bg: #0f1419;
  --bg-gradient: linear-gradient(135deg, #0f1419 0%, #151b24 50%, #1a2230 100%);
  --surface: #1a2230;
  --surface-2: #1f2937;
  --surface-3: #253041;
  --border: #2d3a4d;
  --border-light: #243044;
  --text: #f1f5f9;
  --text-2: #cbd5e1;
  --text-3: #94a3b8;
  --text-muted: #64748b;
  --accent-light: rgba(59, 130, 246, 0.18);
  --accent-glow: rgba(59, 130, 246, 0.22);
  --success-light: rgba(16, 185, 129, 0.15);
  --warning-light: rgba(245, 158, 11, 0.15);
  --danger-light: rgba(239, 68, 68, 0.15);
  --purple-light: rgba(139, 92, 246, 0.15);
  --orange-light: rgba(249, 115, 22, 0.15);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.45);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .lib-head,
[data-theme="dark"] .toolbar,
[data-theme="dark"] .footnote {
  background: rgba(26, 34, 48, 0.88);
}
[data-theme="dark"] .nb-thumb img { background: #fff; }
[data-theme="dark"] button.ghost:hover { background: rgba(255, 255, 255, 0.06); }
[data-theme="dark"] .toolbar button.ghost:hover { background: rgba(255, 255, 255, 0.06); }

/* Type scale */
:root {
  --text-xs: 11px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-lg: 16px;
  --text-xl: 20px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --focus-ring: 0 0 0 3px var(--accent-glow);
}

/* Accessibility — focus rings */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@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;
  }
}

/* Toolbar — hide duplicate panel row; use Panels menu only */
.tbar-top .panel-btns { display: none !important; }
.panel-menu-wrap { display: block; }

.tbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.tbar-actions button,
.tbar-actions .tbar-more-wrap > button {
  min-height: 40px;
  min-width: 40px;
  padding: 8px 12px;
}
.icon-btn {
  padding: 8px 10px !important;
  font-size: 16px;
  line-height: 1;
}

/* Library header utilities */
.lib-util {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Loading skeleton */
.lib-skeleton {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
  padding: 20px 28px;
}
.skel-card {
  height: 280px;
  border-radius: var(--radius-lg);
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
  background-size: 200% 100%;
  animation: skel-shimmer 1.2s ease-in-out infinite;
}
@keyframes skel-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.lib-empty-state {
  text-align: center;
  padding: 48px 24px;
  max-width: 420px;
  margin: 0 auto;
}
.lib-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}
.lib-empty-state h2 {
  margin: 0 0 8px;
  font-size: var(--text-xl);
  font-weight: 700;
}
.lib-empty-state p { margin: 0 0 16px; color: var(--text-3); line-height: 1.5; }

/* Course library cards */
.example-card .badge-new {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  background: var(--success);
  color: #fff;
}
.example-card .badge-done {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}
.example-thumb { position: relative; }

.course-cover {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex: none;
}

/* Present mode — larger HUD + step indicator */
#editor.present-mode .present-hud-inner {
  padding: 14px 28px;
  gap: 20px;
  border-radius: var(--radius-xl);
  background: rgba(15, 20, 25, 0.82);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
#editor.present-mode .present-hud-btn {
  width: 52px;
  height: 52px;
  font-size: 28px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
}
#editor.present-mode .present-page-label {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
}
#editor.present-mode .present-section-label {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.65);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
#editor.present-mode .present-step-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 6px;
}
.present-step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  transition: transform var(--duration-fast) var(--ease), background var(--duration-fast) var(--ease);
}
.present-step-dot.active {
  background: var(--accent);
  transform: scale(1.25);
}

/* About modal */
.about-dialog .sync-box {
  max-width: 520px;
  text-align: left;
}

/* Onboarding tour */
.onboard-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  pointer-events: auto;
}
.onboard-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 20, 25, 0.72);
  backdrop-filter: blur(2px);
}
.onboard-spot {
  position: fixed;
  border-radius: var(--radius-lg);
  box-shadow: 0 0 0 9999px rgba(15, 20, 25, 0.72);
  border: 2px solid var(--accent);
  pointer-events: none;
  z-index: 501;
  transition: top 0.25s var(--ease), left 0.25s var(--ease), width 0.25s var(--ease), height 0.25s var(--ease);
}
.onboard-welcome,
.onboard-card {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 502;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 28px 32px;
  max-width: min(440px, calc(100vw - 32px));
  box-shadow: var(--shadow-xl);
  text-align: center;
}
.onboard-welcome h2,
.onboard-card h3 {
  margin: 0 0 8px;
  font-size: var(--text-xl);
  font-weight: 700;
}
.onboard-welcome p,
.onboard-body {
  margin: 0 0 20px;
  color: var(--text-3);
  line-height: 1.55;
  font-size: var(--text-sm);
}
.onboard-card { text-align: left; }
.onboard-step {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.onboard-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.onboard-welcome .onboard-actions { justify-content: center; }

.legal-text {
  font-size: var(--text-sm);
  color: var(--text-3);
  line-height: 1.6;
  max-height: 50vh;
  overflow-y: auto;
}
.legal-text h4 { margin: 16px 0 6px; color: var(--text); }

/* Touch targets — iPad */
@media (pointer: coarse) {
  button, .tool, .tab-btn, .lib-tab {
    min-height: 44px;
  }
  .toolbar .tool { padding: 10px 14px; }
}
