/* =====================================================================
   Graph Theory & Algorithms Learning Platform — Modern UI Stylesheet
   Phase 4 Day 1: Clean, responsive, accessible, dark/light theme
   ===================================================================== */

:root {
  --bg: #090d14;
  --panel: #0f1722;
  --panel-alt: #141f2e;
  --line: #1c293a;
  --text: #e2edf8;
  --dim: #7e92a6;
  --accent: #f59e0b;
  --accent-hover: #d97706;
  --accent2: #10b981;
  --blue: #0284c7;
  --blue-light: #38bdf8;
  --green: #10b981;
  --red: #ef4444;
  --orange: #ff5722;
  --code-hl: #2d2210;
  --card-bg: #111a28;
  --card-border: #1d2c3f;
  --badge-bg: #162438;
}

body.theme-light {
  /* Soft, soothing, anti-glare light theme (warm slate & paper surfaces) */
  --bg: #e8edf4;
  --panel: #f4f7fb;
  --panel-alt: #dfe5ed;
  --line: #c4d0de;
  --text: #1e293b;
  --dim: #55687d;
  --accent: #d97706;
  --accent-hover: #b45309;
  --blue-light: #0369a1;
  --card-bg: #f4f7fb;
  --card-border: #ccd6e2;
  --badge-bg: #dbe4ee;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.25) transparent;
}

/* Subtle Hierarchical Scrollbars across Webkit/Blink */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.25);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.5);
}

::-webkit-scrollbar-corner {
  background: transparent;
}

html, body {
  height: 100%;
  width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

#app {
  width: 100%;
  height: 100%;
  min-width: 0;
  overflow-x: hidden;
}

/* Global button nowrap enforcement */
button,
.btn-primary,
.btn-sm,
.btn-fullscreen,
.algo-switch-btn,
.code-btn,
.ctrl-btn,
.table-mode-btn,
.table-expand-btn {
  white-space: nowrap !important;
  word-break: normal !important;
}

/* =====================================================================
   APP HEADER & GLOBAL NAVIGATION
   ===================================================================== */

.app-header {
  height: 56px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.brand-icon {
  font-size: 22px;
}

.brand-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #fff;
}

body.theme-light .brand-name {
  color: #0f172a;
}

.brand-badge {
  font-size: 11px;
  background: var(--badge-bg);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
  border: 1px solid var(--line);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-btn {
  background: transparent;
  color: var(--dim);
  border: 1px solid transparent;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}

.nav-btn:hover {
  background: rgba(56, 189, 248, 0.1);
  color: var(--blue-light);
  border-color: rgba(56, 189, 248, 0.35);
  transform: translateY(-1.5px);
  box-shadow: 0 2px 10px rgba(56, 189, 248, 0.18);
}

.nav-btn:active {
  transform: translateY(0) scale(0.97);
}

.nav-btn.active {
  background: rgba(56, 189, 248, 0.12);
  color: var(--blue-light);
  border-color: var(--blue-light);
  box-shadow: 0 2px 8px rgba(56, 189, 248, 0.15);
}

body.theme-light .nav-btn:hover {
  background: #f0f9ff;
  color: #0284c7;
  border-color: #0284c7;
  box-shadow: 0 2px 10px rgba(2, 132, 199, 0.12);
}

body.theme-light .nav-btn.active {
  background: #f0f9ff;
  color: #0284c7;
  border-color: #0284c7;
}

/* =====================================================================
   LAB DROPDOWN MENU
   ===================================================================== */
.nav-dropdown {
  position: relative;
  display: inline-flex;
}

.nav-dropdown-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.nav-dropdown-toggle .dropdown-arrow {
  font-size: 9px;
  margin-left: 3px;
  color: var(--dim);
  transition: transform 0.2s ease;
}

.nav-dropdown.open .nav-dropdown-toggle .dropdown-arrow,
.nav-dropdown:hover .nav-dropdown-toggle .dropdown-arrow {
  transform: rotate(180deg);
  color: var(--accent);
}

.nav-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 330px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.35);
  display: none;
  flex-direction: column;
  gap: 4px;
  z-index: 1000;
  backdrop-filter: blur(12px);
  animation: dropdownSlideIn 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Seamless hover bridge: connects toggle button to dropdown menu without any gap */
.nav-dropdown-menu::before {
  content: '';
  position: absolute;
  top: -10px;
  left: 0;
  right: 0;
  height: 10px;
  background: transparent;
}

body.theme-light .nav-dropdown-menu {
  background: #ffffff;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
  border-color: rgba(226, 232, 240, 0.9);
}

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

.nav-dropdown.open .nav-dropdown-menu,
.nav-dropdown:hover .nav-dropdown-menu {
  display: flex;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  width: 100%;
}

.dropdown-item:hover {
  background: var(--panel-alt);
  border-color: var(--line);
}

.dropdown-item.active {
  background: rgba(59, 130, 246, 0.09);
  border-color: rgba(59, 130, 246, 0.3);
}

.dropdown-item .item-icon {
  font-size: 18px;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-alt);
  border-radius: 8px;
  border: 1px solid var(--line);
}

.dropdown-item .item-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.dropdown-item .item-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.dropdown-item .item-desc {
  font-size: 11px;
  color: var(--dim);
  line-height: 1.35;
  white-space: normal !important;
}

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

.btn-icon {
  background: var(--panel-alt);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.btn-icon:hover {
  border-color: var(--accent);
  color: var(--accent);
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm {
  background: var(--panel-alt);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
}

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

/* ---------------------------------------------------------------------
   Relation Lab > Warshall controls: uniform look for the 4 step buttons
   (Về W₀ / Lùi / Tiếp / W_n). RelationLabView disables two of them at the
   first/last step with inline `opacity:0.4`, which washes the background
   out to near-white next to the enabled pair. Keep the SAME background and
   border in every state; only the text is muted when disabled.
   Styling only: scoped to this bar, no logic or markup changes.
   --------------------------------------------------------------------- */
.warshall-controls-bar .btn-sm {
  background: var(--panel-alt);
  border: 1px solid var(--line);
  color: var(--text);
}

.warshall-controls-bar .btn-sm:disabled {
  opacity: 1 !important; /* overrides the inline opacity:0.4 */
  background: var(--panel-alt);
  border-color: var(--line);
  color: var(--dim);
  cursor: not-allowed;
}

/* =====================================================================
   VIEW WRAPPERS
   ===================================================================== */

#app, #appMain, .app-main {
  display: block;
  width: 100%;
  min-height: calc(100vh - 56px);
}

.app-view {
  display: none;
  width: 100%;
  min-height: calc(100vh - 56px);
}

.app-view.active {
  display: block;
}

/* =====================================================================
   1. HOME VIEW
   ===================================================================== */

.home-container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 40px 20px 80px;
}

.hero-section {
  text-align: center;
  padding: 40px 20px 50px;
  background: radial-gradient(circle at 50% 30%, rgba(245, 158, 11, 0.08) 0%, transparent 70%);
  border-radius: 16px;
  border: 1px solid var(--line);
  margin-bottom: 40px;
}

.hero-pill {
  display: inline-block;
  background: rgba(245, 158, 11, 0.12);
  color: var(--accent);
  border: 1px solid rgba(245, 158, 11, 0.3);
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 16px;
}

.hero-title {
  font-size: 38px;
  font-weight: 800;
  line-height: 1.25;
  margin-bottom: 16px;
  letter-spacing: -0.02em;
}

.hero-subtitle {
  font-size: 17px;
  color: var(--dim);
  max-width: 680px;
  margin: 0 auto 30px;
  line-height: 1.6;
}

.hero-actions {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 30px;
}

.feature-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 24px;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.feature-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.feature-icon {
  font-size: 32px;
  margin-bottom: 14px;
}

.feature-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 8px;
}

.feature-desc {
  font-size: 13.5px;
  color: var(--dim);
  line-height: 1.6;
}

/* =====================================================================
   2. THEORY VIEW
   ===================================================================== */

.theory-container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 30px 20px 80px;
}

.section-head {
  margin-bottom: 26px;
}

.section-title {
  font-size: 26px;
  font-weight: 800;
  margin-bottom: 6px;
}

.section-subtitle {
  font-size: 14px;
  color: var(--dim);
}

.theory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}

.theory-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.theory-badge {
  font-size: 11px;
  font-weight: 700;
  background: var(--badge-bg);
  color: var(--blue-light);
  padding: 3px 8px;
  border-radius: 4px;
  display: inline-block;
  margin-bottom: 12px;
}

.theory-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 10px;
}

.theory-summary {
  font-size: 13.5px;
  color: var(--dim);
  line-height: 1.6;
  margin-bottom: 18px;
}

.theory-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* =====================================================================
   3. ALGORITHM LAB WORKSPACE
   ===================================================================== */

.lab-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px);
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
  min-width: 0;
}

/* Lab Top Toolbar - Stable 2-Row Layout */
.lab-toolbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 6px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
  box-sizing: border-box;
  overflow: visible; /* NO horizontal scrollbar across the page! */
  width: 100%;
}

.toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
}

.toolbar-row-main {
  min-height: 36px;
  flex-wrap: wrap;
}

.toolbar-left-cluster {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  flex-shrink: 1;
}

.toolbar-right-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-left: auto;
}

.toolbar-row-params {
  padding-top: 4px;
  border-top: 1px dashed rgba(255, 255, 255, 0.07);
  min-height: 28px;
}

body.theme-light .toolbar-row-params {
  border-top: 1px dashed rgba(0, 0, 0, 0.08);
}

.toolbar-params-cluster {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.param-help-text {
  font-size: 11.5px;
  color: var(--dim);
  font-style: italic;
  padding-left: 4px;
}

.toolbar-slot {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.toolbar-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--dim);
  white-space: nowrap;
}

.slot-preset {
  gap: 6px;
}

#presetSelect, .slot-preset select {
  width: clamp(140px, 15vw, 175px);
  max-width: 175px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.slot-algo {
  gap: 6px;
}

.slot-start-node {
  width: 115px;
  min-width: 115px;
}

.slot-second-param {
  width: 165px;
  min-width: 165px;
}

.slot-action {
  width: auto;
  min-width: 145px;
  flex-shrink: 0;
}

.slot-action #btnRunAlgo {
  min-width: 145px;
  justify-content: center;
  white-space: nowrap;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.slot-param-inner {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
}

.slot-start-node select,
.slot-second-param select {
  flex: 1;
  min-width: 0;
}

.ham-mode-inner {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  white-space: nowrap;
  color: var(--text);
}

.slot-fullscreen {
  flex-shrink: 0;
}

.btn-fullscreen {
  background: var(--panel-alt);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 4px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
  user-select: none;
  white-space: nowrap;
  min-width: 115px;
  justify-content: center;
  flex-shrink: 0;
}

.btn-fullscreen:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

select.form-select, input.form-input, textarea.form-input {
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  outline: none;
}

select.form-select:focus, input.form-input:focus, textarea.form-input:focus {
  border-color: var(--accent);
}

.algo-switch {
  display: inline-flex;
  align-items: center;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
}

.algo-switch-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--dim);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  user-select: none;
}

.algo-switch-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

body.theme-light .algo-switch-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

.algo-switch-btn.active {
  background: rgba(59, 130, 246, 0.18);
  color: var(--blue-light);
  border: 1px solid rgba(59, 130, 246, 0.4);
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.15);
}

body.theme-light .algo-switch-btn.active {
  background: rgba(3, 105, 161, 0.12);
  color: #0369a1;
  border: 1px solid rgba(3, 105, 161, 0.35);
  box-shadow: 0 2px 6px rgba(3, 105, 161, 0.12);
}

/* Main Split: Top Workspace & Bottom Table */
.lab-main-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.lab-top-workspace, .lab-upper-row {
  flex: 0 0 62%;
  height: 62%;
  display: flex;
  min-height: 280px;
  min-width: 0;
  overflow: hidden;
  position: relative;
}

.graph-pane, .graph-column {
  flex: 0 0 42%;
  width: 42%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #080d15;
  border-right: none;
  position: relative;
  min-height: 0;
  overflow: hidden;
}

/* Draggable Vertical Splitter 1 */
.lab-splitter, .lab-splitter-v {
  width: 8px;
  background: var(--line);
  cursor: col-resize;
  position: relative;
  transition: background 0.15s ease;
  user-select: none;
  touch-action: none;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.lab-splitter:hover, .lab-splitter.dragging,
.lab-splitter-v:hover, .lab-splitter-v.dragging {
  background: var(--accent);
}

.splitter-handle, .splitter-handle-v {
  width: 2px;
  height: 32px;
  background: var(--dim);
  border-radius: 1px;
  pointer-events: none;
}

.lab-splitter:hover .splitter-handle, .lab-splitter.dragging .splitter-handle,
.lab-splitter-v:hover .splitter-handle-v, .lab-splitter-v.dragging .splitter-handle-v {
  background: #ffffff;
}

/* Draggable Horizontal Splitter 2 */
.lab-splitter-h {
  height: 8px;
  width: 100%;
  background: var(--line);
  cursor: row-resize;
  position: relative;
  transition: background 0.15s ease;
  user-select: none;
  touch-action: none;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.lab-splitter-h:hover, .lab-splitter-h.dragging {
  background: var(--accent);
}

.splitter-handle-h {
  height: 2px;
  width: 36px;
  background: var(--dim);
  border-radius: 1px;
  pointer-events: none;
}

.lab-splitter-h:hover .splitter-handle-h, .lab-splitter-h.dragging .splitter-handle-h {
  background: #ffffff;
}

body.theme-light .graph-pane, body.theme-light .graph-column {
  background: #eaeff5;
}

.graph-head {
  padding: 6px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--dim);
  flex-shrink: 0;
  min-height: 34px;
}

.graph-head-left, .graph-head-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.graph-title-text {
  color: var(--text);
  font-weight: 700;
  font-size: 12.5px;
}

.graph-meta-badge {
  font-size: 11px;
  font-family: ui-monospace, monospace;
  color: var(--dim);
}

.graph-status-tag {
  color: var(--orange);
  font-weight: 700;
  font-size: 11px;
}

/* Compact Step Details Status Strip */
.step-compact-strip {
  height: 36px;
  min-height: 34px;
  max-height: 48px;
  background: var(--panel-alt);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  font-size: 12px;
  overflow: hidden;
  flex-shrink: 0;
}

.step-strip-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.step-strip-num {
  font-weight: 700;
  color: var(--text);
  font-size: 12px;
}

.step-strip-desc {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  font-size: 12px;
}

.step-strip-formula {
  background: #090e16;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: #fde68a;
  flex-shrink: 0;
  white-space: nowrap;
}

body.theme-light .step-strip-formula {
  background: #fef3c7;
  color: #92400e;
  border-color: #fde68a;
}

.graph-viewport {
  flex: 1;
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden !important;
  cursor: grab;
  user-select: none;
  min-height: 0;
}

.graph-viewport::-webkit-scrollbar {
  display: none !important;
}

.graph-viewport:active {
  cursor: grabbing;
}

svg#svgCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* SVG Zoom controls */
.zoom-controls {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  gap: 4px;
  z-index: 10;
  background: rgba(12, 18, 26, 0.85);
  border: 1px solid #24364b;
  border-radius: 6px;
  padding: 3px;
  backdrop-filter: blur(4px);
}

.zoom-btn {
  background: #141f2d;
  color: #c7d6e4;
  border: 1px solid #233446;
  border-radius: 4px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.zoom-btn:hover {
  background: #20344d;
  color: #fff;
  border-color: var(--blue-light);
}

.zoom-text {
  font-size: 11px;
  color: var(--dim);
  padding: 0 6px;
  display: flex;
  align-items: center;
}

/* Right Source Code & Playback Pane */
.code-pane, .step-column {
  flex: 0 0 58%;
  width: 58%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.code-panel-container {
  flex: 1;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.playback-container {
  flex-shrink: 0;
}

/* =====================================================================
   ALGORITHM CODE PANEL (REAL EXECUTABLE SOURCE CODE)
   ===================================================================== */

.code-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #080d15;
  border-top: 1px solid var(--line);
  min-height: 0;
}

body.theme-light .code-panel {
  background: #eff3f8;
}

.code-panel-header {
  padding: 6px 12px;
  background: var(--panel-alt);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.code-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-shrink: 1;
  overflow: hidden;
}

.code-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.code-panel-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--blue-light);
  white-space: nowrap;
}

.code-algo-badge {
  font-size: 10.5px;
  padding: 1px 7px;
  border-radius: 4px;
  font-weight: 600;
  background: rgba(56, 189, 248, 0.12);
  color: var(--blue-light);
  border: 1px solid rgba(56, 189, 248, 0.25);
  white-space: nowrap;
}

.code-lang-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.code-lang-label {
  font-size: 11px;
  color: var(--dim);
  white-space: nowrap;
}

.code-lang-select {
  padding: 2px 6px;
  font-size: 11.5px;
  border-radius: 4px;
  height: 24px;
}

.code-btn {
  font-size: 11px;
  padding: 2px 8px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  transition: all 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.code-panel-body {
  flex: 1;
  overflow: auto;
  padding: 6px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  min-width: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(100, 116, 139, 0.35) rgba(0, 0, 0, 0.12);
}

.code-panel-body::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

.code-panel-body::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.12);
}

.code-panel-body::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.35);
  border-radius: 4px;
}

.code-panel-body::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.6);
}

body.theme-light .code-panel-body {
  scrollbar-color: rgba(100, 116, 139, 0.3) rgba(0, 0, 0, 0.04);
}

body.theme-light .code-panel-body::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.04);
}

body.theme-light .code-panel-body::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.3);
}

body.theme-light .code-panel-body::-webkit-scrollbar-thumb:hover {
  background: rgba(71, 85, 105, 0.55);
}

.code-line {
  display: flex;
  align-items: flex-start;
  padding: 1px 10px;
  color: #94a3b8;
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
  white-space: pre;
  word-break: normal;
  min-width: max-content;
}

.code-line:hover {
  background: rgba(255, 255, 255, 0.03);
}

.code-line-num {
  width: 34px;
  flex-shrink: 0;
  color: #475569;
  font-size: 11px;
  text-align: right;
  padding-right: 8px;
  margin-right: 8px;
  border-right: 1px solid var(--line);
  user-select: none;
}

.code-line-content {
  flex: 1;
  white-space: pre;
  word-break: normal;
}

.code-line.active-line {
  background: rgba(245, 158, 11, 0.18) !important;
  color: #ffffff !important;
  font-weight: 700;
  border-left: 3px solid var(--accent);
}

body.theme-light .code-line {
  color: #334155;
}

body.theme-light .code-line:hover {
  background: rgba(0, 0, 0, 0.04);
}

body.theme-light .code-line-num {
  color: #64748b;
  border-right-color: #cbd5e1;
}

body.theme-light .code-line.active-line {
  background: rgba(217, 119, 6, 0.16) !important;
  color: #0f172a !important;
  border-left: 3px solid var(--accent);
}

/* Syntax Highlighting Tokens */
.tok-kw {
  color: #c084fc;
  font-weight: 600;
}

body.theme-light .tok-kw {
  color: #7c3aed;
}

.tok-str {
  color: #34d399;
}

body.theme-light .tok-str {
  color: #059669;
}

.tok-num {
  color: #fb923c;
}

body.theme-light .tok-num {
  color: #ea580c;
}

.tok-com {
  color: #64748b;
  font-style: italic;
}

.tok-type {
  color: #38bdf8;
  font-weight: 600;
}

body.theme-light .tok-type {
  color: #0284c7;
}

.tok-fn {
  color: #fde047;
}

body.theme-light .tok-fn {
  color: #b45309;
}

/* Playback Controller Bar */
.playback-bar {
  background: var(--panel-alt);
  border-top: 1px solid var(--line);
  padding: 5px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  min-height: 40px;
}

.playback-buttons {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ctrl-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ctrl-btn.btn-play {
  min-width: 76px;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.ctrl-btn.btn-play:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
  box-shadow: 0 2px 6px rgba(245, 158, 11, 0.35);
}

.ctrl-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

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

.ctrl-btn.active-play {
  background: var(--orange);
  color: #fff;
  border-color: var(--orange);
  box-shadow: 0 2px 6px rgba(255, 87, 34, 0.4);
}

.step-jump-box {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 10px;
  height: 28px;
}

.step-jump-label {
  font-size: 11.5px;
  color: var(--dim);
  font-weight: 600;
}

.step-jump-input {
  width: 36px;
  height: 20px;
  padding: 0 2px;
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
  background: var(--panel-alt);
  color: var(--accent);
  border: 1px solid var(--line);
  border-radius: 3px;
  outline: none;
  font-family: ui-monospace, monospace;
}

.step-jump-input:focus {
  border-color: var(--accent);
}

.step-counter-text {
  font-size: 12px;
  font-weight: 700;
  font-family: ui-monospace, monospace;
  color: var(--accent);
  padding: 0 2px;
}

/* Step Scrubber Slider: hidden per user request */
.playback-scrubber {
  display: none !important;
}

.step-slider {
  width: 100%;
  cursor: pointer;
  accent-color: var(--accent);
  height: 4px;
}

.step-slider:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.playback-speed-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.playback-speed-label {
  font-size: 11px;
  color: var(--dim);
}

.speed-slider {
  width: 60px;
  cursor: pointer;
  accent-color: var(--accent);
  height: 4px;
}

.speed-val-text {
  font-size: 11px;
  font-weight: 700;
  font-family: ui-monospace, monospace;
  min-width: 30px;
  color: var(--accent);
}

/* Lab Lower Row / Bottom Workspace: Matrix / State Table */
.table-pane, .lab-lower-row, .lab-bottom-workspace {
  flex: 0 0 38%;
  height: 38%;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-height: 0;
  overflow: hidden;
  position: relative;
}

/* =====================================================================
   FOCUS MODES & FULLSCREEN (Full Lab, Graph, Code, Table Fullscreen)
   ===================================================================== */

body.has-lab-focus-mode,
body.is-fullscreen-mode {
  overflow: hidden !important;
}

/* Ensure global app header (including all web navigation tabs) is completely hidden in fullscreen and focus mode */
:fullscreen .app-header,
:-webkit-full-screen .app-header,
body.has-lab-focus-mode .app-header,
body.is-fullscreen-mode .app-header {
  display: none !important;
  visibility: hidden !important;
  height: 0 !important;
  min-height: 0 !important;
  max-height: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  border: none !important;
  overflow: hidden !important;
  pointer-events: none !important;
}

:fullscreen #app,
:-webkit-full-screen #app,
body.has-lab-focus-mode #app,
body.is-fullscreen-mode #app {
  height: 100vh !important;
  max-height: 100vh !important;
  width: 100vw !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
}

/* 1. Full Lab Focus Mode: Lab occupies entire viewport */
.lab-layout.focus-lab,
:fullscreen .lab-layout,
:-webkit-full-screen .lab-layout {
  position: fixed !important;
  inset: 0 !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  z-index: 99999 !important;
  background: var(--bg) !important;
  margin: 0 !important;
  padding: 0 !important;
  box-sizing: border-box !important;
}

/* 2. Graph Fullscreen Focus Mode */
.lab-layout.focus-graph {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 10000 !important;
  background: var(--bg) !important;
  margin: 0 !important;
  padding: 0 !important;
  box-sizing: border-box !important;
}

.lab-layout.focus-graph .lab-toolbar,
.lab-layout.focus-graph #labSplitter,
.lab-layout.focus-graph #labSplitterH,
.lab-layout.focus-graph #stateTableContainer,
.lab-layout.focus-graph #codePanelContainer {
  display: none !important;
}

.lab-layout.focus-graph #labUpperRow {
  flex: 1 1 100% !important;
  height: 100% !important;
  width: 100% !important;
  max-height: none !important;
}

.lab-layout.focus-graph #graphColumn {
  flex: 1 1 100% !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
}

.lab-layout.focus-graph #stepColumn {
  position: fixed !important;
  bottom: 0 !important;
  left: 0 !important;
  right: 0 !important;
  width: 100% !important;
  height: auto !important;
  min-height: 0 !important;
  z-index: 10005 !important;
  background: transparent !important;
  border: none !important;
  pointer-events: none !important;
}

.lab-layout.focus-graph #playbackControlsContainer {
  pointer-events: auto !important;
  background: var(--panel) !important;
  border-top: 1px solid var(--line) !important;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5) !important;
}

/* 3. Code Fullscreen Focus Mode */
.lab-layout.focus-code {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 10000 !important;
  background: var(--bg) !important;
  margin: 0 !important;
  padding: 0 !important;
  box-sizing: border-box !important;
}

.lab-layout.focus-code .lab-toolbar,
.lab-layout.focus-code #graphColumn,
.lab-layout.focus-code #labSplitter,
.lab-layout.focus-code #labSplitterH,
.lab-layout.focus-code #stateTableContainer {
  display: none !important;
}

.lab-layout.focus-code #labUpperRow {
  flex: 1 1 100% !important;
  height: 100% !important;
  width: 100% !important;
  max-height: none !important;
}

.lab-layout.focus-code #stepColumn {
  flex: 1 1 100% !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  display: flex !important;
  flex-direction: column !important;
}

.lab-layout.focus-code #codePanelContainer {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  height: 100% !important;
}

.lab-layout.focus-code #playbackControlsContainer {
  flex-shrink: 0 !important;
}

/* 4. Table Fullscreen Focus Mode */
.lab-layout.focus-table {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 10000 !important;
  background: var(--bg) !important;
  margin: 0 !important;
  padding: 0 !important;
  box-sizing: border-box !important;
}

.lab-layout.focus-table .lab-toolbar,
.lab-layout.focus-table #labUpperRow,
.lab-layout.focus-table #labSplitterH {
  display: none !important;
}

.lab-layout.focus-table #stateTableContainer,
.table-pane.table-expanded,
.lab-lower-row.table-expanded,
.lab-bottom-workspace.table-expanded {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 10000 !important;
  background: var(--bg) !important;
  flex: 1 1 100% !important;
  display: flex !important;
  flex-direction: column !important;
  margin: 0 !important;
  padding: 0 !important;
  box-shadow: none !important;
  overflow: hidden !important;
}

.table-pane.table-expanded .table-head-bar,
.lab-lower-row.table-expanded .table-head-bar {
  padding: 10px 20px;
  font-size: 13px;
}

.table-pane.table-expanded .table-wrap,
.lab-lower-row.table-expanded .table-wrap {
  padding: 16px 20px 40px;
}

.table-pane.table-expanded .state-table,
.lab-lower-row.table-expanded .state-table {
  font-size: 13px;
}

.table-pane.table-expanded .state-table th,
.table-pane.table-expanded .state-table td,
.lab-lower-row.table-expanded .state-table th,
.lab-lower-row.table-expanded .state-table td {
  padding: 8px 10px;
  font-size: 12.5px;
}

.table-head-bar {
  padding: 6px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--blue-light);
  flex-shrink: 0;
}

.table-head-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.table-step-indicator {
  font-size: 11px;
  color: var(--accent);
  font-weight: 700;
  margin-left: 6px;
}

.table-head-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.table-mode-group {
  display: inline-flex;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px;
  gap: 2px;
}

.table-mode-btn {
  background: transparent;
  border: none;
  color: var(--dim);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.table-mode-btn:hover {
  color: var(--text);
}

.table-mode-btn.active {
  background: var(--blue);
  color: #fff;
}

.table-expand-btn {
  background: var(--panel-alt);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.table-expand-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.table-wrap {
  flex: 1;
  overflow: auto;
  padding: 8px 14px;
  min-width: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(100, 116, 139, 0.35) rgba(0, 0, 0, 0.08);
}

.table-wrap::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

.table-wrap::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.08);
}

.table-wrap::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.35);
  border-radius: 4px;
}

.table-wrap::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.6);
}

body.theme-light .table-wrap {
  scrollbar-color: rgba(100, 116, 139, 0.3) rgba(0, 0, 0, 0.03);
}

body.theme-light .table-wrap::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.03);
}

body.theme-light .table-wrap::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.3);
}

body.theme-light .table-wrap::-webkit-scrollbar-thumb:hover {
  background: rgba(71, 85, 105, 0.55);
}

table.state-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
}

table.state-table th {
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  padding: 6px 8px;
  border: 1px solid #19567e;
  font-size: 11.5px;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 5;
}

table.state-table td {
  padding: 6px 6px;
  border: 1px solid var(--line);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11.5px;
  white-space: nowrap;
}

table.state-table tr:nth-child(even) {
  background: var(--panel-alt);
}

table.state-table tbody tr {
  cursor: pointer;
  transition: background 0.1s ease;
}

table.state-table tbody tr:hover {
  background: rgba(245, 158, 11, 0.08) !important;
}

table.state-table tr.active-row {
  background: rgba(245, 158, 11, 0.18) !important;
  outline: 2px solid var(--accent);
  position: relative;
  z-index: 1;
}

td.cell-settled {
  color: var(--red, #ef4444) !important;
  font-weight: 800 !important;
  background: rgba(239, 68, 68, 0.2) !important;
}

td.cell-updated {
  color: var(--green);
  font-weight: 700;
  background: rgba(16, 185, 129, 0.1);
}

td.cell-visited {
  color: #4e6173;
}

/* ---- Bellman-Ford textbook table: (x,y) | w | node columns ---- */
table.state-table tr.bf-pass-band td {
  background: #2f9be0 !important;
  color: #fff;
  font-weight: 800;
  text-align: left;
  border-color: #19567e;
  font-family: inherit;
  font-size: 12.5px;
}

table.state-table td.cell-bf-edge,
table.state-table td.cell-bf-weight {
  font-weight: 600;
}

table.state-table td.cell-bf-update {
  color: #1d4ed8;
  font-weight: 800;
}

body:not(.theme-light) table.state-table td.cell-bf-update {
  color: #60a5fa;
}

table.state-table td.cell-bf-kq {
  color: #dc2626;
  font-weight: 800;
  text-align: left;
}

table.state-table td.cell-bf-kq-val {
  font-weight: 700;
}

table.state-table tr.bf-kq-row td {
  border-top: 2px solid #dc2626;
}

table.state-table tr.bf-active td {
  background: #fde047 !important;
  color: #1f2937 !important;
}

table.state-table td.bf-col-hl,
table.state-table th.bf-col-hl {
  background: #fde047 !important;
  color: #1f2937 !important;
}

table.state-table tr.bf-edge-row.active-row {
  outline: 2px solid #ca8a04;
}

td.cell-tv {
  color: var(--blue-light);
  font-weight: 600;
}

td.cell-te {
  color: var(--accent);
  font-weight: 600;
}

/* =====================================================================
   SVG GRAPH NODES & EDGES STYLING
   ===================================================================== */

.edge {
  stroke: #334155;
  stroke-width: 2.8;
  stroke-linecap: round;
  fill: none;
  transition: all 0.2s ease;
}

body.theme-light .edge {
  stroke: #94a3b8;
}

.edge.directed {
  marker-end: url(#arrow-default);
}

.edge.checking {
  stroke: #f59e0b !important;
  stroke-width: 5px !important;
  stroke-dasharray: 6 3;
}

.edge.directed.checking {
  marker-end: url(#arrow-checking);
}

.edge.relaxed {
  stroke: #10b981 !important;
  stroke-width: 4.5px !important;
}

.edge.directed.relaxed {
  marker-end: url(#arrow-relaxed);
}

.edge.path {
  stroke: #ff4500 !important;
  stroke-width: 5.5px !important;
}

.edge.directed.path {
  marker-end: url(#arrow-path);
}

.edge.rejected {
  stroke: #ef4444 !important;
  stroke-width: 2.5px !important;
  stroke-dasharray: 3 3;
}

.edge.directed.rejected {
  marker-end: url(#arrow-rejected);
}

.nodebox {
  rx: 7px;
  ry: 7px;
  stroke-width: 2px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.nodebox:hover {
  filter: brightness(1.2);
}

.nodebox.active-u {
  stroke: #f59e0b !important;
  stroke-width: 4px !important;
  filter: drop-shadow(0 0 8px rgba(245, 158, 11, 0.7));
}

.nodebox.active-v {
  stroke: #38bdf8 !important;
  stroke-width: 3.5px !important;
}

.nodebox.settled {
  stroke: var(--red, #ef4444) !important;
  stroke-width: 4.5px !important;
  fill: rgba(239, 68, 68, 0.3) !important;
  filter: drop-shadow(0 0 10px rgba(239, 68, 68, 0.85));
}

.nodebox.on-path {
  stroke: #ff4500 !important;
  stroke-width: 4.5px !important;
  filter: drop-shadow(0 0 10px rgba(255, 69, 0, 0.7));
}

.nodebox.node-start {
  stroke: #10b981 !important;
  stroke-width: 3.5px !important;
  filter: drop-shadow(0 0 8px rgba(16, 185, 129, 0.75));
}

.nodebox.node-target {
  stroke: #ea580c !important;
  stroke-width: 3.5px !important;
  filter: drop-shadow(0 0 8px rgba(234, 88, 12, 0.75));
}

.nodelabel {
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  user-select: none;
  pointer-events: none;
}

.node-sub {
  font-size: 10px;
  font-weight: 600;
  text-anchor: middle;
  user-select: none;
  pointer-events: none;
}

.weight-badge {
  fill: #0c141f;
  stroke: #26384d;
  stroke-width: 1px;
  rx: 3px;
  ry: 3px;
}

.weight-text {
  font-size: 10.5px;
  font-weight: 700;
  fill: #94a3b8;
  text-anchor: middle;
  dominant-baseline: central;
  user-select: none;
  pointer-events: none;
}

.floor-tag {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-anchor: middle;
}

.floor-divider {
  stroke: #1e2d3d;
  stroke-dasharray: 5 4;
  stroke-width: 1.5;
}

/* =====================================================================
   4. MODAL FOR USER GRAPH INPUT
   ===================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20000; /* Must be above focus modes (z-index: 10000) */
  backdrop-filter: blur(4px);
}

.modal-dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  width: 92%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
}

.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 15.5px;
  font-weight: 700;
  margin: 0;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--dim);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}

.modal-close-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Modal Tabs */
.modal-tabs {
  display: flex;
  gap: 6px;
  background: rgba(0, 0, 0, 0.15);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--line);
}

body.theme-light .modal-tabs {
  background: rgba(0, 0, 0, 0.04);
}

.modal-tab-btn {
  flex: 1;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--dim);
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

.modal-tab-btn:hover {
  color: var(--text);
}

.modal-tab-btn.active {
  background: var(--blue-main);
  color: #fff;
  box-shadow: 0 2px 6px rgba(14, 165, 233, 0.35);
}

.modal-common-controls {
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--line);
  border-radius: 8px;
}

body.theme-light .modal-common-controls {
  background: rgba(0, 0, 0, 0.02);
}

/* File Dropzone */
.file-dropzone {
  border: 2px dashed rgba(56, 189, 248, 0.4);
  background: rgba(56, 189, 248, 0.03);
  border-radius: 10px;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.file-dropzone:hover,
.file-dropzone.drag-active {
  border-color: var(--blue-light);
  background: rgba(56, 189, 248, 0.1);
  transform: scale(1.005);
}

.dropzone-icon {
  font-size: 32px;
  margin-bottom: 6px;
}

.dropzone-prompt {
  font-size: 13px;
  color: var(--text);
  margin: 0 0 4px 0;
}

.dropzone-sub {
  font-size: 12px;
  color: var(--dim);
  margin: 0 0 8px 0;
}

.btn-browse {
  background: transparent;
  border: none;
  color: var(--blue-light);
  text-decoration: underline;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  padding: 0;
}

.dropzone-formats {
  font-size: 11px;
  color: var(--dim);
  background: rgba(0, 0, 0, 0.1);
  padding: 3px 8px;
  border-radius: 4px;
}

/* File Preview Card */
.file-preview-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
}

body.theme-light .file-preview-card {
  background: rgba(0, 0, 0, 0.02);
}

.file-preview-thumb {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.file-preview-meta {
  flex: 1;
  min-width: 0;
}

.file-preview-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-preview-size {
  font-size: 11.5px;
  color: var(--dim);
  margin-top: 2px;
}

.file-preview-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* AI Loading Indicator */
.ai-loading-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  background: rgba(14, 165, 233, 0.06);
  border: 1px solid rgba(14, 165, 233, 0.2);
  border-radius: 8px;
}

.ai-loading-text {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--blue-light);
}

/* AI Result Box */
.ai-result-box {
  padding: 12px;
  border: 1px solid rgba(34, 197, 94, 0.3);
  background: rgba(34, 197, 94, 0.05);
  border-radius: 8px;
}

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

.ai-confidence-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--dim);
}

.ai-confidence-badge.high {
  background: rgba(34, 197, 94, 0.2);
  color: #22c55e;
}

.ai-confidence-badge.med {
  background: rgba(234, 179, 8, 0.2);
  color: #eab308;
}

.ai-result-summary {
  font-size: 12px;
  color: var(--text);
}

.spec-warning-box {
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(234, 179, 8, 0.1);
  border: 1px solid rgba(234, 179, 8, 0.3);
  border-radius: 6px;
  color: #eab308;
  font-size: 11.5px;
  line-height: 1.5;
}

body.theme-light .spec-warning-box {
  background: rgba(202, 138, 4, 0.1);
  border-color: rgba(202, 138, 4, 0.3);
  color: #b45309;
}

.ai-result-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

/* Feedback Boxes */
.modal-summary-box {
  font-size: 12px;
  padding: 6px 12px;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 6px;
  color: var(--blue-light);
  font-family: monospace;
  font-weight: 600;
}

.modal-error-box {
  color: var(--red);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 12px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 6px;
  line-height: 1.4;
}

/* Canvas Drop Highlight */
.canvas-drag-active {
  outline: 2px dashed var(--blue-main) !important;
  outline-offset: -3px;
  background: rgba(14, 165, 233, 0.08) !important;
}

.modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* =====================================================================
   5. AI ASSISTANT VIEW (PLACEHOLDER)
   ===================================================================== */

.ai-container {
  max-width: 760px;
  margin: 60px auto;
  padding: 30px;
  text-align: center;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
}

.ai-icon {
  font-size: 54px;
  margin-bottom: 16px;
}

.ai-title {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 12px;
}

.ai-desc {
  font-size: 15px;
  color: var(--dim);
  line-height: 1.6;
  margin-bottom: 24px;
}

/* =====================================================================
   RESPONSIVE LAYOUT (TABLET & MOBILE)
   ===================================================================== */

@media (max-width: 860px) {
  .lab-layout {
    height: auto;
    overflow: visible;
  }

  .lab-workspace, .lab-top-workspace, .lab-upper-row {
    flex-direction: column;
    height: auto !important;
    flex: none !important;
  }

  .lab-splitter, .lab-splitter-v, .lab-splitter-h {
    display: none !important;
  }

  .graph-pane, .graph-column {
    width: 100% !important;
    flex: none !important;
    height: 380px;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .code-pane, .step-column {
    width: 100% !important;
    flex: none !important;
    height: auto !important;
    min-height: 280px;
  }

  .table-pane, .lab-lower-row, .lab-bottom-workspace {
    width: 100% !important;
    flex: none !important;
    height: 350px !important;
  }
}

@media (max-width: 600px) {
  .brand-badge {
    display: none;
  }

  .nav-btn span.nav-text {
    display: none;
  }

  .hero-title {
    font-size: 28px;
  }

  .hero-subtitle {
    font-size: 14.5px;
  }

  .graph-column {
    height: 320px;
  }
}

/* =====================================================================
   Logic Lab (Propositional Logic & Truth Table) Styles
   ===================================================================== */
.btn-key {
  background: var(--panel-alt);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 5px;
  font-family: monospace;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.btn-key:hover {
  background: var(--line);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-key:active {
  transform: translateY(1px);
}

.btn-key.var-key {
  color: var(--blue-light);
  font-weight: 700;
}

.btn-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--dim);
  transition: all 0.15s ease;
}

.btn-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.btn-tab.active {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent);
  border: 1px solid rgba(245, 158, 11, 0.35);
}

/* Relation Lab tab bar: inactive tabs get a visible chip (same padding/size as the
   active tab, which only differs by the amber fill) + a hover effect that is also
   visible in light mode (the generic .btn-tab:hover is white-on-white there). */
.relation-tabs-bar .btn-tab:not(.active) {
  background: var(--panel-alt);
  border: 1px solid var(--line);
  color: var(--dim);
}

.relation-tabs-bar .btn-tab:not(.active):hover {
  background: rgba(245, 158, 11, 0.08);
  border-color: rgba(245, 158, 11, 0.35);
  color: var(--text);
}

.btn-style-opt {
  background: var(--panel-alt);
  border: none;
  padding: 4px 10px;
  color: var(--dim);
  cursor: pointer;
  font-size: 11.5px;
  font-weight: 600;
  transition: all 0.15s;
}

.btn-style-opt:hover {
  color: var(--text);
}

.btn-style-opt.active {
  background: var(--accent);
  color: #090d14;
}

.logic-truth-table th,
.logic-truth-table td {
  border: 1px solid var(--line);
  padding: 8px 10px;
}

.logic-truth-table tr:hover {
  background: rgba(255, 255, 255, 0.03) !important;
}

body.theme-light .logic-truth-table tr:hover {
  background: rgba(0, 0, 0, 0.03) !important;
}

/* ---------------------------------------------------------------------
   Light-mode contrast fix: Truth Table (styling only, dark mode untouched).
   LogicLabView writes these greys as inline styles, so !important is
   required to override them. Orange variable headers (p, q, r) are kept.
   --------------------------------------------------------------------- */

/* Sub-expression column headers (p -> q, q -> r, ...): inline #94a3b8 */
body.theme-light .logic-truth-table thead th[style*="94a3b8"] {
  color: #000000 !important;
}

/* Secondary labels (STT, row index, "Đối chiếu"): inline var(--dim) */
body.theme-light .logic-truth-table [style*="var(--dim)"] {
  color: #000000 !important;
}

/* Empty placeholder cell dot before a row is revealed: faded to 25% opacity */
body.theme-light .logic-truth-table [style*="opacity:0.25"],
body.theme-light .logic-truth-table [style*="opacity: 0.25"] {
  color: #000000 !important;
  opacity: 1 !important;
}

/* Copy buttons (keep the blue hover colour from .btn-sm:hover) */
body.theme-light #btnCopyMarkdown:not(:hover):not(:disabled),
body.theme-light #btnCopyLatex:not(:hover):not(:disabled) {
  color: #000000;
}

/* "Sẵn sàng chạy (0%)" badge: only the idle state, which is set to var(--dim) inline */
body.theme-light #logicRunningStatusBadge[style*="var(--dim)"] {
  color: #000000 !important;
}

.btn-subtab {
  background: var(--panel-alt);
  border: 1px solid var(--line);
  color: var(--dim);
  transition: all 0.15s ease;
  user-select: none;
}

.btn-subtab:hover {
  color: var(--text);
  border-color: var(--accent);
}

.btn-subtab.active {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent);
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.kmap-cell {
  position: relative;
  width: 72px;
  height: 64px;
  border: 1px solid var(--line);
  text-align: center;
  vertical-align: middle;
  transition: all 0.15s ease;
}

.kmap-cell:hover {
  background: rgba(255, 255, 255, 0.04);
}

/* Logic Lab Horizontal Splitter (Matches LabView style) */
#logicSplitterH.lab-splitter-h {
  margin: 4px 0 16px 0;
  border-radius: 4px;
  display: flex !important;
}

/* Discrete Math 4-Pillars Card Styling */
.pillar-card {
  position: relative;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.pillar-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent) !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

body.theme-light .pillar-card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

/* =====================================================================
   Quiz & Exam Studio Styles
   ===================================================================== */
.btn-quiz-option {
  position: relative;
  user-select: none;
  border-radius: 8px;
  white-space: normal !important;
  word-break: normal !important;
  text-align: left !important;
  display: flex !important;
  align-items: center !important;
  width: 100% !important;
  transition: all 0.15s ease !important;
}

.btn-quiz-option:not(:disabled):hover {
  border-color: var(--accent) !important;
  background: var(--line) !important;
  transform: translateX(4px) !important;
}

.btn-quiz-option:active {
  transform: translateX(2px) !important;
}

body.theme-light .btn-quiz-option:not(:disabled):hover {
  background: #e2e8f0 !important;
}

body.theme-light .exam-paper-wrapper {
  background: #cbd5e1 !important;
}

/* Helper class toggled right before window.print() to reset viewport clipping in Chromium */
body.is-printing-exam,
body.is-printing-exam html,
body.is-printing-exam #app,
body.is-printing-exam #appMain,
body.is-printing-exam .app-main,
body.is-printing-exam #quizView,
body.is-printing-exam .quiz-view-container,
body.is-printing-exam #paneStudio,
body.is-printing-exam .exam-paper-wrapper {
  overflow: visible !important;
  overflow-x: visible !important;
  overflow-y: visible !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
}

/* Print Styles for A4 Paper Layout */
@media print {
  @page {
    size: A4 portrait;
    margin: 12mm 15mm 15mm 15mm;
  }

  *, *:before, *:after {
    box-sizing: border-box !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  html, 
  body {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    overflow-x: visible !important;
    overflow-y: visible !important;
    position: static !important;
    background: #ffffff !important;
    color: #000000 !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
  }

  #app,
  #appMain,
  .app-main,
  #quizView,
  .quiz-view-container,
  #paneStudio,
  .exam-paper-wrapper {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    overflow-x: visible !important;
    overflow-y: visible !important;
    position: static !important;
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  /* Explicitly hide non-printable UI elements */
  .app-header,
  .nav-links,
  .header-actions,
  .brand-wrap,
  .quiz-header,
  .quiz-main-tabs,
  .no-print,
  #panePractice,
  .exam-studio-controls,
  #homeView,
  #theoryView,
  #labView,
  #logicView,
  #aiView,
  #fundamentalsView,
  #countingView {
    display: none !important;
  }

  .exam-paper {
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 0 20mm 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    background: #ffffff !important;
    color: #000000 !important;
  }

  .exam-question-item {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    margin-bottom: 14px !important;
  }

  .exam-bubble-sheet {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .teacher-key-page {
    page-break-before: always !important;
    break-before: page !important;
    margin-top: 0 !important;
    padding-top: 0 !important;
  }
}

/* =====================================================================
   COUNTING LAB & MAPPING STUDIO STYLES
   ===================================================================== */
.counting-mapping-grid,
.dirichlet-classic-grid,
.counting-perm-grid,
.counting-pie-grid {
  display: grid;
  width: 100%;
  box-sizing: border-box;
}

.mapping-sets-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
}

.mapping-set-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mapping-svg-wrapper {
  width: 100%;
  height: 380px;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}

.counting-lab-container .arrow-group:hover .visible-arrow {
  stroke: var(--accent) !important;
  stroke-width: 3.5px !important;
  marker-end: url(#arrowhead-hover) !important;
  filter: drop-shadow(0 0 4px rgba(245, 158, 11, 0.6));
}

.counting-lab-container .node-domain:hover circle:nth-of-type(1),
.counting-lab-container .node-codomain:hover circle:nth-of-type(1) {
  stroke-width: 3.2px !important;
  filter: drop-shadow(0 0 6px rgba(56, 189, 248, 0.4));
}

.counting-lab-container .edge-chip {
  transition: all 0.15s ease;
}

.counting-lab-container .edge-chip:hover {
  border-color: var(--accent) !important;
  background: var(--panel) !important;
  color: var(--accent) !important;
}

.counting-lab-container .edge-chip .btn-remove-edge:hover {
  color: var(--red) !important;
}

/* Dirichlet Pigeonhole Studio */
.pigeon-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 160px;
  position: relative;
}

.pigeon-box:hover {
  border-color: rgba(56, 189, 248, 0.4);
  transform: translateY(-2px);
}

.pigeon-box.max-box {
  border-color: var(--accent) !important;
  box-shadow: 0 0 14px rgba(245, 158, 11, 0.25);
  background: linear-gradient(180deg, var(--panel) 0%, rgba(245, 158, 11, 0.04) 100%);
}

.pigeon-box.empty-box {
  border-style: dashed;
  opacity: 0.75;
}

.pigeon-icon {
  display: inline-block;
  font-size: 19px;
  line-height: 1;
  transition: transform 0.2s ease;
  user-select: none;
}

.pigeon-icon:hover {
  transform: scale(1.25);
}

.pigeon-cage-arena {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  min-height: 85px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-content: flex-start;
  overflow-y: auto;
  max-height: 140px;
}

/* =====================================================================
   PASCAL TRIANGLE & COMBINATORICS STYLES
   ===================================================================== */
.pascal-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: auto;
  padding: 16px 8px;
}

.pascal-row-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 7px;
  white-space: nowrap;
}

.pascal-row-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--dim);
  width: 60px;
  text-align: right;
  user-select: none;
}

.pascal-cells-row {
  display: flex;
  gap: 7px;
}

.pascal-cell {
  min-width: 44px;
  height: 40px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}

.pascal-cell:hover {
  transform: scale(1.22);
  border-color: var(--blue-light);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.4);
  z-index: 5;
}

.pascal-cell.selected {
  background: #0284c7 !important;
  color: #ffffff !important;
  border-color: #38bdf8 !important;
  transform: scale(1.25);
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.8) !important;
  z-index: 6;
}

.pascal-cell.parent-cell {
  background: rgba(16, 185, 129, 0.22) !important;
  border-color: var(--accent2) !important;
  color: var(--accent2) !important;
  transform: scale(1.12);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.5) !important;
}

.pascal-cell.symmetric-cell {
  background: rgba(168, 85, 247, 0.22) !important;
  border-color: #c084fc !important;
  color: #c084fc !important;
  transform: scale(1.12);
}

.pascal-cell.mod-active {
  background: rgba(245, 158, 11, 0.22) !important;
  border-color: var(--accent) !important;
  color: var(--accent) !important;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.4);
}

.pascal-cell.mod-inactive {
  opacity: 0.25;
}

.combinatorics-config-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  padding: 4px 10px;
  border-radius: 6px;
  font-family: monospace;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s ease;
}

.combinatorics-config-badge.active-config {
  border-color: var(--accent) !important;
  background: rgba(245, 158, 11, 0.15) !important;
  color: var(--accent) !important;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.3);
}

/* =====================================================================
   TOWER OF HANOI & RECURRENCE STYLES
   ===================================================================== */
.hanoi-arena {
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  min-height: 290px;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px 20px 18px;
  position: relative;
  box-sizing: border-box;
}

.hanoi-peg-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 30%;
  position: relative;
}

.hanoi-peg-stage {
  position: relative;
  width: 100%;
  height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
}

.hanoi-peg-stem {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 180px;
  background: #64748b;
  border-radius: 6px 6px 0 0;
  z-index: 1;
  box-shadow: inset 1px 0 2px rgba(255, 255, 255, 0.2);
}

body.theme-light .hanoi-peg-stem {
  background: #94a3b8;
}

.hanoi-peg-base {
  width: 92%;
  height: 12px;
  background: #475569;
  border-radius: 6px;
  z-index: 3;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
  margin-top: 0;
}

body.theme-light .hanoi-peg-base {
  background: #64748b;
}

.hanoi-disks-stack {
  width: 100%;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  z-index: 2;
  margin-bottom: 0;
  padding-bottom: 1px;
}

.hanoi-disk {
  height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-weight: 800;
  font-size: 13px;
  margin-bottom: 2px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
  user-select: none;
}

.hanoi-peg-label {
  margin-top: 14px;
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  text-align: center;
  white-space: nowrap;
  letter-spacing: 0.2px;
}

/* Recurrence Order Selector Buttons */
.btn-order-toggle {
  white-space: normal !important;
  text-align: center;
  padding: 8px 10px;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1.35;
}

.btn-order-toggle.active {
  background: var(--blue) !important;
  color: #ffffff !important;
  border-color: var(--blue-light) !important;
  box-shadow: 0 0 10px rgba(2, 132, 199, 0.4);
}

.btn-order-toggle:not(.active) {
  background: var(--panel-alt);
  color: var(--text);
}

.btn-order-toggle:not(.active):hover {
  background: var(--card-bg);
  border-color: var(--dim);
}

@media (max-width: 960px) {
  .recurrence-solver-grid,
  .hanoi-layout-grid {
    grid-template-columns: 1fr !important;
  }
}

/* =========================================================================
   Chapter 4: Relation Lab (Toán Rời Rạc - Phòng Thí Nghiệm Quan Hệ)
   ========================================================================= */

.relation-matrix-table {
  border-collapse: separate;
  border-spacing: 5px;
}

.relation-matrix-cell {
  width: 42px;
  height: 42px;
  min-width: 42px;
  min-height: 42px;
  padding: 0;
  border-radius: 6px;
  font-weight: 800;
  font-size: 14px;
  font-family: monospace;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  background: var(--panel-alt);
  color: var(--dim);
  border: 1px solid var(--line);
  white-space: nowrap !important;
}

.relation-matrix-cell:hover {
  border-color: var(--blue-light);
  color: var(--text);
  transform: scale(1.06);
}

.relation-matrix-cell.active {
  background: var(--blue) !important;
  color: #ffffff !important;
  border-color: var(--blue-light) !important;
  box-shadow: 0 0 10px rgba(2, 132, 199, 0.4);
}

.relation-matrix-cell.diagonal {
  box-shadow: inset 0 0 0 2px rgba(245, 158, 11, 0.45);
}

.relation-matrix-cell.active.diagonal {
  box-shadow: inset 0 0 0 2px #f59e0b, 0 0 10px rgba(2, 132, 199, 0.4);
}

.relation-matrix-cell.hovered {
  outline: 2px solid var(--accent);
  transform: scale(1.1);
}

.relation-pair-chip {
  transition: background 0.15s ease, border-color 0.15s ease;
}

.relation-pair-chip:hover {
  border-color: var(--blue-light);
  background: var(--card-bg) !important;
}

.relation-node-group circle {
  transition: fill 0.2s ease, stroke 0.2s ease, r 0.2s ease;
}

.relation-node-group:hover circle:first-of-type {
  stroke: var(--accent);
}

.quiz-option-card {
  transition: all 0.15s ease;
}

.quiz-option-card:hover {
  border-color: var(--blue-light) !important;
  background: var(--panel-alt) !important;
}

.property-inspector-card {
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.property-inspector-card:hover {
  border-color: var(--dim);
}

@media (max-width: 960px) {
  .relation-workspace-grid,
  .relation-cards-grid,
  .quiz-options-grid {
    grid-template-columns: 1fr !important;
  }
}

/* =====================================================================
   Teacher Presentation & Laser / Annotation Tools
   ===================================================================== */
.teacher-annotation-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9990;
  pointer-events: none;
}

.teacher-tools-dock {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9995;
  display: flex;
  user-select: none;
  animation: teacherDockPop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes teacherDockPop {
  from {
    opacity: 0;
    transform: translate(-50%, 20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
}

.teacher-dock-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 23, 34, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(245, 158, 11, 0.35);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.5), 0 0 20px rgba(245, 158, 11, 0.15);
  padding: 6px 12px;
  border-radius: 9999px;
  color: var(--text);
}

body.theme-light .teacher-dock-card {
  background: rgba(244, 247, 251, 0.94);
  border-color: rgba(217, 119, 6, 0.4);
  box-shadow: 0 16px 36px rgba(100, 116, 139, 0.25), 0 0 16px rgba(217, 119, 6, 0.15);
}

.teacher-dock-grip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  cursor: grab;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  border-radius: 9999px;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.2);
  touch-action: none;
}

.teacher-dock-grip:active {
  cursor: grabbing;
}

.teacher-dock-grip .grip-icon {
  font-size: 13px;
  opacity: 0.8;
}

.teacher-dock-grip .grip-title {
  white-space: nowrap;
}

.dock-divider {
  width: 1px;
  height: 24px;
  background: var(--line);
}

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

.dock-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 9999px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.dock-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

body.theme-light .dock-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

.dock-btn.active {
  background: rgba(245, 158, 11, 0.2);
  color: var(--accent);
  border-color: rgba(245, 158, 11, 0.45);
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.25);
}

.color-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.color-dot:hover {
  transform: scale(1.15);
}

.color-dot.selected {
  transform: scale(1.25);
  border-color: #ffffff;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
}

body.theme-light .color-dot.selected {
  border-color: #0f172a;
}

.size-pill {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel-alt);
  color: var(--dim);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.15s ease;
}

.size-pill:hover {
  color: var(--text);
  border-color: var(--accent);
}

.size-pill.active {
  background: var(--accent);
  color: #090d14;
  border-color: var(--accent);
  font-weight: 800;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
}

.dock-btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 5px 9px;
  min-height: 28px;
  border-radius: 9999px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  color: var(--dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.dock-btn-action:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-color: var(--dim);
}

body.theme-light .dock-btn-action:hover {
  background: rgba(0, 0, 0, 0.06);
}

.dock-btn-action.active-clickthrough {
  background: #10b981;
  color: #ffffff;
  border-color: #059669;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.45);
  animation: pulseInteraction 1.5s infinite;
}

@keyframes pulseInteraction {
  0% { transform: scale(1); }
  50% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

.dock-btn-action.btn-close-tools:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.4);
}

/* Header button active state */
#btnTeacherToolsToggle.active {
  background: rgba(245, 158, 11, 0.2);
  color: var(--accent);
  border-color: rgba(245, 158, 11, 0.4);
}

@media (max-width: 768px) {
  .teacher-tools-dock {
    bottom: 12px;
    width: 95vw;
    overflow-x: auto;
  }
  .teacher-dock-card {
    padding: 4px 8px;
    gap: 4px;
  }
  .teacher-dock-grip .grip-title,
  .dock-btn .tool-text {
    display: none;
  }
}

/* =====================================================================
   Help Guide & Shortcuts Center Modal (Trung Tâm Hướng Dẫn & Trợ Giúp)
   ===================================================================== */
.help-guide-dialog {
  max-width: 840px;
  width: 94%;
  max-height: 88vh;
  border: 1px solid rgba(56, 189, 248, 0.35);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6), 0 0 30px rgba(56, 189, 248, 0.12);
  display: flex;
  flex-direction: column;
}

body.theme-light .help-guide-dialog {
  border-color: rgba(2, 132, 199, 0.3);
  box-shadow: 0 24px 60px rgba(100, 116, 139, 0.3), 0 0 24px rgba(2, 132, 199, 0.1);
}

.help-modal-head {
  padding: 16px 20px;
  background: var(--panel-alt);
  border-bottom: 1px solid var(--line);
}

.head-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.help-head-icon {
  font-size: 26px;
  line-height: 1;
}

.help-head-sub {
  font-size: 12px;
  color: var(--dim);
  display: block;
  margin-top: 2px;
}

.help-tabs-bar {
  display: flex;
  gap: 8px;
  padding: 10px 20px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--line);
}

body.theme-light .help-tabs-bar {
  background: rgba(0, 0, 0, 0.03);
}

.help-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.help-tab-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

body.theme-light .help-tab-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

.help-tab-btn.active {
  background: var(--panel-alt);
  color: var(--blue-light);
  border-color: rgba(56, 189, 248, 0.4);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.help-modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.guide-intro {
  font-size: 13.5px;
  color: var(--dim);
  margin-bottom: 4px;
  line-height: 1.5;
}

/* Quick Start Cards Grid */
.guide-cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

@media (max-width: 720px) {
  .guide-cards-grid {
    grid-template-columns: 1fr;
  }
}

.guide-lab-card {
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.guide-lab-card:hover {
  transform: translateY(-2px);
  border-color: var(--blue-light);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.guide-lab-card .card-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.guide-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.guide-card-title {
  font-size: 14px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.guide-card-sub {
  font-size: 11.5px;
  color: var(--dim);
  display: block;
  margin-top: 1px;
}

.guide-card-features {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 12px;
  color: var(--dim);
  display: flex;
  flex-direction: column;
  gap: 6px;
  line-height: 1.45;
}

.guide-card-features li strong {
  color: var(--text);
}

.guide-card-features code {
  background: rgba(0, 0, 0, 0.3);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: monospace;
  color: var(--accent);
}

body.theme-light .guide-card-features code {
  background: rgba(0, 0, 0, 0.08);
}

.guide-card-btn {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.guide-card-btn:hover {
  background: var(--blue);
  color: #ffffff;
  border-color: var(--blue);
}

.guide-extra-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 4px;
}

@media (max-width: 600px) {
  .guide-extra-row {
    grid-template-columns: 1fr;
  }
}

.guide-extra-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed var(--line);
  padding: 10px 14px;
  border-radius: 8px;
}

.guide-extra-card .extra-icon {
  font-size: 22px;
}

.guide-extra-card .extra-title {
  font-size: 13px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.guide-extra-card .extra-desc {
  font-size: 11px;
  color: var(--dim);
  margin: 2px 0 0 0;
  line-height: 1.35;
}

.guide-extra-card .extra-nav-btn {
  margin-left: auto;
  white-space: nowrap;
  padding: 5px 9px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--dim);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.guide-extra-card .extra-nav-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* Shortcuts Pane */
.shortcut-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.section-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 9999px;
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.section-title {
  font-size: 14px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.shortcut-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  background: var(--panel-alt);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.shortcut-table th {
  background: rgba(0, 0, 0, 0.2);
  text-align: left;
  padding: 8px 12px;
  font-weight: 600;
  color: var(--dim);
  border-bottom: 1px solid var(--line);
}

body.theme-light .shortcut-table th {
  background: rgba(0, 0, 0, 0.05);
}

.shortcut-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  vertical-align: middle;
}

.shortcut-table tr:last-child td {
  border-bottom: none;
}

.kbd-pill {
  display: inline-block;
  padding: 2px 7px;
  font-size: 11px;
  font-family: monospace;
  font-weight: 700;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 5px;
  box-shadow: 0 2px 0 var(--line);
  vertical-align: middle;
}

.highlight-badge {
  color: #10b981;
  font-weight: 700;
}

/* Tips Pane */
.guide-pane-tips {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.guide-tip-box {
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tip-box-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tip-badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 9999px;
  background: rgba(56, 189, 248, 0.15);
  color: var(--blue-light);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.tip-title {
  font-size: 14px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.tip-text {
  font-size: 12.5px;
  color: var(--dim);
  line-height: 1.5;
  margin: 0;
}

.syntax-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 4px;
}

@media (max-width: 640px) {
  .syntax-grid {
    grid-template-columns: 1fr;
  }
}

.syntax-item {
  background: rgba(0, 0, 0, 0.25);
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

body.theme-light .syntax-item {
  background: rgba(0, 0, 0, 0.04);
}

.syntax-item .syntax-name {
  font-size: 11px;
  color: var(--dim);
}

.syntax-item code {
  color: var(--accent);
  font-family: monospace;
  font-weight: 700;
}

/* Modal Footer */
.help-modal-foot {
  padding: 12px 20px;
  background: var(--panel-alt);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.help-foot-hint {
  font-size: 12px;
  color: var(--dim);
}

.btn-primary-sm {
  padding: 6px 14px;
  background: var(--accent);
  color: #090d14;
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-primary-sm:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* =====================================================================
   AI Assistant & Interactive Lab Bridge Styles
   ===================================================================== */
/* Lock outer window and body to prevent black void layout breakage */
html.view-ai-active,
body.view-ai-active {
  height: 100vh !important;
  max-height: 100vh !important;
  overflow: hidden !important;
}

body.view-ai-active #app,
body.view-ai-active .app-main {
  height: calc(100vh - 56px) !important;
  max-height: calc(100vh - 56px) !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

#aiView.active {
  display: block;
  height: calc(100vh - 56px) !important;
  max-height: calc(100vh - 56px) !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

.ai-assistant-layout {
  display: grid;
  grid-template-columns: 310px 1fr;
  height: 100% !important;
  max-height: 100% !important;
  min-height: 0 !important;
  overflow: hidden !important;
  background: var(--bg);
}

/* Hide mobile-only controls on desktop */
.ai-sidebar-backdrop,
.btn-ai-sidebar-close,
.btn-ai-sidebar-mobile-toggle,
.btn-ai-header-new-chat {
  display: none !important;
}

@media (max-width: 900px) {
  #aiView.active {
    height: calc(100dvh - 56px) !important;
    height: calc(100vh - 56px) !important;
    max-height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .ai-assistant-layout {
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
    max-height: 100% !important;
    width: 100% !important;
    min-height: 0 !important;
    position: relative !important;
    overflow: hidden !important;
  }

  /* Off-canvas mobile drawer for sidebar */
  .ai-sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 320px !important;
    max-width: 86vw !important;
    height: 100% !important;
    max-height: 100% !important;
    z-index: 100000 !important;
    transform: translateX(-100%) !important;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: 6px 0 28px rgba(0, 0, 0, 0.5) !important;
    border-right: 1px solid var(--line) !important;
    border-bottom: none !important;
    background: var(--panel) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior-y: contain !important;
  }

  .ai-sidebar.open {
    transform: translateX(0) !important;
  }

  /* Backdrop for mobile drawer */
  .ai-sidebar-backdrop {
    display: block !important;
    position: fixed !important;
    inset: 0 !important;
    background: rgba(0, 0, 0, 0.65) !important;
    backdrop-filter: blur(4px) !important;
    -webkit-backdrop-filter: blur(4px) !important;
    z-index: 99999 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    transition: opacity 0.25s ease !important;
  }

  .ai-sidebar-backdrop.open {
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  .btn-ai-sidebar-close {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 32px !important;
    height: 32px !important;
    background: rgba(255, 255, 255, 0.08) !important;
    border: 1px solid var(--line) !important;
    border-radius: 6px !important;
    color: var(--dim) !important;
    font-size: 14px !important;
    cursor: pointer !important;
  }

  .btn-ai-sidebar-close:hover {
    color: var(--text) !important;
    background: rgba(255, 255, 255, 0.15) !important;
  }

  /* Full-height chat canvas */
  .ai-chat-canvas {
    flex: 1 1 0% !important;
    height: 100% !important;
    max-height: 100% !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    width: 100% !important;
  }

  .ai-canvas-header {
    padding: 8px 12px !important;
    gap: 8px !important;
    flex-shrink: 0 !important;
  }

  .canvas-title-wrap {
    gap: 8px !important;
    min-width: 0 !important;
  }

  .btn-ai-sidebar-mobile-toggle {
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    padding: 6px 10px !important;
    background: rgba(56, 189, 248, 0.12) !important;
    border: 1px solid rgba(56, 189, 248, 0.3) !important;
    border-radius: 6px !important;
    color: var(--blue-light) !important;
    font-size: 12px !important;
    font-weight: 700 !important;
    cursor: pointer !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
  }

  .btn-ai-header-new-chat {
    display: inline-flex !important;
    align-items: center !important;
    padding: 6px 12px !important;
    background: var(--blue) !important;
    color: #ffffff !important;
    border: 1px solid var(--blue) !important;
    border-radius: 6px !important;
    font-size: 12px !important;
    font-weight: 700 !important;
    cursor: pointer !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
  }

  .ai-avatar-badge {
    width: 32px !important;
    height: 32px !important;
    font-size: 16px !important;
    border-radius: 8px !important;
    flex-shrink: 0 !important;
  }

  .ai-title {
    font-size: 14.5px !important;
    line-height: 1.2 !important;
  }

  .ai-sub-info {
    display: none !important;
  }

  /* Scrollable messages container */
  .ai-messages-scroll {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    height: 100% !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    overscroll-behavior-y: auto !important;
    overscroll-behavior: auto !important;
    padding: 12px 10px !important;
    gap: 12px !important;
  }

  .chat-message-row {
    max-width: 100% !important;
    gap: 8px !important;
  }

  .message-avatar {
    width: 30px !important;
    height: 30px !important;
    font-size: 14px !important;
    flex-shrink: 0 !important;
  }

  .message-bubble {
    padding: 10px 12px !important;
    font-size: 13px !important;
    line-height: 1.5 !important;
    max-width: calc(100% - 38px) !important;
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
    box-sizing: border-box !important;
  }

  .ai-lab-bridge-card {
    padding: 10px 12px !important;
    margin-top: 10px !important;
  }

  .btn-bridge-execute {
    width: 100% !important;
    padding: 8px 12px !important;
    font-size: 12px !important;
    box-sizing: border-box !important;
    white-space: normal !important;
    text-align: center !important;
  }

  /* Fixed bottom input bar */
  .ai-input-wrapper {
    flex-shrink: 0 !important;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px)) !important;
    background: var(--panel) !important;
    border-top: 1px solid var(--line) !important;
    z-index: 20 !important;
    width: 100% !important;
    box-sizing: border-box !important;
    gap: 6px !important;
  }

  .ai-quick-suggestions {
    gap: 5px !important;
    padding-bottom: 2px !important;
  }

  .sugg-chip {
    padding: 3px 8px !important;
    font-size: 10.5px !important;
  }

  .ai-input-form {
    gap: 8px !important;
    width: 100% !important;
  }

  .ai-textarea {
    padding: 8px 10px !important;
    font-size: 13px !important;
    min-height: 38px !important;
    max-height: 100px !important;
  }

  .btn-ai-send {
    height: 38px !important;
    padding: 0 12px !important;
    font-size: 12px !important;
  }

  .btn-ai-send .send-text {
    display: none !important;
  }
}

/* Sidebar */
.ai-sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  gap: 14px;
}

.ai-sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.ai-sidebar-icon {
  font-size: 26px;
}

.ai-sidebar-title {
  font-size: 14.5px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.ai-sidebar-sub {
  font-size: 11px;
  color: var(--dim);
  display: block;
}

/* API Status Card */
.ai-api-status-card {
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.status-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-online {
  background: #10b981;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
}

.status-local {
  background: #f59e0b;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.6);
}

.status-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text);
}

.btn-api-config {
  width: 100%;
  padding: 5px 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--dim);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-api-config:hover {
  color: var(--text);
  border-color: var(--accent);
}

.api-key-input-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.input-api-key {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 11.5px;
  color: var(--text);
  font-family: monospace;
}

.api-key-btn-row {
  display: flex;
  gap: 6px;
}

.btn-save-key {
  flex: 1;
  background: var(--accent);
  color: #090d14;
  font-weight: 700;
  border: none;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
}

.btn-clear-key {
  background: transparent;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
}

.btn-clear-key:hover {
  color: var(--red);
  border-color: var(--red);
}

.api-key-hint {
  font-size: 10px;
  color: var(--dim);
  line-height: 1.35;
}

/* Mode Selector */
.ai-mode-selector {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mode-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--dim);
  letter-spacing: 0.3px;
}

.mode-buttons {
  display: flex;
  gap: 4px;
  background: var(--panel-alt);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.mode-btn {
  flex: 1;
  padding: 5px 6px;
  border: none;
  background: transparent;
  color: var(--dim);
  font-size: 11px;
  font-weight: 600;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.mode-btn:hover {
  color: var(--text);
}

.mode-btn.active {
  background: var(--accent);
  color: #090d14;
  font-weight: 700;
}

/* Prompts Library */
.ai-prompts-library {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.prompts-heading {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--dim);
  letter-spacing: 0.3px;
}

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

.group-title {
  font-size: 11.5px;
  font-weight: 700;
  margin-bottom: 2px;
}

.prompt-chip {
  text-align: left;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  padding: 6px 9px;
  border-radius: 6px;
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1.35;
}

.prompt-chip:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--blue-light);
  transform: translateX(2px);
}

body.theme-light .prompt-chip:hover {
  background: rgba(0, 0, 0, 0.05);
}

/* Sidebar Footer */
.ai-sidebar-foot {
  padding-top: 10px;
  border-top: 1px solid var(--line);
  margin-top: auto;
}

.btn-clear-chat {
  width: 100%;
  padding: 6px 10px;
  background: transparent;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--dim);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-clear-chat:hover {
  color: var(--red);
  border-color: var(--red);
  background: rgba(239, 68, 68, 0.05);
}

/* Right Chat Canvas */
.ai-chat-canvas {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

.ai-canvas-header {
  flex-shrink: 0;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.canvas-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-avatar-badge {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.ai-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.ai-sub-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
}

.ai-sub-text {
  font-size: 12px;
  color: var(--dim);
}

.ai-version-badge {
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 9999px;
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

/* Messages Stream */
.ai-messages-scroll {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.chat-message-row {
  display: flex;
  gap: 12px;
  max-width: 860px;
}

.user-row {
  margin-left: auto;
  flex-direction: row-reverse;
}

.message-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.message-bubble {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 18px;
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.6;
  max-width: 100%;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.user-row .message-bubble {
  background: var(--panel-alt);
  border-color: var(--blue-light);
  border-top-right-radius: 2px;
}

.assistant-row .message-bubble {
  border-top-left-radius: 2px;
}

.message-author-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.message-author {
  font-size: 11px;
  font-weight: 700;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.ai-source-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  letter-spacing: 0.2px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.ai-source-badge.badge-api {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.ai-source-badge.badge-local {
  background: rgba(168, 85, 247, 0.15);
  color: #c084fc;
  border: 1px solid rgba(168, 85, 247, 0.3);
}

.ai-api-notice {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 8px;
  font-size: 11.5px;
  color: #f59e0b;
  line-height: 1.45;
}

.ai-msg-h2 {
  font-size: 16px;
  font-weight: 700;
  margin: 14px 0 8px;
  color: var(--text);
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
}

.ai-msg-h3 {
  font-size: 15px;
  font-weight: 700;
  margin: 12px 0 6px;
  color: var(--blue-light);
}

.ai-msg-h4 {
  font-size: 14px;
  font-weight: 700;
  margin: 10px 0 4px;
  color: var(--accent);
}

.ai-msg-h5 {
  font-size: 13.5px;
  font-weight: 700;
  margin: 9px 0 4px;
  color: var(--blue-light);
}

.ai-msg-h6 {
  font-size: 12.5px;
  font-weight: 600;
  margin: 6px 0 2px;
  color: var(--dim);
}

.ai-msg-list {
  padding-left: 22px;
  margin: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  line-height: 1.55;
}

.ai-msg-list li {
  margin-bottom: 2px;
}

.message-body code {
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  color: var(--accent);
  font-size: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

body.theme-light .message-body code {
  background: rgba(0, 0, 0, 0.06);
  border-color: rgba(0, 0, 0, 0.1);
  color: #b45309;
}

/* Math typography (KaTeX & Fallback) */
.ai-math-inline {
  font-family: 'KaTeX_Math', 'Cambria Math', 'STIX Two Math', 'Times New Roman', serif;
  font-style: italic;
  color: #38bdf8;
  padding: 0 3px;
  font-size: 1.05em;
  letter-spacing: 0.2px;
}

body.theme-light .ai-math-inline {
  color: #0369a1;
}

.ai-math-block {
  display: block;
  margin: 10px 0;
  padding: 10px 16px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 8px;
  font-family: 'KaTeX_Math', 'Cambria Math', 'STIX Two Math', 'Times New Roman', serif;
  overflow-x: auto;
  text-align: center;
  font-size: 15px;
  line-height: 1.7;
  color: #93c5fd;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.25);
}

body.theme-light .ai-math-block {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #1e40af;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* KaTeX custom overrides for message stream */
.message-body .katex {
  font-size: 1.08em;
  color: inherit;
}

.message-body .katex-display {
  margin: 10px 0;
  padding: 10px 14px;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(56, 189, 248, 0.22);
  border-radius: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  text-align: center;
}

body.theme-light .message-body .katex-display {
  background: #f8fafc;
  border-color: #e2e8f0;
}

/* Fenced Code Block */
.ai-code-block {
  margin: 10px 0;
  padding: 12px 16px;
  background: #090d16;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12.5px;
  line-height: 1.5;
  color: #e2edf8;
}

body.theme-light .ai-code-block {
  background: #f8fafc;
  border-color: #e2e8f0;
  color: #1e293b;
}

.ai-code-block code {
  background: transparent !important;
  padding: 0 !important;
  border: none !important;
  color: inherit !important;
  font-size: inherit !important;
}

/* Markdown Tables */
.ai-msg-table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 12.5px;
}

.ai-msg-table th,
.ai-msg-table td {
  padding: 6px 12px;
  border: 1px solid var(--line);
  text-align: left;
}

.ai-msg-table th {
  background: var(--panel-alt);
  font-weight: 700;
  color: var(--text);
}

.ai-msg-hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 14px 0;
}

/* Lab Bridge Action Card */
.ai-lab-bridge-card {
  margin-top: 14px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: cardFadeIn 0.3s ease;
}

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

.bridge-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.bridge-card-badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 9999px;
  border: 1px solid transparent;
}

.bridge-card-lab {
  font-size: 11px;
  font-weight: 600;
  color: var(--dim);
}

.bridge-card-title {
  font-size: 13.5px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.bridge-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 11.5px;
  color: var(--dim);
}

.btn-bridge-execute {
  margin-top: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  color: #ffffff;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn-bridge-execute:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

/* Bottom Input Area */
.ai-input-wrapper {
  flex-shrink: 0;
  padding: 12px 20px 16px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-quick-suggestions {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.sugg-hint {
  font-size: 11px;
  color: var(--dim);
  white-space: nowrap;
}

.sugg-chip {
  padding: 3px 10px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 9999px;
  color: var(--dim);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.sugg-chip:hover {
  color: var(--text);
  border-color: var(--accent);
}

.ai-input-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.ai-textarea {
  flex: 1;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.45;
  resize: none;
  max-height: 140px;
  outline: none;
  transition: border-color 0.15s ease;
}

.ai-textarea:focus {
  border-color: var(--blue-light);
}

.btn-ai-send {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  background: var(--blue);
  color: #ffffff;
  border: 1px solid var(--blue);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  height: 42px;
}

.btn-ai-send:hover {
  background: var(--blue-light);
  border-color: var(--blue-light);
}

/* =====================================================================
   HOME VIEW FOOTER & COPYRIGHT
   ===================================================================== */
.home-footer {
  margin-top: 52px;
  padding: 32px 24px;
  border-top: 1px solid var(--line);
  text-align: center;
  background: rgba(15, 23, 34, 0.45);
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

body.theme-light .home-footer {
  background: rgba(241, 245, 249, 0.7);
  border-color: #cbd5e1;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

.footer-brand-wrap {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.footer-brand-icon {
  font-size: 20px;
}

.footer-brand-title {
  font-size: 15.5px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0.3px;
}

.footer-brand-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(56, 189, 248, 0.12);
  color: var(--blue-light);
  border: 1px solid rgba(56, 189, 248, 0.25);
}

.footer-class-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 20px;
  background: rgba(16, 185, 129, 0.12);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

body.theme-light .footer-class-badge {
  background: #ecfdf5;
  color: #059669;
  border-color: #6ee7b7;
}

.footer-desc {
  font-size: 13px;
  color: var(--dim);
  margin: 0 auto 16px auto;
  line-height: 1.6;
  max-width: 780px;
  text-wrap: balance;
}

.footer-team-row {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 18px;
}

.footer-team-label {
  font-size: 12.5px;
  color: var(--dim);
  font-weight: 600;
}

.footer-author-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
}

.footer-author-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}

.footer-author-pill:hover {
  border-color: var(--blue-light);
  color: var(--blue-light);
  background: rgba(56, 189, 248, 0.1);
  transform: translateY(-1.5px);
  box-shadow: 0 2px 8px rgba(56, 189, 248, 0.15);
}

.footer-author-pill:active {
  transform: translateY(0) scale(0.97);
}

body.theme-light .footer-author-pill {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #1e293b;
}

body.theme-light .footer-author-pill:hover {
  border-color: #0284c7;
  color: #0284c7;
  background: #f0f9ff;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.12);
}

.footer-bottom-bar {
  font-size: 12px;
  color: var(--dim);
  border-top: 1px dashed var(--line);
  padding-top: 14px;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.footer-version-tag {
  color: var(--accent);
  font-weight: 600;
}

/* =====================================================================
   HOME PAGE INTERACTIVE TAB SWITCHING & BUTTON HOVER EFFECTS
   ===================================================================== */

/* 1. Theory Bar Tab Navigation Button */
.home-theory-bar-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 12px 28px;
  max-width: 100%;
  box-sizing: border-box;
  background: var(--panel-alt);
  border: 1.5px solid rgba(56, 189, 248, 0.4);
  border-radius: 30px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 16px rgba(56, 189, 248, 0.12);
  user-select: none;
}

.home-theory-bar-btn .home-theory-icon {
  font-size: 20px;
  transition: transform 0.25s ease;
}

.home-theory-bar-btn .home-theory-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.15);
  color: var(--blue-light);
  font-size: 13px;
  font-weight: 800;
  transition: all 0.25s ease;
}

.home-theory-bar-btn:hover {
  border-color: var(--blue-light);
  color: var(--blue-light);
  background: rgba(56, 189, 248, 0.14);
  transform: translateY(-2.5px);
  box-shadow: 0 8px 24px rgba(56, 189, 248, 0.28);
}

.home-theory-bar-btn:hover .home-theory-icon {
  transform: scale(1.15) rotate(-6deg);
}

.home-theory-bar-btn:hover .home-theory-arrow {
  background: var(--blue-light);
  color: #0f172a;
  transform: translateX(3px);
}

.home-theory-bar-btn:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 2px 8px rgba(56, 189, 248, 0.2);
}

body.theme-light .home-theory-bar-btn {
  background: #ffffff;
  border-color: #7dd3fc;
  color: #0f172a;
  box-shadow: 0 4px 16px rgba(2, 132, 199, 0.08);
}

body.theme-light .home-theory-bar-btn:hover {
  background: #f0f9ff;
  border-color: #0284c7;
  color: #0284c7;
  box-shadow: 0 8px 24px rgba(2, 132, 199, 0.2);
}

/* 2. Pillar Lab Action Buttons Lift & Glow */
#btnPillarLogic, #btnPillarCounting, #btnPillarRelation, #btnPillarGraph {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}

#btnPillarLogic:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(245, 158, 11, 0.4);
  filter: brightness(1.08);
}
#btnPillarLogic:active {
  transform: translateY(0) scale(0.97);
}

#btnPillarCounting:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.4);
  filter: brightness(1.08);
}
#btnPillarCounting:active {
  transform: translateY(0) scale(0.97);
}

#btnPillarRelation:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(139, 92, 246, 0.4);
  filter: brightness(1.08);
}
#btnPillarRelation:active {
  transform: translateY(0) scale(0.97);
}

#btnPillarGraph:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(59, 130, 246, 0.4);
  filter: brightness(1.08);
}
#btnPillarGraph:active {
  transform: translateY(0) scale(0.97);
}

/* 3. Pillar Cards Lift & Ambient Glow */
#pillarLogic:hover {
  border-color: #f59e0b !important;
  box-shadow: 0 8px 24px rgba(245, 158, 11, 0.16) !important;
}

#pillarCounting:hover {
  border-color: #10b981 !important;
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.16) !important;
}

#pillarRelation:hover {
  border-color: #a78bfa !important;
  box-shadow: 0 8px 24px rgba(139, 92, 246, 0.16) !important;
}

#pillarGraph:hover {
  border-color: #60a5fa !important;
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.16) !important;
}

/* 4. Academic Suite Navigation Buttons */
#btnHomeQuizArena, #btnHomeQuizStudio, #btnHomeAiVision {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}

#btnHomeQuizArena:hover, #btnHomeQuizStudio:hover, #btnHomeAiVision:hover {
  border-color: var(--blue-light);
  color: var(--blue-light);
  background: rgba(56, 189, 248, 0.12);
  transform: translateY(-1.5px);
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.18);
}

#btnHomeQuizArena:active, #btnHomeQuizStudio:active, #btnHomeAiVision:active {
  transform: translateY(0) scale(0.97);
}

/* =====================================================================
   USER AUTHENTICATION & PROFILE SYSTEM (PHASE 1)
   ===================================================================== */

/* 1. Header Auth User Button */
.btn-auth-user {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
  white-space: nowrap;
}

.auth-btn-label {
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  vertical-align: middle;
}

.btn-auth-user:hover {
  border-color: var(--blue-light);
  color: var(--blue-light);
  background: rgba(56, 189, 248, 0.1);
  transform: translateY(-1.5px);
  box-shadow: 0 3px 10px rgba(56, 189, 248, 0.2);
}

.btn-auth-user:active {
  transform: translateY(0) scale(0.97);
}

.btn-auth-user.logged-in {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.4);
  color: #10b981;
}

.btn-auth-user.logged-in:hover {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.16);
  box-shadow: 0 3px 12px rgba(16, 185, 129, 0.25);
}

body.theme-light .btn-auth-user {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #1e293b;
}

body.theme-light .btn-auth-user:hover {
  border-color: #0284c7;
  color: #0284c7;
  background: #f0f9ff;
  box-shadow: 0 3px 10px rgba(2, 132, 199, 0.15);
}

body.theme-light .btn-auth-user.logged-in {
  background: #ecfdf5;
  border-color: #10b981;
  color: #059669;
}

/* User & Quick Settings Dropdown Container */
.user-dropdown-wrap {
  position: relative;
  display: inline-flex;
}

.auth-btn-caret {
  font-size: 10px;
  margin-left: 2px;
  color: var(--dim);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.user-dropdown-wrap.open .auth-btn-caret,
.user-dropdown-wrap:hover .auth-btn-caret {
  transform: rotate(180deg);
  color: var(--accent);
}

.user-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 290px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4), 0 0 1px rgba(255, 255, 255, 0.1);
  display: none;
  flex-direction: column;
  gap: 3px;
  z-index: 1000;
  backdrop-filter: blur(16px);
  animation: dropdownSlideIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Hover bridge */
.user-dropdown-menu::before {
  content: '';
  position: absolute;
  top: -12px;
  left: 0;
  right: 0;
  height: 12px;
  background: transparent;
}

.user-dropdown-wrap.open .user-dropdown-menu,
.user-dropdown-wrap:hover .user-dropdown-menu {
  display: flex;
}

body.theme-light .user-dropdown-menu {
  background: #ffffff;
  border-color: rgba(226, 232, 240, 0.9);
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.14);
}

.user-dropdown-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--panel-alt);
}

body.theme-light .user-dropdown-header {
  background: #f8fafc;
}

.user-dropdown-avatar {
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: rgba(245, 158, 11, 0.12);
  border-radius: 50%;
  flex-shrink: 0;
}

.user-dropdown-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.user-dropdown-name {
  font-size: 13.5px;
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-dropdown-role {
  font-size: 11px;
  color: var(--dim);
}

.user-dropdown-divider {
  height: 1px;
  background: var(--line);
  margin: 4px 6px;
}

.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  width: 100%;
  color: var(--text);
  font-family: inherit;
  transition: all 0.15s ease;
}

.user-dropdown-item:hover {
  background: var(--panel-alt);
  color: var(--accent);
}

body.theme-light .user-dropdown-item:hover {
  background: #f1f5f9;
  color: var(--accent);
}

.user-dropdown-item .dropdown-item-icon {
  font-size: 17px;
  flex-shrink: 0;
  width: 22px;
  text-align: center;
}

.user-dropdown-item .dropdown-item-text {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.user-dropdown-item .dropdown-item-title {
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.3;
}

.user-dropdown-item .dropdown-item-sub {
  font-size: 11px;
  color: var(--dim);
  line-height: 1.3;
}

.user-dropdown-item .dropdown-item-badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent);
}

.user-dropdown-item-danger {
  color: #ef4444;
}

.user-dropdown-item-danger:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

/* 2. Auth Modal Dialog */
.auth-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  padding: 16px;
}

.auth-modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.auth-modal-dialog {
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  transform: translateY(12px) scale(0.97);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  flex-direction: column;
}

.auth-modal-overlay.open .auth-modal-dialog {
  transform: translateY(0) scale(1);
}

.auth-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 14px 22px;
  border-bottom: 1px solid var(--line);
}

.auth-modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.auth-modal-icon {
  font-size: 26px;
}

.auth-modal-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  margin: 0;
}

.auth-modal-sub {
  font-size: 12px;
  color: var(--dim);
}

.btn-close-modal {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  color: var(--dim);
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
  outline: none;
}

.btn-close-modal:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: #ef4444;
  transform: rotate(90deg);
}

.btn-close-modal:active {
  transform: rotate(90deg) scale(0.92);
}

body.theme-light .btn-close-modal {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #64748b;
}

body.theme-light .btn-close-modal:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #ef4444;
}

.auth-modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: var(--panel-alt);
  padding: 4px 8px 0 8px;
  gap: 6px;
}

.auth-tab-btn {
  background: transparent;
  border: none;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--dim);
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  border-bottom: 2px solid transparent;
  transition: all 0.15s ease;
}

.auth-tab-btn:hover {
  color: var(--text);
}

.auth-tab-btn.active {
  color: var(--blue-light);
  border-bottom-color: var(--blue-light);
  background: var(--panel);
}

.auth-modal-body {
  padding: 22px;
  max-height: 75vh;
  overflow-y: auto;
}

/* 3. Demo Accounts 1-Click Grid */
.auth-hint-text {
  font-size: 13px;
  color: var(--dim);
  margin: 0 0 16px 0;
  line-height: 1.5;
}

.demo-accounts-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.demo-account-pill {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.demo-account-pill:hover {
  border-color: var(--blue-light);
  background: rgba(56, 189, 248, 0.08);
  transform: translateX(4px);
}

.demo-account-pill.current {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.08);
}

.demo-avatar {
  font-size: 24px;
}

.demo-meta {
  flex: 1;
}

.demo-name {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.demo-sub {
  display: block;
  font-size: 12px;
  color: var(--dim);
  margin-top: 2px;
}

.demo-check {
  font-size: 12px;
  font-weight: 700;
  color: #10b981;
  background: rgba(16, 185, 129, 0.15);
  padding: 3px 8px;
  border-radius: 6px;
}

.demo-arrow {
  color: var(--dim);
  font-size: 13px;
  transition: transform 0.2s ease;
}

.demo-account-pill:hover .demo-arrow {
  transform: translateX(3px);
  color: var(--blue-light);
}

/* 4. Form Controls */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-alert {
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #ef4444;
  font-size: 13px;
  font-weight: 600;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-field label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
}

.auth-field input {
  padding: 10px 14px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-field input:focus {
  border-color: var(--blue-light);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.auth-submit-btn {
  width: 100%;
  padding: 11px;
  font-size: 14px;
  font-weight: 700;
  margin-top: 6px;
}

/* 5. User Profile Card */
.auth-profile-card {
  text-align: center;
}

.profile-avatar-large {
  font-size: 52px;
  margin-bottom: 8px;
}

.profile-name {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  margin: 0 0 4px 0;
}

.profile-class-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 12px;
  background: rgba(56, 189, 248, 0.12);
  color: var(--blue-light);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 20px;
  margin-bottom: 12px;
}

.profile-bio {
  font-size: 13px;
  color: var(--dim);
  margin: 0 0 20px 0;
  line-height: 1.5;
}

.profile-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 22px;
  text-align: left;
}

.profile-info-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.profile-info-item .info-label {
  font-size: 11.5px;
  color: var(--dim);
  font-weight: 600;
}

.profile-info-item .info-val {
  font-size: 13px;
  color: var(--text);
  font-weight: 700;
  word-break: break-all;
}

.profile-info-item .info-val.highlight {
  color: #10b981;
}

.profile-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.btn-danger-outline {
  background: transparent;
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #ef4444;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  transition: all 0.15s ease;
}

.btn-danger-outline:hover {
  background: rgba(239, 68, 68, 0.12);
  border-color: #ef4444;
}

/* =====================================================================
   AI ASSISTANT SIDEBAR: USER BADGE & MULTI-SESSION HISTORY
   ===================================================================== */

.ai-user-profile-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 12px;
}

.ai-user-profile-badge .user-avatar-tiny {
  font-size: 20px;
}

.ai-user-profile-badge .user-meta-tiny {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.ai-user-profile-badge .user-name-tiny {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
}

.ai-user-profile-badge .user-status-tiny {
  font-size: 11px;
  color: #10b981;
}

.ai-user-profile-badge.guest .user-status-tiny {
  color: var(--dim);
}

.btn-user-switch-tiny, .btn-user-login-tiny {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--dim);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-user-login-tiny {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.35);
  color: var(--blue-light);
}

.btn-user-switch-tiny:hover, .btn-user-login-tiny:hover {
  border-color: var(--blue-light);
  color: var(--blue-light);
}

/* Sidebar Tab Navigator */
.ai-sidebar-tab-row {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.ai-sidebar-nav-tab {
  flex: 1;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 8px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  color: var(--dim);
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

.ai-sidebar-nav-tab.active {
  background: rgba(56, 189, 248, 0.12);
  border-color: var(--blue-light);
  color: var(--blue-light);
}

/* New Chat Button */
.btn-ai-new-chat {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 700;
  border-radius: 8px;
  margin-bottom: 12px;
  cursor: pointer;
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  border: 1px solid #38bdf8;
  color: #fff;
  transition: all 0.2s ease;
}

.btn-ai-new-chat:hover {
  transform: translateY(-1.5px);
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.35);
}

/* History Sessions List */
.ai-history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
}

.ai-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
}

.ai-history-item:hover {
  border-color: var(--blue-light);
  background: rgba(56, 189, 248, 0.08);
}

.ai-history-item.active {
  border-color: var(--blue-light);
  background: rgba(56, 189, 248, 0.14);
}

.ai-history-info {
  flex: 1;
  overflow: hidden;
}

.ai-history-title {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-history-time {
  display: block;
  font-size: 11px;
  color: var(--dim);
  margin-top: 2px;
}

.ai-history-del-btn {
  background: transparent;
  border: none;
  color: var(--dim);
  font-size: 13px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  opacity: 0.6;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.ai-history-del-btn:hover {
  opacity: 1;
  color: #ef4444;
}

.ai-history-empty {
  text-align: center;
  padding: 24px 12px;
  font-size: 12px;
  color: var(--dim);
  line-height: 1.5;
}

/* AI History Search Box */
.ai-history-search-box {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 10px;
  gap: 6px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ai-history-search-box:focus-within {
  border-color: var(--blue-light);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.15);
}

.history-search-icon {
  font-size: 13px;
  color: var(--dim);
  line-height: 1;
}

.input-search-history {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 12.5px;
  color: var(--text);
}

.input-search-history::placeholder {
  color: var(--dim);
  opacity: 0.7;
}

.btn-clear-search {
  background: transparent;
  border: none;
  color: var(--dim);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s ease, background 0.15s ease;
}

.btn-clear-search:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

/* =========================================================================
   QUIZ LEADERBOARD & HALL OF FAME
   ========================================================================= */

.quiz-leaderboard-container {
  display: flex;
  flex-direction: column;
  gap: 22px;
  animation: fadeIn 0.25s ease-out;
}

/* 1. Hero Card */
.leaderboard-hero-card {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.12) 0%, rgba(59, 130, 246, 0.12) 100%), var(--panel);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 14px;
  padding: 22px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 18px;
}

.leaderboard-hero-card .hero-tag {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: #f59e0b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.leaderboard-hero-card .dot-sep {
  color: var(--dim);
}

.leaderboard-hero-card .hero-title {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
}

.leaderboard-hero-card .hero-desc {
  margin: 6px 0 0;
  font-size: 13.5px;
  color: var(--dim);
  max-width: 720px;
  line-height: 1.5;
}

/* 2. Top 3 Podium Row */
.leaderboard-podium-row {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  gap: 16px;
  align-items: end;
  margin-top: 10px;
}

@media (max-width: 860px) {
  .leaderboard-podium-row {
    grid-template-columns: 1fr;
    gap: 14px;
  }
}

.podium-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px 18px 0;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.podium-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.podium-card .podium-medal {
  font-size: 26px;
  line-height: 1;
  margin-bottom: 4px;
}

.podium-card .podium-crown {
  position: absolute;
  top: -16px;
  font-size: 28px;
  filter: drop-shadow(0 2px 6px rgba(245, 158, 11, 0.5));
  animation: bounceSoft 2.5s infinite ease-in-out;
}

@keyframes bounceSoft {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.podium-card .podium-avatar {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--panel-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  border: 2px solid var(--line);
  margin-bottom: 8px;
}

.podium-rank-1 .podium-avatar {
  width: 68px;
  height: 68px;
  font-size: 34px;
  border-color: #f59e0b;
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.35);
}

.podium-card .podium-name {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.podium-rank-1 .podium-name {
  font-size: 18px;
}

.podium-card .podium-class {
  font-size: 11.5px;
  color: var(--dim);
  margin-top: 2px;
}

.podium-card .podium-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 12px;
  margin-top: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  color: var(--text);
}

.podium-rank-1 .podium-badge {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.4);
  color: #f59e0b;
}

.podium-rank-2 .podium-badge {
  background: rgba(148, 163, 184, 0.15);
  border-color: rgba(148, 163, 184, 0.4);
  color: #94a3b8;
}

.podium-rank-3 .podium-badge {
  background: rgba(217, 119, 6, 0.15);
  border-color: rgba(217, 119, 6, 0.4);
  color: #d97706;
}

.podium-card .podium-stat-pill {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 700;
  margin-top: 10px;
}

.podium-stat-pill.gold {
  border-color: rgba(245, 158, 11, 0.4);
}

.podium-stat-pill .stat-score {
  color: var(--brand);
}

.podium-stat-pill .stat-acc {
  color: #10b981;
}

.podium-card .podium-streak {
  font-size: 12px;
  color: var(--dim);
  margin-top: 6px;
  margin-bottom: 14px;
}

.podium-card .podium-stand {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
  font-weight: 900;
  font-size: 28px;
}

.podium-stand.stand-1 {
  height: 64px;
  background: linear-gradient(180deg, rgba(245, 158, 11, 0.3) 0%, rgba(245, 158, 11, 0.1) 100%);
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-bottom: none;
  color: #f59e0b;
}

.podium-stand.stand-2 {
  height: 48px;
  background: linear-gradient(180deg, rgba(148, 163, 184, 0.25) 0%, rgba(148, 163, 184, 0.08) 100%);
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-bottom: none;
  color: #94a3b8;
}

.podium-stand.stand-3 {
  height: 38px;
  background: linear-gradient(180deg, rgba(217, 119, 6, 0.25) 0%, rgba(217, 119, 6, 0.08) 100%);
  border: 1px solid rgba(217, 119, 6, 0.35);
  border-bottom: none;
  color: #d97706;
}

/* 3. Personal Card */
.leaderboard-my-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 24px;
}

.my-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.my-card-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.my-card-avatar {
  font-size: 32px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--panel-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
}

.my-card-name {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.my-card-subtitle {
  font-size: 12px;
  color: var(--dim);
}

.my-card-rank-badge {
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: var(--blue-light);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
}

.my-card-stats-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}

@media (max-width: 768px) {
  .my-card-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.my-card-stats-grid .stat-box {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-box .box-label {
  font-size: 11.5px;
  color: var(--dim);
}

.stat-box .box-val {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
}

.stat-box .box-val.highlight {
  color: var(--brand);
}

.stat-box .box-val.text-green {
  color: #10b981;
}

.stat-box .box-val.text-orange {
  color: #f97316;
}

.my-card-guest {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.my-card-guest .guest-info {
  display: flex;
  align-items: center;
  gap: 14px;
}

.my-card-recent-exams {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
}

.my-card-recent-exams .recent-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--dim);
  display: block;
  margin-bottom: 8px;
}

.my-card-recent-exams .recent-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.my-card-recent-exams .recent-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  border: 1px solid var(--line);
}

.recent-item .exam-name {
  font-weight: 600;
  color: var(--text);
}

.recent-item .exam-score {
  color: #10b981;
}

.recent-item .exam-date {
  color: var(--dim);
}

/* 4. Full Leaderboard Table */
.leaderboard-table-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}

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

.table-card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.table-card-count {
  font-size: 12px;
  color: var(--dim);
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.leaderboard-table th {
  padding: 12px 16px;
  background: var(--panel-alt);
  color: var(--dim);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--line);
}

.leaderboard-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.leaderboard-table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.leaderboard-table tr.row-current-user {
  background: rgba(56, 189, 248, 0.08);
  border-left: 3px solid var(--blue-light);
}

.table-user-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.table-user-cell .cell-avatar {
  font-size: 20px;
}

.table-user-cell .cell-name {
  font-weight: 700;
  color: var(--text);
  display: block;
}

.table-user-cell .tag-you {
  font-size: 11px;
  color: var(--blue-light);
  font-weight: 600;
  margin-left: 4px;
}

.table-user-cell .cell-class {
  font-size: 11px;
  color: var(--dim);
  display: block;
}

.table-acc-pill {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11.5px;
  font-weight: 700;
}

.table-acc-pill.acc-high {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.table-acc-pill.acc-mid {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.table-acc-pill.acc-low {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.table-badge-chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--dim);
}

/* =====================================================================
   7. ASSIGNED EXAM & TIMED EXAMINATION SYSTEM
   ===================================================================== */

.exam-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
  margin-top: 16px;
}

.exam-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: all 0.2s ease;
  position: relative;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.exam-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
}

.exam-card-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 8px;
  line-height: 1.4;
}

.exam-card-desc {
  font-size: 13px;
  color: var(--dim);
  line-height: 1.5;
  margin: 0 0 16px;
}

.exam-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.exam-meta-pill {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 14px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.exam-status-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.exam-status-badge.completed {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.exam-status-badge.pending {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

/* Active Timed Exam Room */
.active-exam-room {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  margin-bottom: 24px;
}

.active-exam-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}

.active-exam-timer-box {
  background: var(--panel-alt);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 8px 18px;
  font-size: 20px;
  font-weight: 800;
  font-family: monospace;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
}

.active-exam-timer-box.urgent {
  border-color: #ef4444;
  color: #ef4444;
  animation: pulse-urgent 1s infinite alternate;
}

@keyframes pulse-urgent {
  from { transform: scale(1); }
  to { transform: scale(1.04); }
}

.exam-q-jump-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
  padding: 12px;
  background: var(--panel-alt);
  border-radius: 8px;
  border: 1px solid var(--line);
}

.exam-q-jump-btn {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.exam-q-jump-btn:hover {
  border-color: var(--accent);
}

.exam-q-jump-btn.current {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
  color: var(--accent);
}

.exam-q-jump-btn.answered {
  background: #10b981;
  color: #ffffff;
  border-color: #10b981;
}

.exam-q-jump-btn.answered.current {
  box-shadow: 0 0 0 2px #38bdf8;
}

/* Active Timed Exam Options */
.btn-active-exam-opt {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  width: 100%;
  line-height: 1.5;
  box-sizing: border-box;
  white-space: normal !important;
  word-break: break-word !important;
  overflow-wrap: anywhere !important;
  touch-action: manipulation;
}

.btn-active-exam-opt:hover {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.06);
}

.btn-active-exam-opt.selected {
  background: rgba(56, 189, 248, 0.15) !important;
  border: 2px solid var(--accent) !important;
}

.btn-active-exam-opt .opt-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
  background: var(--line);
  color: var(--text);
}

.btn-active-exam-opt.selected .opt-badge {
  background: var(--accent);
  color: #000;
  font-weight: bold;
}

.btn-active-exam-opt .opt-text {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 500;
  white-space: normal !important;
  word-break: break-word !important;
  overflow-wrap: anywhere !important;
  line-height: 1.5;
}

.btn-active-exam-opt .opt-selected-tag {
  color: var(--accent);
  font-weight: bold;
  font-size: 12.5px;
  flex-shrink: 0;
  margin-left: 8px;
  white-space: nowrap;
  margin-top: 3px;
}

.exam-question-card {
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
}

.exam-navigation-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

/* Nhiệm vụ 3: Auto-save status indicator badge */
.exam-autosave-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  color: #10b981;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 2px 8px;
  border-radius: 12px;
  user-select: none;
}

.exam-autosave-badge .autosave-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
  animation: autosavePulse 2s infinite ease-in-out;
}

@keyframes autosavePulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
    box-shadow: 0 0 6px #10b981;
  }
  50% {
    opacity: 0.45;
    transform: scale(0.85);
    box-shadow: 0 0 2px #10b981;
  }
}

/* Nhiệm vụ 1: Chống tràn chữ, công thức toán và hình ảnh cho câu hỏi & đáp án */
.exam-question-card,
.active-exam-question-card,
.quiz-question-card,
.quiz-question-box,
.exam-question-text,
.exam-q-text,
.question-content,
.btn-active-exam-opt,
.btn-quiz-option,
.opt-text,
.quiz-option-text,
.exam-opt-text {
  word-break: break-word;
  overflow-wrap: anywhere;
  box-sizing: border-box;
  max-width: 100%;
}

.exam-question-card img,
.active-exam-room img,
.btn-active-exam-opt img,
.opt-text img,
.quiz-question-card img,
.quiz-question-box img {
  max-width: 100%;
  height: auto;
  box-sizing: border-box;
  border-radius: 6px;
}

/* Công thức toán KaTeX (.katex-display) và bảng mạch logic cuộn ngang mượt mà */
.katex-display,
.katex-html,
.katex,
.logic-circuit,
.circuit-canvas-wrap,
.circuit-board,
.truth-table-scroll,
.exam-circuit-preview,
.table-scroll,
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  scrollbar-width: thin;
}

.katex-display::-webkit-scrollbar,
.logic-circuit::-webkit-scrollbar,
.truth-table-scroll::-webkit-scrollbar {
  height: 4px;
}

.katex-display::-webkit-scrollbar-thumb,
.logic-circuit::-webkit-scrollbar-thumb,
.truth-table-scroll::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 4px;
}

/* Modal Overlay for Gradebook */
.gradebook-modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}

.gradebook-modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  max-width: 900px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

/* Teacher's Studio Exam Assignment Button */
.btn-studio-assign {
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-studio-assign:hover {
  transform: translateY(-1.5px);
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
}

/* =====================================================================
   MOBILE NAVIGATION TOGGLE & DRAWER (DESKTOP DEFAULT: HIDDEN)
   ===================================================================== */
.btn-mobile-menu-toggle {
  display: none !important;
}

.mobile-nav-drawer {
  display: none !important;
}

/* =====================================================================
   MOBILE RESPONSIVENESS (< 768px & < 480px)
   ===================================================================== */
@media (max-width: 768px) {
  /* 1. Header & Mobile Navigation */
  .app-header {
    height: 56px !important;
    padding: 0 12px !important;
    gap: 10px !important;
    justify-content: space-between !important;
  }

  .header-left {
    gap: 8px !important;
    max-width: none !important;
    overflow: visible !important;
    flex: 1 !important;
    min-width: 0 !important;
  }

  .brand-wrap {
    gap: 8px !important;
  }

  .brand-icon {
    font-size: 20px !important;
  }

  .brand-name {
    font-size: 15px !important;
    max-width: 170px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    font-weight: 700 !important;
  }

  .brand-badge {
    display: none !important;
  }

  /* Hide Desktop Horizontal Navigation on Mobile as requested */
  .nav-links {
    display: none !important;
  }

  .header-actions {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    flex-shrink: 0 !important;
  }

  .btn-auth-user {
    padding: 6px 10px !important;
    font-size: 13px !important;
    gap: 6px !important;
    border-radius: 8px !important;
  }

  .btn-auth-user .auth-btn-caret {
    display: none !important;
  }

  /* Hamburger Menu Toggle Button (Góc trái trên mobile) */
  .btn-mobile-menu-toggle {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 38px !important;
    height: 38px !important;
    border-radius: 8px !important;
    background: var(--panel-alt) !important;
    border: 1px solid var(--line) !important;
    color: var(--text) !important;
    cursor: pointer !important;
    padding: 0 !important;
    transition: all 0.2s ease !important;
    flex-shrink: 0 !important;
  }

  .btn-mobile-menu-toggle:hover {
    background: rgba(56, 189, 248, 0.12) !important;
    border-color: var(--accent) !important;
    color: var(--accent) !important;
  }

  .btn-mobile-menu-toggle svg {
    display: block !important;
    flex-shrink: 0 !important;
  }

  .btn-mobile-menu-toggle .hamburger-icon-open {
    display: block !important;
  }

  .btn-mobile-menu-toggle .hamburger-icon-close {
    display: none !important;
  }

  .btn-mobile-menu-toggle.active .hamburger-icon-open {
    display: none !important;
  }

  .btn-mobile-menu-toggle.active .hamburger-icon-close {
    display: block !important;
    color: #ef4444 !important;
  }

  /* Mobile Navigation Drawer (Trượt ra từ bên trái) */
  .mobile-nav-drawer {
    display: block !important;
    position: fixed !important;
    inset: 0 !important;
    z-index: 99999 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    transition: visibility 0.25s ease !important;
  }

  .mobile-nav-drawer.open {
    visibility: visible !important;
    pointer-events: auto !important;
  }

  .mobile-nav-backdrop {
    position: fixed !important;
    inset: 0 !important;
    background: rgba(0, 0, 0, 0.65) !important;
    backdrop-filter: blur(4px) !important;
    -webkit-backdrop-filter: blur(4px) !important;
    opacity: 0 !important;
    transition: opacity 0.25s ease !important;
  }

  .mobile-nav-drawer.open .mobile-nav-backdrop {
    opacity: 1 !important;
  }

  .mobile-nav-panel {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 310px !important;
    max-width: 86vw !important;
    background: var(--panel) !important;
    border-right: 1px solid var(--line) !important;
    border-left: none !important;
    display: flex !important;
    flex-direction: column !important;
    transform: translateX(-100%) !important;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1) !important;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.5) !important;
    z-index: 100000 !important;
    overflow: hidden !important;
  }

  body.theme-light .mobile-nav-panel {
    background: #ffffff !important;
    box-shadow: 8px 0 28px rgba(0, 0, 0, 0.15) !important;
  }

  .mobile-nav-drawer.open .mobile-nav-panel {
    transform: translateX(0) !important;
  }

  .mobile-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
  }

  .mobile-nav-brand {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .mobile-brand-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
  }

  .btn-mobile-nav-close {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--panel-alt);
    color: var(--text);
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
  }

  .btn-mobile-nav-close:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.3);
  }

  .mobile-nav-user-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--panel-alt);
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
  }

  .mobile-user-avatar {
    font-size: 24px;
  }

  .mobile-user-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .mobile-user-name {
    font-size: 13.5px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 700;
  }

  .mobile-user-role {
    font-size: 11px;
    color: var(--dim);
  }

  .mobile-nav-body {
    flex: 1;
    overflow-y: auto;
    padding: 10px 10px 40px;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 3px;
  }

  .mobile-nav-section-title {
    font-size: 10.5px;
    font-weight: 700;
    color: var(--dim);
    letter-spacing: 0.05em;
    padding: 10px 10px 4px;
    text-transform: uppercase;
  }

  .mobile-nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    font-size: 13.5px;
    text-align: left;
    cursor: pointer;
    transition: all 0.15s ease;
  }

  .mobile-nav-item:hover {
    background: rgba(56, 189, 248, 0.1);
    color: var(--blue-light);
  }

  .mobile-nav-item.active {
    background: rgba(56, 189, 248, 0.14) !important;
    color: var(--blue-light) !important;
    border-color: rgba(56, 189, 248, 0.35) !important;
    font-weight: 700;
  }

  .mobile-nav-icon {
    font-size: 17px;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
  }

  .mobile-nav-label {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .mobile-nav-title {
    font-size: 13.5px;
    font-weight: 600;
  }

  .mobile-nav-sub {
    font-size: 11px;
    color: var(--dim);
    font-weight: 400;
  }

  body.mobile-nav-locked {
    overflow: hidden !important;
  }

  /* 2. Home View Mobile */
  .home-container {
    padding: 16px 12px 60px !important;
  }

  .hero-section {
    padding: 24px 12px 28px !important;
    margin-bottom: 24px !important;
    overflow: hidden !important;
  }

  .hero-pill-badge {
    max-width: 100% !important;
    box-sizing: border-box !important;
    white-space: normal !important;
    line-height: 1.4 !important;
    text-align: center !important;
    padding: 6px 12px !important;
    font-size: 11.5px !important;
  }

  .hero-pill-badge span:last-child {
    font-size: 11.5px !important;
    word-break: break-word !important;
  }

  .hero-section h1 {
    font-size: 21px !important;
    line-height: 1.35 !important;
  }

  /* Home Theory Navigation Bar Button (Full container width & no overflow) */
  .home-theory-bar-wrap {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding: 0 !important;
  }

  .home-theory-bar-btn {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding: 11px 14px !important;
    font-size: 13px !important;
    gap: 8px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    border-radius: 12px !important;
    margin: 0 auto !important;
    text-align: left !important;
  }

  .home-theory-bar-btn .home-theory-icon {
    font-size: 18px !important;
    flex-shrink: 0 !important;
  }

  .home-theory-bar-btn .home-theory-text,
  .home-theory-bar-btn span:nth-child(2) {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    white-space: normal !important;
    line-height: 1.35 !important;
    word-break: break-word !important;
    font-size: 12.5px !important;
  }

  .home-theory-bar-btn .home-theory-arrow {
    width: 24px !important;
    height: 24px !important;
    font-size: 12px !important;
    flex-shrink: 0 !important;
  }

  .pillar-cards-grid,
  .four-pillars-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  .pillar-card {
    padding: 18px 16px !important;
  }

  .pillar-card > div:last-child {
    width: 100% !important;
  }

  .pillar-card button {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  .academic-suite {
    grid-template-columns: 1fr !important;
    padding: 16px !important;
    gap: 16px !important;
  }

  .home-footer {
    padding: 20px 14px !important;
    margin-top: 36px !important;
  }

  .footer-brand-wrap {
    flex-wrap: wrap !important;
    justify-content: center !important;
    gap: 6px !important;
  }

  .footer-brand-title {
    font-size: 14px !important;
  }

  /* 3. Quiz & Exam System Mobile Optimization */
  .quiz-view-container {
    padding: 12px 10px 50px !important;
  }

  .quiz-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
    margin-bottom: 16px !important;
  }

  .quiz-header h1 {
    font-size: 19px !important;
  }

  .quiz-main-tabs {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 3px !important;
    justify-content: flex-start !important;
  }

  .quiz-main-tabs::-webkit-scrollbar {
    display: none;
  }

  .quiz-main-tabs .btn-tab {
    flex-shrink: 0;
    padding: 6px 12px !important;
    font-size: 12px !important;
  }

  /* Active Exam Room */
  .active-exam-room {
    padding: 14px 12px 60px !important;
    border-radius: 10px !important;
    position: relative;
  }

  /* Nhiệm vụ 2 — Ghim cố định thanh trạng thái (Sticky Header): top: 0; z-index: 50; */
  body.in-active-exam .app-header,
  body:has(.active-exam-room) .app-header {
    display: none !important;
  }

  .active-exam-topbar {
    position: sticky !important;
    top: 0 !important;
    z-index: 50 !important;
    background: rgba(15, 23, 42, 0.96) !important;
    backdrop-filter: blur(14px) !important;
    -webkit-backdrop-filter: blur(14px) !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
    padding: 12px 14px 14px !important;
    margin: -14px -12px 16px -12px !important;
    border-bottom: 1px solid var(--line) !important;
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45) !important;
  }

  body.theme-light .active-exam-topbar {
    background: rgba(255, 255, 255, 0.97) !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08) !important;
  }

  .active-exam-actions-wrap {
    display: flex !important;
    gap: 10px !important;
    width: 100% !important;
  }

  .active-exam-timer-box {
    justify-content: center !important;
    font-size: 17px !important;
    padding: 8px 12px !important;
    flex: 1 !important;
    min-height: 46px !important;
    box-sizing: border-box !important;
  }

  #btnSubmitActiveExam {
    flex: 1.2 !important;
    padding: 8px 14px !important;
    font-size: 13.5px !important;
    box-sizing: border-box !important;
    justify-content: center !important;
    min-height: 46px !important;
    touch-action: manipulation;
  }

  .exam-q-jump-hint {
    display: block !important;
  }

  /* Nhiệm vụ 3 — Thanh mục lục câu hỏi: Hỗ trợ vuốt trượt ngang mượt mà */
  .exam-q-jump-grid {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scroll-behavior: smooth !important;
    gap: 8px !important;
    padding: 8px 4px 12px !important;
    margin-bottom: 16px !important;
    scrollbar-width: thin;
  }

  .exam-q-jump-grid::-webkit-scrollbar {
    height: 4px;
  }

  .exam-q-jump-grid::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 4px;
  }

  /* Nhiệm vụ 3 — Nút số câu: Chiều cao & rộng tối thiểu 44px – 48px chuẩn ngón tay bấm */
  .exam-q-jump-btn {
    flex-shrink: 0 !important;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    border-radius: 10px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    touch-action: manipulation !important;
  }

  /* Nhiệm vụ 1 — Thẻ câu hỏi & điều khiển: Chống tràn chữ & hình ảnh */
  .exam-question-card {
    padding: 16px 14px !important;
    margin-bottom: 16px !important;
    border-radius: 10px !important;
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
    box-sizing: border-box !important;
    max-width: 100% !important;
  }

  .exam-question-card img {
    max-width: 100% !important;
    height: auto !important;
    box-sizing: border-box !important;
    border-radius: 6px !important;
  }

  .exam-q-top-nav .btn-sm {
    min-height: 34px !important;
    padding: 4px 10px !important;
    font-size: 12px !important;
    font-weight: 700 !important;
    border-radius: 6px !important;
    touch-action: manipulation;
  }

  /* Nhiệm vụ 1 & 3 — Nút chọn đáp án: Chiều cao tối thiểu 48px & Chống tràn */
  .btn-active-exam-opt {
    padding: 12px 14px !important;
    font-size: 14px !important;
    gap: 10px !important;
    min-height: 48px !important;
    touch-action: manipulation;
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
    box-sizing: border-box !important;
    max-width: 100% !important;
  }

  .btn-active-exam-opt .opt-badge {
    width: 26px !important;
    height: 26px !important;
    font-size: 12px !important;
  }

  .btn-quiz-option {
    width: 100% !important;
    text-align: left !important;
    padding: 12px 14px !important;
    font-size: 13.5px !important;
  }

  /* Bottom Question Navigation Bar — STICKY DOCKED TO SCREEN BOTTOM */
  .exam-navigation-bar {
    position: sticky !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    background: rgba(15, 23, 42, 0.96) !important;
    backdrop-filter: blur(14px) !important;
    -webkit-backdrop-filter: blur(14px) !important;
    border-top: 1px solid var(--line) !important;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    margin: 16px -12px -14px -12px !important;
    z-index: 95 !important;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.45) !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    gap: 8px !important;
  }

  body.theme-light .exam-navigation-bar {
    background: rgba(255, 255, 255, 0.97) !important;
    box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.08) !important;
  }

  .exam-navigation-bar button {
    min-height: 48px !important;
    padding: 8px 14px !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    flex: 1 1 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 8px !important;
    touch-action: manipulation;
  }

  .exam-navigation-bar .exam-progress-counter {
    font-size: 11.5px !important;
    flex: 1.2 1 auto !important;
    min-width: 85px !important;
    text-align: center !important;
    line-height: 1.35 !important;
  }

  /* Student Exam Cards Grid */
  .exam-cards-grid {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }

  .exam-card {
    padding: 16px !important;
  }

  .exam-card > div:last-child {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  .exam-card .btn-start-exam,
  .exam-card .btn-review-exam {
    width: 100% !important;
    min-height: 44px !important;
    justify-content: center !important;
    font-size: 14px !important;
  }

  .exam-status-badge {
    white-space: normal !important;
    word-break: break-word !important;
    line-height: 1.35 !important;
    font-size: 11px !important;
  }

  /* Teacher's Exam Studio Mobile Optimization & Button Fix */
  .studio-card {
    padding: 16px 14px !important;
  }

  .studio-inner-card {
    padding: 14px 12px !important;
  }

  .studio-toolbar-actions {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  .studio-toolbar-actions > div,
  .studio-toolbar-actions button,
  #btnDownloadSampleWord,
  #btnClearAllWordData {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    justify-content: center !important;
    white-space: normal !important;
    word-break: break-word !important;
    text-align: center !important;
  }

  .studio-dist-quick-bar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  .studio-dist-quick-bar > div:first-child {
    display: flex !important;
    flex-direction: column !important;
    gap: 6px !important;
    width: 100% !important;
  }

  .studio-dist-quick-bar button {
    width: 100% !important;
    justify-content: center !important;
  }

  .studio-dist-quick-bar > div:last-child {
    justify-content: center !important;
    text-align: center !important;
  }

  .studio-print-actions {
    width: 100% !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }

  .studio-print-actions button,
  #btnSwitchToAssignTabFromPrint {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    justify-content: center !important;
    white-space: normal !important;
  }

  /* Critical Fix: Fix overflowing & misaligned "Phát Đề Cho Sinh Viên & Xuất File Đáp Án" button */
  .studio-assign-action-bar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .studio-assign-action-hint {
    width: 100% !important;
    text-align: center !important;
    font-size: 12.5px !important;
    line-height: 1.4 !important;
  }

  #btnCreateAndAssignExam,
  .btn-studio-assign {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 12px 14px !important;
    font-size: 13.5px !important;
    white-space: normal !important;
    word-break: break-word !important;
    border-radius: 8px !important;
    text-align: center !important;
    gap: 8px !important;
    margin: 0 !important;
  }

  #btnCreateAndAssignExam span,
  .btn-studio-assign span,
  .btn-studio-assign-text,
  .btn-assign-text {
    white-space: normal !important;
    word-break: break-word !important;
    line-height: 1.35 !important;
    text-align: center !important;
  }

  /* 4. Horizontal Scrollable Tabs across all Labs & Views */
  .theory-filter-tabs,
  .logic-sub-tabs,
  .counting-sub-tabs,
  .relation-sub-tabs,
  .lab-controls-bar {
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    gap: 6px !important;
    padding-bottom: 4px !important;
  }

  .theory-filter-tabs::-webkit-scrollbar,
  .logic-sub-tabs::-webkit-scrollbar,
  .counting-sub-tabs::-webkit-scrollbar,
  .relation-sub-tabs::-webkit-scrollbar,
  .lab-controls-bar::-webkit-scrollbar {
    display: none !important;
  }

  /* 5. Admin Database View */
  .admin-dashboard-wrap {
    padding: 12px 10px 40px !important;
  }

  .admin-header-banner {
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 14px 16px !important;
    gap: 12px !important;
  }

  .admin-header-banner > div:last-child {
    flex-direction: column;
    width: 100%;
  }

  .admin-header-banner button {
    width: 100%;
    justify-content: center;
  }

  .admin-stats-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }

  .admin-create-user-section,
  .admin-users-table-section,
  .admin-leaderboard-section {
    padding: 14px !important;
  }

  /* 6. Auth Modal */
  .auth-modal-dialog {
    max-width: 95vw !important;
    margin: 10px auto;
    border-radius: 12px !important;
  }

  .auth-modal-header {
    padding: 14px 16px !important;
  }

  .auth-modal-body {
    padding: 16px 14px !important;
    max-height: 80vh !important;
  }

  .profile-info-grid {
    grid-template-columns: 1fr !important;
  }

  /* 7. Counting Lab Mobile Responsive Rules */
  .counting-mapping-grid,
  .dirichlet-classic-grid,
  .counting-perm-grid,
  .counting-pie-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
    width: 100% !important;
  }

  .mapping-sets-bar {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
    padding: 0 !important;
    width: 100% !important;
  }

  .mapping-sets-bar .mapping-set-group {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    width: 100% !important;
    gap: 8px !important;
    flex-wrap: wrap !important;
  }

  .mapping-sets-bar .source-title,
  .mapping-sets-bar .target-title,
  .mapping-sets-bar .source-group span,
  .mapping-sets-bar .target-group span {
    font-size: 13px !important;
    white-space: normal !important;
    word-break: break-word !important;
    line-height: 1.35 !important;
  }

  .mapping-sets-bar .func-group {
    justify-content: center !important;
    padding: 6px 10px !important;
    border-top: 1px dashed var(--line) !important;
    border-bottom: 1px dashed var(--line) !important;
    background: rgba(0, 0, 0, 0.15) !important;
    border-radius: 6px !important;
    text-align: center !important;
  }

  .mapping-svg-wrapper {
    height: auto !important;
    aspect-ratio: 760 / 380 !important;
    min-height: 220px !important;
    max-height: 360px !important;
    width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* 8. Graph Lab Toolbar & Algorithm Switcher Mobile Optimization */
  .algo-switch {
    max-width: 100% !important;
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    padding: 4px 2px !important;
  }

  .algo-switch::-webkit-scrollbar {
    display: none !important;
  }

  .algo-switch-btn {
    flex-shrink: 0 !important;
    font-size: 12px !important;
    padding: 6px 10px !important;
  }

  .lab-toolbar {
    padding: 8px 10px !important;
    width: 100% !important;
  }

  .toolbar-row-main {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }

  .toolbar-left-cluster {
    width: 100% !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }

  .toolbar-right-cluster {
    width: 100% !important;
    margin-left: 0 !important;
    justify-content: flex-end !important;
  }

  .slot-preset {
    width: 100% !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
  }

  #presetSelect, .slot-preset select {
    flex: 1 1 140px !important;
    max-width: none !important;
    width: auto !important;
  }

  .toolbar-params-cluster {
    width: 100% !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }

  .slot-start-node, .slot-second-param {
    width: 100% !important;
    min-width: 0 !important;
  }

  .slot-start-node select, .slot-second-param select {
    width: 100% !important;
  }

  .param-help-text {
    padding-left: 0 !important;
    font-size: 11.5px !important;
    line-height: 1.4 !important;
  }

  /* 9. Logic Lab Mobile Optimization */
  .logic-toolbar-panel {
    padding: 8px 10px !important;
  }

  .logic-toolbar-panel > div {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  .logic-toolbar-panel > div > div:first-child {
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    padding-bottom: 2px !important;
  }

  .logic-toolbar-panel > div > div:first-child::-webkit-scrollbar {
    display: none !important;
  }

  .logic-playback-bar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
  }

  .logic-playback-bar > div:first-child {
    justify-content: center !important;
    width: 100% !important;
    flex-wrap: wrap !important;
  }

  .logic-playback-bar > div:nth-child(2) {
    max-width: 100% !important;
    width: 100% !important;
  }

  .circuit-presets-bar {
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    padding-bottom: 2px !important;
    width: 100% !important;
  }

  .circuit-presets-bar::-webkit-scrollbar {
    display: none !important;
  }

  .circuit-presets-bar button {
    flex-shrink: 0 !important;
  }

  /* 10. General Mobile Labs Container & Overflow Protections */
  .lab-layout,
  .counting-lab-container,
  .relation-lab-container,
  .logic-lab-container,
  .theory-container,
  .fundamentals-container {
    max-width: 100vw !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
  }

  .table-responsive-wrapper,
  .relation-matrix-table-wrap,
  .logic-table-wrapper {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    max-width: 100% !important;
  }

  .relation-matrix-table {
    margin: 0 auto !important;
    max-width: 100% !important;
  }

  .relation-matrix-cell {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    font-size: 13px !important;
  }
}

@media (max-width: 480px) {
  .admin-stats-grid {
    grid-template-columns: 1fr !important;
  }

  .brand-name {
    max-width: 120px !important;
    font-size: 13px !important;
  }

  .btn-auth-user #lblUserAuthName {
    display: none !important;
  }

  .btn-auth-user {
    padding: 6px 8px !important;
  }

  .auth-tab-btn {
    padding: 8px 10px !important;
    font-size: 12px !important;
  }

  .exam-q-top-nav .btn-sm {
    padding: 3px 6px !important;
    font-size: 11px !important;
  }

  .exam-navigation-bar button {
    font-size: 13px !important;
    padding: 8px 6px !important;
    min-height: 48px !important;
  }

  .exam-q-jump-btn {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
  }

  .home-theory-bar-btn {
    padding: 9px 10px !important;
  }

  .home-theory-bar-btn .home-theory-text,
  .home-theory-bar-btn span:nth-child(2) {
    font-size: 12px !important;
  }

  #btnCreateAndAssignExam,
  .btn-studio-assign {
    padding: 10px 10px !important;
    font-size: 12.5px !important;
  }

  /* Extra Small Devices (< 480px) Enhancements */
  .relation-matrix-cell {
    width: 30px !important;
    height: 30px !important;
    min-width: 30px !important;
    min-height: 30px !important;
    font-size: 11px !important;
  }

  .mapping-sets-bar .source-title,
  .mapping-sets-bar .target-title,
  .mapping-sets-bar .source-group span,
  .mapping-sets-bar .target-group span {
    font-size: 12px !important;
  }

  .mapping-sets-bar button {
    padding: 3px 6px !important;
    font-size: 11px !important;
  }

  .btn-key {
    padding: 3px 6px !important;
    font-size: 12px !important;
  }

  .algo-switch-btn {
    padding: 5px 8px !important;
    font-size: 11px !important;
  }
}

/* =====================================================================
   SENIOR FULLSTACK CROSS-BROWSER MOBILE ENHANCEMENTS (ANDROID & IOS SAFARI)
   ===================================================================== */
@media (max-width: 768px) {
  /* 1. iOS Safari Auto-Zoom Fix: Prevent zoom when focusing inputs with font-size < 16px */
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea {
    font-size: 16px !important;
  }

  /* 2. Fast Responsive Taps: Eliminate 300ms tap delay and touch callouts */
  * {
    -webkit-tap-highlight-color: transparent;
  }

  button,
  a,
  input[type="button"],
  input[type="submit"],
  .btn-quiz-option,
  .btn-active-exam-opt {
    touch-action: manipulation;
  }

  /* 3. iOS Momentum Scrolling */
  .table-responsive,
  .gradebook-table-container,
  .ai-messages-scroll,
  .theory-sidebar,
  .theory-content,
  .mobile-nav-panel,
  .admin-table-container,
  .exam-history-list {
    -webkit-overflow-scrolling: touch;
  }

  /* 4. Safe Area Inset Support (iPhone Notch & Dynamic Island) */
  .app-header {
    padding-top: env(safe-area-inset-top, 0px) !important;
    height: calc(56px + env(safe-area-inset-top, 0px)) !important;
  }

  .mobile-nav-panel {
    padding-top: env(safe-area-inset-top, 0px) !important;
    padding-bottom: env(safe-area-inset-bottom, 0px) !important;
  }

  /* 5. Mobile User Dropdown Bounds Protection */
  .user-dropdown-menu {
    max-width: calc(100vw - 20px) !important;
    right: 0 !important;
  }

  /* 6. AI Header Subtitle Mobile Ellipsis */
  .ai-sub-text {
    max-width: 200px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
}

/* Graph Canvas & SVG Touch Support */
.graph-canvas-container svg,
#graphCanvas,
#graphSvg {
  touch-action: none;
}

