:root {
  color-scheme: dark;
  --bg-page: #040510;
  --bg-surface: #080b1c;
  --bg-elevated: rgba(13, 18, 42, 0.92);
  --bg-muted: rgba(20, 26, 54, 0.78);
  --surface-highlight: rgba(34, 40, 80, 0.75);
  --border-soft: rgba(129, 140, 248, 0.22);
  --border-strong: rgba(99, 102, 241, 0.48);
  --text-primary: #e8ebff;
  --text-secondary: rgba(232, 235, 255, 0.7);
  --accent-primary: #6366f1;
  --accent-primary-soft: rgba(99, 102, 241, 0.18);
  --accent-secondary: #f97316;
  --accent-secondary-soft: rgba(249, 115, 22, 0.2);
  --accent-tertiary: #22d3ee;
  --focus-ring: rgba(129, 140, 248, 0.38);
  --success-soft: rgba(34, 197, 94, 0.22);
  --success-strong: #bbf7d0;
  --error-soft: rgba(248, 113, 113, 0.2);
  --error-strong: #fecaca;
  --card-gradient: var(--surface-gradient-primary);
  --transition: 180ms ease;
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", "Segoe UI", Roboto, sans-serif;
  color: var(--text-primary);
  background:
    radial-gradient(circle at 18% 20%, rgba(88, 132, 255, 0.22), transparent 58%),
    radial-gradient(circle at 82% 18%, rgba(48, 196, 255, 0.16), transparent 55%),
    radial-gradient(circle at 70% 84%, rgba(60, 120, 235, 0.14), transparent 60%),
    var(--bg-page);
  -webkit-font-smoothing: antialiased;
}

body.has-mobile-nav-open {
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

.hidden {
  display: none !important;
}

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 3rem 1.5rem 4.5rem;
}

.page > * + * {
  margin-top: 2.75rem;
}

/* Global navigation */
.global-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  --nav-padding: clamp(1.5rem, 4vw, 3rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: clamp(0.6rem, 1vw, 1rem);
  padding: 1rem var(--nav-padding);
  background: linear-gradient(135deg, rgba(14, 20, 48, 0.96), rgba(24, 30, 68, 0.92));
  border-bottom: 1px solid rgba(129, 140, 248, 0.28);
  box-shadow: 0 20px 40px rgba(3, 7, 18, 0.55);
  backdrop-filter: blur(16px);
}

.global-nav__brand {
  display: inline-flex;
  align-items: center;
  gap: clamp(0.7rem, 1vw, 1rem);
  margin-right: clamp(0.65rem, 2vw, 1.5rem);
  flex: 0 1 auto;
  min-width: 0;
}

.global-nav__menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1.2rem;
  border-radius: 999px;
  border: 1px solid rgba(129, 140, 248, 0.35);
  background: rgba(12, 16, 36, 0.85);
  color: #f8faff;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition);
  margin-left: auto;
}

.global-nav__menu-toggle:hover,
.global-nav__menu-toggle:focus-visible {
  outline: none;
  background: rgba(18, 22, 48, 0.95);
  border-color: rgba(129, 140, 248, 0.6);
  box-shadow: 0 12px 24px rgba(99, 102, 241, 0.25);
}

.global-nav__menu-toggle-icon {
  position: relative;
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 999px;
  transition: transform var(--transition), background var(--transition);
}

.global-nav__menu-toggle-icon::before,
.global-nav__menu-toggle-icon::after {
  content: "";
  position: absolute;
  left: 0;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 999px;
  transition: transform var(--transition), opacity var(--transition);
}

.global-nav__menu-toggle-icon::before { transform: translateY(-6px); }
.global-nav__menu-toggle-icon::after { transform: translateY(6px); }

.global-nav--menu-open .global-nav__menu-toggle-icon { background: transparent; }
.global-nav--menu-open .global-nav__menu-toggle-icon::before { transform: rotate(45deg); }
.global-nav--menu-open .global-nav__menu-toggle-icon::after { transform: rotate(-45deg); }

.global-nav__logo {
  height: clamp(44px, 8vw, 58px);
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 8px 16px rgba(3, 7, 18, 0.55));
}

.global-nav__brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}

.global-nav__overline {
  font-size: clamp(0.6rem, 0.7vw, 0.72rem);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(232, 235, 255, 0.62);
}

.global-nav__title {
  font-size: clamp(0.98rem, 1.1vw + 0.7rem, 1.35rem);
  font-weight: 600;
  color: #f8faff;
  white-space: normal;
}

.global-nav__menu {
  position: absolute;
  top: calc(100% + 0.55rem);
  left: auto;
  right: var(--nav-padding);
  width: min(360px, calc(100% - 2 * var(--nav-padding)));
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  list-style: none;
  margin: 0;
  padding: 1.1rem 1.4rem 1.6rem;
  background: linear-gradient(135deg, rgba(14, 20, 48, 0.96), rgba(24, 30, 68, 0.92));
  border: 1px solid rgba(129, 140, 248, 0.32);
  border-radius: 20px;
  box-shadow: 0 26px 48px rgba(5, 9, 24, 0.6);
  backdrop-filter: blur(12px);
  z-index: 120;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.global-nav--menu-open .global-nav__menu { display: flex; }

.global-nav__item { position: relative; width: 100%; }

.global-nav__link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.55rem clamp(0.85rem, 1.2vw, 1.2rem);
  border-radius: 999px;
  font-size: clamp(0.85rem, 0.55vw + 0.7rem, 1.05rem);
  font-weight: 500;
  color: rgba(232, 235, 255, 0.9);
  border: 1px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition), box-shadow var(--transition);
  width: 100%;
  text-align: left;
}

.global-nav__link:hover,
.global-nav__link:focus-visible {
  color: #f8faff;
  background: rgba(129, 140, 248, 0.2);
  border-color: rgba(129, 140, 248, 0.45);
  box-shadow: 0 12px 24px rgba(99, 102, 241, 0.25);
  outline: none;
}

.global-nav__link--active {
  background: rgba(129, 140, 248, 0.25);
  border-color: rgba(129, 140, 248, 0.6);
  color: #f8faff;
  box-shadow: 0 12px 24px rgba(99, 102, 241, 0.3);
}

.global-nav__toggle { background: none; cursor: pointer; }
.global-nav__caret {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid rgba(232, 235, 255, 0.8);
  transition: transform 0.2s ease;
  margin-top: 2px;
  margin-left: auto;
}

.global-nav__item--open .global-nav__caret { transform: rotate(-180deg); }

.global-nav__dropdown {
  display: none;
  flex-direction: column;
  gap: 0.45rem;
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.6rem;
  background: rgba(10, 14, 34, 0.9);
  border: 1px solid rgba(129, 140, 248, 0.22);
  border-radius: 16px;
  box-shadow: inset 0 0 0 1px rgba(3, 7, 18, 0.4);
}

.global-nav__item--open .global-nav__dropdown { display: flex; }

.global-nav__dropdown-link {
  display: block;
  padding: 0.65rem 1rem;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 500;
  color: rgba(232, 235, 255, 0.92);
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
}

.global-nav__dropdown-link:hover,
.global-nav__dropdown-link:focus-visible {
  background: rgba(129, 140, 248, 0.25);
  color: #f8faff;
  outline: none;
}

/* Card shell */
.card {
  background: var(--card-gradient);
  border-radius: 22px;
  padding: 2rem clamp(1.5rem, 3vw, 2.75rem);
  box-shadow: 0 28px 60px rgba(3, 7, 18, 0.65);
  border: 1px solid var(--border-soft);
  backdrop-filter: blur(12px);
}

.card__header {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: clamp(1.25rem, 2.2vw, 1.75rem);
}

.card__header h2 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 600;
  color: #f8faff;
}

.card__header p {
  margin: 0;
  color: var(--text-secondary);
}

/* Study info */
.card--info {
  display: none;
}

.card--info[style*="block"],
.card--info[style*="flex"],
.card--info[style*="inline"],
.card--info:not(.hidden) {
  display: block;
}

.study-info__main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.study-info__main h2 {
  margin: 0;
  font-size: 1.45rem;
  color: #f8faff;
}

.study-navigation {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 1.5rem;
  border-radius: 999px;
  border: 1px solid rgba(129, 140, 248, 0.35);
  background: rgba(129, 140, 248, 0.2);
  color: #f8faff;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition), box-shadow var(--transition);
}

.btn:hover {
  background: rgba(129, 140, 248, 0.3);
  border-color: rgba(129, 140, 248, 0.55);
  box-shadow: 0 16px 28px rgba(12, 16, 36, 0.4);
  transform: translateY(-2px);
}

.btn-text {
  background: rgba(12, 16, 36, 0.65);
  border-color: rgba(129, 140, 248, 0.25);
  color: var(--text-secondary);
}

.btn-text:hover {
  background: rgba(18, 22, 48, 0.85);
  border-color: rgba(129, 140, 248, 0.45);
  color: #f8faff;
}

/* Selection cards */
.card--selection .selection-content {
  display: flex;
  flex-direction: column;
  gap: clamp(1.75rem, 3vw, 2.5rem);
}

.selection-subtitle {
  margin: 0;
  color: var(--text-secondary);
  font-size: 1rem;
}

.books-grid,
.chapters-grid {
  display: grid;
  gap: clamp(1rem, 2vw, 1.6rem);
}

.books-grid {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.chapters-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.book-card,
.chapter-card {
  position: relative;
  display: flex;
  gap: 1rem;
  padding: 1.4rem 1.5rem;
  border-radius: 20px;
  background: rgba(12, 16, 36, 0.82);
  border: 1px solid rgba(129, 140, 248, 0.22);
  box-shadow: inset 0 0 0 1px rgba(3, 7, 18, 0.38);
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.book-card:hover,
.chapter-card:hover {
  transform: translateY(-4px);
  border-color: rgba(129, 140, 248, 0.45);
  box-shadow: 0 24px 48px rgba(3, 7, 18, 0.55);
  background: rgba(20, 26, 54, 0.9);
}

.book-card .book-icon,
.chapter-card .chapter-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: rgba(99, 102, 241, 0.18);
  border: 1px solid rgba(129, 140, 248, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  position: relative;
}

.book-level {
  position: absolute;
  bottom: -10px;
  right: -10px;
  background: rgba(249, 115, 22, 0.9);
  color: #fef9f5;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.8rem;
  font-weight: 600;
}

.book-info h3,
.chapter-info h3 {
  margin: 0;
  font-size: 1.15rem;
  color: #f8faff;
}

.book-info p,
.chapter-info p {
  margin: 0.4rem 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.book-stats,
.chapter-stats {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.stat {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.22);
  border: 1px solid rgba(129, 140, 248, 0.32);
  color: #f8faff;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.selection-actions {
  display: flex;
  justify-content: flex-start;
}

/* Study interface */
.card--study {
  display: none;
  flex-direction: column;
  gap: clamp(1.5rem, 2.5vw, 2rem);
}

.card--study[style*="block"],
.card--study:not(.hidden) {
  display: flex;
}

.card-progress {
  display: flex;
  justify-content: center;
}

.progress-indicator {
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(232, 235, 255, 0.7);
}

.flashcard-stage {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1.5rem;
}

.side-nav-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(129, 140, 248, 0.35);
  background: rgba(12, 16, 36, 0.75);
  color: #f8faff;
  font-size: 1.2rem;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}

.side-nav-btn:hover {
  background: rgba(18, 22, 48, 0.9);
  border-color: rgba(129, 140, 248, 0.55);
  transform: translateY(-2px);
}

.flashcard {
  position: relative;
  width: min(540px, 100%);
  min-height: 320px;
  perspective: 1600px;
}

.flashcard .card-inner {
  position: relative;
  width: 100%;
  min-height: inherit;
  transition: transform 0.7s ease;
  transform-style: preserve-3d;
}

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

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  background: rgba(12, 16, 36, 0.88);
  border: 1px solid rgba(129, 140, 248, 0.28);
  box-shadow: inset 0 0 0 1px rgba(3, 7, 18, 0.35);
  padding: 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  backface-visibility: hidden;
}

.card-back {
  transform: rotateY(180deg);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-type {
  font-size: 0.8rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(232, 235, 255, 0.6);
}

.flip-hint {
  border: none;
  background: rgba(99, 102, 241, 0.16);
  color: #cfd3ff;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.flip-hint:hover {
  background: rgba(99, 102, 241, 0.26);
  transform: translateY(-1px);
}

.card-content h2 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2rem);
  color: #f8faff;
}

.card-content p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 1.05rem;
  line-height: 1.6;
}

.simple-controls {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

.control-btn {
  border: 1px solid rgba(129, 140, 248, 0.32);
  border-radius: 999px;
  background: rgba(12, 16, 36, 0.78);
  color: #f8faff;
  padding: 0.55rem 1.6rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}

.control-btn:hover {
  background: rgba(18, 22, 48, 0.9);
  border-color: rgba(129, 140, 248, 0.55);
  transform: translateY(-2px);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 0.85rem 1.6rem;
  border-radius: 999px;
  background: rgba(12, 16, 36, 0.9);
  border: 1px solid rgba(129, 140, 248, 0.32);
  color: #f8faff;
  box-shadow: 0 20px 38px rgba(3, 7, 18, 0.55);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  z-index: 950;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: clamp(2.5rem, 6vw, 4rem) 1.5rem;
  background: rgba(4, 6, 18, 0.78);
  backdrop-filter: blur(12px);
  z-index: 1000;
  overflow-y: auto;
}

.modal {
  background: rgba(12, 16, 36, 0.95);
  border-radius: 24px;
  border: 1px solid rgba(129, 140, 248, 0.32);
  width: min(760px, 100%);
  padding: clamp(1.75rem, 3vw, 2.5rem);
  box-shadow: 0 30px 60px rgba(3, 7, 18, 0.7);
  color: var(--text-primary);
  display: grid;
  gap: 1.75rem;
}

.modal h3 {
  margin: 0;
  font-size: 1.5rem;
  color: #f8faff;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.modal-btn {
  border-radius: 999px;
  border: 1px solid rgba(129, 140, 248, 0.35);
  background: rgba(129, 140, 248, 0.22);
  color: #f8faff;
  padding: 0.6rem 1.4rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}

.modal-btn:hover {
  background: rgba(129, 140, 248, 0.32);
  border-color: rgba(129, 140, 248, 0.55);
  transform: translateY(-2px);
}

.shortcuts-info {
  background: rgba(12, 16, 36, 0.82);
  border: 1px solid rgba(129, 140, 248, 0.28);
  border-radius: 16px;
  padding: 1rem 1.25rem;
  color: var(--text-secondary);
  line-height: 1.55;
}

.shortcuts-info strong {
  color: #f8faff;
}

/* Responsive tweaks */
@media (max-width: 900px) {
  .books-grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }

  .flashcard-stage {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .flashcard-stage .side-nav-btn {
    display: none;
  }
}

@media (max-width: 720px) {
  .page {
    padding: 2.5rem 1.25rem 3.5rem;
  }

  .selection-actions {
    justify-content: center;
  }

  .simple-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .modal-actions {
    justify-content: center;
  }

  .modal-btn {
    flex: 1;
    min-width: 140px;
  }
}
