/* ========================================================
   Calcwillow - Free Online Scientific Calculator
   Ultra-Premium Modern Web Design System
   ======================================================== */

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

/* --- Root Variables & Theme System --- */
:root {
  --font-main: 'Outfit', 'Inter', -apple-system, sans-serif;
  --font-mono: 'Fira Code', monospace;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 9999px;
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 1. Classic Dark (Default) */
body.theme-classic-dark {
  --bg-page: radial-gradient(circle at 50% 10%, #171d34 0%, #090c15 100%);
  --bg-card: rgba(22, 28, 48, 0.75);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  --bg-display: #0b0f1b;
  --display-border: rgba(255, 255, 255, 0.06);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --btn-num-bg: rgba(255, 255, 255, 0.06);
  --btn-num-text: #f1f5f9;
  --btn-num-hover: rgba(255, 255, 255, 0.12);
  
  --btn-fn-bg: rgba(99, 102, 241, 0.12);
  --btn-fn-text: #a5b4fc;
  --btn-fn-hover: rgba(99, 102, 241, 0.22);
  
  --btn-op-bg: rgba(56, 189, 248, 0.14);
  --btn-op-text: #38bdf8;
  --btn-op-hover: rgba(56, 189, 248, 0.25);
  
  --btn-eq-bg: linear-gradient(135deg, #6366f1 0%, #3b82f6 100%);
  --btn-eq-text: #ffffff;
  --btn-eq-shadow: 0 4px 18px rgba(99, 102, 241, 0.45);
  
  --btn-clear-bg: rgba(244, 63, 94, 0.14);
  --btn-clear-text: #fb7185;
  --btn-clear-hover: rgba(244, 63, 94, 0.25);

  --accent-color: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --note-line-color: rgba(255, 255, 255, 0.05);
}

/* 2. iOS Glass */
body.theme-ios {
  --bg-page: #000000;
  --bg-card: rgba(28, 28, 30, 0.85);
  --bg-card-border: rgba(255, 255, 255, 0.12);
  --bg-display: #000000;
  --display-border: transparent;
  --text-main: #ffffff;
  --text-muted: #8e8e93;
  --text-dim: #636366;
  
  --btn-num-bg: #333333;
  --btn-num-text: #ffffff;
  --btn-num-hover: #505050;
  
  --btn-fn-bg: #a5a5a5;
  --btn-fn-text: #000000;
  --btn-fn-hover: #d4d4d2;
  
  --btn-op-bg: #ff9f0a;
  --btn-op-text: #ffffff;
  --btn-op-hover: #fcc169;
  
  --btn-eq-bg: #ff9f0a;
  --btn-eq-text: #ffffff;
  --btn-eq-shadow: 0 4px 14px rgba(255, 159, 10, 0.4);
  
  --btn-clear-bg: #a5a5a5;
  --btn-clear-text: #000000;
  --btn-clear-hover: #d4d4d2;

  --accent-color: #ff9f0a;
  --accent-glow: rgba(255, 159, 10, 0.25);
  --note-line-color: rgba(255, 255, 255, 0.07);
}

/* 3. Pastel Candy */
body.theme-pastel {
  --bg-page: linear-gradient(135deg, #fdf2f8 0%, #f5f3ff 50%, #eff6ff 100%);
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-border: rgba(226, 232, 240, 0.8);
  --bg-display: #faf5ff;
  --display-border: #e9d5ff;
  --text-main: #1e1b4b;
  --text-muted: #6b7280;
  --text-dim: #9ca3af;
  
  --btn-num-bg: #f8fafc;
  --btn-num-text: #334155;
  --btn-num-hover: #f1f5f9;
  
  --btn-fn-bg: #ede9fe;
  --btn-fn-text: #6d28d9;
  --btn-fn-hover: #ddd6fe;
  
  --btn-op-bg: #fce7f3;
  --btn-op-text: #db2777;
  --btn-op-hover: #fbcfe8;
  
  --btn-eq-bg: linear-gradient(135deg, #ec4899 0%, #8b5cf6 100%);
  --btn-eq-text: #ffffff;
  --btn-eq-shadow: 0 4px 14px rgba(236, 72, 153, 0.35);
  
  --btn-clear-bg: #ffe4e6;
  --btn-clear-text: #e11d48;
  --btn-clear-hover: #fecdd3;

  --accent-color: #ec4899;
  --accent-glow: rgba(236, 72, 153, 0.2);
  --note-line-color: rgba(139, 92, 246, 0.1);
}

/* 4. Cyber Teal */
body.theme-cyber-teal {
  --bg-page: radial-gradient(circle at 50% 20%, #03141f 0%, #01080d 100%);
  --bg-card: rgba(7, 26, 38, 0.8);
  --bg-card-border: rgba(6, 182, 212, 0.25);
  --bg-display: #020f18;
  --display-border: rgba(6, 182, 212, 0.4);
  --text-main: #ecfeff;
  --text-muted: #67e8f9;
  --text-dim: #155e75;
  
  --btn-num-bg: rgba(6, 182, 212, 0.08);
  --btn-num-text: #cffafe;
  --btn-num-hover: rgba(6, 182, 212, 0.18);
  
  --btn-fn-bg: rgba(6, 182, 212, 0.16);
  --btn-fn-text: #22d3ee;
  --btn-fn-hover: rgba(6, 182, 212, 0.28);
  
  --btn-op-bg: rgba(16, 185, 129, 0.18);
  --btn-op-text: #34d399;
  --btn-op-hover: rgba(16, 185, 129, 0.3);
  
  --btn-eq-bg: linear-gradient(135deg, #06b6d4 0%, #10b981 100%);
  --btn-eq-text: #01141c;
  --btn-eq-shadow: 0 0 20px rgba(6, 182, 212, 0.6);
  
  --btn-clear-bg: rgba(239, 68, 68, 0.2);
  --btn-clear-text: #f87171;
  --btn-clear-hover: rgba(239, 68, 68, 0.35);

  --accent-color: #06b6d4;
  --accent-glow: rgba(6, 182, 212, 0.35);
  --note-line-color: rgba(6, 182, 212, 0.12);
}

/* 5. Light Minimal */
body.theme-light-minimal {
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-border: #e2e8f0;
  --bg-display: #f1f5f9;
  --display-border: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  
  --btn-num-bg: #f8fafc;
  --btn-num-text: #1e293b;
  --btn-num-hover: #e2e8f0;
  
  --btn-fn-bg: #f1f5f9;
  --btn-fn-text: #475569;
  --btn-fn-hover: #e2e8f0;
  
  --btn-op-bg: #f8fafc;
  --btn-op-text: #2563eb;
  --btn-op-hover: #dbeafe;
  
  --btn-eq-bg: #2563eb;
  --btn-eq-text: #ffffff;
  --btn-eq-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
  
  --btn-clear-bg: #fee2e2;
  --btn-clear-text: #dc2626;
  --btn-clear-hover: #fecaca;

  --accent-color: #2563eb;
  --accent-glow: rgba(37, 99, 235, 0.15);
  --note-line-color: rgba(0, 0, 0, 0.05);
}

/* 6. Android Material */
body.theme-android {
  --bg-page: #1a1c1e;
  --bg-card: #202327;
  --bg-card-border: #2e3135;
  --bg-display: #121416;
  --display-border: transparent;
  --text-main: #e2e2e6;
  --text-muted: #c4c7c5;
  --text-dim: #8e918f;
  
  --btn-num-bg: #2e3135;
  --btn-num-text: #e2e2e6;
  --btn-num-hover: #393d42;
  
  --btn-fn-bg: #35383f;
  --btn-fn-text: #a8c7fa;
  --btn-fn-hover: #434750;
  
  --btn-op-bg: #004a77;
  --btn-op-text: #c2e7ff;
  --btn-op-hover: #005d95;
  
  --btn-eq-bg: #a8c7fa;
  --btn-eq-text: #062e6f;
  --btn-eq-shadow: 0 4px 14px rgba(168, 199, 250, 0.3);
  
  --btn-clear-bg: #601410;
  --btn-clear-text: #f2b8b5;
  --btn-clear-hover: #8c1d18;

  --accent-color: #a8c7fa;
  --accent-glow: rgba(168, 199, 250, 0.2);
  --note-line-color: rgba(255, 255, 255, 0.06);
}

/* 7. Retro Scientific (TI / Casio LCD Style) */
body.theme-retro-scientific {
  --bg-page: #1e2022;
  --bg-card: #2b2e31;
  --bg-card-border: #3d4146;
  --bg-display: #9bb391; /* Vintage dot matrix LCD */
  --display-border: #758a6d;
  --text-main: #e5e7eb;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  
  --btn-num-bg: #3f4348;
  --btn-num-text: #ffffff;
  --btn-num-hover: #4e5359;
  
  --btn-fn-bg: #35373a;
  --btn-fn-text: #eab308;
  --btn-fn-hover: #44474b;
  
  --btn-op-bg: #4a4d52;
  --btn-op-text: #38bdf8;
  --btn-op-hover: #585c62;
  
  --btn-eq-bg: #3b82f6;
  --btn-eq-text: #ffffff;
  --btn-eq-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
  
  --btn-clear-bg: #7f1d1d;
  --btn-clear-text: #fecaca;
  --btn-clear-hover: #991b1b;

  --accent-color: #eab308;
  --accent-glow: rgba(234, 179, 8, 0.2);
  --note-line-color: rgba(255, 255, 255, 0.05);
}

/* Special LCD display text for retro theme */
body.theme-retro-scientific #calc-display-primary,
body.theme-retro-scientific #calc-display-secondary,
body.theme-retro-scientific .calc-mode-indicator {
  color: #172414 !important;
  font-family: 'Courier New', monospace;
  font-weight: 700;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.1);
}

/* --- Base Global Resets --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-main);
  background: var(--bg-page);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  transition: background var(--transition-normal), color var(--transition-normal);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Top App Header & Navbar */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--bg-card-border);
  padding: 12px 24px;
}

.header-container {
  max-width: 1300px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand-logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #6366f1 0%, #38bdf8 100%);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 1.25rem;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
}

.brand-info h1 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.5px;
}

.brand-info span {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
}

/* Navigation Tabs */
.nav-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding: 4px;
  background: rgba(0, 0, 0, 0.15);
  border-radius: var(--radius-pill);
}

.nav-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px 16px;
  font-size: 0.88rem;
  font-weight: 500;
  font-family: inherit;
  border-radius: var(--radius-pill);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

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

.nav-tab-btn.active {
  color: #ffffff;
  background: var(--accent-color);
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* Header Controls */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-selector-box select {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--bg-card-border);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: border var(--transition-fast);
}

.theme-selector-box select:focus {
  border-color: var(--accent-color);
}

.icon-action-btn {
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--bg-card-border);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: all var(--transition-fast);
}

.icon-action-btn:hover {
  color: var(--text-main);
  border-color: var(--accent-color);
  background: rgba(255, 255, 255, 0.05);
}

.icon-action-btn.muted {
  opacity: 0.5;
}

/* --- Main Layout Grid --- */
.main-wrapper {
  max-width: 1300px;
  margin: 28px auto;
  padding: 0 20px;
}

.tab-pane {
  display: none;
  animation: fadeIn 0.25s ease-out;
}

.tab-pane.active {
  display: block;
}

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

/* Calculator & Working Layout */
.calc-layout-grid {
  display: grid;
  grid-template-columns: 580px 1fr;
  gap: 28px;
  align-items: start;
}

@media (max-width: 1080px) {
  .calc-layout-grid {
    grid-template-columns: 1fr;
  }
}

/* --- Calculator Unit --- */
.calculator-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(16px);
  position: relative;
  overflow: hidden;
}

/* Top toolbar above display */
.calc-top-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 0.85rem;
}

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

.calc-pill-btn {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.calc-pill-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.12);
}

.calc-pill-btn.rad-mode {
  background: #f59e0b;
  color: #000000;
  border-color: #f59e0b;
}

.calc-pill-btn.active {
  background: var(--accent-color);
  color: #ffffff;
  border-color: var(--accent-color);
}

.code-mode-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.code-mode-label input {
  accent-color: var(--accent-color);
  cursor: pointer;
}

.mem-badge {
  display: none;
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.4);
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
}

/* Calculator Screen Display */
.calc-display {
  background: var(--bg-display);
  border: 1px solid var(--display-border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  margin-bottom: 20px;
  text-align: right;
  min-height: 105px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);
  position: relative;
}

.calc-display-secondary {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 1rem;
  min-height: 24px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calc-display-primary {
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1.1;
  word-break: break-all;
  transition: font-size var(--transition-fast);
}

.display-actions {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 6px;
  opacity: 0.6;
  transition: opacity var(--transition-fast);
}

.calc-display:hover .display-actions {
  opacity: 1;
}

.display-copy-btn {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  transition: all var(--transition-fast);
}

.display-copy-btn:hover {
  background: var(--accent-color);
  color: #fff;
}

/* --- Standard Keypad Grid --- */
.calc-keypad {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
}

.calc-btn {
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 500;
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-md);
  padding: 14px 6px;
  cursor: pointer;
  user-select: none;
  outline: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}

.calc-btn:hover {
  transform: translateY(-2px);
}

.calc-btn:active {
  transform: scale(0.95);
}

/* Button Variants */
.calc-btn.btn-digit {
  background: var(--btn-num-bg);
  color: var(--btn-num-text);
  font-weight: 600;
  font-size: 1.25rem;
}
.calc-btn.btn-digit:hover {
  background: var(--btn-num-hover);
}

.calc-btn.btn-fn {
  background: var(--btn-fn-bg);
  color: var(--btn-fn-text);
  font-size: 0.92rem;
}
.calc-btn.btn-fn:hover {
  background: var(--btn-fn-hover);
}

.calc-btn.btn-op {
  background: var(--btn-op-bg);
  color: var(--btn-op-text);
  font-weight: 600;
  font-size: 1.2rem;
}
.calc-btn.btn-op:hover {
  background: var(--btn-op-hover);
}

.calc-btn.btn-clear {
  background: var(--btn-clear-bg);
  color: var(--btn-clear-text);
  font-weight: 700;
}
.calc-btn.btn-clear:hover {
  background: var(--btn-clear-hover);
}

.calc-btn.btn-eq {
  background: var(--btn-eq-bg);
  color: var(--btn-eq-text);
  box-shadow: var(--btn-eq-shadow);
  font-weight: 700;
  font-size: 1.3rem;
}

/* --- Code Mode Interface --- */
.code-mode-container {
  display: none;
}

.code-editor-box {
  background: var(--bg-display);
  border: 1px solid var(--display-border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 14px;
}

.code-editor-box textarea {
  width: 100%;
  height: 90px;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 1.15rem;
  resize: none;
  outline: none;
  line-height: 1.5;
}

.code-eval-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--bg-card-border);
  padding-top: 10px;
  font-family: var(--font-mono);
  font-size: 1.1rem;
  color: #38bdf8;
}

.code-eval-bar.preview-error {
  color: #fb7185;
}

.code-run-btn {
  background: var(--accent-color);
  color: #ffffff;
  border: none;
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.code-chips-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.code-chip {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.code-chip:hover {
  background: var(--accent-color);
  color: #ffffff;
}

/* --- Calculation History Drawer --- */
.calc-history-drawer {
  position: absolute;
  top: 0;
  right: -320px;
  width: 300px;
  height: 100%;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border-left: 1px solid var(--bg-card-border);
  padding: 20px;
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 50;
}

.calc-history-drawer.open {
  right: 0;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.history-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.history-clear-btn {
  background: transparent;
  border: none;
  color: #fb7185;
  font-size: 0.8rem;
  cursor: pointer;
}

.calc-history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-sm);
  padding: 10px;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.history-item .h-expr {
  color: var(--text-dim);
  font-size: 0.8rem;
  font-family: var(--font-mono);
}

.history-item .h-res {
  color: var(--text-main);
  font-size: 1.1rem;
  font-weight: 600;
  font-family: var(--font-mono);
}

.history-item .h-time {
  font-size: 0.68rem;
  color: var(--text-dim);
  text-align: right;
}

.history-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 30px 0;
  font-size: 0.85rem;
}

/* --- Ruled Scratch Notes Section --- */
.scratchpad-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 15px 35px -10px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(16px);
  height: 100%;
}

.scratchpad-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 10px;
}

.scratchpad-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.scratchpad-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.sp-btn {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all var(--transition-fast);
}

.sp-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-main);
}

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

.sp-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Ruled notepad paper effect */
.scratchpad-paper {
  position: relative;
  background: var(--bg-display);
  border: 1px solid var(--display-border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  flex: 1;
  min-height: 380px;
  display: flex;
  flex-direction: column;
}

.scratchpad-paper::before {
  content: '';
  position: absolute;
  top: 0;
  left: 36px;
  bottom: 0;
  width: 2px;
  background: rgba(244, 63, 94, 0.3); /* Margin line */
  pointer-events: none;
}

.scratchpad-textarea {
  width: 100%;
  height: 100%;
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  line-height: 28px;
  outline: none;
  resize: vertical;
  background-image: linear-gradient(to bottom, transparent 27px, var(--note-line-color) 28px);
  background-size: 100% 28px;
  padding-left: 30px; /* offset for margin line */
}

.scratchpad-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.scratchpad-status {
  color: #10b981;
  opacity: 0;
  transition: opacity 0.3s;
}

.scratchpad-status.visible {
  opacity: 1;
}

/* --- Math & Study Tools Section --- */
.tools-grid-section {
  margin-top: 36px;
}

.section-title-wrap {
  text-align: center;
  max-width: 750px;
  margin: 0 auto 30px;
}

.section-badge {
  display: inline-block;
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.3);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 14px;
  border-radius: var(--radius-pill);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.section-title-wrap h2 {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.section-title-wrap p {
  color: var(--text-muted);
  font-size: 1rem;
}

/* Interactive Tool Card */
.tool-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 28px;
  margin-bottom: 30px;
  box-shadow: 0 15px 35px -10px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(16px);
}

.tool-card-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--bg-card-border);
  padding-bottom: 16px;
}

.tool-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
}

.tool-card-header h3 {
  font-size: 1.35rem;
  font-weight: 700;
}

.tool-card-header p {
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* Fraction Tool Styles */
.fraction-calc-ui {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.fraction-inputs-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
}

.fraction-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 80px;
}

.fraction-box input {
  width: 100%;
  text-align: center;
  background: var(--bg-display);
  border: 1px solid var(--display-border);
  color: var(--text-main);
  font-size: 1.25rem;
  font-weight: 600;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  outline: none;
}

.frac-div-bar {
  width: 100%;
  height: 3px;
  background: var(--text-muted);
  margin: 6px 0;
  border-radius: 2px;
}

.fraction-op-select select {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--bg-card-border);
  font-size: 1.4rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  outline: none;
}

.tool-submit-btn {
  background: var(--accent-color);
  color: #fff;
  border: none;
  font-weight: 600;
  padding: 10px 24px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.95rem;
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: all var(--transition-fast);
}

.tool-submit-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.1);
}

.tool-result-box {
  background: var(--bg-display);
  border: 1px solid var(--display-border);
  border-radius: var(--radius-md);
  padding: 18px 22px;
  margin-top: 10px;
}

.frac-main-display {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 1.6rem;
  font-weight: 700;
}

.frac-symbol-view {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  line-height: 1.1;
}

.frac-symbol-view .frac-bar {
  width: 100%;
  height: 2px;
  background: var(--text-main);
  margin: 2px 0;
}

.step-line {
  padding: 6px 0;
  font-size: 0.92rem;
  color: var(--text-muted);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.mixed-badge {
  display: inline-block;
  margin-top: 8px;
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

/* Percentage Tool Styles */
.pct-modes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}

.pct-mode-card {
  background: var(--bg-display);
  border: 1px solid var(--display-border);
  border-radius: var(--radius-md);
  padding: 18px;
}

.pct-mode-card h4 {
  font-size: 0.98rem;
  margin-bottom: 12px;
  color: var(--text-main);
}

.pct-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.pct-input-row input {
  width: 80px;
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  outline: none;
}

.pct-result-output {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--bg-card-border);
  font-size: 1.15rem;
}

.pct-up { color: #10b981; }
.pct-down { color: #ef4444; }
.pct-badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 4px;
  margin-left: 6px;
}
.pct-badge.increase { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.pct-badge.decrease { background: rgba(239, 68, 68, 0.2); color: #f87171; }

/* 2D Graphing Canvas */
.graph-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.graph-input-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.graph-input-group input {
  flex: 1;
  background: var(--bg-display);
  border: 1px solid var(--display-border);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  outline: none;
}

.graph-canvas-container {
  position: relative;
  width: 100%;
  height: 480px;
  background: var(--bg-display);
  border: 1px solid var(--display-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

#graph-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.graph-coord-tooltip {
  position: absolute;
  display: none;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  color: #38bdf8;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 4px;
  pointer-events: none;
  border: 1px solid rgba(56, 189, 248, 0.3);
  z-index: 10;
}

.graph-presets-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.graph-preset-chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.graph-preset-chip:hover {
  background: var(--accent-color);
  color: #fff;
}

/* Equation Solver */
.eq-solver-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 24px;
}

.eq-subcard {
  background: var(--bg-display);
  border: 1px solid var(--display-border);
  border-radius: var(--radius-md);
  padding: 20px;
}

.eq-subcard h4 {
  font-size: 1.1rem;
  margin-bottom: 12px;
}

.eq-input-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 1.1rem;
  font-family: var(--font-mono);
}

.eq-input-line input {
  width: 65px;
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  padding: 6px;
  border-radius: var(--radius-sm);
  text-align: center;
  outline: none;
}

.eq-root-highlight {
  font-size: 1.2rem;
  color: #38bdf8;
  font-family: var(--font-mono);
  margin-bottom: 8px;
}

.eq-roots-box {
  display: flex;
  gap: 16px;
  margin-bottom: 8px;
}

/* Unit Converter */
.unit-converter-ui {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.unit-cat-select {
  max-width: 250px;
  background: var(--bg-display);
  color: var(--text-main);
  border: 1px solid var(--display-border);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  outline: none;
}

.unit-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
}

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

.unit-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.unit-box input {
  background: var(--bg-display);
  border: 1px solid var(--display-border);
  color: var(--text-main);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 1.3rem;
  font-weight: 600;
  font-family: var(--font-mono);
  outline: none;
}

.unit-box select {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  outline: none;
}

.unit-swap-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: all var(--transition-fast);
}

.unit-swap-btn:hover {
  background: var(--accent-color);
  color: #fff;
  transform: rotate(180deg);
}

/* Statistics Grid */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.stat-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-sm);
  padding: 10px;
  display: flex;
  flex-direction: column;
}

.stat-card.highlight {
  border-color: var(--accent-color);
  background: rgba(99, 102, 241, 0.1);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.stat-val {
  font-size: 1.15rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-main);
}

/* Base Converter */
.base-converter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.base-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.base-item label {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.base-item input {
  background: var(--bg-display);
  border: 1px solid var(--display-border);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 1.05rem;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  outline: none;
}

.nibble-box {
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  margin: 0 2px;
}

/* Geometry Tool */
.geometry-ui {
  display: grid;
  grid-template-columns: 240px 180px 1fr;
  gap: 24px;
  align-items: center;
}

@media (max-width: 800px) {
  .geometry-ui {
    grid-template-columns: 1fr;
  }
}

.geo-svg-container {
  width: 160px;
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.geo-input-group {
  margin-bottom: 12px;
}

.geo-input-group label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.geo-input-group input {
  width: 100%;
  background: var(--bg-display);
  border: 1px solid var(--display-border);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  outline: none;
}

.geo-metric-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--bg-card-border);
  font-size: 0.95rem;
}

.geo-metric-val {
  font-weight: 700;
  font-family: var(--font-mono);
  color: #38bdf8;
}

/* Prime & GCF/LCM */
.prime-gcf-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

@media (max-width: 700px) {
  .prime-gcf-grid {
    grid-template-columns: 1fr;
  }
}

.prime-badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.prime-badge.is-prime {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
}

.prime-badge.not-prime {
  background: rgba(244, 63, 94, 0.2);
  color: #fb7185;
}

.gcf-lcm-box {
  display: flex;
  gap: 20px;
  margin-top: 10px;
}

.gl-item {
  display: flex;
  flex-direction: column;
}

.gl-label {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.gl-val {
  font-size: 1.4rem;
  font-weight: 700;
  color: #38bdf8;
  font-family: var(--font-mono);
}

/* --- Worked Examples & Guides --- */
.guides-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

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

.guide-card h4 {
  font-size: 1.1rem;
  margin-bottom: 8px;
  color: var(--text-main);
}

.guide-card p {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 12px;
}

.guide-code-box {
  background: var(--bg-display);
  border: 1px solid var(--display-border);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: #38bdf8;
  margin-bottom: 12px;
}

.try-example-btn {
  align-self: flex-start;
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #a5b4fc;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.try-example-btn:hover {
  background: var(--accent-color);
  color: #ffffff;
}

/* --- Keyboard Shortcuts Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-overlay.open {
  display: flex;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  max-width: 650px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 28px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--bg-card-border);
  padding-bottom: 14px;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.shortcuts-table {
  width: 100%;
  border-collapse: collapse;
}

.shortcuts-table th, .shortcuts-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--bg-card-border);
  font-size: 0.9rem;
}

.kbd-badge {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  padding: 2px 7px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

/* --- Toast Feedback --- */
#calc-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 300;
  pointer-events: none;
}

#calc-toast.toast-show {
  transform: translateY(0);
  opacity: 1;
}

/* --- Footer --- */
.app-footer {
  margin-top: 60px;
  border-top: 1px solid var(--bg-card-border);
  padding: 40px 20px 30px;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.88rem;
}

.footer-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}

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

/* =============================================
   Blog Section Styles
   ============================================= */

/* --- Blog Hero Banner --- */
.blog-hero {
  background: linear-gradient(135deg, var(--accent-color) 0%, rgba(56, 189, 248, 0.8) 100%);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  margin-bottom: 28px;
  position: relative;
  overflow: hidden;
}

.blog-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E") repeat;
  pointer-events: none;
}

.blog-hero-content {
  position: relative;
  z-index: 1;
  max-width: 680px;
}

.blog-hero-eyebrow {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.8);
  display: block;
  margin-bottom: 12px;
}

.blog-hero-title {
  font-size: 2.4rem;
  font-weight: 800;
  color: #ffffff;
  line-height: 1.15;
  margin-bottom: 14px;
  letter-spacing: -0.5px;
}

.blog-hero-sub {
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.85);
  line-height: 1.65;
  margin-bottom: 24px;
}

.blog-search-bar {
  display: flex;
  gap: 10px;
  max-width: 500px;
}

.blog-search-bar input {
  flex: 1;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #ffffff;
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: background var(--transition-fast), border var(--transition-fast);
  backdrop-filter: blur(6px);
}

.blog-search-bar input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.blog-search-bar input:focus {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.7);
}

.blog-search-btn {
  background: #ffffff;
  color: var(--accent-color);
  border: none;
  padding: 10px 22px;
  border-radius: var(--radius-pill);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  font-family: inherit;
}

.blog-search-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.2);
}

/* --- Cornerstone Pillar Article --- */
.blog-pillar-article {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 36px 40px;
  margin-bottom: 28px;
  box-shadow: var(--shadow-card);
  line-height: 1.75;
  color: var(--text-color);
}

.pillar-header {
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 20px;
  margin-bottom: 24px;
}

.pillar-badge-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.pillar-badge {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
}

.pillar-badge-primary {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.25), rgba(56, 189, 248, 0.25));
  color: var(--accent-light, #818cf8);
  border: 1px solid rgba(99, 102, 241, 0.4);
}

.pillar-badge-sub {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.pillar-badge-time {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

.pillar-title {
  font-size: 1.85rem;
  font-weight: 800;
  line-height: 1.25;
  color: #ffffff;
  margin-bottom: 14px;
  letter-spacing: -0.02em;
}

.pillar-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.pillar-dot {
  opacity: 0.6;
}

.pillar-body {
  font-size: 0.98rem;
  color: var(--text-muted);
}

.pillar-body p {
  margin-bottom: 18px;
}

.pillar-lead {
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--text-color);
  font-weight: 400;
  padding: 16px 20px;
  background: rgba(99, 102, 241, 0.08);
  border-left: 4px solid var(--accent-color);
  border-radius: 4px;
  margin-bottom: 24px;
}

.pillar-body h3 {
  font-size: 1.35rem;
  font-weight: 700;
  color: #ffffff;
  margin-top: 32px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pillar-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 20px 0 28px;
}

.pillar-action-btn {
  background: var(--bg-card);
  border: 1px solid var(--accent-color);
  color: #ffffff;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pillar-action-btn:hover {
  background: var(--accent-color);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.pillar-feature-list {
  list-style: none;
  padding: 0;
  margin: 16px 0 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pillar-feature-list li {
  position: relative;
  padding-left: 24px;
  font-size: 0.95rem;
  line-height: 1.65;
}

.pillar-feature-list li::before {
  content: '▸';
  position: absolute;
  left: 0;
  color: var(--accent-color);
  font-weight: bold;
}

.pillar-i18n-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin: 20px 0 28px;
}

.pillar-i18n-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px 18px;
}

.pillar-i18n-card h4 {
  font-size: 0.92rem;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 8px;
}

.pillar-i18n-card p {
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-dim);
  margin-bottom: 0;
}

@media (max-width: 640px) {
  .blog-pillar-article {
    padding: 24px 18px;
  }
  .pillar-title {
    font-size: 1.45rem;
  }
  .pillar-body h3 {
    font-size: 1.18rem;
  }
  .pillar-i18n-grid {
    grid-template-columns: 1fr;
  }
}

/* --- Category Filter Chips --- */
.blog-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 28px;
}

.blog-filter-chip {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  padding: 7px 18px;
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.blog-filter-chip:hover {
  color: var(--text-main);
  border-color: var(--accent-color);
}

.blog-filter-chip.active {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: #ffffff;
  box-shadow: 0 2px 10px var(--accent-glow);
}

/* --- Blog Grid --- */
.blog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
  margin-bottom: 40px;
}

/* --- Blog Card --- */
.blog-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal), border-color var(--transition-fast);
  position: relative;
}

.blog-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  border-color: var(--accent-color);
}

.blog-card-icon {
  font-size: 2.5rem;
  padding: 28px 28px 0;
  display: block;
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.3));
}

.blog-card-body {
  padding: 20px 28px 24px;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 10px;
}

.blog-card-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.blog-date {
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* Category color badges */
.blog-category-badge {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
}

.blog-category-badge.basics      { background: rgba(99,102,241,0.18); color: #a5b4fc; }
.blog-category-badge.algebra     { background: rgba(16,185,129,0.18); color: #34d399; }
.blog-category-badge.trigonometry{ background: rgba(245,158,11,0.18); color: #fbbf24; }
.blog-category-badge.calculus    { background: rgba(239,68,68,0.18);  color: #f87171; }
.blog-category-badge.statistics  { background: rgba(56,189,248,0.18); color: #38bdf8; }
.blog-category-badge.geometry    { background: rgba(168,85,247,0.18); color: #c084fc; }

.blog-featured-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: rgba(250, 204, 21, 0.2);
  color: #facc15;
  letter-spacing: 0.04em;
}

/* Featured card left accent */
.blog-card-featured {
  border-left: 3px solid var(--accent-color);
}

.blog-card-title {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.4;
  margin: 0;
}

.blog-card-title a {
  color: var(--text-main);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.blog-card-title a:hover {
  color: var(--accent-color);
}

.blog-card-excerpt {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.65;
  flex: 1;
}

.blog-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}

.blog-read-time {
  font-size: 0.78rem;
  color: var(--text-dim);
}

.blog-try-btn {
  background: transparent;
  border: 1px solid var(--bg-card-border);
  color: var(--accent-color);
  padding: 5px 14px;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: inherit;
}

.blog-try-btn:hover {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: #ffffff;
}

/* No results */
.blog-no-results {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px;
  color: var(--text-dim);
  font-size: 1rem;
}

/* --- Newsletter CTA --- */
.blog-newsletter {
  background: linear-gradient(135deg, rgba(99,102,241,0.12) 0%, rgba(56,189,248,0.08) 100%);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 32px 36px;
  margin-bottom: 20px;
}

.blog-newsletter-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.blog-newsletter-icon {
  font-size: 2.4rem;
  flex-shrink: 0;
}

.blog-newsletter-inner h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.blog-newsletter-inner p {
  font-size: 0.88rem;
  color: var(--text-muted);
}

.blog-newsletter-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-left: auto;
}

.blog-newsletter-form input[type="email"] {
  background: var(--bg-display);
  border: 1px solid var(--display-border);
  color: var(--text-main);
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  min-width: 220px;
  transition: border var(--transition-fast);
}

.blog-newsletter-form input[type="email"]:focus {
  border-color: var(--accent-color);
}

/* --- Responsive Blog --- */
@media (max-width: 768px) {
  .blog-hero {
    padding: 32px 24px;
  }

  .blog-hero-title {
    font-size: 1.7rem;
  }

  .blog-search-bar {
    flex-direction: column;
  }

  .blog-grid {
    grid-template-columns: 1fr;
  }

  .blog-newsletter-inner {
    flex-direction: column;
    align-items: flex-start;
  }

  .blog-newsletter-form {
    margin-left: 0;
    width: 100%;
  }

  .blog-newsletter-form input[type="email"] {
    flex: 1;
    min-width: unset;
  }
}

/* ========================================================
   Mobile Responsiveness Enhancements (iOS & Android)
   ======================================================== */

@media (max-width: 868px) {
  .app-header {
    padding: 10px 14px;
  }

  .header-container {
    flex-wrap: wrap;
    gap: 10px 8px;
  }

  .brand-section {
    flex: 1;
    min-width: 160px;
  }

  .brand-logo-icon {
    width: 34px;
    height: 34px;
    font-size: 1.05rem;
  }

  .brand-info h1 {
    font-size: 1.15rem;
  }

  .brand-info span {
    font-size: 0.7rem;
  }

  .header-actions {
    gap: 6px;
  }

  /* Hide physical shortcuts button & fullscreen on mobile */
  #shortcuts-modal-btn,
  #calc-fullscreen-btn {
    display: none;
  }

  .lang-select {
    font-size: 0.78rem;
  }

  .theme-selector-box select {
    padding: 6px 8px;
    font-size: 0.78rem;
  }

  .icon-action-btn {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
  }

  /* Row 2: Full width scrollable tab bar */
  .nav-tabs {
    order: 3;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 3px 4px;
    border-radius: var(--radius-pill);
    gap: 4px;
  }

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

  .nav-tab-btn {
    padding: 6px 12px;
    font-size: 0.8rem;
    flex-shrink: 0;
  }
}

@media (max-width: 600px) {
  .main-wrapper {
    margin: 12px auto;
    padding: 0 10px;
  }

  /* Calculator Unit on mobile */
  .calculator-card {
    padding: 14px 10px;
    border-radius: var(--radius-md);
    box-shadow: 0 10px 25px -10px rgba(0, 0, 0, 0.4);
  }

  .calc-top-toolbar {
    margin-bottom: 8px;
    font-size: 0.75rem;
    gap: 6px;
  }

  .calc-pill-btn {
    padding: 3px 8px;
    font-size: 0.7rem;
  }

  .code-mode-label {
    font-size: 0.75rem;
  }

  /* Screen Display */
  .calc-display {
    padding: 12px 14px;
    min-height: 80px;
    margin-bottom: 12px;
    border-radius: var(--radius-sm);
  }

  .calc-display-secondary {
    font-size: 0.85rem;
    min-height: 18px;
  }

  .calc-display-primary {
    font-size: 1.85rem;
  }

  /* Keypad */
  .calc-keypad {
    gap: 5px;
  }

  .calc-btn {
    padding: 11px 2px;
    font-size: 0.88rem;
    border-radius: 8px;
    min-height: 42px;
  }

  /* Ruled Scratchpad on mobile */
  .scratchpad-card {
    padding: 14px 10px;
    border-radius: var(--radius-md);
  }

  .scratchpad-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .scratchpad-header h2 {
    font-size: 1.15rem;
  }

  .scratchpad-tools {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
    gap: 4px;
  }

  .scratchpad-tools::-webkit-scrollbar {
    display: none;
  }

  .sp-btn {
    padding: 5px 9px;
    font-size: 0.75rem;
    flex-shrink: 0;
  }

  .scratchpad-textarea {
    font-size: 0.88rem;
    line-height: 28px;
    min-height: 220px;
  }

  .scratchpad-footer {
    font-size: 0.75rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  /* General Tools Cards */
  .tool-card {
    padding: 16px 12px;
    border-radius: var(--radius-md);
  }

  .tool-card-header {
    gap: 10px;
  }

  .tool-card-header h3 {
    font-size: 1.2rem;
  }

  .fraction-inputs-row {
    flex-direction: column;
    align-items: center;
    gap: 12px;
  }

  .fraction-box input {
    width: 90px;
    font-size: 1.25rem;
  }

  .fraction-op-select select {
    font-size: 1.4rem;
  }

  .graph-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .graph-input-group {
    width: 100%;
  }

  .graph-canvas-container {
    height: 280px;
  }

  .eq-input-line {
    font-size: 0.95rem;
    flex-wrap: wrap;
    gap: 6px;
  }

  .eq-input-line input {
    width: 65px;
    padding: 6px;
  }

  .unit-box input {
    font-size: 1.1rem;
    padding: 10px 12px;
  }

  /* Footer Links */
  .footer-links {
    flex-wrap: wrap;
    gap: 8px 12px;
    justify-content: center;
    font-size: 0.82rem;
  }

  .app-footer p {
    font-size: 0.75rem;
    padding: 0 8px;
  }
}

/* Extra small screens (iPhone SE, Galaxy A series, 320px - 360px) */
@media (max-width: 370px) {
  .calc-display-primary {
    font-size: 1.6rem;
  }

  .calc-keypad {
    gap: 3px;
  }

  .calc-btn {
    padding: 9px 1px;
    font-size: 0.8rem;
    min-height: 38px;
    border-radius: 6px;
  }
}

