:root {
  --bg: #0b0f14;
  --panel: #121824;
  --accent: #4f7cff;
  --text: #e6eaf0;
  --muted: #9aa4b2;
  --good: #39d98a;
  --bad: #ff6b6b;
}

:root.theme-light {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #111827;
  --muted: #5f6675;
  --good: #17b26a;
  --bad: #e5484d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-y: hidden !important;
}

.waves {
  position: fixed;
  inset: auto 0 -2px 0;
  height: 170px;
  z-index: -1;
  pointer-events: none;
  opacity: 0.55;
}

.waves svg {
  width: 120%;
  height: 100%;
  transform: translateX(-8%);
}

.wave1 { animation: waveMove 10s ease-in-out infinite; }
.wave2 { animation: waveMove 14s ease-in-out infinite reverse; opacity: 0.7; }

@keyframes waveMove {
  0%   { transform: translateX(-8%); }
  50%  { transform: translateX(-2%); }
  100% { transform: translateX(-8%); }
}

/* NAV */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 280px;
  background: linear-gradient(180deg, rgba(18,24,36,0.98), rgba(11,15,22,0.96));
  padding: 26px 24px 48px;
  border-right: 1px solid rgba(255,255,255,0.06);
  box-shadow: 18px 0 60px rgba(0,0,0,0.45);
  transform: translateX(0);
  transition: transform 0.42s cubic-bezier(.2,.9,.2,1);
  z-index: 1000;
}

.theme-light .nav {
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(244,246,252,0.96));
  border-right: 1px solid rgba(0,0,0,0.08);
  box-shadow: 12px 0 36px rgba(0,0,0,0.12);
}

.nav.open { transform: translateX(0); }

.nav-title {
  font-weight: 700;
  font-size: 1.4rem;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  transition: background 0.25s, color 0.25s, transform 0.15s;
}

.nav a:hover {
  background: rgba(79, 124, 255, 0.15);
  color: var(--accent);
  transform: translateX(4px);
}

.nav a.active {
  background: rgba(79, 124, 255, 0.2);
  color: #d7e2ff;
  box-shadow: inset 0 0 0 1px rgba(79, 124, 255, 0.35);
}

.theme-light .nav a { color: #1f2937; }

.theme-light .nav a.active {
  color: #0f172a;
  background: rgba(79,124,255,0.18);
  box-shadow: inset 0 0 0 1px rgba(79,124,255,0.28);
}

.icon { width: 22px; text-align: center; }

.hamburger,
.overlay {
  display: none !important;
}

.hamburger {
  position: fixed;
  top: 20px;
  left: 20px;
  font-size: 28px;
  cursor: pointer;
  z-index: 1100;
  user-select: none;
  transition: left 0.35s ease;
}

.hamburger.open { left: 300px; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.42s cubic-bezier(.2,.9,.2,1);
  z-index: 900;
}

.overlay.show {
  opacity: 1;
  pointer-events: auto;
}

/* Bottom nav */
.bottom-nav {
  position: fixed !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  padding: 10px 12px;
  border-radius: 0;
  background: rgba(12,16,26,0.92);
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 16px 50px rgba(0,0,0,0.45);
  display: none !important;
  justify-content: space-around;
  gap: 8px;
  z-index: 1200;
  backdrop-filter: blur(8px);
  will-change: transform;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.theme-light .bottom-nav {
  background: rgba(255,255,255,0.95);
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 12px 32px rgba(0,0,0,0.12);
}

.bottom-nav a {
  flex: 1;
  text-decoration: none;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 6px;
  border-radius: 14px;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.bottom-nav a .icon {
  font-size: 1.15rem;
}

.bottom-nav a.active {
  color: var(--text);
  background: rgba(79,124,255,0.22);
  box-shadow: inset 0 0 0 1px rgba(79,124,255,0.4);
  transform: translateY(-1px);
}

.theme-light .bottom-nav a { color: #5f6675; }
.theme-light .bottom-nav a.active { color: #0f172a; }

.theme-light .bottom-nav a:hover {
  color: #0f172a;
  background: rgba(79,124,255,0.12);
}

.theme-light .bottom-nav-more button:hover {
  color: #0f172a;
}

.bottom-nav-more {
  position: relative;
  flex: 1;
}

.bottom-nav-more button {
  width: 100%;
  background: none;
  border: none;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 6px;
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.bottom-nav-more button .icon {
  font-size: 1.15rem;
}

.bottom-nav-more button:hover {
  background: rgba(79,124,255,0.12);
}

.theme-light .bottom-nav-more button {
  color: #5f6675;
}

.bottom-nav-more-menu {
  position: absolute;
  bottom: calc(100% + 12px);
  right: 0;
  background: rgba(12,16,26,0.96);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  padding: 8px;
  min-width: 180px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  backdrop-filter: blur(12px);
  display: none !important;
  flex-direction: column;
  gap: 4px;
  z-index: 1250;
}

.bottom-nav-more-menu.active {
  display: flex;
}

.theme-light .bottom-nav-more-menu {
  background: rgba(255,255,255,0.96);
  border: 1px solid rgba(0,0,0,0.12);
}

.bottom-nav-more-menu a {
  padding: 12px 16px;
  color: var(--text);
  text-decoration: none;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.2s ease;
}

.bottom-nav-more-menu a:hover {
  background: rgba(79,124,255,0.15);
}

.bottom-nav-more-menu a .icon {
  font-size: 1.2rem;
}

/* Page layout */
.main {
  padding: 112px 24px 140px;
  max-width: 1100px;
  margin: 0 auto 0 280px;
  width: calc(100% - 280px);
}

.header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.title {
  font-size: 2.0rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-weight: 650;
}

.hidden { display: none !important; }

/* Subject tabs */
.subject-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0 12px;
  scrollbar-width: none;
}

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

.subject-tab {
  padding: 10px 16px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(18,24,36,0.6);
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.25s ease, border-color 0.25s ease, transform 0.15s ease;
  font-family: inherit;
}

.subject-tab:hover {
  background: rgba(79,124,255,0.15);
  transform: translateY(-1px);
}

.subject-tab.active {
  background: rgba(79,124,255,0.22);
  border-color: rgba(79,124,255,0.4);
  box-shadow: inset 0 0 0 1px rgba(79,124,255,0.3);
}

.theme-light .subject-tab {
  background: rgba(255,255,255,0.7);
  border-color: rgba(0,0,0,0.08);
  color: #1f2937;
}

.theme-light .subject-tab.active {
  background: rgba(79,124,255,0.14);
  border-color: rgba(79,124,255,0.3);
}

/* Progress bar */
.progress-bar {
  margin-bottom: 18px;
}

.progress-text {
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 6px;
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  overflow: hidden;
}

.theme-light .progress-track {
  background: rgba(0,0,0,0.06);
}

.progress-fill {
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--accent), var(--good));
  transition: width 0.4s ease;
}

/* Lesson grid */
.lesson-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
  margin-top: 12px;
}

/* Lesson card */
.lesson-card {
  background: linear-gradient(145deg, rgba(20,27,46,0.95), rgba(15,21,36,0.92));
  border-radius: 18px;
  padding: 20px;
  border: 1px solid rgba(255,255,255,0.06);
  box-shadow: 0 16px 50px rgba(0,0,0,0.30);
  backdrop-filter: blur(8px);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.3s ease, box-shadow 0.3s ease;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
}

.theme-light .lesson-card {
  background: linear-gradient(145deg, rgba(255,255,255,0.98), rgba(238,242,248,0.98));
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 12px 32px rgba(0,0,0,0.12);
}

.lesson-card::before {
  content: "";
  position: absolute;
  inset: -60px;
  background: radial-gradient(220px 180px at 20% 10%, rgba(79,124,255,0.20), transparent 60%);
  opacity: 0.6;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.lesson-card:hover {
  transform: translateY(-5px) scale(1.02);
  border-color: rgba(79,124,255,0.35);
  box-shadow:
    0 25px 65px rgba(0,0,0,0.42),
    0 0 35px rgba(79,124,255,0.2);
}

.lesson-card:hover::before {
  opacity: 1;
  transform: scale(1.1);
}

.lesson-card.completed {
  border-color: rgba(57,217,138,0.3);
}

.lesson-card.completed::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(57,217,138,0.3), rgba(79,124,255,0.2));
  opacity: 0.4;
  z-index: -1;
  filter: blur(15px);
}

.lesson-card-title {
  font-weight: 800;
  font-size: 1.05rem;
  position: relative;
  z-index: 1;
}

.lesson-card-desc {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.88rem;
  line-height: 1.5;
  position: relative;
  z-index: 1;
}

.lesson-card-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  position: relative;
  z-index: 1;
}

.lesson-badge {
  font-size: 0.78rem;
  font-weight: 800;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(57,217,138,0.30);
  background: rgba(57,217,138,0.12);
  color: var(--good);
}

.btn {
  padding: 10px 16px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.08);
  font-size: 0.92rem;
  font-weight: 800;
  cursor: pointer;
  background: rgba(79,124,255,0.18);
  color: var(--text);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.25s ease, box-shadow 0.25s ease;
  user-select: none;
  position: relative;
  overflow: hidden;
  font-family: inherit;
}

.btn::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  transform: translate(-50%, -50%);
  transition: width 0.5s ease, height 0.5s ease;
}

.btn:hover::before {
  width: 200px;
  height: 200px;
}

.theme-light .btn {
  background: rgba(79,124,255,0.12);
  border: 1px solid rgba(0,0,0,0.12);
  color: #0f172a;
}

.btn:hover {
  transform: translateY(-2px) scale(1.05);
  filter: brightness(1.12);
  box-shadow:
    0 10px 28px rgba(79,124,255,0.2),
    0 0 25px rgba(79,124,255,0.15);
}

.btn:active {
  transform: translateY(0) scale(1);
  transition: transform 0.1s ease;
}

/* Reader view */
.reader-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.back-btn {
  padding: 10px 16px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(18,24,36,0.6);
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.25s ease, transform 0.15s ease;
  font-family: inherit;
}

.back-btn:hover {
  background: rgba(79,124,255,0.15);
  transform: translateX(-2px);
}

.theme-light .back-btn {
  background: rgba(255,255,255,0.7);
  border-color: rgba(0,0,0,0.08);
  color: #1f2937;
}

.reader-title {
  font-size: 1.6rem;
  font-weight: 800;
  margin: 0;
}

/* Section progress */
.section-progress {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  margin-bottom: 16px;
  padding: 8px;
  background: rgba(79,124,255,0.08);
  border-radius: 12px;
}

.theme-light .section-progress {
  background: rgba(79,124,255,0.06);
}

/* Lesson content (copy-protected) */
.lesson-content.no-copy {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Section navigation animations */
@keyframes slideOutLeft {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(-40px); opacity: 0; }
}

@keyframes slideOutRight {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(40px); opacity: 0; }
}

@keyframes slideInLeft {
  from { transform: translateX(-40px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes slideInRight {
  from { transform: translateX(40px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.lesson-content.slide-out-left {
  animation: slideOutLeft 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.lesson-content.slide-out-right {
  animation: slideOutRight 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.lesson-content.slide-in-left {
  animation: slideInLeft 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.lesson-content.slide-in-right {
  animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.lesson-section {
  background: linear-gradient(145deg, rgba(20,27,46,0.95), rgba(15,21,36,0.92));
  border-radius: 20px;
  padding: 32px;
  border: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 20px;
  min-height: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}

.theme-light .lesson-section {
  background: linear-gradient(145deg, rgba(255,255,255,0.98), rgba(238,242,248,0.98));
  border: 1px solid rgba(0,0,0,0.08);
}

.lesson-section h3 {
  font-size: 1.15rem;
  font-weight: 800;
  margin: 0 0 12px;
}

.lesson-section-body {
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.75;
  color: var(--text);
}

.theme-light .lesson-section-body {
  color: #374151;
}

/* Key terms highlight */
.key-term {
  background: rgba(79,124,255,0.14);
  padding: 1px 5px;
  border-radius: 6px;
  font-weight: 700;
  color: var(--text);
  cursor: help;
  transition: all 0.2s ease;
}

.key-term:hover {
  background: rgba(79,124,255,0.25);
  transform: translateY(-1px);
}

.theme-light .key-term {
  background: rgba(79,124,255,0.10);
  color: #1e40af;
}

.theme-light .key-term:hover {
  background: rgba(79,124,255,0.18);
}

/* Key term tooltip */
.key-term-tooltip {
  position: fixed;
  background: linear-gradient(145deg, rgba(20,27,46,0.98), rgba(15,21,36,0.96));
  border: 1px solid rgba(79,124,255,0.4);
  border-radius: 12px;
  padding: 12px 16px;
  max-width: 280px;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 16px 50px rgba(0,0,0,0.5), 0 0 30px rgba(79,124,255,0.25);
  z-index: 10000;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-5px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.theme-light .key-term-tooltip {
  background: linear-gradient(145deg, rgba(255,255,255,0.98), rgba(238,242,248,0.98));
  border-color: rgba(79,124,255,0.3);
  color: #1f2937;
  box-shadow: 0 12px 32px rgba(0,0,0,0.15), 0 0 20px rgba(79,124,255,0.15);
}

.key-term-tooltip:not(.hidden) {
  opacity: 1;
  transform: translateY(0);
}

/* Key terms list */
.key-terms-section {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.theme-light .key-terms-section {
  border-top-color: rgba(0,0,0,0.06);
}

.key-terms-label {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.key-terms-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.key-term-pill {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(79,124,255,0.12);
  border: 1px solid rgba(79,124,255,0.22);
  color: var(--text);
}

.theme-light .key-term-pill {
  background: rgba(79,124,255,0.08);
  border-color: rgba(79,124,255,0.18);
  color: #1e40af;
}

/* Section navigation */
.section-nav {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin: 20px 0;
}

.section-nav-btn {
  flex: 1;
  padding: 14px 20px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(79,124,255,0.16);
  color: var(--text);
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.25s ease, box-shadow 0.25s ease;
  font-family: inherit;
}

.theme-light .section-nav-btn {
  background: rgba(79,124,255,0.12);
  border: 1px solid rgba(0,0,0,0.12);
  color: #0f172a;
}

.section-nav-btn:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.03);
  filter: brightness(1.12);
  box-shadow:
    0 10px 28px rgba(79,124,255,0.2),
    0 0 25px rgba(79,124,255,0.15);
}

.section-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
  filter: none;
  box-shadow: none;
}

/* Complete button */
.complete-section {
  margin-top: 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.complete-btn {
  padding: 13px 24px;
  border-radius: 14px;
  border: 1px solid rgba(57,217,138,0.3);
  background: rgba(57,217,138,0.16);
  color: var(--good);
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.25s ease, box-shadow 0.25s ease;
  font-family: inherit;
}

.complete-btn:hover {
  transform: translateY(-2px) scale(1.03);
  filter: brightness(1.1);
  box-shadow:
    0 10px 28px rgba(57,217,138,0.2),
    0 0 25px rgba(57,217,138,0.15);
}

.complete-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  filter: none;
  box-shadow: none;
}

.complete-status {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--good);
}

/* Loading state */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-weight: 700;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-weight: 700;
}

/* Responsive */
@media (min-width: 821px) {
  .nav { transform: translateX(0); }
  .hamburger, .overlay { display: none; }
}

@media (max-width: 820px) {
  .nav, .overlay, .hamburger { display: none; }

  body { padding-bottom: 120px; }

  .main {
    padding: 90px 20px 170px;
    margin: 0 auto;
    width: auto;
  }

  .bottom-nav { display: flex; }

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

@media (max-width: 820px) {
  /* Hide text labels on all mobile screens */
  .bottom-nav a span:not(.icon),
  .bottom-nav-more button span:not(.icon) { display: none; }
  .bottom-nav a,
  .bottom-nav-more button { font-size: 0; gap: 0; }
  .bottom-nav a .icon,
  .bottom-nav-more button .icon { font-size: 1.3rem; }
}

@media (max-width: 540px) {
  .subject-tabs { gap: 6px; }
  .subject-tab { padding: 8px 12px; font-size: 0.82rem; }
}

