:root {
  color-scheme: light;
  --bg: #0e1320;
  --panel: #151b2e;
  --panel-2: #1a2238;
  --card: #f7f8fc;
  --card-soft: #eef1f8;
  --text: #e8ecff;
  --text-strong: #0d1730;
  --muted: #98a4c7;
  --accent: #ffb703;
  --accent-2: #7ce0c3;
  --accent-3: #7aa7ff;
  --accent-4: #ff9f1c;
  --accent-5: #90be6d;
  --accent-6: #f28482;
  --accent-7: #b8f2e6;
  --danger: #ff6b6b;
  --success: #38b000;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  --radius: 24px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(122, 167, 255, 0.18), transparent 30%),
    radial-gradient(circle at top right, rgba(124, 224, 195, 0.14), transparent 24%),
    linear-gradient(160deg, #0b1020 0%, #10172a 42%, #11182d 100%);
  color: var(--text);
}

button {
  font: inherit;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px 1fr;
}

.sidebar {
  padding: 24px;
  background: rgba(7, 11, 24, 0.75);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 20px;
}

.brand__badge {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: linear-gradient(145deg, var(--accent), #ff7b00);
  color: #1b1200;
  font-weight: 800;
  letter-spacing: 0.04em;
  box-shadow: var(--shadow);
}

.brand h1,
.topbar h2,
.sidebar__card h2 {
  margin: 0;
}

.brand p,
.sidebar__card p,
.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.sidebar__card {
  padding: 18px;
  margin-bottom: 18px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.tag {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-size: 0.82rem;
}

.tag--accent {
  background: rgba(255, 183, 3, 0.18);
  color: #ffd166;
}

.topic-nav {
  display: grid;
  gap: 12px;
  max-height: calc(100vh - 240px);
  overflow: auto;
  padding-right: 4px;
}

.topic {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
}

.topic__title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-weight: 700;
}

.topic__title > span:first-child {
  min-width: 0;
}

.topic__count {
  flex: 0 0 auto;
  white-space: nowrap;
  background: #ffd166 !important;
  color: #241600 !important;
  border: 1px solid rgba(36, 22, 0, 0.18);
  font-weight: 800;
}

.topic__list {
  display: grid;
  gap: 8px;
}

.lesson-link {
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.lesson-link:hover,
.lesson-link:focus-visible {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.11);
  outline: none;
}

.lesson-link.is-active {
  background: linear-gradient(145deg, rgba(124, 224, 195, 0.2), rgba(122, 167, 255, 0.16));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.main {
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  padding: 18px 20px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.eyebrow {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--accent-2);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.mode-switch {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-switch__btn {
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  cursor: pointer;
}

.mode-switch__btn.is-active {
  background: linear-gradient(145deg, var(--accent), #ffd166);
  color: #221700;
  font-weight: 700;
}

.workspace {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

.workspace__hero,
.workspace__content {
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.workspace__hero {
  padding: 18px 20px;
}

.workspace__content {
  padding: 20px;
  min-height: 520px;
  color: var(--text);
}

.hero-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.hero-card {
  padding: 14px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03));
}

.hero-card h3,
.hero-card p {
  margin: 0;
}

.hero-card p {
  margin-top: 6px;
  color: var(--muted);
}

.panel {
  display: grid;
  gap: 16px;
}

.panel h3 {
  margin: 0;
}

.lesson-intro {
  display: grid;
  gap: 10px;
  padding: 16px;
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(255, 183, 3, 0.12), rgba(124, 224, 195, 0.08));
  color: var(--text);
}

.sidebar__note {
  margin: 16px 0 0;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  line-height: 1.5;
}

.print-header {
  display: none;
}

.print-header__eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
  color: #5d6786;
}

.lesson-actions {
  display: flex;
  justify-content: flex-start;
  margin-top: 6px;
}

.lesson-print-btn {
  padding: 10px 14px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(145deg, var(--accent-2), #b7f1e0);
  color: #0e1a18;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(124, 224, 195, 0.22);
}

.lesson-print-btn:hover,
.lesson-print-btn:focus-visible {
  transform: translateY(-1px);
  outline: none;
}

.section-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.info-card {
  padding: 16px;
  border-radius: 18px;
  background: var(--card);
  color: var(--text-strong);
}

.info-card--soft {
  background: var(--card-soft);
}

.info-card h4 {
  margin: 0 0 8px;
}

.info-card ul {
  margin: 0;
  padding-left: 18px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(11, 16, 32, 0.08);
  font-size: 0.9rem;
}

.flashcard,
.drill-card,
.glossary-card {
  padding: 16px;
  border-radius: 18px;
  background: var(--card);
  color: var(--text-strong);
}

.flashcard-deck {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 56px;
  gap: 14px;
  align-items: center;
  margin-top: 14px;
}

.deck-arrow {
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--accent), #ffd166);
  color: #241600;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.flashcard {
  min-height: 300px;
  position: relative;
  cursor: pointer;
  perspective: 1200px;
  overflow: hidden;
}

.flashcard__face {
  position: absolute;
  inset: 0;
  padding: 18px;
  display: grid;
  align-content: start;
  gap: 12px;
  backface-visibility: hidden;
  transition: transform 0.45s ease;
  overflow-y: auto;
}

.flashcard__face--front {
  transform: rotateY(0deg);
}

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

.flashcard.is-flipped .flashcard__face--front {
  transform: rotateY(-180deg);
}

.flashcard.is-flipped .flashcard__face--back {
  transform: rotateY(0deg);
}

.flashcard__label {
  display: inline-flex;
  width: fit-content;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(122, 167, 255, 0.12);
  color: #3958b7;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.flashcard__face p {
  margin: 0;
  line-height: 1.45;
}

.flashcard__question {
  font-size: 1.18rem;
  font-weight: 700;
}

.flashcard__answer {
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.6;
  color: #22304f;
}

.flashcard-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
  color: var(--text);
}

.visual-card {
  overflow: hidden;
  border-radius: 18px;
  background: var(--card);
  color: var(--text-strong);
  max-width: 100%;
}

.visual-card__header {
  padding: 16px 16px 0;
}

.visual-card__header h4,
.visual-card__header p {
  margin: 0;
}

.visual-card__header p {
  margin-top: 6px;
  color: #5d6786;
}

.visual-card__body {
  padding: 12px 16px 16px;
  display: flex;
  justify-content: center;
}

.glossary-search {
  display: grid;
  gap: 8px;
}

.glossary-search__row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.glossary-search__label {
  font-weight: 700;
  color: var(--text);
}

.glossary-search__input {
  width: 100%;
  max-width: 540px;
  flex: 1 1 320px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.glossary-search__button {
  flex: 0 0 auto;
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  background: linear-gradient(145deg, var(--accent), #ffd166);
  color: #241600;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(255, 183, 3, 0.22);
}

.glossary-search__button.secondary-btn {
  background: linear-gradient(145deg, var(--accent), #ffd166) !important;
  color: #241600 !important;
  border: 1px solid rgba(36, 22, 0, 0.18);
}

.glossary-card {
  overflow-x: auto;
}

.glossary-search__input::placeholder {
  color: var(--muted);
}

.lesson-svg {
  width: 100%;
  max-width: 540px;
  max-height: 300px;
  height: auto;
  display: block;
}

.code-block {
  margin-top: 14px;
  padding: 14px;
  border-radius: 16px;
  background: #0e1320;
  color: #dfe8ff;
  font-family: Consolas, "Courier New", monospace;
  overflow-x: auto;
}

.code-block__title {
  margin-bottom: 10px;
  color: #7ce0c3;
  font-weight: 700;
}

@media print {
  .sidebar,
  .topbar,
  .mode-switch,
  .lesson-actions,
  .workspace__hero,
  .app-nav,
  .lesson-print-btn,
  .lesson-link,
  .lesson-svg {
    display: none !important;
  }

  .shell,
  .main,
  .workspace,
  .panel {
    display: block !important;
  }

  body {
    background: #fff;
    color: #000;
  }

  .panel,
  .lesson-intro,
  .info-card,
  .flashcard,
  .drill-card,
  .glossary-card {
    background: #fff !important;
    color: #000 !important;
    box-shadow: none !important;
    border: 1px solid #ccc;
  }

  .function-visual,
  .plane-visual,
  .stats-visual {
    break-inside: avoid;
  }

  .print-header {
    display: block !important;
    margin-bottom: 18px;
    padding-bottom: 10px;
    border-bottom: 2px solid #000;
  }

  .print-header h2,
  .print-header h3,
  .print-header p {
    margin: 0 0 6px;
    color: #000;
  }

  .code-block {
    background: #fff !important;
    color: #000 !important;
    border: 1px solid #bbb;
  }

  .visual-card__header p {
    color: #000;
  }
}

.code-line {
  padding: 2px 0;
  white-space: pre;
}

.code-line::before {
  content: " ";
}

.noscript-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 9999;
  padding: 12px 16px;
  border-radius: 14px;
  background: #fff3cd;
  color: #463200;
  border: 1px solid #f0d27a;
  box-shadow: var(--shadow);
}

.primary-btn,
.secondary-btn,
a.primary-btn {
  display: inline-block;
  text-decoration: none;
}

.flashcard__question {
  font-size: 1.15rem;
  font-weight: 700;
}

.flashcard__answer,
.solution-box {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(13, 23, 48, 0.12);
}

.action-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.primary-btn,
.secondary-btn {
  border: 0;
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
}

.primary-btn {
  background: linear-gradient(145deg, var(--accent), #ffd166);
  color: #241600;
  font-weight: 700;
}

.secondary-btn {
  background: rgba(11, 16, 32, 0.08);
  color: var(--text-strong);
}

.drill-options {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.option-btn {
  text-align: left;
  border: 1px solid rgba(13, 23, 48, 0.12);
  padding: 12px;
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
  white-space: pre-line;
}

.option-btn.is-correct {
  border-color: rgba(56, 176, 0, 0.45);
  background: rgba(56, 176, 0, 0.08);
}

.option-btn.is-wrong {
  border-color: rgba(255, 107, 107, 0.45);
  background: rgba(255, 107, 107, 0.08);
}

.feedback {
  margin-top: 12px;
  font-weight: 700;
}

.feedback--good {
  color: var(--success);
}

.feedback--bad {
  color: var(--danger);
}

.glossary-table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
}

.glossary-table th,
.glossary-table td {
  text-align: left;
  vertical-align: top;
  padding: 12px;
  border-bottom: 1px solid rgba(13, 23, 48, 0.12);
}

.glossary-table code {
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(13, 23, 48, 0.06);
}

.math-preview {
  display: inline-flex;
  align-items: center;
  gap: 0.08em;
  font-size: 1.08rem;
  font-weight: 700;
  line-height: 1;
}

.math-preview sup {
  font-size: 0.72em;
  line-height: 0;
  vertical-align: super;
}

.math-fraction {
  flex-direction: column;
  align-items: stretch;
  min-width: 1.8em;
  text-align: center;
}

.math-fraction__num,
.math-fraction__den {
  display: block;
  padding: 0 0.25em;
}

.math-fraction__bar {
  height: 1px;
  margin: 2px 0;
  background: currentColor;
}

.math-sqrt {
  gap: 0.15em;
}

.glossary-table th {
  position: sticky;
  top: 0;
  background: #f0f3fb;
}

.muted {
  color: #5d6786;
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .topic-nav {
    max-height: 38vh;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .hero-grid,
  .section-grid {
    grid-template-columns: 1fr;
  }

  .flashcard-deck {
    grid-template-columns: 48px minmax(0, 1fr) 48px;
  }

  .deck-arrow {
    width: 48px;
    height: 48px;
  }

  .visual-card svg {
    max-width: 100%;
    height: auto;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 14px;
  }

  .sidebar {
    padding: 16px;
  }

  .topic-nav {
    max-height: 34vh;
  }

  .workspace__content,
  .workspace__hero,
  .topbar {
    border-radius: 18px;
  }

  .workspace__content {
    padding: 14px;
  }

  .mode-switch {
    width: 100%;
  }

  .mode-switch__btn {
    flex: 1 1 42%;
    text-align: center;
  }

  .flashcard-deck {
    grid-template-columns: 1fr;
  }

  .flashcard {
    min-height: 340px;
  }

  .deck-arrow {
    width: 100%;
    border-radius: 14px;
  }

  .flashcard-meta {
    flex-direction: column;
    align-items: start;
  }
}
