:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-hover: #eef2f7;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #64748b;
  --primary: #2563eb;
  --primary-soft: #eff6ff;
  --primary-ink: #1d4ed8;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --code-bg: #1e293b;
  --code-text: #e2e8f0;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.16);
  --radius: 12px;
  --radius-sm: 8px;
  --topbar-h: 60px;
  --sidebar-w: 276px;
  --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", Consolas, "Courier New", monospace;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #131c31;
  --surface-2: #1b2640;
  --surface-hover: #212e4d;
  --border: #253352;
  --border-strong: #33456b;
  --text: #f1f5f9;
  --text-2: #cbd5e1;
  --text-3: #94a3b8;
  --primary: #3b82f6;
  --primary-soft: rgba(59, 130, 246, 0.16);
  --primary-ink: #93c5fd;
  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.15);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.15);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.15);
  --code-bg: #0a0f1d;
  --code-text: #e2e8f0;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: clip;
}

/* Subtle custom scrollbars on desktop */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

@keyframes viewFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.main-content > * {
  animation: viewFadeIn 0.18s ease-out;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--text-2); }

/* Lucide icon alignment */
.ui-icon, svg.lucide {
  display: inline-block;
  vertical-align: -0.15em;
  flex-shrink: 0;
  stroke-width: 2;
}
.inline-flex-icon {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.pomo-reset, .pomo-btn span, .icon-btn span, .lightbox-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.toc-link {
  display: flex;
  align-items: center;
  gap: 6px;
}
.reader-body h2 {
  display: flex;
  align-items: center;
  gap: 9px;
}
.fc-done-icon {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
}

/* ================= TOPBAR ================= */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  gap: 12px;
}

.reading-progress-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  background: transparent;
  pointer-events: none;
}
.reading-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #00509b, #3b82f6);
  transition: width 0.1s linear;
}

.mobile-search-btn { display: none; }

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.topbar-center {
  flex: 1;
  min-width: 0;
  max-width: 440px;
  display: flex;
  justify-content: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  text-align: left;
}
.brand:hover { background: var(--surface-2); }

.brand-logo-img {
  height: 34px;
  width: auto;
  display: block;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 80, 155, 0.18);
}

.brand-divider {
  width: 1px;
  height: 26px;
  background: var(--border-strong);
  margin: 0 2px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.brand-text strong { font-size: 15px; font-weight: 700; }
.brand-text small { font-size: 11px; color: var(--text-3); font-weight: 500; }

.search-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 13.5px;
  transition: border-color 0.15s, background 0.15s;
}
.search-trigger:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}
.search-trigger span { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-trigger kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  display: grid;
  place-items: center;
  transition: all 0.15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* Pomodoro Widget */
.pomo-widget {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13px;
}
.pomo-widget.running {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.pomo-widget.break.running {
  border-color: var(--success);
  background: var(--success-soft);
}
.pomo-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
}
.pomo-widget.break .pomo-btn { background: var(--success); }
.pomo-time {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  min-width: 44px;
  text-align: center;
}
.pomo-tag {
  border: none;
  background: transparent;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  padding: 2px 5px;
  border-radius: 5px;
}
.pomo-tag:hover { background: rgba(128, 128, 128, 0.15); }
.pomo-reset {
  border: none;
  background: transparent;
  color: var(--text-3);
  font-size: 14px;
  padding: 0 3px;
}
.pomo-reset:hover { color: var(--text); }

/* ================= WORKSPACE & SIDEBAR ================= */
.workspace {
  display: flex;
  flex: 1;
  min-height: calc(100vh - var(--topbar-h));
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  gap: 18px;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}

.nav-section { display: flex; flex-direction: column; gap: 3px; flex-shrink: 0; }
.nav-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  padding: 0 10px 4px;
}
.nav-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 8px;
}
.nav-sub-progress {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-weight: 500;
  font-size: 14px;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary-ink);
  font-weight: 600;
}
.nav-badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
}

.subject-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: all 0.12s;
}
.subject-nav-item:hover { background: var(--surface-2); }
.subject-nav-item.active {
  background: var(--surface-2);
  border-color: var(--border-strong);
  font-weight: 600;
}
.subject-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.subject-nav-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.subject-nav-meta strong {
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.subject-nav-meta small {
  font-size: 11.5px;
  color: var(--text-3);
}

.chapters-nav {
  flex: 0 0 auto;
}
.chapter-nav-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chapter-nav-btn {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 8px;
  border: none;
  background: transparent;
  text-align: left;
  font-size: 13px;
  line-height: 1.35;
  color: var(--text-2);
  transition: background 0.12s;
}
.chapter-nav-btn:hover { background: var(--surface-2); color: var(--text); }
.chapter-nav-btn.active {
  background: var(--primary-soft);
  color: var(--primary-ink);
  font-weight: 600;
}
.ch-badge {
  font-size: 11px;
  font-weight: 700;
  min-width: 22px;
  height: 20px;
  padding: 0 5px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-2);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.chapter-nav-btn.active .ch-badge {
  background: var(--primary);
  color: #fff;
}
.ch-status-icon {
  margin-left: auto;
  font-size: 12px;
  flex-shrink: 0;
}
.ch-status-done { color: var(--success); }
.ch-status-hard { color: var(--warn); }

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}
.streak-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--warn-soft);
  color: var(--warn);
  font-weight: 600;
  font-size: 13px;
}

/* ================= MAIN CONTENT ================= */
.main-content {
  flex: 1;
  min-width: 0;
  padding: 28px 34px 60px;
  max-width: 1180px;
  margin: 0 auto;
  width: 100%;
}

/* ================= BUTTONS & COMMON UI ================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 13.5px;
  border: 1px solid transparent;
  transition: all 0.15s;
  text-decoration: none;
}
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 7px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.08); }
.btn-danger-outline { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger-outline:hover { background: var(--danger-soft); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-2);
}

.progress-track {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.35s ease;
}

/* ================= DASHBOARD ================= */
.dash-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.dash-hero h1 {
  margin: 0 0 4px;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.dash-hero p { margin: 0; color: var(--text-2); font-size: 14.5px; }
.dash-hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 26px;
}
.stat-card {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-label { font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 26px; font-weight: 800; line-height: 1.15; letter-spacing: -0.02em; }
.stat-sub { font-size: 12.5px; color: var(--text-3); }

.resume-banner {
  padding: 16px 20px;
  margin-bottom: 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: linear-gradient(135deg, var(--primary-soft), var(--surface));
  border-color: var(--border-strong);
}
.resume-banner-left { display: flex; align-items: center; gap: 14px; }
.resume-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 20px;
  flex-shrink: 0;
}

.section-heading {
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.subjects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(295px, 1fr));
  gap: 18px;
  margin-bottom: 28px;
}

.subject-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  position: relative;
  overflow: hidden;
}
.subject-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.subject-card-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
}
.subject-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.subject-code-badge {
  font-size: 12px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 7px;
  color: #fff;
  letter-spacing: 0.04em;
}
.subject-lang-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-2);
}
.subject-card h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
}
.subject-card p {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-2);
  line-height: 1.5;
  flex: 1;
}
.subject-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--text-3);
}
.subject-progress-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
}
.subject-progress-row > div:first-child {
  display: flex;
  justify-content: space-between;
  color: var(--text-2);
  font-weight: 600;
}
.subject-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding-top: 4px;
}

/* Study method guide strip */
.method-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.method-step {
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.method-step .step-num {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary-ink);
  font-weight: 800;
  font-size: 13px;
  display: grid;
  place-items: center;
}
.method-step strong { font-size: 14px; }
.method-step span { font-size: 12.5px; color: var(--text-2); line-height: 1.45; }

/* ================= READER VIEW ================= */
.reader-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 230px;
  gap: 28px;
  align-items: start;
}
.reader-article {
  min-width: 0;
}
.reader-header {
  padding-bottom: 18px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--border);
}
.reader-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-3);
  margin-bottom: 8px;
}
.reader-header h1 {
  margin: 0 0 12px;
  font-size: 28px;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.02em;
}
.reader-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
  transition: all 0.15s;
}
.toggle-pill:hover { background: var(--surface-2); color: var(--text); }
.toggle-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.toggle-pill.active-warn {
  background: var(--warn-soft);
  border-color: var(--warn);
  color: var(--warn);
}
.toggle-pill.active-success {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}

/* Reader typography */
.reader-body {
  font-size: clamp(14.8px, 1.1vw, 15.8px);
  line-height: 1.72;
  overflow-wrap: break-word;
  word-break: normal;
}
.reader-body h2 {
  margin: 32px 0 12px;
  font-size: clamp(18.5px, 2vw, 21.5px);
  font-weight: 750;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  scroll-margin-top: 78px;
  flex-wrap: wrap;
}
.reader-body h2.exercise-h2 {
  color: var(--primary-ink);
  border-bottom-color: var(--primary);
}
.reader-body h3 {
  margin: 22px 0 8px;
  font-size: 16.5px;
  font-weight: 700;
  color: var(--text);
  scroll-margin-top: 80px;
}
.reader-body p {
  margin: 0 0 13px;
  color: var(--text);
}
.reader-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.reader-body ul, .reader-body ol {
  margin: 0 0 15px;
  padding-left: 24px;
}
.reader-body li { margin-bottom: 6px; }

/* Callout boxes */
.callout {
  margin: 18px 0;
  padding: 15px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-left-width: 4px;
}
.callout-title {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 7px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.callout p { margin: 0 0 7px; font-size: 14.5px; }
.callout p:last-child { margin-bottom: 0; }

.callout-objectives {
  background: var(--primary-soft);
  border-color: rgba(37, 99, 235, 0.25);
  border-left-color: var(--primary);
}
.callout-objectives .callout-title { color: var(--primary-ink); }

.callout-merke {
  background: var(--warn-soft);
  border-color: rgba(217, 119, 6, 0.28);
  border-left-color: var(--warn);
}
.callout-merke .callout-title { color: var(--warn); }

.callout-example {
  background: var(--success-soft);
  border-color: rgba(5, 150, 105, 0.25);
  border-left-color: var(--success);
}
.callout-example .callout-title { color: var(--success); }

/* Code blocks */
.code-block-wrap {
  position: relative;
  margin: 16px 0;
}
.code-block {
  margin: 0;
  padding: 15px 18px;
  border-radius: var(--radius);
  background: var(--code-bg);
  color: var(--code-text);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  overflow-x: auto;
  white-space: pre;
}
.copy-code-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 9px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
  color: #cbd5e1;
  font-size: 11.5px;
  font-weight: 600;
}
.copy-code-btn:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }

/* Tables */
.table-wrap {
  margin: 18px 0;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}
.book-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.8px;
  line-height: 1.5;
}
.book-table th {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  text-align: left;
  padding: 10px 13px;
  border-bottom: 1px solid var(--border-strong);
}
.book-table td {
  padding: 9px 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.book-table tr:last-child td { border-bottom: none; }
.book-table tbody tr:hover { background: var(--surface-hover); }

/* Figures / Diagrams */
.book-figure {
  margin: 20px 0;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: center;
}
.book-figure img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  cursor: zoom-in;
  background: #fff;
  padding: 4px;
}
.book-figure figcaption {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-3);
  font-style: italic;
}

/* Exercise Practice Reveal */
.exercise-item {
  margin: 16px 0;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}
.exercise-q-title {
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}
.exercise-answer.blurred {
  display: none;
}
.reveal-btn {
  margin-top: 4px;
  font-size: 12.5px;
}

/* Reader right mini-TOC + notes */
.reader-aside {
  position: sticky;
  top: calc(var(--topbar-h) + 20px);
  max-height: calc(100vh - var(--topbar-h) - 40px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.toc-card {
  padding: 14px;
}
.toc-card h4 {
  margin: 0 0 10px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
}
.toc-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.toc-link {
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--text-2);
  text-decoration: none;
  padding: 4px 6px;
  border-radius: 6px;
  display: block;
}
.toc-link:hover { background: var(--surface-2); color: var(--text); }
.toc-link.lvl-3 { padding-left: 16px; font-size: 12px; color: var(--text-3); }

.notes-card {
  padding: 14px;
}
.notes-card h4 {
  margin: 0 0 8px;
  font-size: 12.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.notes-card textarea {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13px;
  line-height: 1.5;
}
.notes-card textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }

.reader-footer-actions {
  margin-top: 34px;
  padding: 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* Essentials mode banner */
.essentials-banner {
  padding: 10px 14px;
  margin-bottom: 18px;
  border-radius: 10px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 13.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* ================= FLASHCARDS VIEW ================= */
.fc-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}
.fc-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  max-width: 100%;
  min-width: 0;
}
.select-input {
  padding: 8px 12px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: 13.5px;
  font-weight: 500;
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.fc-filters .select-input {
  flex: 1 1 180px;
}

.fc-stage {
  max-width: 720px;
  margin: 0 auto;
}
.fc-progress-bar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-2);
  font-weight: 600;
  margin-bottom: 8px;
}

.flashcard-scene {
  perspective: 1200px;
  margin: 16px 0 20px;
}
.flashcard {
  position: relative;
  display: grid;
  min-height: 310px;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}
.flashcard.flipped {
  transform: rotateY(180deg);
}
.flashcard-face {
  grid-area: 1 / 1;
  position: relative;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  padding: 26px 28px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
}
.flashcard-back {
  transform: rotateY(180deg);
  border-color: var(--primary);
}
.fc-face-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
}
.fc-face-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.fc-question {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.45;
  text-align: center;
  margin: 0;
}
.fc-answer {
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  white-space: pre-line;
}
.fc-face-hint {
  margin-top: 18px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-3);
}

.fc-rating-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.rate-btn {
  padding: 12px 10px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-weight: 700;
  transition: all 0.14s;
}
.rate-btn small { font-size: 11.5px; font-weight: 500; opacity: 0.8; }
.rate-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.rate-again { border-color: rgba(220, 38, 38, 0.4); color: var(--danger); }
.rate-again:hover { background: var(--danger-soft); }
.rate-hard { border-color: rgba(217, 119, 6, 0.4); color: var(--warn); }
.rate-hard:hover { background: var(--warn-soft); }
.rate-good { border-color: rgba(37, 99, 235, 0.4); color: var(--primary); }
.rate-good:hover { background: var(--primary-soft); }
.rate-easy { border-color: rgba(5, 150, 105, 0.4); color: var(--success); }
.rate-easy:hover { background: var(--success-soft); }

.fc-done-card {
  padding: 40px 28px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* ================= QUIZ VIEW ================= */
.quiz-setup {
  max-width: 680px;
  margin: 0 auto;
  padding: 28px;
}
.quiz-setup h2 { margin: 0 0 6px; }
.quiz-form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  margin: 20px 0;
}
.quiz-form-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  min-width: 0;
}
.quiz-form-grid .select-input,
.quiz-form-grid select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.quiz-mode-cards {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.mode-choice {
  padding: 14px;
  border-radius: 11px;
  border: 2px solid var(--border);
  background: var(--surface);
  text-align: left;
  transition: all 0.14s;
}
.mode-choice:hover { border-color: var(--border-strong); }
.mode-choice.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.mode-choice strong { display: block; font-size: 14.5px; margin-bottom: 4px; }
.mode-choice span { font-size: 12.5px; color: var(--text-2); }

.quiz-runner {
  max-width: 760px;
  margin: 0 auto;
}
.quiz-q-card {
  padding: 28px;
  margin-top: 14px;
}
.quiz-q-text {
  font-size: 18.5px;
  font-weight: 700;
  line-height: 1.45;
  margin: 12px 0 20px;
}
.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.quiz-opt {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 16px;
  border-radius: 10px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  text-align: left;
  font-size: 14.8px;
  line-height: 1.45;
  transition: all 0.14s;
}
.quiz-opt:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-soft); }
.quiz-opt.selected { border-color: var(--primary); background: var(--primary-soft); font-weight: 600; }
.quiz-opt.correct { border-color: var(--success); background: var(--success-soft); color: var(--text); font-weight: 600; }
.quiz-opt.wrong { border-color: var(--danger); background: var(--danger-soft); color: var(--text); }
.opt-letter {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--surface-2);
  font-weight: 700;
  font-size: 13px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.quiz-opt.correct .opt-letter { background: var(--success); color: #fff; }
.quiz-opt.wrong .opt-letter { background: var(--danger); color: #fff; }

.quiz-explanation {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--surface-2);
  border-left: 4px solid var(--primary);
  font-size: 14px;
}
.quiz-nav-row {
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.quiz-results-card {
  padding: 28px;
  margin-bottom: 20px;
}
.score-circle {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 800;
  border: 6px solid var(--primary);
  background: var(--primary-soft);
  color: var(--primary-ink);
}
.chapter-breakdown {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}
.breakdown-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13.5px;
}

/* ================= CHEAT SHEET / GLOSSARY ================= */
.tabs-bar {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.tab-btn {
  padding: 10px 16px;
  border: none;
  border-bottom: 2.5px solid transparent;
  background: transparent;
  color: var(--text-2);
  font-weight: 600;
  font-size: 14px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--primary-ink);
  border-bottom-color: var(--primary);
}

.formula-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.formula-card {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.formula-expr {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow-x: auto;
}

.glossary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.glossary-item {
  padding: 15px 17px;
}
.glossary-item h4 {
  margin: 0 0 5px;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.glossary-item p { margin: 0; font-size: 13.5px; color: var(--text-2); }

.merke-bank-item {
  margin-bottom: 12px;
}

/* ================= MODALS & LIGHTBOX ================= */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: start center;
  padding-top: 8vh;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(3px);
}
.modal-panel {
  position: relative;
  z-index: 1;
  width: min(640px, 92vw);
  max-height: 82vh;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.search-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.search-input-row input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 15px;
  outline: none;
}
.modal-close-btn {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 7px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-3);
}
.search-filter-chips {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.chip {
  padding: 4px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.search-results {
  overflow-y: auto;
  padding: 10px;
  max-height: 55vh;
}
.search-empty {
  padding: 28px;
  text-align: center;
  color: var(--text-3);
  font-size: 14px;
}
.search-hit {
  width: 100%;
  text-align: left;
  padding: 11px 13px;
  border-radius: 9px;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.search-hit:hover { background: var(--surface-2); }
.search-hit-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 700;
}
.search-hit-snippet {
  font-size: 12.5px;
  color: var(--text-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.form-panel { padding: 0; }
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { margin: 0; font-size: 17px; }
.modal-form, .settings-body {
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  overflow-y: auto;
}
.modal-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  min-width: 0;
}
.modal-form input, .modal-form select, .modal-form textarea {
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.form-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.settings-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.info-box {
  padding: 12px 14px;
  border-radius: 9px;
  background: var(--surface-2);
  font-size: 13px;
}
.info-box p { margin: 5px 0 0; color: var(--text-2); }

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: grid;
  place-items: center;
  padding: 24px;
}
.lightbox-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
}
.lightbox-figure {
  position: relative;
  z-index: 1;
  margin: 0;
  max-width: 92vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.lightbox-figure img {
  max-width: 90vw;
  max-height: 80vh;
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  box-shadow: var(--shadow-lg);
}
.lightbox-figure figcaption {
  color: #e2e8f0;
  font-size: 14px;
  text-align: center;
}
.lightbox-x {
  position: fixed;
  top: 18px;
  right: 22px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 18px;
}
.lightbox-x:hover { background: rgba(255, 255, 255, 0.3); }

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 200;
  padding: 11px 16px;
  border-radius: 10px;
  background: #0f172a;
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
}
[data-theme="dark"] .toast { background: #f1f5f9; color: #0f172a; }

/* ================= AUTH SCREEN & SYNC PILL ================= */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: var(--bg);
  display: grid;
  place-items: center;
  padding: 20px;
}
.auth-card {
  width: min(410px, 100%);
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.auth-logo {
  height: 44px;
  width: auto;
  border-radius: 5px;
  margin: 0 auto 14px;
  display: block;
  box-shadow: 0 4px 14px rgba(0, 80, 155, 0.22);
}
.auth-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 800;
}
.auth-card p {
  margin: 0;
  font-size: 13.5px;
}
.auth-card label { text-align: left; }
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 10px;
  background: var(--surface-2);
  margin-top: 16px;
}
.auth-tab {
  padding: 7px 10px;
  border-radius: 7px;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}
.auth-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.auth-error {
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
}
.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}
.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}
.sync-pill.syncing .sync-dot { background: var(--warn); }
.sync-pill.error .sync-dot { background: var(--danger); }

/* ================= MOBILE READER QUICK BAR, BOTTOM NAV & SCROLL-TOP ================= */
.reader-mobile-bar {
  display: none;
  margin-bottom: 16px;
  flex-direction: column;
  gap: 10px;
}
.reader-mobile-selectors {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr);
  gap: 8px;
}
.reader-mobile-selectors select {
  min-width: 0;
  width: 100%;
  text-overflow: ellipsis;
}
.reader-mobile-drawer-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.reader-mobile-panel {
  padding: 14px;
  margin-top: 2px;
}

.sidebar-mobile-head {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.sidebar-mobile-logo {
  height: 28px;
  width: auto;
  border-radius: 4px;
}

.bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 42;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
}
.bottom-nav-item {
  border: none;
  background: transparent;
  color: var(--text-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 5px 2px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  transition: color 0.14s, background 0.14s;
}
.bottom-nav-item.active {
  color: var(--primary-ink);
  background: var(--primary-soft);
}
.bottom-nav-icon-wrap {
  position: relative;
  display: inline-flex;
}
.bottom-badge {
  position: absolute;
  top: -5px;
  right: -10px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.scroll-top-btn {
  position: fixed;
  right: 20px;
  bottom: 24px;
  z-index: 38;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-md);
  display: grid;
  place-items: center;
  transition: transform 0.15s, background 0.15s;
}
.scroll-top-btn:hover { background: var(--surface-2); transform: translateY(-2px); }

/* ================= RESPONSIVE BREAKPOINTS ================= */
.mobile-only { display: none; }
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 48;
  background: rgba(15, 23, 42, 0.52);
  backdrop-filter: blur(2px);
}

/* Medium Laptops */
@media (max-width: 1240px) {
  :root { --sidebar-w: 248px; }
  .main-content { padding: 24px 24px 60px; }
  .reader-layout { grid-template-columns: minmax(0, 1fr) 210px; gap: 22px; }
}

/* Tablets & Small Laptops */
@media (max-width: 1040px) {
  .stats-row, .method-grid { grid-template-columns: repeat(2, 1fr); }
  .reader-layout { grid-template-columns: 1fr; }
  .reader-aside { display: none; }
  .reader-mobile-bar { display: flex; }
  .formula-grid, .glossary-grid { grid-template-columns: 1fr; }
}

/* Mobile & Portrait Tablets */
@media (max-width: 820px) {
  :root { --topbar-h: 56px; }
  .mobile-only { display: grid; }
  .sidebar-mobile-head { display: flex; }
  .bottom-nav { display: grid; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100dvh;
    width: min(300px, 84vw);
    z-index: 55;
    transform: translateX(-100%);
    transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: var(--shadow-lg);
    padding-top: calc(14px + env(safe-area-inset-top));
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }
  .sidebar.open { transform: translateX(0); }

  .main-content {
    padding: 18px 14px calc(86px + env(safe-area-inset-bottom));
  }

  .topbar { padding: 0 10px; gap: 8px; }
  .topbar-center { display: none; }
  .mobile-search-btn { display: grid; }
  .pomo-tag, .pomo-reset { display: none; }
  .brand-divider, .brand-text { display: none; }
  .brand-logo-img { height: 28px; }
  .sync-pill { display: none; }

  .scroll-top-btn {
    right: 14px;
    bottom: calc(74px + env(safe-area-inset-bottom));
  }
  .toast {
    left: 14px;
    right: 14px;
    bottom: calc(74px + env(safe-area-inset-bottom));
    text-align: center;
  }

  .dash-hero h1 { font-size: 22px; }
  .reader-header h1 { font-size: 22px; }
  .resume-banner { flex-direction: column; align-items: stretch; }
  .resume-banner .btn { width: 100%; }

  .fc-rating-row { grid-template-columns: repeat(2, 1fr); }
  .flashcard { min-height: 260px; }
  .flashcard-face { padding: 20px 18px; }
  .fc-question { font-size: 17.5px; }
  .fc-answer { font-size: 14.8px; }

  .quiz-setup, .quiz-q-card, .quiz-results-card { padding: 18px; }
  .quiz-q-text { font-size: 16.5px; }
  .quiz-opt { padding: 12px 13px; min-height: 48px; }
  .quiz-form-grid, .quiz-mode-cards, .form-row { grid-template-columns: minmax(0, 1fr); }

  .fc-filters { width: 100%; }
  .fc-filters .select-input { flex: 1 1 160px; width: 100%; }

  /* Sheet-style modals on mobile */
  .modal { padding: 12px; align-items: center; }
  .modal-panel { width: 100%; max-height: 86dvh; }
}

/* Compact Phones (320px–480px) */
@media (max-width: 480px) {
  .brand-logo-img { height: 24px; }
  .pomo-widget { padding: 3px 6px; gap: 4px; }
  .pomo-time { font-size: 12px; min-width: 38px; }
  .icon-btn { width: 34px; height: 34px; }
  .stat-card { padding: 13px 14px; }
  .stat-value { font-size: 22px; }
  .method-grid { grid-template-columns: 1fr; }
  .subject-card { padding: 16px; }
  .dash-hero-actions { width: 100%; }
  .dash-hero-actions .btn { flex: 1 1 auto; }
  .reader-footer-actions { padding: 14px; }
  .reader-footer-actions > div { width: 100%; justify-content: space-between; }
  .tabs-bar { gap: 2px; overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tab-btn { padding: 9px 11px; font-size: 13px; white-space: nowrap; }
  .code-block { font-size: 12px; padding: 12px 13px; }
  .book-table { font-size: 12.8px; }
  .book-table th, .book-table td { padding: 7px 9px; }
  .score-circle { width: 76px; height: 76px; font-size: 20px; }
}

/* Touch devices: hide desktop-only keyboard shortcut hints */
@media (hover: none) {
  .desktop-hint { display: none !important; }
  .btn-primary:hover, .subject-card:hover, .rate-btn:hover { transform: none; }
}
