/* ===== CSS VARIABLES ===== */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #1a1a2e;
  --bg-card-hover: #222240;
  --bg-input: #16162a;
  --border: #2a2a4a;
  --border-focus: #f59e0b;
  --text-primary: #f1f1f4;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent: #f59e0b;
  --accent-hover: #d97706;
  --accent-glow: rgba(245,158,11,0.15);
  --accent-soft: rgba(245,158,11,0.1);
  --success: #10b981;
  --success-bg: rgba(16,185,129,0.1);
  --danger: #ef4444;
  --danger-bg: rgba(239,68,68,0.1);
  --warning: #f59e0b;
  --info: #3b82f6;
  --info-bg: rgba(59,130,246,0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.5);
  --transition: all 0.2s ease;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.6;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
button { cursor: pointer; font-family: var(--font); }
input, select, textarea { font-family: var(--font); }
img { max-width: 100%; }

/* ===== FORM INPUT STYLING ===== */
/* Hide number input spinners globally */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none; margin: 0;
}
input[type="number"] { -moz-appearance: textfield; }

/* Universal input styling */
input[type="text"], input[type="number"], input[type="email"],
input[type="password"], input[type="tel"], input[type="url"], textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 10px 14px;
  font-size: 0.95rem;
  transition: var(--transition);
  outline: none;
  width: 100%;
}
input[type="text"]:focus, input[type="number"]:focus, input[type="email"]:focus,
input[type="password"]:focus, input[type="tel"]:focus, input[type="url"]:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
input::placeholder, textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}
input:disabled, textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Select styling */
select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 10px 14px;
  font-size: 0.95rem;
  transition: var(--transition);
  outline: none;
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Range slider styling */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  outline: none;
  border: none;
  padding: 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-primary);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  transition: transform 0.15s ease;
}
input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}
input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-primary);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
/* Colored slider variants */
input[type="range"].range-purple::-webkit-slider-thumb { background: #8b5cf6; }
input[type="range"].range-purple::-moz-range-thumb { background: #8b5cf6; }
input[type="range"].range-green::-webkit-slider-thumb { background: #22c55e; }
input[type="range"].range-green::-moz-range-thumb { background: #22c55e; }
input[type="range"].range-red::-webkit-slider-thumb { background: #ef4444; }
input[type="range"].range-red::-moz-range-thumb { background: #ef4444; }

/* Checkbox & radio styling */
input[type="checkbox"], input[type="radio"] {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  background: var(--bg-input);
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
  position: relative;
}
input[type="checkbox"] { border-radius: 4px; }
input[type="radio"] { border-radius: 50%; }
input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 4px; top: 1px;
  width: 6px; height: 10px;
  border: solid #000;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
input[type="radio"]:checked {
  border-color: var(--accent);
  background: var(--bg-input);
}
input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  left: 3px; top: 3px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ===== NAVBAR ===== */
.navbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  background: rgba(10,10,15,0.9);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 64px;
  display: flex; align-items: center; justify-content: space-between;
}
.nav-brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 1.25rem; font-weight: 800; color: var(--accent);
}
.nav-brand svg { width: 28px; height: 28px; }
.nav-links {
  display: flex; align-items: center; gap: 2px;
  list-style: none;
}
.nav-hidden { display: none !important; }
.nav-visible { display: flex !important; }
.nav-links a {
  /* Bigger tap targets so iOS Safari lands the tap on the first try.
     Apple recommends 44pt min for touch. Previous 6px vertical padding
     produced ~30px tall targets, which caused the "takes a bunch of taps"
     bug the user reported. */
  padding: 12px 14px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 0.85rem; font-weight: 500;
  transition: var(--transition); white-space: nowrap;
  /* touch-action:manipulation removes the 300ms iOS double-tap-zoom delay.
     -webkit-tap-highlight-color gives immediate visual feedback so users
     know their tap registered even if the navigation takes a beat. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(245,158,11,0.25);
  cursor: pointer;
  display: inline-flex; align-items: center;
  min-height: 44px;
}
/* Split hover from active. Hover-styling only on devices that actually
   hover (mouse). On touch devices, iOS Safari's "first tap shows hover,
   second tap actually clicks" bug is why nav taps needed multiple presses. */
@media (hover: hover) {
  .nav-links a:hover {
    color: var(--accent); background: var(--accent-soft);
  }
}
.nav-links a.active {
  color: var(--accent); background: var(--accent-soft);
}
/* Dropdown nav */
.nav-dropdown { position: relative; }
.nav-dropdown-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 12px 16px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 0.9rem; font-weight: 500;
  cursor: pointer; background: none; border: none;
  transition: var(--transition); white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(245,158,11,0.25);
  min-height: 44px;
}
@media (hover: hover) {
  .nav-dropdown-btn:hover {
    color: var(--accent); background: var(--accent-soft);
  }
}
.nav-dropdown-btn.active {
  color: var(--accent); background: var(--accent-soft);
}
.nav-dropdown-btn svg { transition: transform 0.2s; }
.nav-dropdown.open .nav-dropdown-btn svg { transform: rotate(180deg); }
.nav-dropdown-menu {
  display: none; position: absolute; top: calc(100% + 6px); left: 0;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); min-width: 200px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3); z-index: 200;
  padding: 6px;
}
.nav-dropdown.open .nav-dropdown-menu { display: block; }
.nav-dropdown-menu a {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: 8px;
  color: var(--text-secondary); font-size: 0.9rem; font-weight: 500;
  transition: var(--transition);
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(245,158,11,0.25);
  min-height: 44px;
}
@media (hover: hover) {
  .nav-dropdown-menu a:hover {
    color: var(--accent); background: var(--accent-soft);
  }
}
.nav-dropdown-menu a.active {
  color: var(--accent); background: var(--accent-soft);
}
.nav-right { display: flex; align-items: center; gap: 12px; }
.nav-streak {
  display: flex; align-items: center; gap: 6px;
  background: var(--accent-soft); padding: 6px 14px;
  border-radius: 20px; font-size: 0.85rem; font-weight: 600; color: var(--accent);
}
.nav-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: var(--bg-primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; cursor: pointer;
}
.burger {
  display: none; background: none; border: none; color: var(--text-primary);
  font-size: 1.5rem; padding: 10px 12px; z-index: 1001; cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(245,158,11,0.20);
  -webkit-appearance: none; appearance: none;
  min-width: 48px; min-height: 48px;
}
.owner-badge {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #000; font-size: 0.75rem; font-weight: 700;
  padding: 4px 12px; border-radius: 20px;
  text-transform: uppercase; letter-spacing: 0.5px;
}

/* ===== MAIN LAYOUT ===== */
.app-container { padding-top: 64px; min-height: 100vh; min-height: 100dvh; }
.page { display: none; animation: fadeIn 0.3s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
/* iOS Safari drops the first tap on elements that have a compositor layer
   from a translateY, until the layer is promoted. Drop the transform on
   mobile — a plain opacity fade is still smooth and doesn't eat taps. */
@media (max-width: 768px) {
  @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
  .page { animation-duration: 0.15s; }
}

/* ===== COMMON COMPONENTS ===== */
.container { max-width: 1400px; margin: 0 auto; padding: 32px 40px; }
.container-wide { max-width: 1600px; margin: 0 auto; padding: 32px 40px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 24px; border-radius: var(--radius-sm); font-weight: 600;
  font-size: 0.95rem; border: none; transition: var(--transition);
}
.btn-primary {
  background: var(--accent); color: #000;
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 20px rgba(245,158,11,0.3); }
.btn-secondary {
  background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--accent); background: var(--accent-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 8px 16px; font-size: 0.85rem; }
.btn-lg { padding: 16px 32px; font-size: 1.1rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-secondary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-ghost:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ntb:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.char-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.notes-sidebar-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
/* Loading spinner for buttons */
.btn-loading { pointer-events: none; position: relative; color: transparent !important; }
.btn-loading::after { content: ''; position: absolute; width: 18px; height: 18px; border: 2px solid rgba(0,0,0,0.2); border-top-color: #000; border-radius: 50%; animation: btnSpin 0.6s linear infinite; }
@keyframes btnSpin { to { transform: rotate(360deg); } }

.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  transition: var(--transition);
}
.card:hover { border-color: rgba(245,158,11,0.3); }
.card-glow:hover { box-shadow: 0 0 30px var(--accent-glow); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 12px; border-radius: 20px; font-size: 0.75rem; font-weight: 600;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-warning { background: var(--accent-soft); color: var(--accent); }

.input-group { margin-bottom: 20px; }
.input-group label { display: block; margin-bottom: 6px; font-size: 0.9rem; font-weight: 500; color: var(--text-secondary); }
.input-group input, .input-group select {
  width: 100%; padding: 12px 16px; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-primary); font-size: 0.95rem;
  transition: var(--transition);
}
.input-group input:focus, .input-group select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow);
}

.progress-bar {
  height: 8px; background: var(--bg-input); border-radius: 4px; overflow: hidden;
}
.progress-bar .fill {
  height: 100%; border-radius: 4px; transition: width 0.5s ease;
  background: linear-gradient(90deg, var(--accent), #fbbf24);
}

.section-title {
  font-size: 1.1rem; font-weight: 700; margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}

.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
}
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; text-align: center;
}
.stat-card .stat-value { font-size: 2rem; font-weight: 800; color: var(--accent); }
.stat-card .stat-label { font-size: 0.85rem; color: var(--text-secondary); margin-top: 4px; }

.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-muted);
}
.empty-state svg { width: 64px; height: 64px; margin-bottom: 16px; opacity: 0.5; }
.empty-state h3 { font-size: 1.2rem; color: var(--text-secondary); margin-bottom: 8px; }

/* Topic mastery colors */
.mastery-expert { color: #10b981; }
.mastery-mastered { color: #34d399; }
.mastery-review { color: #fbbf24; }
.mastery-learning { color: #f97316; }
.mastery-new { color: #ef4444; }

/* ===== LANDING PAGE ===== */
.landing-hero {
  min-height: calc(100vh - 64px);
  display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 40px 24px;
  background: radial-gradient(ellipse at 50% 0%, rgba(245,158,11,0.08) 0%, transparent 60%);
}
.hero-content { max-width: 700px; }
.hero-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-soft); border: 1px solid rgba(245,158,11,0.2);
  padding: 6px 16px; border-radius: 20px;
  font-size: 0.8rem; color: var(--accent); font-weight: 600; margin-bottom: 24px;
}
.hero-title {
  font-size: clamp(2.5rem, 6vw, 4rem); font-weight: 800;
  line-height: 1.1; margin-bottom: 20px;
  background: linear-gradient(135deg, #fff 0%, #f59e0b 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero-subtitle {
  font-size: 1.15rem; color: var(--text-secondary); line-height: 1.7;
  margin-bottom: 36px; max-width: 560px; margin-left: auto; margin-right: auto;
}
.hero-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.hero-stats {
  display: flex; gap: 40px; justify-content: center; margin-top: 60px;
  padding-top: 40px; border-top: 1px solid var(--border);
}
.hero-stat-value { font-size: 1.8rem; font-weight: 800; color: var(--accent); }
.hero-stat-label { font-size: 0.85rem; color: var(--text-muted); }

.features-section { padding: 80px 24px; }
.features-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px; max-width: 1400px; margin: 0 auto;
}
.feature-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px;
  transition: var(--transition);
}
.feature-card:hover { border-color: var(--accent); transform: translateY(-4px); box-shadow: var(--shadow); }
.feature-icon {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--accent-soft); display: flex; align-items: center; justify-content: center;
  margin-bottom: 16px; font-size: 1.4rem;
}
.feature-card h3 { font-size: 1.1rem; margin-bottom: 8px; }
.feature-card p { font-size: 0.9rem; color: var(--text-secondary); line-height: 1.6; }

/* ===== AUTH PAGES ===== */
.auth-page {
  min-height: calc(100vh - 64px);
  display: flex; align-items: center; justify-content: center; padding: 40px 24px;
}
.auth-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 40px; width: 100%; max-width: 440px;
  box-shadow: var(--shadow-lg);
}
.auth-card h2 { font-size: 1.5rem; margin-bottom: 8px; text-align: center; }
.auth-card .auth-subtitle { text-align: center; color: var(--text-secondary); margin-bottom: 28px; font-size: 0.9rem; }
.auth-divider { text-align: center; margin: 20px 0; color: var(--text-muted); font-size: 0.85rem; }
.period-select {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px;
}
.period-option {
  padding: 16px; background: var(--bg-input); border: 2px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; text-align: center;
  transition: var(--transition);
}
.period-option:hover { border-color: var(--accent); }
.period-option.selected { border-color: var(--accent); background: var(--accent-soft); }
.period-option .period-num { font-size: 1.3rem; font-weight: 800; color: var(--accent); }
.period-option .period-label { font-size: 0.8rem; color: var(--text-secondary); }

/* ===== DIAGNOSTIC ===== */
.diagnostic-page { padding: 40px 40px; max-width: 1100px; margin: 0 auto; }
.diag-header {
  text-align: center; margin-bottom: 40px;
}
.diag-progress {
  display: flex; align-items: center; gap: 16px; margin-bottom: 32px;
}
.diag-progress .progress-bar { flex: 1; }
.diag-counter { font-size: 0.9rem; color: var(--text-secondary); white-space: nowrap; font-weight: 600; }
.diag-topic-badge {
  display: inline-flex; padding: 4px 12px; border-radius: 20px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 0.8rem; font-weight: 600; margin-bottom: 16px;
}
.diag-question {
  font-size: 1.15rem; font-weight: 600; line-height: 1.6; margin-bottom: 28px;
}
.diag-options { display: flex; flex-direction: column; gap: 12px; margin-bottom: 32px; }
.diag-option {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 20px; background: var(--bg-input); border: 2px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; transition: var(--transition);
  font-size: 0.95rem;
}
.diag-option:hover { border-color: var(--accent); background: var(--bg-card); }
.diag-option.selected { border-color: var(--accent); background: var(--accent-soft); }
.diag-option .option-letter {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg-card); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; flex-shrink: 0;
}
.diag-option.selected .option-letter { background: var(--accent); color: #000; border-color: var(--accent); }
.diag-actions { display: flex; justify-content: space-between; }

/* Diagnostic Results */
.diag-results { text-align: center; }
.diag-score-circle {
  width: 160px; height: 160px; border-radius: 50%;
  background: conic-gradient(var(--accent) var(--score-pct), var(--bg-input) 0);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 24px; position: relative;
}
.diag-score-inner {
  width: 130px; height: 130px; border-radius: 50%;
  background: var(--bg-card); display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.diag-score-inner .score-num { font-size: 2.5rem; font-weight: 800; color: var(--accent); }
.diag-score-inner .score-label { font-size: 0.8rem; color: var(--text-secondary); }
.diag-breakdown {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  max-width: 600px; margin: 32px auto; text-align: left;
}
.diag-topic-result {
  padding: 14px 16px; background: var(--bg-input); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: space-between;
}
.diag-topic-result .topic-name { font-size: 0.85rem; font-weight: 500; }
.diag-topic-result .topic-score { font-weight: 700; font-size: 0.9rem; }

/* ===== DASHBOARD ===== */
.dash-welcome {
  margin-bottom: 32px;
}
.dash-welcome h1 { font-size: 1.8rem; font-weight: 800; }
.dash-welcome p { color: var(--text-secondary); margin-top: 4px; }

.dash-grid {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px;
}
.dash-grid .full-width { grid-column: 1 / -1; }

.daily-goals .goal-item {
  display: flex; align-items: center; gap: 14px; padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.daily-goals .goal-item:last-child { border-bottom: none; }
.goal-icon { font-size: 1.3rem; }
.goal-info { flex: 1; }
.goal-info .goal-title { font-size: 0.9rem; font-weight: 500; }
.goal-info .goal-progress-text { font-size: 0.8rem; color: var(--text-muted); }
.goal-check { font-size: 1.2rem; }

.weak-areas-list { display: flex; flex-direction: column; gap: 12px; }
.weak-area-item {
  display: flex; align-items: center; gap: 14px; padding: 14px;
  background: var(--bg-input); border-radius: var(--radius-sm);
}
.weak-area-item .wa-info { flex: 1; }
.weak-area-item .wa-name { font-size: 0.9rem; font-weight: 600; }
.weak-area-item .wa-mastery { font-size: 0.8rem; color: var(--text-muted); }
.weak-area-item .progress-bar { width: 100px; }
.weak-area-item .btn-sm { flex-shrink: 0; }

.quick-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.quick-action {
  padding: 20px; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; transition: var(--transition);
  text-align: center;
}
.quick-action:hover { border-color: var(--accent); background: var(--bg-card); transform: translateY(-2px); }
.quick-action .qa-icon { font-size: 1.5rem; margin-bottom: 8px; }
.quick-action .qa-title { font-size: 0.9rem; font-weight: 600; }
.quick-action .qa-desc { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

/* Heat map */
.mastery-heatmap { display: flex; flex-direction: column; gap: 6px; }
.heatmap-row { display: flex; align-items: center; gap: 8px; }
.heatmap-label { width: 140px; font-size: 0.8rem; color: var(--text-secondary); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.heatmap-bar-wrap { flex: 1; height: 24px; background: var(--bg-input); border-radius: 4px; overflow: hidden; position: relative; }
.heatmap-bar { height: 100%; border-radius: 4px; transition: width 0.6s ease; }
.heatmap-pct { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 0.7rem; font-weight: 700; }

/* ===== FLASHCARDS ===== */
.fc-session-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 32px; flex-wrap: wrap; gap: 12px;
}
.fc-count { font-size: 0.9rem; color: var(--text-secondary); }

.fc-card-wrapper {
  perspective: 1000px; max-width: 600px; margin: 0 auto 32px;
}
.fc-card {
  width: 100%; min-height: 300px; position: relative;
  transform-style: preserve-3d; transition: transform 0.5s ease;
  cursor: pointer;
}
.fc-card.flipped { transform: rotateY(180deg); }
.fc-card-face {
  position: absolute; inset: 0; backface-visibility: hidden;
  background: var(--bg-card); border: 2px solid var(--border);
  border-radius: var(--radius-lg); padding: 40px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
}
.fc-card-back { transform: rotateY(180deg); }
.fc-card-face .fc-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin-bottom: 16px; }
.fc-card-face .fc-text { font-size: 1.2rem; font-weight: 600; line-height: 1.6; }
.fc-card-face .fc-hint { font-size: 0.85rem; color: var(--text-muted); margin-top: 16px; font-style: italic; }
.fc-tap-hint { text-align: center; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 20px; }

.fc-rating {
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
}
.fc-rating .btn { min-width: 100px; }
.fc-rating .rate-again { background: var(--danger); color: #fff; }
.fc-rating .rate-hard { background: #f97316; color: #fff; }
.fc-rating .rate-good { background: var(--accent); color: #000; }
.fc-rating .rate-easy { background: var(--success); color: #fff; }

.fc-complete { text-align: center; padding: 60px 20px; }
.fc-complete .check-icon { font-size: 4rem; margin-bottom: 16px; }
.fc-complete h2 { font-size: 1.5rem; margin-bottom: 8px; }
.fc-complete p { color: var(--text-secondary); margin-bottom: 24px; }

/* Flashcard topic picker */
.fc-topics-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px;
}
.fc-topic-card {
  padding: 16px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; transition: var(--transition);
}
.fc-topic-card:hover { border-color: var(--accent); }
.fc-topic-card .tc-name { font-weight: 600; font-size: 0.9rem; margin-bottom: 8px; }
.fc-topic-card .tc-stats { font-size: 0.8rem; color: var(--text-muted); }
.fc-topic-card .tc-due { font-size: 0.8rem; color: var(--accent); font-weight: 600; margin-top: 6px; }

/* ===== EXAM ENGINE ===== */
.exam-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; background: var(--bg-card); border-bottom: 1px solid var(--border);
  position: sticky; top: 64px; z-index: 100;
}
.exam-timer {
  font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.exam-timer.warning { color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

.exam-question-area { max-width: 1000px; margin: 0 auto; padding: 32px 40px; }
.exam-q-num { font-size: 0.85rem; color: var(--text-muted); font-weight: 600; margin-bottom: 8px; }
.exam-q-text { font-size: 1.1rem; font-weight: 600; line-height: 1.6; margin-bottom: 24px; }
.exam-word-hl { background: rgba(245, 158, 11, 0.35); color: #fbbf24; border-radius: 3px; }
.exam-options { display: flex; flex-direction: column; gap: 10px; margin-bottom: 32px; }
.exam-option {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px; background: var(--bg-input); border: 2px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; transition: var(--transition);
}
.exam-option:hover { border-color: var(--accent); }
.exam-option.selected { border-color: var(--accent); background: var(--accent-soft); }
.exam-option.correct { border-color: var(--success); background: var(--success-bg); }
.exam-option.incorrect { border-color: var(--danger); background: var(--danger-bg); }
.exam-option .opt-letter {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--bg-card); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.8rem; flex-shrink: 0;
}
.exam-option.selected .opt-letter { background: var(--accent); color: #000; border-color: var(--accent); }

.exam-nav { display: flex; justify-content: space-between; padding-top: 16px; border-top: 1px solid var(--border); }
.exam-dots {
  display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; padding: 16px;
}
.exam-dot {
  width: 28px; height: 28px; border-radius: 50%; font-size: 0.7rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-input); border: 1px solid var(--border); cursor: pointer;
  transition: var(--transition);
}
.exam-dot.answered { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.exam-dot.current { background: var(--accent); color: #000; }
.exam-dot.flagged { border-color: var(--danger); }

/* Exam results */
.exam-results { text-align: center; padding: 40px 24px; }
.exam-results .big-score { font-size: 4rem; font-weight: 800; }
.exam-results .big-score.pass { color: var(--success); }
.exam-results .big-score.fail { color: var(--danger); }

/* Exam list */
.exam-list { display: flex; flex-direction: column; gap: 16px; }
.exam-list-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); transition: var(--transition);
}
.exam-list-item:hover { border-color: var(--accent); }
.exam-list-item .eli-info h3 { font-size: 1rem; font-weight: 600; }
.exam-list-item .eli-info p { font-size: 0.85rem; color: var(--text-secondary); }
.exam-list-item .eli-meta { text-align: right; }
.exam-list-item .eli-meta .best-score { font-size: 1.3rem; font-weight: 800; }

/* ===== STUDY GUIDE ===== */
.sg-sidebar {
  position: sticky; top: 96px; max-height: calc(100vh - 128px); overflow-y: auto;
}
.sg-layout { display: grid; grid-template-columns: 240px 1fr; gap: 32px; }
.sg-nav-list { list-style: none; }
.sg-nav-item {
  padding: 10px 14px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 0.85rem; color: var(--text-secondary); transition: var(--transition);
  margin-bottom: 2px;
}
.sg-nav-item:hover { background: var(--bg-card); color: var(--text-primary); }
.sg-nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sg-content h2 { font-size: 1.5rem; font-weight: 700; margin-bottom: 16px; }
.sg-content h3 { font-size: 1.1rem; font-weight: 600; margin: 24px 0 12px; color: var(--accent); }
.sg-content p { color: var(--text-secondary); line-height: 1.8; margin-bottom: 16px; }
.sg-content .formula-box {
  background: var(--bg-input); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); padding: 16px 20px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-family: 'Courier New', monospace; margin: 16px 0;
}
.sg-content .key-point {
  background: var(--accent-soft); border-radius: var(--radius-sm);
  padding: 14px 18px; margin: 12px 0; font-size: 0.9rem;
}
.sg-content .key-point strong { color: var(--accent); }

/* ===== ANALYTICS ===== */
.analytics-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 20px;
}
.analytics-grid .full-width { grid-column: 1 / -1; }
.chart-container { position: relative; }
.chart-container canvas { width: 100% !important; }

/* Streak calendar */
.streak-calendar {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
}
.streak-day {
  aspect-ratio: 1; border-radius: 4px; background: var(--bg-input);
  position: relative;
}
.streak-day.studied { background: var(--accent-soft); }
.streak-day.studied-heavy { background: var(--accent); }
.streak-day-labels { display: flex; justify-content: space-around; margin-bottom: 6px; }
.streak-day-labels span { font-size: 0.65rem; color: var(--text-muted); }

/* ===== REVIEW MODE ===== */
.review-tabs {
  display: flex; gap: 4px; margin-bottom: 24px; border-bottom: 1px solid var(--border); padding-bottom: 4px;
}
.review-tab {
  padding: 10px 20px; border: none; background: none; color: var(--text-secondary);
  font-size: 0.9rem; font-weight: 500; cursor: pointer; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: var(--transition);
}
.review-tab:hover { color: var(--text-primary); }
.review-tab.active { color: var(--accent); background: var(--accent-soft); }

.review-question {
  padding: 20px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 12px;
}
.review-question .rq-topic { font-size: 0.75rem; color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.review-question .rq-text { font-size: 0.95rem; font-weight: 600; margin: 8px 0; }
.review-question .rq-answer { font-size: 0.85rem; color: var(--text-secondary); }
.review-question .rq-your-answer { color: var(--danger); }
.review-question .rq-correct-answer { color: var(--success); }
.review-question .rq-explanation { font-size: 0.85rem; color: var(--text-muted); margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }

/* ===== SETTINGS ===== */
.settings-section { margin-bottom: 32px; }
.settings-section h3 { font-size: 1rem; font-weight: 600; margin-bottom: 16px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; border-bottom: 1px solid rgba(42,42,74,0.5);
}
.setting-row .setting-info { flex: 1; }
.setting-row .setting-label { font-size: 0.9rem; font-weight: 500; }
.setting-row .setting-desc { font-size: 0.8rem; color: var(--text-muted); }
.toggle {
  width: 48px; height: 26px; border-radius: 13px; background: var(--bg-input);
  border: 1px solid var(--border); cursor: pointer; position: relative; transition: var(--transition);
}
.toggle.on { background: var(--accent); border-color: var(--accent); }
.toggle::after {
  content: ''; position: absolute; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; top: 2px; left: 2px;
  transition: var(--transition);
}
.toggle.on::after { left: 24px; }

/* ===== OWNER ANALYTICS ===== */
.oa-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.oa-stat { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; text-align: center; }
.oa-stat-value { font-size: 2rem; font-weight: 800; color: var(--accent); }
.oa-stat-label { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.oa-stat-sub { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }
.oa-section { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; margin-bottom: 20px; }
.oa-section h3 { margin-bottom: 16px; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }
.oa-chart { width: 100%; height: 220px; position: relative; }
.oa-bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding-top: 10px; }
.oa-bar { flex: 1; background: linear-gradient(to top, var(--accent), #fbbf24); border-radius: 4px 4px 0 0; min-width: 20px; position: relative; transition: 0.3s; cursor: pointer; }
.oa-bar:hover { opacity: 0.8; }
.oa-bar-label { position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%); font-size: 0.65rem; color: var(--text-muted); white-space: nowrap; }
.oa-bar-value { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: 0.7rem; color: var(--text-secondary); font-weight: 600; }
.oa-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.oa-table th { text-align: left; padding: 10px 12px; border-bottom: 2px solid var(--border); color: var(--text-secondary); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; }
.oa-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.oa-table tr:hover td { background: rgba(245,158,11,0.03); }
.oa-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 0.7rem; font-weight: 600; }
.oa-badge-active { background: rgba(34,197,94,0.15); color: #22c55e; }
.oa-badge-inactive { background: rgba(239,68,68,0.15); color: #ef4444; }
.oa-badge-trial { background: rgba(59,130,246,0.15); color: #3b82f6; }
.oa-badge-paid { background: rgba(245,158,11,0.15); color: #f59e0b; }
.oa-badge-free { background: rgba(107,114,128,0.15); color: #9ca3af; }
.oa-metric-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.oa-metric-row:last-child { border-bottom: none; }
.oa-sparkline { display: flex; align-items: flex-end; gap: 2px; height: 30px; }
.oa-sparkline-bar { width: 4px; background: var(--accent); border-radius: 2px; min-height: 2px; }
.oa-donut-wrap { display: flex; align-items: center; gap: 24px; }
.oa-legend { display: flex; flex-direction: column; gap: 8px; }
.oa-legend-item { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.oa-legend-dot { width: 10px; height: 10px; border-radius: 50%; }
.oa-two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
/* Simulator responsive two-col: left controls, right canvas */
.sim-two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
.oa-heatmap { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.oa-heat-cell { aspect-ratio: 1; border-radius: 3px; min-width: 14px; }
.oa-tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.oa-tab {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.9rem;
  transition: var(--transition);
  /* Same iOS Safari fix as .nav-links a — no 300ms tap delay, visible
     tap highlight, min touch target 44 pt. Without these the Users /
     Diagnostics / Exams etc. tabs in Owner Analytics needed multiple
     taps or wouldn't respond at all on iPhone. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(245,158,11,0.25);
  -webkit-appearance: none; appearance: none;
  min-height: 44px;
  font-family: inherit;
  display: inline-flex; align-items: center;
}
.oa-tab.active { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 600; }
.oa-tab:active { transform: scale(0.98); }
.oa-live-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; display: inline-block; animation: livePulse 2s infinite; }
@keyframes livePulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ===== MOBILE DRAWER ===== */
.mobile-drawer-overlay {
  display: none; position: fixed; inset: 0; z-index: 1998;
  background: rgba(0,0,0,0.65); backdrop-filter: blur(3px);
}
.mobile-drawer-overlay.open { display: block; }
.mobile-drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 285px; z-index: 1999;
  background: #0d0d1a; border-right: 1px solid var(--border);
  transform: translateX(-100%); transition: transform 0.27s cubic-bezier(0.4,0,0.2,1);
  display: flex; flex-direction: column; overflow: hidden;
}
.mobile-drawer.open { transform: translateX(0); }
.mobile-drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 18px 14px; border-bottom: 1px solid var(--border);
}
.mobile-drawer-brand {
  display: flex; align-items: center; gap: 9px;
  font-size: 1.2rem; font-weight: 800; color: var(--accent);
}
.mobile-drawer-brand svg { width: 24px; height: 24px; }
.mobile-drawer-close {
  background: none; border: none; color: var(--text-secondary);
  padding: 8px; cursor: pointer; border-radius: 8px; line-height: 0;
  -webkit-tap-highlight-color: transparent;
}
.mobile-drawer-user {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.mobile-drawer-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); color: #000;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1.1rem; flex-shrink: 0;
}
.mobile-drawer-name { font-weight: 700; font-size: 0.95rem; color: var(--text-primary); }
.mobile-drawer-streak {
  font-size: 0.8rem; color: var(--accent);
  display: flex; align-items: center; gap: 4px; margin-top: 3px;
}
.mobile-drawer-nav { flex: 1; overflow-y: auto; padding: 10px 8px; }
.mobile-drawer-section-label {
  padding: 12px 12px 4px; font-size: 0.68rem;
  text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-muted); font-weight: 700;
}
.mobile-drawer-item {
  display: flex; align-items: center; gap: 13px;
  padding: 14px 12px; border-radius: 10px; margin-bottom: 2px;
  color: var(--text-secondary); font-size: 0.95rem; font-weight: 500;
  cursor: pointer; transition: background 0.13s, color 0.13s;
  border: none; background: none; width: 100%; text-align: left;
  /* touch-action:manipulation prevents iOS's 300ms double-tap-zoom
     delay. Tap highlight is visible so users know their tap registered. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(245,158,11,0.20);
  min-height: 48px;
  -webkit-appearance: none; appearance: none;
  font-family: inherit;
}
.mobile-drawer-item:active { background: var(--bg-card); }
.mobile-drawer-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.mobile-drawer-item .mdi { font-size: 1.2rem; width: 26px; text-align: center; flex-shrink: 0; }

/* ===== AI-GENERATED CONTENT BADGE =====
   Visible "✨ AI-generated" pill that auto-appears on known AI render
   surfaces. Reinforces the legal disclaimer at the point users actually
   see the AI's output, and discharges any "I didn't know it was AI"
   claim. Opt-in by adding class="ai-content" to a wrapper, or use the
   selector list below for surfaces guaranteed to be AI. */
/* Two styles of badge:
   - Corner pill: position: absolute on a wrapper. Use on standalone
     content blocks where there's headroom. Auto-applied to .rq-explanation.
   - Inline chip: position: static, used in flow inside modal headers
     so it sits next to the title without overlapping controls. */
.ai-content,
.rq-explanation {
  position: relative;
}
.ai-content::before,
.rq-explanation::before {
  content: "\2728 AI-generated";
  position: absolute;
  top: 8px;
  right: 10px;
  background: rgba(245,158,11,0.14);
  border: 1px solid rgba(245,158,11,0.4);
  color: #f59e0b;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  pointer-events: none;
  z-index: 2;
  white-space: nowrap;
  font-family: var(--font);
}
/* Auto-applied surfaces need top padding so the badge doesn't sit on
   top of their first line of text. */
.rq-explanation {
  padding-top: 28px !important;
}
/* Inline chip — embed directly in HTML next to a heading, like:
     <span class="ai-chip">AI-generated</span> */
.ai-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: rgba(245,158,11,0.14);
  border: 1px solid rgba(245,158,11,0.4);
  color: #f59e0b;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
  vertical-align: middle;
}
.ai-chip::before { content: "\2728"; font-size: 0.7rem; }
/* Inline variant of ai-content — sits in flow rather than positioned. */
.ai-content.ai-inline::before {
  position: static;
  display: inline-block;
  margin: 0 0 6px 0;
}

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
  background: rgba(10,10,15,0.97); backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding: 6px 0 env(safe-area-inset-bottom, 4px);
  grid-template-columns: repeat(5, 1fr);
}
.bottom-nav.bn-visible { display: grid; }
.bottom-nav.kb-open { display: none !important; }
.bn-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 2px 6px; cursor: pointer; color: var(--text-muted);
  font-size: 0.6rem; font-weight: 600; letter-spacing: 0.3px;
  text-transform: uppercase; border: none; background: none;
  /* touch-action:manipulation removes iOS's 300ms tap-delay wait for
     a possible double-tap zoom. Was the reason bottom nav taps "took
     multiple presses" on iPhone. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(245,158,11,0.20);
  min-height: 48px;
  -webkit-appearance: none; appearance: none;
}
.bn-item:active { background: rgba(245,158,11,0.10); }
.bn-item:active .bn-icon { transform: scale(0.88); }
.bn-item.active { color: var(--accent); }
.bn-item.active .bn-icon { background: var(--accent-soft); }
/* Active-tab indicator bar under the icon — the "you are here" cue that
   makes native iOS/Android tab bars feel like tab bars. Subtle, animated. */
.bn-item::after {
  content: '';
  position: absolute; top: 2px; left: 50%;
  width: 22px; height: 3px;
  border-radius: 0 0 3px 3px;
  background: transparent;
  transform: translateX(-50%);
  transition: background 0.15s;
}
.bn-item.active::after { background: var(--accent); }
.bn-item { position: relative; }
.bn-icon {
  width: 42px; height: 30px; border-radius: 15px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; transition: background 0.15s, transform 0.12s;
}

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  html { font-size: 15px; }
  /* Prevent iOS Safari auto-zoom on input focus (any input <16px triggers it).
     Without this, every tap on a sign-up form, notes editor, or AI chat box
     zooms the page in and Safari doesn't zoom back out. */
  input[type="text"], input[type="number"], input[type="email"],
  input[type="password"], input[type="tel"], input[type="url"],
  input[type="search"], input[type="date"], textarea, select {
    font-size: 16px;
  }
  .nav-links { display: none !important; }
  .burger { display: flex !important; align-items: center; justify-content: center; }
  .nav-right { display: none !important; }

  /* Containers */
  .container, .container-wide { padding: 20px 16px; }
  .app-container { padding-top: 64px; padding-bottom: 80px; }

  /* Grids */
  .dash-grid { grid-template-columns: 1fr; }
  .analytics-grid { grid-template-columns: 1fr; }
  .quick-actions { grid-template-columns: 1fr; }
  .hero-stats { flex-direction: column; gap: 20px; }
  .oa-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .oa-two-col { grid-template-columns: 1fr; }
  .hero-steps { grid-template-columns: 1fr !important; }
  .diag-breakdown { grid-template-columns: 1fr; }
  .period-select { grid-template-columns: 1fr; }

  /* Study Guide */
  .sg-layout { grid-template-columns: 1fr; }
  .sg-sidebar { position: static; max-height: none; }

  /* Flashcards */
  .fc-rating { flex-direction: column; }
  .fc-rating .btn { width: 100%; }

  /* Exams */
  .exam-header { flex-wrap: wrap; gap: 8px; }

  /* Landing page */
  .hero-diag-demo { display: none; }

  /* Buttons - more touch friendly */
  .btn { min-height: 48px; padding: 12px 20px; font-size: 0.95rem; }
  .btn-sm { min-height: 42px; padding: 10px 16px; }
  .btn-lg { min-height: 52px; padding: 14px 28px; }

  /* Cards */
  .card { padding: 16px; }

  /* Settings */
  .setting-row { flex-direction: column; align-items: flex-start !important; gap: 10px; }
  .setting-row select, .setting-row button { width: 100%; }

  /* Tables */
  .oa-table { font-size: 0.75rem; }
  .oa-table th, .oa-table td { padding: 6px 4px; }

  /* Owner dashboard tabs — WRAP to multiple rows on mobile.
     The previous overflow-x:auto + -webkit-overflow-scrolling:touch
     turned this row into a native iOS scroll container, which
     intercepts every tap as a potential pan gesture and eats the
     click. With 12 tabs, wrapping is fine (3-4 rows tall). */
  .oa-tabs { flex-wrap: wrap; overflow: visible; gap: 6px; padding-bottom: 0; }
  .oa-tab { flex: 0 0 auto; font-size: 0.82rem; padding: 10px 14px; white-space: nowrap; min-height: 44px; }

  /* Toast on mobile — anchor to bottom (above bottom-nav) so soft keyboard
     doesn't cover them when typing in note/exam/chat fields */
  .toast-container { top: auto; bottom: 96px; right: 12px; left: 12px; }
  .toast { font-size: 0.85rem; padding: 12px 14px; }

  /* FAB position - raise above bottom nav */
  #fabContainer { bottom: 88px; left: 12px; }
  #fabContainer button { width: 42px !important; height: 42px !important; font-size: 1rem !important; }
  /* iOS: inline onmouseover on the AI FAB (app.js:createFAB) sticks
     transform:scale(1.1) after the first tap. That enlarged 62x62 button
     then floats over the leftmost .oa-tab on narrow phones and eats
     taps meant for it. Force scale(1) on touch devices. */
  #fabContainer button { transform: scale(1) !important; }

  /* Tools page */
  .tools-grid { grid-template-columns: 1fr !important; }

  /* Simulator two-col → single col on mobile */
  .sim-two-col { grid-template-columns: 1fr !important; }
  #toolsContent [style*="grid-template-columns:1fr 1fr"],
  #toolsContent [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Notes page - single column on mobile */
  .notes-layout { grid-template-columns: 1fr !important; gap: 10px !important; }
  #notesPracticePanel { display: none; }
  .notes-sidebar { position: static !important; border-radius: 12px; padding: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
  .notes-sidebar > div[style*="font-size:0.65rem"] { display: none; } /* hide "My Notes" label */
  .notes-sidebar > div[style*="height:1px"] { display: none; } /* hide divider */
  .notes-sidebar > button { flex: 1; min-width: 120px; }
  /* Sidebar items become horizontal row */
  .notes-sidebar-item { display: inline-flex; align-items: center; gap: 4px; padding: 8px 12px; font-size: 0.8rem; margin-bottom: 0; border-radius: 8px; flex-shrink: 0; }
  /* Notes toolbar wraps better */
  .notes-toolbar { gap: 2px; }
  .ntb { padding: 6px 6px; font-size: 0.75rem; }
  .ntb-sep { margin: 0 2px; }
  /* Character bar - scroll horizontally instead of wrapping */
  /* Horizontal chip row of buttons. touch-action:pan-x lets the row scroll
     sideways but tells WebKit a stationary tap is NOT a pan candidate, so
     the button underneath gets it. (-webkit-overflow-scrolling is a no-op
     since iOS 13 and was implicated in the .oa-tabs gesture hijack.) */
  .notes-char-bar { flex-wrap: nowrap; overflow-x: auto; touch-action: pan-x; padding: 8px 10px; }
  .char-btn { padding: 6px 8px; font-size: 0.82rem; flex-shrink: 0; }
  /* Notes editor - smaller padding */
  .notes-editor { padding: 14px; min-height: 250px; font-size: 0.9rem; }
  /* Notes action buttons - wrap and size better */
  #notesContent .btn-sm { min-height: 36px; padding: 6px 10px; font-size: 0.75rem; }
  #notesContent div[style*="display:flex"][style*="gap:6px"] { gap: 4px !important; }

  /* Lessons page mobile */
  #lessonsContent div[style*="grid-template-columns:1fr 320px"] {
    grid-template-columns: 1fr !important;
  }
  #lessonNotesPanel { position: static !important; max-height: 400px !important; }
  /* Lesson section buttons wrap on mobile */
  #lessonsContent div[style*="display:flex"][style*="gap:10px"][style*="flex-wrap"] { gap: 6px !important; }
  #lessonsContent button[style*="font-size:0.78rem"] { font-size: 0.72rem !important; padding: 5px 8px !important; }
  /* Lesson header */
  #lessonsContent h1 { font-size: 1.4rem !important; }
  #lessonsContent div[style*="padding:32px"] { padding: 20px !important; }
  /* Lesson cards grid */
  #lessonsContent div[style*="grid-template-columns: repeat"] { grid-template-columns: 1fr !important; }

  /* Exam builder on mobile */
  #examsContent div[style*="grid-template-columns"] { grid-template-columns: 1fr !important; }

  /* Math practice on mobile */
  #mathContent div[style*="grid-template-columns"] { grid-template-columns: 1fr !important; }

  /* Dashboard cards on mobile */
  #dashContent div[style*="grid-template-columns: repeat(2"] { grid-template-columns: 1fr !important; }
  #dashContent div[style*="grid-template-columns: repeat(3"] { grid-template-columns: 1fr !important; }

  /* General inline grid overrides */
  div[style*="grid-template-columns: repeat(2, 1fr)"] { grid-template-columns: 1fr !important; }
  div[style*="grid-template-columns: repeat(3, 1fr)"] { grid-template-columns: 1fr !important; }
  div[style*="grid-template-columns: repeat(4, 1fr)"] { grid-template-columns: repeat(2, 1fr) !important; }

  /* Upload prompt banner */
  #notesContent div[style*="border:2px dashed"] { padding: 16px !important; }
  #notesContent div[style*="border:2px dashed"] h3 { font-size: 1rem !important; }
  #notesContent div[style*="border:2px dashed"] button { width: 100%; }

  /* Form inputs - prevent iOS zoom */
  input, select, textarea { font-size: 16px !important; }

  /* Sim inline-styled inputs: override narrow widths */
  #toolsContent input[style*="width:80px"],
  #toolsContent input[style*="width:100px"],
  #toolsContent input[style*="width:120px"] {
    width: 100% !important; min-width: 80px;
  }

  /* Sim canvas: scale to full width, maintain aspect ratio */
  canvas { max-width: 100% !important; height: auto !important; }

  /* ── Mobile-native polish ─────────────────────────────────────
     Makes the site feel more like a phone app: safe-area insets
     for notch + home indicator, native momentum scroll, taller
     bottom-nav labels, hide desktop-heavy marketing sections. */

  /* Notch clearance on the top navbar. env(safe-area-inset-top) is
     20-59px on notched iPhones, 0 elsewhere. */
  .navbar {
    padding-top: env(safe-area-inset-top, 0);
    padding-left: max(16px, env(safe-area-inset-left, 0));
    padding-right: max(16px, env(safe-area-inset-right, 0));
    height: calc(64px + env(safe-area-inset-top, 0));
  }
  /* App container matches the actual navbar height when notched */
  .app-container { padding-top: calc(64px + env(safe-area-inset-top, 0)); }

  /* Bottom-nav home-indicator space + horizontal safe-area */
  .bottom-nav {
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
    padding-bottom: max(6px, env(safe-area-inset-bottom, 0));
  }

  /* Native momentum scroll on scrollable content */
  html, body { -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; }
  /* Kill horizontal scroll — a single overflowing element on the page
     produces a "swipe left to see nothing" gesture that feels broken. */
  body { overflow-x: hidden; }

  /* Mobile-only / desktop-only utility classes. Anything with
     class="mobile-only" is hidden on desktop; anything with
     class="desktop-only" is hidden on mobile. Use these to swap in
     a short punchy mobile hero for the long-form desktop marketing. */
  .desktop-only { display: none !important; }

  /* Landing page: hide long marketing sections on mobile — they exist
     for desktop conversion + SEO. Phone visitors want to sign up fast,
     not scroll a wall of copy. Content below the hero is still there
     if they scroll; this just tightens the initial viewport. */
  .landing-marketing-long { display: none !important; }

  /* Larger, more thumb-friendly touch targets on lists + cards */
  .quick-action, .fc-topic-card, .exam-list-item, .exam-option {
    min-height: 56px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(245,158,11,0.15);
  }

  /* Every clickable button/link/div gets touch-action + tap highlight
     globally on mobile. [onclick] catches inline-handler divs the
     owner analytics + question grids use. Cheap insurance against
     future "why doesn't this tap work" bugs. */
  button, a, [role="button"], [onclick],
  .oa-tab, .oa-stat, .signup-period-opt, .diag-option, .exam-option,
  .fc-topic-card, .quick-action, .card[onclick], .weak-area-item {
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(245,158,11,0.15);
  }

  /* Standard "primary" buttons should be BIG on mobile. Same treatment
     that made login field-focus targets easy. */
  .btn-lg, .btn-block { min-height: 52px; }

  /* Mobile app-feel: no text selection on nav elements (accidental
     text selection while trying to tap the top navbar is annoying). */
  .navbar, .bottom-nav, .mobile-drawer, .mobile-drawer-header { -webkit-user-select: none; user-select: none; }
}

/* On DESKTOP, the inverse utility class */
@media (min-width: 769px) {
  .mobile-only { display: none !important; }
}

/* Small phones */
@media (max-width: 380px) {
  html { font-size: 14px; }
  .container, .container-wide { padding: 16px 12px; }
  .oa-grid { grid-template-columns: 1fr; }
  .oa-stat-value { font-size: 1.3rem; }
  .nav-brand { font-size: 1.1rem; }
  .nav-brand svg { width: 22px; height: 22px; }
  /* Must clear the fixed .bottom-nav: ~68px of bar + the safe-area floor
     (up to 34px on Face ID phones) = ~100px. 76px left the last row of
     buttons on long pages (Settings' Log Out) partly under the nav. */
  .app-container { padding-bottom: calc(112px + env(safe-area-inset-bottom, 0px)); }
}

/* ===== NOTES LAYOUT ===== */
.notes-layout {
  display: grid; grid-template-columns: 200px 1fr 300px; gap: 16px; min-height: calc(100vh - 120px);
}
.notes-sidebar {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px;
  padding: 14px; height: fit-content; position: sticky; top: 80px;
}

/* ===== NOTES EDITOR STYLES ===== */
.notes-editor {
  min-height: 320px; outline: none; font-size: 0.95rem; line-height: 1.8;
  color: var(--text-primary); padding: 20px 24px;
  background: var(--bg-secondary); border-radius: 0 0 14px 14px;
  white-space: pre-wrap; word-wrap: break-word;
}
.notes-editor:empty:before { content: attr(data-placeholder); color: var(--text-muted); pointer-events: none; }
.notes-toolbar { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.ntb { background: none; border: none; color: var(--text-secondary); padding: 5px 8px; border-radius: 6px;
  cursor: pointer; font-size: 0.85rem; font-weight: 600; transition: background 0.12s, color 0.12s;
  line-height: 1; -webkit-tap-highlight-color: transparent; }
.ntb:hover { background: var(--accent-soft); color: var(--accent); }
.ntb.active { background: var(--accent); color: #000; }
.ntb-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; flex-shrink: 0; }
.notes-char-bar { display: flex; flex-wrap: wrap; gap: 4px; padding: 10px 14px;
  background: rgba(245,158,11,0.04); border-top: 1px solid rgba(255,255,255,0.05); }
.char-btn { background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 9px; font-size: 0.9rem; color: var(--text-primary); cursor: pointer;
  font-family: 'Courier New', monospace; transition: all 0.12s; user-select: none;
  -webkit-tap-highlight-color: transparent; }
.char-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.notes-sidebar-item { padding: 10px 14px; border-radius: 9px; cursor: pointer; font-size: 0.88rem;
  color: var(--text-secondary); transition: background 0.13s, color 0.13s; margin-bottom: 2px; }
.notes-sidebar-item:hover { background: var(--bg-card); color: var(--text-primary); }
.notes-sidebar-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.notes-quiz-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; margin-bottom: 12px; }

/* Editor block-type styling so lists/quotes/code render the way the editor needs */
.notes-editor h1 { font-size: 1.6rem; font-weight: 800; margin: 0.6em 0 0.3em; }
.notes-editor h2 { font-size: 1.3rem; font-weight: 700; margin: 0.6em 0 0.3em; }
.notes-editor h3 { font-size: 1.1rem; font-weight: 700; margin: 0.5em 0 0.25em; }
.notes-editor ul, .notes-editor ol { padding-left: 1.6em; margin: 0.4em 0; }
.notes-editor ul[data-list-type="disc"]   { list-style-type: disc;   }
.notes-editor ul[data-list-type="circle"] { list-style-type: circle; }
.notes-editor ul[data-list-type="square"] { list-style-type: square; }
.notes-editor ol[style*="lower-alpha"] { list-style-type: lower-alpha; }
/* Normalize marker sizing so disc, circle, and square render at matched sizes */
.notes-editor ul li::marker { font-size: 1.15em; }
.notes-editor ul[data-list-type="checkbox"] { list-style: none; padding-left: 1.2em; }
.notes-editor ul[data-list-type="checkbox"] li { padding: 2px 0; }
.notes-editor ul[data-list-type="checkbox"] input[type="checkbox"] { margin-right: 8px; cursor: pointer; vertical-align: middle; accent-color: var(--accent); }
.notes-editor blockquote { border-left: 3px solid var(--accent); padding: 4px 14px; margin: 0.5em 0; color: var(--text-secondary); font-style: italic; }
.notes-editor pre { background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px; padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; overflow-x: auto; margin: 0.5em 0; }
.notes-editor hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }
.notes-editor a { color: var(--accent); text-decoration: underline; }

/* Slash command menu rows */
.slash-item:hover { background: rgba(245,158,11,0.12); color: var(--accent); }
.notes-search-hit + .notes-search-hit { border-top: 1px solid rgba(255,255,255,0.05); }

/* Print styles for notes */
@media print {
  body > *:not(#page-notes) { display: none !important; }
  #page-notes { display: block !important; }
  .notes-no-print { display: none !important; }
  .notes-print-area { background: white !important; color: black !important; padding: 0 !important; }
  .notes-editor { background: white !important; color: black !important; border: none !important; min-height: unset; }
  @page { margin: 1.5cm; }
}

/* ===== CELEBRATION ANIMATION ===== */
@keyframes celebrate {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}
.celebrate { animation: celebrate 0.4s ease; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.slide-up { animation: slideUp 0.4s ease forwards; }

/* Toast notifications */
.toast-container { position: fixed; top: 80px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 14px 20px; border-radius: var(--radius-sm);
  background: var(--bg-card); border: 1px solid var(--border);
  box-shadow: var(--shadow); font-size: 0.9rem;
  animation: slideIn 0.3s ease;
  display: flex; align-items: center; gap: 10px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--info); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== iOS SAFARI TAP RELIABILITY (research-backed, 2026-09) =====
   Three WebKit behaviours that drop taps intermittently, each with a
   primary source. Applied globally on purpose — these are correct on
   every platform, not just iOS. */

/* 1. WebKit only fires click when mousedown and mouseup land on the SAME
      node. A finger that rolls from a tab's emoji <span> onto its text, or
      from a button's icon onto its padding, produces two targets and the
      click is silently dropped (bugs.webkit.org/show_bug.cgi?id=39620,
      still REOPENED). Children of tappables must never be hit targets. */
.btn > *, .bn-item > *, .oa-tab > *, .nav-links a > *, .mobile-drawer-item > *,
.nav-dropdown-btn > *, .nav-dropdown-menu a > *, .quick-action > *,
.signup-period-opt > *, .period-opt > *, .diag-option > *, .exam-option > *,
.fc-topic-card > *, .review-tab > *, [role="button"] > *, [onclick] > * {
  pointer-events: none;
}
/* …except things inside a tappable that are themselves controls. */
.btn input, .btn select, .btn a, [onclick] input, [onclick] select, [onclick] a,
[onclick] button, [onclick] textarea, .fc-topic-card button, .quick-action button {
  pointer-events: auto;
}

/* 2. A tap held slightly too long (~125ms+) on text becomes a selection /
      loupe instead of a click; -webkit-touch-callout:none was 0 hits in
      this codebase. (bugs.webkit.org/show_bug.cgi?id=231161, regressions
      re-reported July 2025 + iOS 26.1.) */
.btn, .bn-item, .oa-tab, .nav-links a, .mobile-drawer-item, .nav-dropdown-btn,
.nav-dropdown-menu a, .quick-action, .signup-period-opt, .period-opt,
.diag-option, .exam-option, .fc-topic-card, .review-tab, [role="button"] {
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}

/* 3. env(safe-area-inset-bottom) collapses to 0 when Safari's toolbar
      auto-hides mid-scroll, so a bottom bar padded with it SHRINKS as the
      finger comes down and the target moves. Floor it.
      (developer.apple.com/forums/thread/716552) */
.bottom-nav { padding-bottom: max(env(safe-area-inset-bottom, 0px), 21px); }

/* 4. The touch-action / tap-highlight catch-all lived only inside
      @media (max-width:768px), so iPads (769px+) and any phone in landscape
      wider than that got none of it. These are correct on every platform —
      make them global. [onclick] also gets cursor:pointer, which is one of
      the three things that make iOS treat a plain div as clickable at all. */
button, a, [role="button"], [onclick] {
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(245,158,11,0.15);
}
[onclick], [role="button"] { cursor: pointer; }

/* 5. The toast container on mobile spans full width at bottom:96px —
      directly over the last row of buttons on every long page (Settings'
      Log Out, exam Submit, etc). Even EMPTY it's fine, but a toast is on
      screen ~3.3s and for its final 300ms is opacity:0 yet hit-testable.
      The container itself must never intercept; only a visible toast card
      does. (audit C#1 / B#3) */
.toast-container { pointer-events: none; }
.toast-container .toast { pointer-events: auto; }

/* ===== MOBILE FIT SAFETY NET (2026-09) =====
   Rules that make any page shrink to the phone instead of overflowing it.
   Root cause of "the subscribe part gets cut off": inline grids with
   fixed-px columns + a 1fr track that can't drop below its longest word
   forced a card wider than a 375px viewport, and body{overflow-x:hidden}
   clipped the right edge. These rules remove that floor everywhere. */
@media (max-width: 768px) {
  /* .diagnostic-page had NO mobile override — 40px each side on a phone. */
  .diagnostic-page { padding: 16px 12px; }

  /* Grid/flex children default to min-width:auto (= their min-content
     width), which is exactly what stops a track from shrinking. Removing
     that floor is the canonical fix and is safe: content still lays out
     at its natural size when there's room. */
  /* GRID children only. Measured: applying this to flex children let a
     flex:1 text block collapse to 18px on a 320px phone (its text then
     overflowed by 50px). Flex rows here already use flex-wrap:wrap, which
     is the correct shrink mechanism for them. */
  .page [style*="grid-template-columns"] > *,
  .page [style*="display:grid"] > *,
  .page [style*="display: grid"] > * { min-width: 0; }

  /* Media and tables can never be wider than the screen; tables scroll
     sideways inside their own box (pan-x so a tap still lands). */
  .page img, .page svg, .page video, .page canvas { max-width: 100%; height: auto; }
  .page table { display: block; max-width: 100%; overflow-x: auto; touch-action: pan-x; }

  /* Long unbroken strings (URLs, codes, formulas) wrap instead of pushing
     the layout out. */
  .page p, .page li, .page td, .page code, .page pre { overflow-wrap: anywhere; }

  /* .slide-up used translateY — same first-tap-eater as .page fadeIn.
     Opacity-only on phones. */
  .slide-up { animation: fadeIn 0.15s ease forwards; }
}

/* ===== DASHBOARD STATS ROW ON PHONES (measured fix, 2026-09) =====
   .stat-grid is a CLASS rule (repeat(4,1fr)); the only mobile override
   for 4-column grids matched inline style="" attributes, so this row
   never collapsed. Four cards can't shrink below "Mastery" + 40px of
   padding each ≈ 428px; that widened the parent .dash-grid track and
   every dashboard card with it — measured +23px overflow on iPhone 13,
   +62px on iPhone SE. Two columns on phones, tighter padding, and a
   min-width:0 guard so no single child can drag the dashboard grid
   past the screen again. */
@media (max-width: 768px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px 10px; min-width: 0; }
  .stat-card .stat-value { font-size: 1.6rem; }
  .stat-card .stat-label { font-size: 0.78rem; }
  .dash-grid > *, .stat-grid > * { min-width: 0; }
}

/* ===== INLINE-GRID MOBILE OVERRIDES: match BOTH spacings =====
   The earlier rules (styles.css ~1226-1232) target
   style*="grid-template-columns: repeat(4, 1fr)" — WITH a space after the
   comma. app.js emits every inline grid WITHOUT the space
   (repeat(4,1fr)), so those overrides have never matched anything. The
   two owner-analytics stat grids and the diagnostic-gate period picker
   are inline repeat(4,1fr) and stayed 4 columns on phones, beating the
   .oa-grid class rule (inline wins), and overflowing. Match the prefix
   so any spacing works. */
@media (max-width: 768px) {
  div[style*="grid-template-columns:repeat(4"],
  div[style*="grid-template-columns: repeat(4"] { grid-template-columns: repeat(2, 1fr) !important; }
  div[style*="grid-template-columns:repeat(3"],
  div[style*="grid-template-columns: repeat(3"] { grid-template-columns: 1fr !important; }
  #dashContent div[style*="grid-template-columns:repeat(2"] { grid-template-columns: 1fr !important; }
}
@media (max-width: 400px) {
  /* Very narrow phones: even 2 columns of stat cards get cramped. */
  .oa-grid { grid-template-columns: 1fr !important; }
}

/* ── Native app shell ──────────────────────────────────────────────────────
   native-app.js adds .ss-native to <html> when the site is running inside
   the iOS/Android WebView. Mark any purchase chrome with data-web-only and
   it disappears there — App Store Guideline 3.1.1 forbids selling digital
   subscriptions in-app through anything but Apple's billing. */
html.ss-native [data-web-only] { display: none !important; }
