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

/* ==========================================================================
   CSS Variables & Theme Systems
   ========================================================================== */
:root {
  /* Theme: Dark Cyber Glow (Default) */
  --bg-main: #0b0f19;
  --bg-surface: #111827;
  --bg-card: rgba(17, 24, 39, 0.75);
  --bg-card-hover: rgba(31, 41, 55, 0.85);
  --bg-sidebar: #0d1322;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-active: rgba(99, 102, 241, 0.4);
  
  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  
  --accent-primary: #6366f1;
  --accent-primary-glow: rgba(99, 102, 241, 0.35);
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
  
  --highlight-row: rgba(234, 179, 8, 0.18);
  --highlight-col: rgba(234, 179, 8, 0.18);
  --highlight-cross: #eab308;
  --highlight-cross-text: #000000;
  --highlight-header: #facc15;
  --highlight-header-text: #1e1b4b;
  
  --grid-border: #1f293d;
  --grid-header-bg: #1e293b;
  --grid-cell-bg: #131b2e;
  --grid-cell-text: #e2e8f0;
  --grid-even-bg: #0f172a;
  
  --badge-bg: rgba(99, 102, 241, 0.15);
  --badge-text: #818cf8;
  
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 30px -5px rgba(0, 0, 0, 0.5), 0 0 20px rgba(99, 102, 241, 0.15);
  --glass-blur: blur(16px);
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  --sidebar-width: 270px;
}

/* Theme: Rainbow Prism */
[data-theme="rainbow"] {
  --bg-main: #0c081e;
  --bg-surface: #140e33;
  --bg-card: rgba(25, 17, 60, 0.7);
  --bg-sidebar: #0f0a28;
  --border-subtle: rgba(255, 255, 255, 0.12);
  --text-primary: #ffffff;
  --text-secondary: #c4b5fd;
  --accent-primary: #ec4899;
  --accent-gradient: linear-gradient(135deg, #ff007a 0%, #7928ca 35%, #0070f3 70%, #00dfd8 100%);
  --highlight-row: rgba(236, 72, 153, 0.22);
  --highlight-col: rgba(59, 130, 246, 0.22);
  --highlight-cross: #f43f5e;
  --highlight-cross-text: #ffffff;
  --grid-border: #281a54;
  --grid-header-bg: #2d1b69;
  --grid-cell-bg: #191142;
  --grid-even-bg: #130c33;
}

/* Theme: Solar Candy Pastel */
[data-theme="candy"] {
  --bg-main: #faf5ff;
  --bg-surface: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-hover: #f3e8ff;
  --bg-sidebar: #f5f3ff;
  --border-subtle: rgba(139, 92, 246, 0.15);
  --border-active: rgba(139, 92, 246, 0.5);
  --text-primary: #1e1b4b;
  --text-secondary: #6b21a8;
  --text-muted: #9333ea;
  --accent-primary: #8b5cf6;
  --accent-gradient: linear-gradient(135deg, #f43f5e 0%, #fb923c 40%, #8b5cf6 100%);
  --highlight-row: #fed7aa;
  --highlight-col: #fed7aa;
  --highlight-cross: #f97316;
  --highlight-cross-text: #ffffff;
  --highlight-header: #f43f5e;
  --highlight-header-text: #ffffff;
  --grid-border: #e9d5ff;
  --grid-header-bg: #8b5cf6;
  --grid-cell-bg: #ffffff;
  --grid-even-bg: #faf5ff;
  --grid-cell-text: #1e1b4b;
  --shadow-sm: 0 4px 12px rgba(139, 92, 246, 0.08);
  --shadow-lg: 0 12px 28px rgba(139, 92, 246, 0.15);
}

/* Theme: Emerald Cyber */
[data-theme="emerald"] {
  --bg-main: #061e14;
  --bg-surface: #0a2e20;
  --bg-card: rgba(10, 46, 32, 0.75);
  --bg-sidebar: #051910;
  --border-subtle: rgba(52, 211, 153, 0.15);
  --text-primary: #ecfdf5;
  --text-secondary: #6ee7b7;
  --accent-primary: #10b981;
  --accent-gradient: linear-gradient(135deg, #10b981 0%, #06b6d4 50%, #3b82f6 100%);
  --highlight-row: rgba(16, 185, 129, 0.2);
  --highlight-col: rgba(16, 185, 129, 0.2);
  --highlight-cross: #10b981;
  --highlight-cross-text: #022c22;
  --grid-border: #134e38;
  --grid-header-bg: #065f46;
  --grid-cell-bg: #0b3424;
  --grid-even-bg: #08261a;
  --grid-cell-text: #d1fae5;
}

/* Theme: High-Contrast Light */
[data-theme="light"] {
  --bg-main: #f8fafc;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-sidebar: #f1f5f9;
  --border-subtle: #e2e8f0;
  --border-active: #3b82f6;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --accent-primary: #2563eb;
  --accent-gradient: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
  --highlight-row: #fef08a;
  --highlight-col: #fef08a;
  --highlight-cross: #eab308;
  --highlight-cross-text: #0f172a;
  --highlight-header: #2563eb;
  --highlight-header-text: #ffffff;
  --grid-border: #cbd5e1;
  --grid-header-bg: #1e293b;
  --grid-cell-bg: #ffffff;
  --grid-even-bg: #f8fafc;
  --grid-cell-text: #0f172a;
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.08);
}

/* ==========================================================================
   Base & Reset
   ========================================================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-primary);
  overflow-x: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Smooth custom scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-main);
}
::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent-primary);
}

/* App Container Layout */
.app-container {
  display: flex;
  min-height: 100vh;
  position: relative;
}

/* ==========================================================================
   Sidebar Navigation
   ========================================================================== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 50;
  overflow-y: auto;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), width 0.3s ease;
  backdrop-filter: var(--glass-blur);
}

.brand {
  padding: 1.5rem 1.25rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.35rem;
  font-weight: 800;
  box-shadow: 0 4px 14px var(--accent-primary-glow);
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.nav-section {
  padding: 1.25rem 0.85rem 0.5rem;
}

.nav-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0 0.6rem 0.5rem;
}

.nav-menu {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.nav-item:hover {
  color: var(--text-primary);
  background: var(--bg-card-hover);
  transform: translateX(3px);
}

.nav-item.active {
  color: #fff;
  background: var(--accent-gradient);
  box-shadow: 0 4px 15px var(--accent-primary-glow);
  font-weight: 600;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  background: var(--badge-bg);
  color: var(--badge-text);
  font-weight: 700;
}

.quick-table-chips {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
  padding: 0.5rem 0.6rem;
}

.table-chip {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  padding: 0.35rem 0.2rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
}

.table-chip:hover, .table-chip.active {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
  transform: scale(1.05);
}

/* ==========================================================================
   Main Content Layout
   ========================================================================== */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Header */
.top-header {
  height: 56px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: var(--glass-blur);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex: 1;
}

.header-center {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mobile-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 0.5rem;
}

.search-box {
  position: relative;
  width: 320px;
}

.search-box input {
  width: 100%;
  background: var(--bg-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 0.6rem 2.8rem 0.6rem 2.5rem;
  color: var(--text-primary);
  font-size: 0.88rem;
  font-family: var(--font-sans);
  transition: border-color 0.2s, box-shadow 0.2s;
}

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

.search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-shortcut {
  position: absolute;
  right: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.header-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  flex: 1;
}

.theme-selector {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 0.25rem 0.4rem;
}

.theme-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
}
.theme-dot:hover {
  transform: scale(1.15);
}
.theme-dot.active {
  border-color: #fff;
  box-shadow: 0 0 8px currentColor;
}
.theme-dot[data-set="dark"] { background: #1e1b4b; }
.theme-dot[data-set="rainbow"] { background: linear-gradient(135deg, #ec4899, #8b5cf6, #3b82f6); }
.theme-dot[data-set="candy"] { background: linear-gradient(135deg, #f43f5e, #fb923c); }
.theme-dot[data-set="emerald"] { background: linear-gradient(135deg, #10b981, #06b6d4); }
.theme-dot[data-set="light"] { background: #f8fafc; border: 1px solid #cbd5e1; }

.header-btn {
  background: var(--bg-main);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.header-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-primary);
  transform: translateY(-1px);
}

.header-btn.primary {
  background: var(--accent-gradient);
  border: none;
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-primary-glow);
}

.header-home-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.42rem 0.95rem;
  border-radius: var(--radius-full);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 0.84rem;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
}

.header-home-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-primary);
  color: var(--text-primary);
  box-shadow: 0 0 14px var(--accent-primary-glow);
  transform: translateY(-1px);
}

.header-home-btn svg {
  width: 14px;
  height: 14px;
  color: var(--text-primary);
  transition: transform 0.2s ease, color 0.2s ease;
  flex-shrink: 0;
}

.header-home-btn:hover svg {
  transform: scale(1.12);
  color: var(--accent-primary);
}

@media (max-width: 480px) {
  .header-home-btn span {
    display: none;
  }
  .header-home-btn {
    padding: 0.42rem 0.6rem;
  }
}

/* ==========================================================================
   Hero Banner & Stats
   ========================================================================== */
.hero-banner {
  padding: 2.25rem 2rem 1.5rem;
  background: radial-gradient(circle at 80% 20%, var(--accent-primary-glow) 0%, transparent 60%);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1.5rem;
}

.hero-info h1 {
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.hero-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
  background: var(--accent-gradient);
  color: #fff;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.hero-info p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  max-width: 650px;
}

.hero-stats {
  display: flex;
  gap: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem 1.25rem;
  text-align: center;
  min-width: 110px;
  backdrop-filter: var(--glass-blur);
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  font-family: var(--font-mono);
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.stat-title {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

/* ==========================================================================
   Tab Navigation & Control Bar
   ========================================================================== */
.controls-bar {
  padding: 1.5rem 2rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.views-tabs {
  display: flex;
  gap: 0.5rem;
  background: var(--bg-surface);
  padding: 0.35rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.view-tab {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.view-tab:hover {
  color: var(--text-primary);
}

.view-tab.active {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 4px 12px var(--accent-primary-glow);
}

.grid-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.preset-pill-group {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.25rem;
}

.preset-pill {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.preset-pill:hover {
  color: var(--text-primary);
}

.preset-pill.active {
  background: var(--bg-card-hover);
  color: var(--accent-primary);
  border: 1px solid var(--border-active);
}

.pattern-select, .range-select {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  outline: none;
}

.pattern-select:focus, .range-select:focus {
  border-color: var(--accent-primary);
}

#worksheetTableSelect {
  min-width: 270px;
}

/* Differentiated Dropdown Optgroup Colors */
.pattern-select optgroup, select optgroup {
  font-weight: 800;
  font-style: normal;
  background-color: var(--bg-surface);
  padding: 6px 14px 4px 6px;
  margin-left: 0;
  text-align: left;
}

.pattern-select optgroup.group-mixed,
select optgroup[label*="Mixed"] {
  color: #f43f5e !important; /* Vibrant Rose/Pink for Mixed */
  font-weight: 800;
}

.pattern-select optgroup.group-individual,
select optgroup[label*="Individual"] {
  color: var(--accent-primary) !important; /* Theme Primary Accent for Individual */
  font-weight: 800;
}

/* Theme specific overrides for optgroups */
[data-theme="candy"] select optgroup.group-mixed { color: #ea580c !important; }
[data-theme="candy"] select optgroup.group-individual { color: #7c3aed !important; }
[data-theme="emerald"] select optgroup.group-mixed { color: #06b6d4 !important; }
[data-theme="emerald"] select optgroup.group-individual { color: #10b981 !important; }
[data-theme="light"] select optgroup.group-mixed { color: #dc2626 !important; }
[data-theme="light"] select optgroup.group-individual { color: #2563eb !important; }

.pattern-select option, select option {
  color: var(--text-primary);
  background-color: var(--bg-surface);
  font-weight: 500;
  padding: 4px 12px;
}

/* ==========================================================================
   Active Content Container & Views
   ========================================================================== */
.content-body {
  padding: 1.5rem 2rem 3rem;
  flex: 1;
}

.view-panel {
  display: none;
  animation: fadeIn 0.3s ease forwards;
}

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

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

/* ==========================================================================
   Interactive Multiplication Grid (Matrix)
   ========================================================================== */
.grid-container-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
  position: relative;
}

.grid-toolbar-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.grid-floating-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding: 0.85rem 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  backdrop-filter: var(--glass-blur);
}

.active-equation {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.3rem;
  font-weight: 800;
  font-family: var(--font-mono);
}

.eq-chip {
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
}

.eq-product {
  color: var(--highlight-cross);
  background: rgba(234, 179, 8, 0.15);
  border: 1px solid var(--highlight-cross);
}

.visual-hint {
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.table-scroll-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--grid-border);
  max-height: 75vh;
  position: relative;
}

.mult-matrix {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  user-select: none;
}

.mult-matrix th, .mult-matrix td {
  padding: 0.6rem 0.5rem;
  text-align: center;
  border: 1px solid var(--grid-border);
  min-width: 44px;
  height: 40px;
  position: relative;
  transition: background-color 0.12s ease, transform 0.1s ease, color 0.12s ease;
}

.mult-matrix th {
  background: var(--grid-header-bg);
  color: var(--text-primary);
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 10;
}

.mult-matrix th.row-header {
  left: 0;
  z-index: 11;
}

.mult-matrix th.corner-cell {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 20;
  background: var(--accent-gradient);
  color: #fff;
  font-size: 1.1rem;
}

.mult-matrix td {
  background: var(--grid-cell-bg);
  color: var(--grid-cell-text);
  cursor: pointer;
}

.mult-matrix tr:nth-child(even) td {
  background: var(--grid-even-bg);
}

/* Dynamic Hover Crosshair Highlights */
.mult-matrix th.col-highlight,
.mult-matrix th.row-highlight {
  background: var(--highlight-header) !important;
  color: var(--highlight-header-text) !important;
  font-weight: 800;
  box-shadow: 0 0 10px rgba(250, 204, 21, 0.4);
}

.mult-matrix td.row-highlight,
.mult-matrix td.col-highlight {
  background-color: var(--highlight-row) !important;
  color: var(--text-primary);
}

.mult-matrix td.cell-active {
  background-color: var(--highlight-cross) !important;
  color: var(--highlight-cross-text) !important;
  font-weight: 800;
  transform: scale(1.12);
  z-index: 5;
  box-shadow: 0 0 16px var(--highlight-cross);
  border-radius: 4px;
  border-color: #fff !important;
}

/* Pattern Highlights */
.mult-matrix td.pattern-prime {
  background: rgba(16, 185, 129, 0.25) !important;
  border: 1px solid #10b981;
  color: #6ee7b7;
}

.mult-matrix td.pattern-square {
  background: rgba(168, 85, 247, 0.3) !important;
  border: 1px solid #a855f7;
  color: #f3e8ff;
  font-weight: 700;
}

.mult-matrix td.pattern-multiple {
  background: rgba(236, 72, 153, 0.3) !important;
  border: 1px solid #ec4899;
  color: #fce7f3;
  font-weight: 700;
  animation: pulseGlow 1.5s infinite;
}

@keyframes pulseGlow {
  0%, 100% { opacity: 0.9; }
  50% { opacity: 0.6; }
}

/* ==========================================================================
   Multiplication Cards Studio (Individual Tables 1-100)
   ========================================================================== */
.cards-view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.table-slider-control {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 0.4rem 1rem;
}

.table-slider-control input[type="range"] {
  accent-color: var(--accent-primary);
  cursor: pointer;
}

.table-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.25rem;
}

.single-table-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.25s;
}

.single-table-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-active);
}

.card-header-bar {
  background: var(--accent-gradient);
  color: #fff;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-weight: 800;
  font-size: 1.1rem;
}

.card-audio-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
}

.card-audio-btn:hover {
  background: rgba(255, 255, 255, 0.4);
  transform: scale(1.08);
}

.card-audio-btn.is-playing {
  background: #ef4444;
  color: #ffffff;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.7);
  animation: audioPulse 1.2s infinite ease-in-out;
}

.card-audio-btn.is-playing:hover {
  background: #dc2626;
  transform: scale(1.12);
}

@keyframes audioPulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 6px rgba(239, 68, 68, 0.6);
  }
  50% {
    transform: scale(1.14);
    box-shadow: 0 0 16px rgba(239, 68, 68, 0.95);
  }
}

.card-list {
  list-style: none;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.88rem;
}

.card-list-item {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
}

.card-list-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  font-weight: 700;
}

.card-list-item .res {
  color: var(--accent-primary);
  font-weight: 700;
}

/* ==========================================================================
   Visual Area & Dot Array Visualizer
   ========================================================================== */
.visualizer-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
}

.vis-controls-panel {
  display: flex;
  gap: 2rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  align-items: center;
  background: var(--bg-card);
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.vis-input-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.vis-input-group label {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.vis-num-input {
  width: 70px;
  background: var(--bg-main);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.6rem;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  font-family: var(--font-mono);
}

.vis-area-canvas-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 380px;
  background: var(--bg-main);
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 2rem;
  overflow: auto;
}

.dot-array-grid {
  display: inline-grid;
  gap: 6px;
  padding: 1.25rem;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 2px solid var(--border-active);
  box-shadow: var(--shadow-lg);
}

.dot-cell {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.65rem;
  font-family: var(--font-mono);
  font-weight: 700;
  animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popIn {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.vis-breakdown-formula {
  margin-top: 1.5rem;
  text-align: center;
  font-size: 1.4rem;
  font-weight: 800;
  font-family: var(--font-mono);
}

/* ==========================================================================
   Flashcards Mode (3D Flip Memorizer)
   ========================================================================== */
.flashcards-wrapper {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.flashcard-3d-scene {
  width: 100%;
  height: 320px;
  perspective: 1000px;
}

.flashcard-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.flashcard-inner.flipped {
  transform: rotateY(180deg);
}

.flashcard-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-subtle);
  padding: 2rem;
  text-align: center;
}

.flashcard-front {
  background: linear-gradient(145deg, var(--bg-surface), var(--bg-card));
}

.flashcard-back {
  background: var(--accent-gradient);
  color: #fff;
  transform: rotateY(180deg);
}

.card-question {
  font-size: 3.5rem;
  font-weight: 900;
  font-family: var(--font-mono);
  margin-bottom: 1rem;
}

.card-answer {
  font-size: 4rem;
  font-weight: 900;
  font-family: var(--font-mono);
  text-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.card-hint-text {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.card-controls-row {
  display: flex;
  gap: 1rem;
  width: 100%;
  justify-content: center;
}

.flash-action-btn {
  flex: 1;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  border: none;
  transition: transform 0.15s;
}
.flash-action-btn:hover {
  transform: translateY(-2px);
}
.flash-btn-flip { 
  background: var(--bg-surface); 
  border: 1px solid var(--border-subtle); 
  color: var(--text-primary); 
}
.flash-btn-flip:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-primary);
}
.flash-btn-next { 
  background: var(--accent-gradient); 
  color: #fff; 
  box-shadow: 0 4px 14px var(--accent-primary-glow);
}

/* ==========================================================================
   Speed Quiz & Challenge Arena
   ========================================================================== */
.quiz-arena {
  max-width: 700px;
  margin: 0 auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 2.25rem;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.quiz-timer-bar-wrap {
  width: 100%;
  height: 8px;
  background: var(--bg-main);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.quiz-timer-bar {
  height: 100%;
  width: 100%;
  background: var(--accent-gradient);
  transition: width 1s linear;
}

.quiz-streak-badge {
  font-weight: 800;
  font-size: 0.9rem;
  color: #f59e0b;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.quiz-prompt-eq {
  font-size: 3.5rem;
  font-weight: 900;
  font-family: var(--font-mono);
  margin: 1.5rem 0 2rem;
  letter-spacing: 0.05em;
}

.quiz-options-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.quiz-opt-btn {
  background: var(--bg-main);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  font-size: 1.6rem;
  font-family: var(--font-mono);
  font-weight: 800;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

.quiz-opt-btn:hover {
  border-color: var(--accent-primary);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
}

.quiz-opt-btn.correct {
  background: #10b981 !important;
  border-color: #10b981 !important;
  color: #fff !important;
  animation: pulseScale 0.3s ease;
}

.quiz-opt-btn.wrong {
  background: #ef4444 !important;
  border-color: #ef4444 !important;
  color: #fff !important;
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

@keyframes pulseScale {
  0% { transform: scale(0.95); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* ==========================================================================
   Finger Chart Tricks & Vedic Math Section
   ========================================================================== */
.tricks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
}

.trick-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.trick-card h3 {
  font-size: 1.2rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--accent-primary);
}

.trick-card p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 1rem;
}

.trick-visual-box {
  background: var(--bg-main);
  border-radius: var(--radius-sm);
  padding: 1rem;
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

/* ==========================================================================
   Printable Worksheet Generator & Print CSS
   ========================================================================== */
.worksheet-builder {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 2rem;
}

.worksheet-controls {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.worksheet-sheet {
  background: #ffffff;
  color: #000000;
  padding: 2.5rem;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  max-width: 800px;
  margin: 0 auto;
}

.worksheet-header-print {
  display: flex;
  justify-content: space-between;
  border-bottom: 2px solid #000;
  padding-bottom: 0.75rem;
  margin-bottom: 1.5rem;
}

.worksheet-questions-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem 1rem;
  font-family: var(--font-mono);
  font-size: 1.15rem;
}

.worksheet-item {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.worksheet-blank {
  display: inline-block;
  width: 60px;
  border-bottom: 2px solid #333;
}

/* High Quality Print Styles */
@media print {
  body * {
    visibility: hidden;
  }
  .worksheet-sheet, .worksheet-sheet * {
    visibility: visible;
  }
  .worksheet-sheet {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    margin: 0;
    padding: 0;
    box-shadow: none;
    border: none;
  }
  .sidebar, .top-header, .hero-banner, .controls-bar, .worksheet-controls {
    display: none !important;
  }
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */
/* ==========================================================================
   About MathsLover, Guides & FAQ (SEO/AEO Suite)
   ========================================================================== */
.about-container-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
  max-width: 950px;
  margin: 0 auto;
}

.about-header {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.about-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.about-feature-box {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.about-feature-box:hover {
  transform: translateY(-3px);
  border-color: var(--accent-primary);
}

.about-section {
  margin-bottom: 2.5rem;
}

.property-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  border-left: 4px solid var(--accent-primary);
}

.property-card code {
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.08);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  color: var(--accent-primary);
  font-weight: 700;
}

/* FAQ Accordion Styling */
.faq-container {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.faq-item {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color 0.2s;
}

.faq-item:hover {
  border-color: var(--border-active);
}

.faq-question {
  padding: 1rem 1.25rem;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text-primary);
  user-select: none;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.faq-question::-webkit-details-marker {
  display: none;
}

.faq-question::after {
  content: "＋";
  font-size: 1.2rem;
  color: var(--accent-primary);
  transition: transform 0.2s;
}

details[open] .faq-question::after {
  content: "−";
  transform: rotate(180deg);
}

.faq-answer {
  padding: 0 1.25rem 1.25rem;
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.6;
}

/* Footer Styling */
.app-footer {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-subtle);
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
}

.footer-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
  transition: color 0.2s;
}

.footer-links a:hover {
  color: var(--accent-primary);
}

.footer-bottom {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}

@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .mobile-toggle {
    display: block;
  }
  .hero-banner {
    padding: 1.5rem 1rem;
  }
  .top-header {
    padding: 0 1rem;
  }
  .content-body {
    padding: 1rem;
  }
}

@media (max-width: 640px) {
  .hero-info h1 {
    font-size: 1.6rem;
  }
  .stat-card {
    min-width: 80px;
    padding: 0.5rem 0.75rem;
  }
  .quiz-options-grid {
    grid-template-columns: 1fr;
  }
}
