@font-face {
  font-family: "Source Han Sans CN Local";
  src: url("/fonts/source-han/SourceHanSansCN-Regular.otf") format("opentype");
  font-display: swap;
  font-weight: 400;
}

@font-face {
  font-family: "Source Han Sans CN Local";
  src: url("/fonts/source-han/SourceHanSansCN-Bold.otf") format("opentype");
  font-display: swap;
  font-weight: 700;
}

@font-face {
  font-family: "Source Han Serif CN Local";
  src: url("/fonts/source-han/SourceHanSerifCN-Regular.otf") format("opentype");
  font-display: swap;
  font-weight: 400;
}

@font-face {
  font-family: "HongLei BanShu Local";
  src: url("/fonts/handwriting/HongLeiBanShu-Regular.ttf") format("truetype");
  font-display: swap;
  font-weight: 400;
}

@font-face {
  font-family: "Muyao Softbrush Local";
  src: url("/fonts/handwriting/Muyao-Softbrush-Regular.ttf") format("truetype");
  font-display: swap;
  font-weight: 400;
}

:root {
  --font-sans: "Source Han Sans CN Local", "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  --font-serif: "Source Han Serif CN Local", "SimSun", "Songti SC", serif;
  --font-hand-board: "HongLei BanShu Local", "KaiTi", cursive;
  --font-hand-brush: "Muyao Softbrush Local", "KaiTi", cursive;
  --font-code: Consolas, "Courier New", ui-monospace, monospace;
  --bg: #f6f7f2;
  --surface: #ffffff;
  --surface-soft: #f3f6f4;
  --ink: #1f2933;
  --muted: #65727f;
  --line: #d8e0df;
  --brand: #0f766e;
  --brand-strong: #115e59;
  --accent: #b45309;
  --danger: #b42318;
  --success: #16803a;
  --shadow: 0 10px 30px rgba(22, 35, 44, 0.12);
  --radius: 8px;
  font-family: var(--font-sans);
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  background-color: var(--bg);
  background-image: var(--page-bg-image, none);
  background-repeat: var(--page-bg-repeat, no-repeat);
  background-position: var(--page-bg-position, center);
  background-size: var(--page-bg-size, cover);
  background-attachment: var(--page-bg-attachment, fixed);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

a {
  color: inherit;
}

.hidden {
  display: none !important;
}

.auth-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.16), rgba(180, 83, 9, 0.12)),
    var(--bg);
}

.auth-panel {
  width: min(430px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.auth-logo img,
.site-logo {
  width: 42px;
  height: 42px;
  object-fit: contain;
  border-radius: 6px;
}

.auth-logo h1,
.brand-title {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.muted {
  color: var(--muted);
}

.form-grid {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  font-size: 14px;
  color: #344250;
}

.field input,
.field select,
.field textarea,
.toolbar-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

.field textarea {
  min-height: 92px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.toolbar-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.btn {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 6px;
  padding: 9px 14px;
  color: var(--ink);
  background: var(--surface-soft);
  border: 1px solid var(--line);
}

.btn.primary {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}

.btn.primary:hover {
  background: var(--brand-strong);
}

.btn.danger {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.btn.ghost {
  background: transparent;
}

.btn.icon {
  width: 38px;
  padding: 0;
  font-size: 19px;
}

.auth-switch {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  font-size: 14px;
}

.text-link {
  border: 0;
  padding: 0;
  color: var(--brand-strong);
  background: transparent;
  text-decoration: underline;
}

.auth-landing-page {
  display: block;
  min-height: 100vh;
  padding: 0;
  color: #0b2f66;
  background-color: #f4f8ff !important;
  font-family: var(--font-sans);
}

.auth-landing {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  background: #fff;
  box-shadow: 0 10px 40px rgba(0, 45, 120, 0.12);
}

.auth-landing-header {
  display: flex;
  height: 76px;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  border-bottom: 1px solid #e6eef8;
  padding: 0 48px;
  background: #fff;
}

.auth-landing-logo {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
  color: #073b8e;
}

.auth-logo-mark,
.auth-logo-image {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 10px;
}

.auth-logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(135deg, #0052cc, #003b8e);
  font-size: 24px;
}

.auth-logo-image {
  object-fit: contain;
}

.auth-landing-logo h1 {
  margin: 0;
  color: #073b8e;
  font-size: 22px;
  line-height: 1.25;
}

.auth-landing-logo p {
  margin: 2px 0 0;
  color: #6b7c92;
  font-size: 13px;
  font-weight: 400;
}

.auth-landing-nav {
  display: flex;
  align-items: center;
  gap: 32px;
  color: #13294b;
  font-size: 15px;
}

.auth-landing-nav a {
  text-decoration: none;
}

.auth-nav-login {
  border-radius: 6px;
  padding: 9px 20px;
  color: #fff !important;
  background: #0052cc;
}

.auth-menu {
  display: none;
  color: #003b8e;
  font-size: 28px;
}

.auth-hero {
  display: grid;
  min-height: 620px;
  grid-template-columns: minmax(0, 1.1fr) 420px;
  gap: 60px;
  align-items: center;
  padding: 80px 70px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0.78)),
    url("https://images.unsplash.com/photo-1589829545856-d10d557cf95f?auto=format&fit=crop&w=1600&q=80");
  background-position: center;
  background-size: cover;
}

.auth-hero-text {
  text-align: center;
}

.auth-hero h2 {
  margin: 0 0 14px;
  color: #003b8e;
  font-size: clamp(34px, 3.5vw, 50px);
  line-height: 1.16;
  letter-spacing: 0;
}

.auth-hero h2 span {
  display: block;
  color: #0c4fb3;
  font-weight: 400;
}

.auth-hero-line {
  display: none;
}

.auth-slogan {
  margin: 0 0 40px;
  color: #173b6c;
  font-size: 21px;
  font-weight: 600;
}

.auth-feature-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  align-items: stretch;
}

.auth-feature {
  display: grid;
  grid-template-rows: 46px 24px minmax(44px, 1fr);
  justify-items: center;
  align-items: start;
  gap: 10px;
  color: #0b3d86;
  text-align: center;
}

.auth-feature-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  color: #0052cc;
  line-height: 1;
}

.auth-feature-icon svg {
  width: 38px;
  height: 38px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.auth-feature h3 {
  margin: 0;
  min-height: 22px;
  font-size: 17px;
  line-height: 1.3;
}

.auth-feature p {
  margin: 0;
  color: #526b8c;
  font-size: 13px;
  line-height: 1.6;
}

.auth-login-card {
  border-radius: 16px;
  padding: 42px 36px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(0, 50, 120, 0.18);
}

.auth-login-card h2 {
  margin: 0 0 30px;
  color: #13294b;
  font-size: 26px;
  text-align: center;
}

.auth-login-card .field label {
  color: #344968;
}

.auth-login-card .field input {
  height: 50px;
  border-color: #d7e2f0;
  border-radius: 7px;
  padding: 0 16px;
  color: #13294b;
  font-size: 15px;
}

.auth-login-card .field input:focus {
  border-color: #0052cc;
  box-shadow: 0 0 0 3px rgba(0, 82, 204, 0.12);
}

.auth-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 2px 0 8px;
  color: #5b6f8a;
  font-size: 14px;
}

.auth-options label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.auth-primary-btn {
  width: 100%;
  min-height: 52px;
  border-radius: 7px;
  background: linear-gradient(135deg, #0052cc, #003f9e) !important;
  border-color: #0052cc !important;
  font-size: 17px;
}

.auth-login-card .auth-switch {
  justify-content: center;
  margin-top: 20px;
}

.auth-login-card .text-link {
  color: #0052cc;
  font-weight: 700;
  text-decoration: none;
}

.auth-bottom-features {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid #eef3fa;
  padding: 50px 70px;
  background: #fff;
}

.auth-bottom-features article {
  display: grid;
  justify-items: center;
  gap: 10px;
  border-right: 1px solid #e1e8f2;
  padding: 0 18px;
  text-align: center;
}

.auth-bottom-features article:last-child {
  border-right: 0;
}

.auth-bottom-icon {
  color: #0052cc;
  font-size: 38px;
  line-height: 1;
}

.auth-bottom-features h3 {
  margin: 0 0 10px;
  color: #003b8e;
  font-size: 20px;
}

.auth-bottom-features p {
  margin: 0;
  color: #5b6f8a;
  font-size: 14px;
  line-height: 1.8;
}

.auth-footer {
  display: grid;
  gap: 10px;
  padding: 26px;
  color: #dbe8ff;
  background: #003f9e;
  font-size: 14px;
  text-align: center;
}

.auth-footer a {
  margin: 0 16px;
  color: #dbe8ff;
  text-decoration: none;
}

@media (max-width: 920px) {
  .auth-landing {
    box-shadow: none;
  }

  .auth-landing-header {
    height: 64px;
    padding: 0 18px;
  }

  .auth-landing-logo h1 {
    font-size: 17px;
  }

  .auth-logo-mark,
  .auth-logo-image {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
    font-size: 20px;
  }

  .auth-landing-nav {
    display: none;
  }

  .auth-menu {
    display: block;
  }

  .auth-hero {
    grid-template-columns: 1fr;
    gap: 28px;
    min-height: 0;
    padding: 38px 18px 28px;
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0.86)),
      url("https://images.unsplash.com/photo-1589829545856-d10d557cf95f?auto=format&fit=crop&w=1000&q=80");
    background-position: center;
    background-size: cover;
  }

  .auth-hero h2 {
    font-size: 31px;
    line-height: 1.18;
  }

  .auth-slogan {
    margin-bottom: 24px;
    font-size: 15px;
  }

  .auth-feature-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
  }

  .auth-feature-icon {
    width: 40px;
    height: 40px;
  }

  .auth-feature-icon svg {
    width: 32px;
    height: 32px;
  }

  .auth-feature h3 {
    font-size: 16px;
  }

  .auth-feature p {
    font-size: 12px;
    line-height: 1.55;
  }

  .auth-login-card {
    border-radius: 14px;
    padding: 30px 22px;
  }

  .auth-login-card h2 {
    font-size: 22px;
  }

  .auth-bottom-features {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 20px 18px;
  }

  .auth-bottom-features article {
    grid-template-columns: auto minmax(0, 1fr);
    justify-items: start;
    align-items: center;
    gap: 16px;
    border-right: 0;
    border-bottom: 1px solid #edf2f8;
    padding: 16px;
    text-align: left;
  }

  .auth-bottom-features article:last-child {
    border-bottom: 0;
  }

  .auth-bottom-icon {
    font-size: 30px;
  }

  .auth-footer {
    font-size: 12px;
    line-height: 2;
  }

  .auth-footer a {
    margin: 0 8px;
  }
}

.message {
  min-height: 22px;
  margin-top: 12px;
  color: var(--danger);
  font-size: 14px;
}

.page-loader {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 2500;
  width: 100%;
  height: 3px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.page-loader.active {
  opacity: 1;
}

.page-loader span {
  display: block;
  width: 100%;
  height: 100%;
  transform: scaleX(var(--loader-progress, 0));
  transform-origin: left center;
  background: linear-gradient(90deg, var(--brand), #b45309);
  box-shadow: 0 0 14px rgba(15, 118, 110, 0.3);
  transition: transform 0.28s ease;
}

.app-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 318px minmax(0, 1fr);
  background-color: rgba(246, 247, 242, 0.92);
  background-image: var(--page-bg-image, none);
  background-repeat: var(--page-bg-repeat, no-repeat);
  background-position: var(--page-bg-position, center);
  background-size: var(--page-bg-size, cover);
  background-attachment: var(--page-bg-attachment, fixed);
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  transition: transform 0.2s ease;
}

.sidebar-inner {
  display: grid;
  min-height: 100%;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  padding: 18px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.brand-title {
  overflow-wrap: anywhere;
}

.course-tree {
  display: grid;
  gap: 10px;
}

.course-block {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

.skeleton-card {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.skeleton-content {
  display: grid;
  align-content: start;
  gap: 16px;
}

.skeleton-line {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 14px;
  border-radius: 999px;
  background: #edf2f0;
}

.skeleton-line::after {
  position: absolute;
  inset: 0;
  content: "";
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.78), transparent);
  animation: skeleton-shimmer 1.18s ease-in-out infinite;
}

.skeleton-line.title,
.skeleton-line.heading {
  width: 58%;
  height: 20px;
}

.skeleton-line.wide {
  width: 96%;
}

.skeleton-line.mid {
  width: 76%;
}

.skeleton-line.short {
  width: 42%;
}

.skeleton-line.mini {
  width: 28%;
}

@keyframes skeleton-shimmer {
  100% {
    transform: translateX(100%);
  }
}

.course-toggle {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px;
  color: var(--ink);
  background: #fff;
  text-align: left;
}

.chapter-list {
  display: grid;
  gap: 4px;
  padding: 0 8px 10px;
}

.chapter-node {
  display: grid;
  gap: 4px;
}

.chapter-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.chapter-button {
  display: grid;
  width: 100%;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--ink);
  background: transparent;
  text-align: left;
}

.chapter-button:hover,
.chapter-button.active {
  color: var(--brand-strong);
  background: #eaf4f1;
}

.chapter-children {
  display: grid;
  gap: 4px;
  margin-left: 16px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

.chapter-detail-list {
  display: grid;
  gap: 5px;
  margin-left: calc(12px + var(--chapter-depth, 0) * 10px);
  padding: 4px 0 6px 12px;
  border-left: 1px solid var(--line);
}

.knowledge-link {
  width: 100%;
  border-radius: 6px;
  padding: 7px 9px;
  color: var(--muted);
  background: transparent;
  text-align: left;
}

.knowledge-link:hover {
  color: var(--brand-strong);
  background: #f0f7f5;
}

.chapter-expand {
  width: 32px;
  min-height: 32px;
  font-size: 15px;
}

.status-pill {
  display: inline-flex;
  min-width: 58px;
  justify-content: center;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 12px;
  color: var(--muted);
  background: #eef2f2;
}

.status-pill.completed {
  color: var(--success);
  background: #e8f7ee;
}

.status-pill.in_progress {
  color: var(--accent);
  background: #fff3df;
}

.sidebar-footer {
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.main {
  min-width: 0;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.mobile-menu {
  display: none;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.mobile-utility-menu {
  display: none;
}

.mobile-progress-close {
  display: none;
}

.app-shell .summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: rgba(255, 255, 255, 0.94);
}

.metric strong {
  display: block;
  margin-bottom: 4px;
  font-size: 24px;
}

.study-panel {
  position: relative;
  min-height: calc(100vh - 40px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 24px rgba(31, 41, 51, 0.08);
}

.study-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.98);
}

.study-title h2 {
  margin: 0 0 4px;
  font-size: 21px;
  letter-spacing: 0;
}

.page-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.page-indicator {
  min-width: 118px;
  text-align: center;
  color: var(--muted);
}

.study-body {
  display: grid;
  gap: 22px;
  padding: 22px 22px 92px;
}

.knowledge-content {
  min-height: 240px;
  line-height: 1.78;
  overflow-wrap: anywhere;
}

.knowledge-content h1,
.knowledge-content h2,
.knowledge-content h3 {
  letter-spacing: 0;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.section-title h3 {
  margin: 0;
  font-size: 18px;
}

.question-list {
  display: grid;
  gap: 14px;
}

.question-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: #fff;
}

.question-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.question-title {
  margin: 0;
  line-height: 1.55;
}

.answer-options {
  display: grid;
  gap: 8px;
  margin: 8px 0 12px;
}

.option-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
}

.option-row input {
  margin-top: 4px;
}

.question-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.result-tag {
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 13px;
}

.result-tag.correct {
  color: var(--success);
  background: #e8f7ee;
}

.result-tag.wrong {
  color: var(--danger);
  background: #fdecec;
}

.modal-question-section {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.modal-question-section h4 {
  margin: 0;
}

.answer-feedback {
  border-radius: 6px;
  padding: 10px;
  color: #713f12;
  background: #fff7ed;
}

.answer-feedback p {
  margin: 0 0 6px;
}

.study-actions {
  position: sticky;
  bottom: 0;
  z-index: 11;
  display: flex;
  justify-content: center;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 12px;
  background: rgba(255, 255, 255, 0.97);
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 22px;
  color: var(--muted);
  background: #fff;
  text-align: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(18, 24, 31, 0.42);
}

.modal {
  width: min(860px, 100%);
  max-height: 86vh;
  overflow: auto;
  border-radius: var(--radius);
  padding: 20px;
  background: #fff;
  box-shadow: var(--shadow);
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.progress-bar {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7eeee;
}

.progress-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
}

.profile-section {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.profile-section h4 {
  margin: 0;
}

.profile-course-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto minmax(160px, 240px);
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
}

.profile-list {
  display: grid;
  gap: 10px;
}

.profile-record {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fff;
}

.profile-record p {
  margin: 0;
}

.modal h3 {
  margin: 0 0 12px;
}

.modal-content {
  line-height: 1.68;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}

.admin-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 248px minmax(0, 1fr);
  background: var(--bg);
}

.file-mode-warning {
  position: sticky;
  top: 0;
  z-index: 200;
  padding: 12px 18px;
  color: #7a2e0e;
  background: #fff3df;
  border-bottom: 1px solid #f1c27d;
  text-align: center;
}

.file-mode-warning a {
  color: var(--brand-strong);
  font-weight: 700;
}

.admin-nav {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--line);
  padding: 18px;
  background: #fff;
}

.admin-nav .brand {
  margin-bottom: 18px;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-button {
  width: 100%;
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--ink);
  background: transparent;
  text-align: left;
}

.nav-button.active {
  color: #fff;
  background: var(--brand);
}

.nav-button:hover:not(.active) {
  color: var(--brand-strong);
  background: #eef7f4;
}

.admin-main {
  min-width: 0;
  padding: 22px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.admin-section {
  display: grid;
  gap: 16px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: #fff;
}

.panel h2,
.panel h3 {
  margin: 0 0 12px;
  letter-spacing: 0;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-title-row h2 {
  margin: 0;
}

body.admin-dialog-open::before {
  position: fixed;
  inset: 0;
  z-index: 80;
  content: "";
  background: rgba(18, 24, 31, 0.42);
}

.admin-dialog-form {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 90;
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  transform: translate(-50%, -50%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  background: #fff;
  box-shadow: var(--shadow);
}

.dialog-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-title-row h3 {
  margin: 0;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  margin-bottom: 12px;
}

.knowledge-admin-toolbar {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #f7faf9;
}

.knowledge-admin-toolbar .field {
  flex: 1 1 260px;
}

.knowledge-admin-toolbar input[type="file"] {
  flex: 1 1 220px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px;
  background: #fff;
}

.toolbar .field {
  min-width: 180px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: #344250;
  background: #f7faf9;
  font-weight: 600;
}

tr:last-child td {
  border-bottom: 0;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

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

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

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

.settings-group-title {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.settings-group-title h3 {
  margin: 0 0 4px;
  font-size: 17px;
}

.settings-group-title p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  padding: 8px;
  background: #f7faf9;
}

.secondary-editor-toolbar {
  border-top: 0;
  border-radius: 0;
}

.editor-toolbar select,
.editor-toolbar input[type="color"] {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  background: #fff;
}

.rich-editor {
  min-height: 210px;
  border: 1px solid var(--line);
  border-radius: 0 0 6px 6px;
  padding: 12px;
  font-family: var(--font-sans);
  line-height: 1.75;
  background: #fff;
  outline: none;
}

.html-source {
  width: 100%;
  min-height: 240px;
  border: 1px solid var(--line);
  border-radius: 0 0 6px 6px;
  padding: 12px;
  color: var(--ink);
  background: #fff;
  font-family: var(--font-code);
  line-height: 1.6;
  resize: vertical;
}

.rich-editor table,
.knowledge-html table {
  width: 100%;
  margin: 14px 0;
  border-collapse: collapse;
  table-layout: fixed;
}

.rich-editor th,
.rich-editor td,
.knowledge-html th,
.knowledge-html td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  vertical-align: top;
}

.rich-editor th,
.knowledge-html th {
  background: #f3f8f6;
  font-weight: 700;
}

.rich-editor pre,
.knowledge-html pre {
  overflow: auto;
  border: 1px solid #d9e4e2;
  border-radius: 6px;
  padding: 12px 14px;
  color: #1f2933;
  background: #f7faf9;
  white-space: pre-wrap;
  tab-size: 2;
}

.rich-editor code,
.knowledge-html code {
  border-radius: 4px;
  padding: 1px 5px;
  color: #a34000;
  background: #fff3df;
  font-family: var(--font-code);
  font-size: 0.94em;
}

.rich-editor pre code,
.knowledge-html pre code {
  padding: 0;
  color: inherit;
  background: transparent;
  font-size: inherit;
}

.rich-editor blockquote,
.knowledge-content blockquote {
  margin: 12px 0;
  border-left: 4px solid var(--brand);
  padding: 8px 12px;
  color: #40505e;
  background: #f3f8f6;
}

.rich-editor ul,
.rich-editor ol,
.knowledge-content ul,
.knowledge-content ol {
  padding-left: 1.4em;
}

.import-help {
  display: grid;
  gap: 6px;
  margin: 10px 0;
  color: var(--muted);
  font-size: 14px;
}

.ai-helper-grid {
  display: grid;
  grid-template-columns: 1.2fr 1.6fr 120px;
  gap: 14px;
  margin-bottom: 14px;
}

.ai-knowledge-raw {
  min-height: 260px;
  line-height: 1.7;
  resize: vertical;
}

.ai-knowledge-preview {
  min-height: 240px;
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 18px;
  background: #fff;
  line-height: 1.8;
}

.ai-html-source {
  min-height: 180px;
}

.ai-highlight,
.knowledge-html .ai-highlight,
.knowledge-content .ai-highlight,
.rich-editor .ai-highlight {
  border-radius: 4px;
  padding: 1px 4px;
  font-weight: 700;
}

.ai-highlight-yellow {
  color: #7a4b00;
  background: #fff1a8;
}

.ai-highlight-blue {
  color: #0b4b83;
  background: #dbeafe;
}

.ai-highlight-green {
  color: #11613a;
  background: #d9fbe7;
}

.ai-highlight-orange {
  color: #9a3412;
  background: #ffedd5;
}

.ai-highlight-red {
  color: #9f1239;
  background: #ffe4e6;
}

.chapter-summary {
  margin: 0 0 18px;
  border: 1px solid #d7e6f5;
  border-radius: 8px;
  padding: 14px 16px;
  background: #f7fbff;
}

.chapter-summary h3:first-child {
  margin-top: 0;
}

.pipeline-target-grid {
  grid-template-columns: 1.2fr 1.5fr 130px;
}

.pipeline-quality {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.pipeline-quality-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #f7faf9;
}

.pipeline-editor {
  display: grid;
  gap: 16px;
}

.pipeline-chapter,
.pipeline-lesson {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.pipeline-chapter {
  display: grid;
  gap: 12px;
  background: #fbfdfc;
}

.pipeline-chapter-head,
.pipeline-lesson-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.pipeline-chapter-head .field {
  flex: 1;
}

.pipeline-lessons {
  display: grid;
  gap: 12px;
}

.pipeline-lesson textarea {
  min-height: 120px;
}

.pipeline-lesson .code-textarea {
  min-height: 180px;
  font-family: var(--font-code);
}

.error-list {
  display: grid;
  gap: 4px;
  margin-top: 8px;
  color: var(--danger);
  font-size: 14px;
}

@media (max-width: 980px) {
  .app-shell {
    display: block;
  }

  .ai-helper-grid {
    grid-template-columns: 1fr;
  }

  .pipeline-target-grid {
    grid-template-columns: 1fr;
  }

  .pipeline-chapter-head,
  .pipeline-lesson-head {
    align-items: stretch;
    flex-direction: column;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 330px);
    transform: translateX(-100%);
    box-shadow: var(--shadow);
  }

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

  .app-shell.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
  }

  .mobile-menu {
    display: inline-flex;
  }

  .main {
    padding: 14px;
  }

  .main {
    padding: 0;
  }

  .topbar {
    position: fixed;
    top: 8px;
    right: 8px;
    z-index: 45;
    display: block;
    margin: 0;
  }

  .topbar-actions,
  #showSidebar {
    display: none !important;
  }

  .mobile-menu {
    width: 42px;
    min-height: 42px;
    border-radius: 999px;
    padding: 0;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 8px 20px rgba(31, 41, 51, 0.14);
    font-size: 0;
  }

  .mobile-menu::before {
    content: "☰";
    font-size: 22px;
    line-height: 1;
  }

  .mobile-utility-menu {
    position: fixed;
    top: 56px;
    right: 8px;
    z-index: 46;
    display: grid;
    width: 156px;
    gap: 4px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 6px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: var(--shadow);
  }

  .mobile-utility-menu.hidden {
    display: none !important;
  }

  .mobile-utility-menu .btn {
    width: 100%;
    min-height: 34px;
    justify-content: flex-start;
    padding: 7px 10px;
    background: transparent;
  }

  .summary-grid {
    position: fixed;
    top: 56px;
    left: 8px;
    right: 8px;
    z-index: 44;
    display: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: 46vh;
    overflow: auto;
    gap: 8px;
    margin: 0;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.98);
    box-shadow: var(--shadow);
  }

  .summary-grid.mobile-summary-open {
    display: grid;
  }

  .mobile-progress-close {
    position: fixed;
    top: 62px;
    right: 16px;
    z-index: 45;
    display: inline-flex;
    width: auto;
    min-height: 30px;
    padding: 4px 10px;
    font-size: 12px;
  }

  .mobile-progress-close.hidden {
    display: none !important;
  }

  .summary-grid .metric {
    padding: 10px;
  }

  .summary-grid .metric strong {
    font-size: 19px;
  }

  .study-panel {
    min-height: 100vh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .study-header {
    top: 0;
    z-index: 34;
    gap: 7px;
    padding: 8px 58px 8px 12px;
    background: rgba(255, 255, 255, 0.97);
  }

  .study-title h2 {
    margin: 0;
    font-size: 17px;
    line-height: 1.28;
  }

  #courseTitle {
    display: none;
  }

  .page-controls {
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 1px;
  }

  .page-controls .btn {
    width: auto;
    min-height: 30px;
    flex: 0 0 auto;
    padding: 5px 8px;
    font-size: 13px;
    white-space: nowrap;
  }

  .page-indicator {
    min-width: auto;
    flex: 0 0 auto;
    font-size: 12px;
    white-space: nowrap;
  }

  .study-body {
    gap: 10px;
    padding: 10px 12px 64px;
  }

  .knowledge-content {
    min-height: calc(100vh - 172px);
    font-size: 16px;
    line-height: 1.72;
  }

  .knowledge-content h1,
  .knowledge-content h2,
  .knowledge-content h3 {
    margin: 0 0 8px;
    line-height: 1.35;
  }

  .knowledge-content h2 {
    font-size: 18px;
  }

  .empty-state {
    padding: 14px;
  }

  .study-actions {
    gap: 8px;
    justify-content: space-between;
    padding: 8px 10px;
  }

  .study-actions .btn {
    width: auto;
    min-height: 36px;
    flex: 1 1 0;
    padding: 6px 10px;
    font-size: 14px;
  }

  .study-actions .btn.danger {
    color: var(--danger);
    background: #fff;
    border-color: #efc1bd;
  }

  .study-header,
  .topbar,
  .admin-header {
    align-items: stretch;
    flex-direction: column;
  }

  .page-controls,
  .topbar-actions {
    justify-content: flex-start;
  }

  .admin-shell {
    display: block;
  }

  .admin-nav {
    position: static;
    height: auto;
  }

  .two-col,
  .three-col,
  .four-col {
    grid-template-columns: 1fr;
  }

  .panel-title-row {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 620px) {
  .auth-panel,
  .study-body,
  .panel {
    padding: 14px;
  }

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

  .profile-grid,
  .profile-course-row {
    grid-template-columns: 1fr;
  }

  .study-actions {
    align-items: center;
    flex-direction: row;
  }

  .btn {
    width: 100%;
  }

  .btn.icon {
    width: 38px;
  }

  .mobile-menu {
    width: 42px;
  }

  .mobile-utility-menu .btn,
  .page-controls .btn,
  .study-actions .btn,
  .mobile-progress-close {
    width: auto;
  }

  .study-actions .btn {
    flex: 1 1 0;
  }
}

/* Unified immersive learning layout for desktop and mobile. */
.app-shell {
  display: block;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 70;
  width: min(88vw, 340px);
  transform: translateX(-100%);
  box-shadow: var(--shadow);
}

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

.app-shell.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
}

.main {
  min-height: 100vh;
  padding: 0;
}

.topbar {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 75;
  display: block;
  margin: 0;
}

.app-shell .topbar-actions,
.app-shell #showSidebar {
  display: none !important;
}

.mobile-menu {
  display: inline-flex;
  width: 46px;
  min-height: 46px;
  border-radius: 999px;
  padding: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 10px 26px rgba(31, 41, 51, 0.18);
  font-size: 0;
}

.mobile-menu::before {
  content: "☰";
  font-size: 22px;
  line-height: 1;
}

.mobile-utility-menu {
  position: fixed;
  right: 16px;
  bottom: 70px;
  z-index: 76;
  display: grid;
  width: 168px;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
}

.mobile-utility-menu.hidden {
  display: none !important;
}

.mobile-utility-menu .btn {
  width: 100%;
  min-height: 34px;
  justify-content: flex-start;
  padding: 7px 10px;
  background: transparent;
}

.app-shell .summary-grid {
  position: fixed;
  right: 16px;
  bottom: 70px;
  z-index: 74;
  display: none;
  width: min(420px, calc(100vw - 32px));
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-height: 48vh;
  overflow: auto;
  gap: 8px;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
}

.app-shell .summary-grid.mobile-summary-open {
  display: grid;
}

.app-shell .summary-grid .metric {
  padding: 10px;
}

.app-shell .summary-grid .metric strong {
  font-size: 20px;
}

.mobile-progress-close {
  position: fixed;
  right: 24px;
  bottom: calc(70px + 48vh - 40px);
  z-index: 75;
  display: inline-flex;
  width: auto;
  min-height: 30px;
  padding: 4px 10px;
  font-size: 12px;
}

.mobile-progress-close.hidden {
  display: none !important;
}

.study-panel {
  min-height: 100vh;
  border: 0;
  border-radius: 0;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: none;
}

.study-header {
  top: 0;
  z-index: 35;
  display: block;
  gap: 8px;
  border-bottom: 0;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.98);
}

.study-title h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
}

#courseTitle {
  display: none;
}

.page-controls {
  position: fixed;
  left: 12px;
  right: 72px;
  bottom: 52px;
  z-index: 36;
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 6px;
  overflow-x: auto;
  border-radius: var(--radius);
  padding: 4px;
  background: rgba(255, 255, 255, 0.92);
}

.page-controls .btn {
  width: auto;
  min-height: 30px;
  flex: 0 0 auto;
  padding: 5px 8px;
  font-size: 13px;
  white-space: nowrap;
}

.page-indicator {
  min-width: auto;
  flex: 0 0 auto;
  font-size: 12px;
  white-space: nowrap;
}

.study-body {
  gap: 10px;
  padding: 12px 18px 108px;
}

.knowledge-content {
  min-height: calc(100vh - 134px);
  line-height: 1.76;
}

.knowledge-content h1,
.knowledge-content h2,
.knowledge-content h3 {
  margin: 0 0 8px;
  line-height: 1.35;
}

.knowledge-content h2 {
  font-size: 20px;
}

.study-actions {
  gap: 8px;
  justify-content: center;
  border-top: 0;
  padding: 8px 72px 8px 12px;
}

.study-actions .btn {
  width: auto;
  min-width: 118px;
  min-height: 36px;
  padding: 6px 12px;
  font-size: 14px;
}

.study-actions .btn.danger {
  color: var(--danger);
  background: #fff;
  border-color: #efc1bd;
}

.admin-shell .summary-grid {
  display: grid;
  position: static;
  width: auto;
  max-height: none;
  overflow: visible;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

@media (max-width: 620px) {
  .topbar {
    right: 10px;
    bottom: 10px;
  }

  .mobile-menu {
    width: 42px;
    min-height: 42px;
  }

  .mobile-utility-menu {
    right: 10px;
    bottom: 58px;
  }

  .app-shell .summary-grid {
    right: 10px;
    left: 10px;
    bottom: 58px;
    width: auto;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mobile-progress-close {
    right: 18px;
    bottom: 60px;
  }

  .study-header {
    padding: 7px 10px;
  }

  .study-title h2 {
    font-size: 16px;
  }

  .study-body {
    padding: 10px 12px 104px;
  }

  .knowledge-content {
    min-height: calc(100vh - 128px);
    font-size: 16px;
  }

  .study-actions {
    align-items: center;
    flex-direction: row;
    padding: 7px 60px 7px 8px;
  }

  .study-actions .btn {
    min-width: 0;
    flex: 1 1 0;
    padding: 6px 8px;
  }

  .app-shell .topbar {
    right: 10px !important;
    bottom: 10px !important;
  }

  .app-shell .mobile-utility-menu {
    right: 10px !important;
    bottom: 58px !important;
  }
}

/* Hard guard: the learning-page floating menu must always be reachable. */
.app-shell .topbar {
  position: fixed !important;
  right: 16px !important;
  bottom: 16px !important;
  top: auto !important;
  left: auto !important;
  z-index: 1000 !important;
  display: block !important;
  margin: 0 !important;
  pointer-events: auto;
}

.app-shell .mobile-menu {
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  width: 46px !important;
  min-width: 46px !important;
  min-height: 46px !important;
  border-radius: 999px !important;
  pointer-events: auto;
}

.app-shell .mobile-utility-menu {
  right: 16px !important;
  bottom: 70px !important;
  top: auto !important;
  left: auto !important;
  z-index: 1001 !important;
}

.app-shell .mobile-utility-menu .btn {
  display: inline-flex !important;
}

/* Final full-screen catalog learning layout. */
body.catalog-open,
body.modal-open {
  overflow: hidden;
}

.app-shell {
  display: block !important;
  min-height: 100vh;
  background-color: rgba(247, 249, 246, 0.94);
}

.main {
  min-height: 100vh;
  padding: 0 !important;
}

.app-shell .summary-grid {
  display: none !important;
}

.catalog-overlay,
.app-shell .sidebar {
  position: fixed !important;
  inset: 0 !important;
  z-index: 900 !important;
  width: 100vw !important;
  height: 100vh !important;
  overflow: auto;
  border: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(244, 248, 246, 0.98)),
    var(--surface);
  box-shadow: none;
  transform: translateY(100%);
  transition: transform 0.22s ease;
  pointer-events: none;
}

.catalog-overlay.open,
.app-shell .sidebar.open {
  transform: translateY(0);
  pointer-events: auto;
}

.catalog-inner,
.sidebar-inner {
  width: min(1180px, 100%);
  min-height: 100%;
  margin: 0 auto;
  padding: 26px clamp(16px, 4vw, 42px) 96px;
}

.catalog-header,
.sidebar-header {
  position: sticky;
  top: 0;
  z-index: 2;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 0 0 18px;
  background: rgba(255, 255, 255, 0.96);
}

.catalog-subtitle {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.course-tree {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  align-content: start;
  padding-top: 22px;
}

.course-block {
  align-self: start;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.course-toggle {
  padding: 14px;
}

.course-toggle small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.chapter-list {
  gap: 8px;
  padding: 0 12px 14px;
}

.chapter-node {
  gap: 6px;
}

.chapter-button {
  grid-template-columns: minmax(0, 1fr) auto;
  border: 1px solid transparent;
  padding-left: calc(10px + var(--chapter-depth, 0) * 12px);
}

.chapter-button.locked,
.knowledge-link.locked,
.profile-record[data-locked="true"] {
  color: #8a949e;
  cursor: not-allowed;
  background: #f5f7f7;
}

.chapter-button.active {
  border-color: rgba(15, 118, 110, 0.22);
}

.status-pill.locked {
  color: #7c8792;
  background: #edf0f1;
}

.chapter-detail-list {
  margin-left: calc(16px + var(--chapter-depth, 0) * 12px);
  padding-left: 12px;
}

.chapter-children {
  margin-left: 0;
  padding-left: 0;
  border-left: 0;
}

.catalog-footer {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 14px 0 0;
  background: rgba(255, 255, 255, 0.96);
}

.catalog-footer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.app-shell .topbar {
  position: fixed !important;
  left: 16px !important;
  right: auto !important;
  bottom: 16px !important;
  top: auto !important;
  z-index: 1000 !important;
  display: block !important;
}

.app-shell .catalog-toggle,
.app-shell .mobile-menu {
  display: inline-flex !important;
  width: auto !important;
  min-width: 86px !important;
  min-height: 44px !important;
  border-radius: 999px !important;
  padding: 0 18px !important;
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
  box-shadow: 0 12px 28px rgba(17, 94, 89, 0.26);
  font-size: 15px !important;
}

.app-shell .catalog-toggle::before,
.app-shell .mobile-menu::before {
  content: none !important;
}

.app-shell .catalog-toggle.is-open {
  background: var(--ink);
  border-color: var(--ink);
}

.mobile-utility-menu,
.mobile-progress-close,
.app-shell .topbar-actions,
.app-shell #showSidebar {
  display: none !important;
}

.study-panel {
  min-height: 100vh;
  border: 0 !important;
  border-radius: 0 !important;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: none !important;
}

.study-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line) !important;
  padding: 16px clamp(14px, 4vw, 38px) !important;
}

.study-title h2 {
  margin: 0 0 3px;
  font-size: 20px;
}

#courseTitle {
  display: block !important;
}

.page-controls {
  position: static !important;
  inset: auto !important;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  overflow: visible;
  border-radius: 0;
  padding: 0;
  background: transparent;
}

.page-controls .btn {
  width: auto;
}

.study-body {
  width: min(980px, 100%);
  margin: 0 auto;
  gap: 24px;
  padding: 26px clamp(14px, 4vw, 34px) 110px;
}

.knowledge-content {
  min-height: calc(100vh - 226px);
  font-size: 17px;
}

.knowledge-content h2 {
  margin-top: 0;
  font-size: 24px;
}

.knowledge-html {
  overflow-wrap: anywhere;
}

.knowledge-html span[style*="background"],
.knowledge-html font[style*="background"],
.knowledge-html [style*="background-color"] {
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  padding: 0 0.08em;
}

.view-progress {
  margin-top: 22px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  color: var(--muted);
  font-size: 14px;
}

.view-progress.complete {
  color: var(--success);
}

.question-section.hidden {
  display: none !important;
}

.question-card.pending {
  border-color: #ead7b8;
}

.question-card.correct {
  border-color: #b9e4c8;
}

.result-tag.neutral {
  color: var(--muted);
  background: #eef2f2;
}

.study-actions {
  position: sticky;
  bottom: 0;
  z-index: 45;
  justify-content: center;
  border-top: 1px solid var(--line) !important;
  padding: 12px 16px 12px 116px !important;
}

.study-actions .btn {
  width: auto;
  min-width: 124px;
}

.modal-backdrop {
  z-index: 1100;
}

.modal {
  position: relative;
  width: min(920px, calc(100vw - 32px));
  max-height: min(86vh, 760px);
  padding: 22px;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 3;
}

.modal h3 {
  margin: 0 46px 16px 0;
  font-size: 20px;
}

.profile-shell {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 18px;
  min-height: 520px;
}

.profile-menu {
  display: grid;
  align-content: start;
  gap: 8px;
  border-right: 1px solid var(--line);
  padding-right: 14px;
}

.profile-menu-button {
  width: 100%;
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--ink);
  background: transparent;
  text-align: left;
}

.profile-menu-button.active,
.profile-menu-button:hover {
  color: #fff;
  background: var(--brand);
}

.profile-panel {
  min-width: 0;
  overflow: auto;
  padding-right: 4px;
}

.search-result {
  width: 100%;
  text-align: left;
}

.profile-catalog,
.profile-course {
  display: grid;
  gap: 8px;
}

.profile-course {
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.profile-chapter {
  margin-left: calc(var(--chapter-depth, 0) * 14px);
}

@media (max-width: 780px) {
  .catalog-inner,
  .sidebar-inner {
    padding: 18px 14px 86px;
  }

  .course-tree {
    grid-template-columns: 1fr;
  }

  .catalog-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .study-header {
    align-items: stretch;
    flex-direction: column;
  }

  .page-controls {
    justify-content: flex-start;
  }

  .study-title h2 {
    font-size: 18px;
  }

  .knowledge-content {
    min-height: calc(100vh - 260px);
    font-size: 16px;
  }

  .study-actions {
    padding-left: 108px !important;
  }

  .study-actions .btn {
    min-width: 0;
    flex: 1 1 0;
  }

  .profile-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .profile-menu {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0 0 12px;
  }

  .profile-grid,
  .profile-course-row,
  .two-col,
  .three-col,
  .four-col {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .app-shell .topbar {
    left: 10px !important;
    bottom: 10px !important;
  }

  .app-shell .catalog-toggle,
  .app-shell .mobile-menu {
    min-width: 76px !important;
    min-height: 40px !important;
    padding: 0 14px !important;
  }

  .study-actions {
    gap: 8px;
    padding: 8px 8px 8px 94px !important;
  }

  .study-actions .btn {
    padding: 6px 8px;
    font-size: 14px;
  }

  .profile-menu {
    grid-template-columns: 1fr;
  }
}

/* Final locked learning layout: desktop sidebar, mobile drawer, clean study surface. */
body.catalog-open,
body.modal-open {
  overflow: hidden;
}

.learning-layout {
  display: grid !important;
  min-height: 100vh;
  grid-template-columns: 320px minmax(0, 1fr) !important;
  background-color: rgba(247, 249, 246, 0.94);
  transition: grid-template-columns 0.22s ease;
}

.learning-layout.sidebar-collapsed {
  grid-template-columns: 0 minmax(0, 1fr) !important;
}

.learning-layout .learning-sidebar {
  position: sticky !important;
  inset: auto !important;
  top: 0 !important;
  z-index: 30 !important;
  width: 320px !important;
  height: 100vh !important;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: none !important;
  transform: none !important;
  pointer-events: auto !important;
}

.learning-layout.sidebar-collapsed .learning-sidebar {
  width: 0 !important;
  min-width: 0 !important;
  overflow: hidden;
  border-right: 0;
  transform: translateX(-100%) !important;
}

.learning-layout .sidebar-inner {
  width: auto !important;
  min-height: 100%;
  margin: 0 !important;
  grid-template-rows: auto 1fr auto;
  padding: 18px !important;
}

.learning-layout .sidebar-header {
  position: static !important;
  border-bottom: 1px solid var(--line);
  padding: 0 0 14px !important;
  background: transparent !important;
}

.catalog-subtitle {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.learning-layout .course-tree {
  display: grid;
  grid-template-columns: 1fr !important;
  gap: 10px;
  align-content: start;
  padding-top: 14px;
}

.learning-layout .course-block {
  align-self: stretch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

.learning-layout .course-toggle {
  padding: 12px;
}

.learning-layout .course-toggle small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.learning-layout .chapter-list {
  display: grid;
  gap: 6px;
  padding: 0 10px 12px;
}

.learning-layout .chapter-button {
  grid-template-columns: minmax(0, 1fr) auto;
  border: 1px solid transparent;
  padding-left: calc(10px + var(--chapter-depth, 0) * 12px);
}

.learning-layout .chapter-button.locked,
.learning-layout .knowledge-link.locked,
.profile-record[data-locked="true"] {
  color: #8a949e;
  cursor: not-allowed;
  background: #f5f7f7;
}

.learning-layout .chapter-button.active {
  border-color: rgba(15, 118, 110, 0.24);
}

.learning-layout .status-pill.locked {
  color: #7c8792;
  background: #edf0f1;
}

.learning-layout .chapter-detail-list {
  margin-left: calc(16px + var(--chapter-depth, 0) * 12px);
  padding-left: 12px;
}

.learning-layout .chapter-children {
  margin-left: 0;
  padding-left: 0;
  border-left: 0;
}

.learning-layout .sidebar-footer {
  position: sticky;
  bottom: 0;
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  background: rgba(255, 255, 255, 0.98);
}

.sidebar-actions {
  display: grid;
  gap: 8px;
}

.sidebar-actions .btn {
  width: 100%;
}

.mobile-sidebar-close {
  display: none !important;
}

.sidebar-toggle {
  position: fixed;
  top: 50%;
  left: 320px;
  z-index: 60;
  width: 30px;
  height: 58px;
  transform: translate(-50%, -50%);
  border: 1px solid var(--line);
  border-radius: 0 999px 999px 0;
  color: var(--brand-strong);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 22px rgba(31, 41, 51, 0.12);
  font-size: 24px;
  line-height: 1;
}

.learning-layout.sidebar-collapsed .sidebar-toggle {
  left: 0;
  transform: translate(0, -50%);
}

.learning-layout .learning-main {
  min-width: 0;
  min-height: 100vh;
  padding: 0 !important;
}

.learning-layout .topbar {
  display: none !important;
}

.learning-layout .summary-grid {
  display: none !important;
}

.learning-layout .study-panel {
  min-height: 100vh;
  border: 0 !important;
  border-radius: 0 !important;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: none !important;
}

.learning-layout.has-page-background .learning-sidebar,
.learning-layout.has-page-background .study-header,
.learning-layout.has-page-background .study-actions {
  background: rgba(255, 255, 255, 0.9) !important;
  backdrop-filter: blur(8px);
}

.learning-layout.has-page-background .study-panel {
  background: rgba(255, 255, 255, 0.82) !important;
}

.learning-layout .study-header {
  position: sticky;
  top: 0;
  z-index: 25;
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line) !important;
  padding: 14px clamp(18px, 3vw, 36px) !important;
  background: rgba(255, 255, 255, 0.98);
}

.learning-layout .study-title h2 {
  margin: 0 0 3px;
  font-size: 20px;
  line-height: 1.32;
}

.learning-layout #courseTitle {
  display: block !important;
}

.learning-layout .page-controls {
  position: static !important;
  inset: auto !important;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  overflow: visible;
  border-radius: 0;
  padding: 0;
  background: transparent;
}

.learning-layout .page-controls .btn {
  width: auto;
  min-height: 34px;
  padding: 7px 11px;
}

.learning-layout .study-body {
  width: min(1180px, 100%);
  margin: 0 auto;
  gap: 0;
  padding: 28px clamp(18px, 4vw, 42px) 108px;
}

.learning-layout .knowledge-content {
  min-height: calc(100vh - 220px);
  font-size: 17px;
  line-height: 1.82;
}

.learning-layout .knowledge-content h2 {
  margin-top: 0;
  font-size: 25px;
}

.learning-layout .knowledge-html {
  overflow-wrap: anywhere;
}

.learning-layout .view-progress {
  margin-top: 22px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  color: var(--muted);
  font-size: 14px;
}

.learning-layout .view-progress.complete {
  color: var(--success);
}

.learning-layout .question-section,
.learning-layout .question-section.hidden {
  display: none !important;
}

.learning-layout .study-actions {
  position: sticky;
  bottom: 0;
  z-index: 26;
  justify-content: center;
  border-top: 1px solid var(--line) !important;
  padding: 12px 16px !important;
  background: rgba(255, 255, 255, 0.98);
}

.learning-layout .study-actions .btn {
  width: auto;
  min-width: 124px;
}

.modal-backdrop {
  z-index: 1100;
}

.modal {
  position: relative;
  width: min(920px, calc(100vw - 32px));
  max-height: min(86vh, 760px);
  padding: 22px;
}

.question-modal-open .modal {
  width: min(980px, calc(100vw - 28px));
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 3;
}

.modal h3 {
  margin: 0 46px 16px 0;
  font-size: 20px;
}

.answer-modal-intro {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: #40505e;
  background: #f7faf9;
}

.answer-modal-intro p {
  margin: 0;
}

.question-card.pending {
  border-color: #ead7b8;
}

.question-card.correct {
  border-color: #b9e4c8;
}

.result-tag.neutral {
  color: var(--muted);
  background: #eef2f2;
}

.profile-shell {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 18px;
  min-height: 520px;
}

.profile-menu {
  display: grid;
  align-content: start;
  gap: 8px;
  border-right: 1px solid var(--line);
  padding-right: 14px;
}

.profile-menu-button {
  width: 100%;
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--ink);
  background: transparent;
  text-align: left;
}

.profile-menu-button.active,
.profile-menu-button:hover {
  color: #fff;
  background: var(--brand);
}

.profile-panel {
  min-width: 0;
  overflow: auto;
  padding-right: 4px;
}

.search-result {
  width: 100%;
  text-align: left;
}

.profile-catalog,
.profile-course {
  display: grid;
  gap: 8px;
}

.profile-course {
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.profile-chapter {
  margin-left: calc(var(--chapter-depth, 0) * 14px);
}

@media (max-width: 860px) {
  .learning-layout,
  .learning-layout.sidebar-collapsed {
    display: block !important;
    grid-template-columns: none !important;
  }

  .learning-layout .learning-sidebar,
  .learning-layout.sidebar-collapsed .learning-sidebar {
    position: fixed !important;
    inset: 0 auto 0 0 !important;
    z-index: 900 !important;
    width: min(86vw, 340px) !important;
    height: 100vh !important;
    overflow: auto;
    border-right: 1px solid var(--line);
    transform: translateX(-100%) !important;
    box-shadow: var(--shadow) !important;
    pointer-events: none !important;
  }

  .learning-layout .learning-sidebar.open {
    transform: translateX(0) !important;
    pointer-events: auto !important;
  }

  .learning-layout .sidebar-inner {
    padding: 16px !important;
  }

  .mobile-sidebar-close {
    display: inline-flex !important;
    position: static !important;
  }

  .sidebar-toggle {
    display: none;
  }

  .learning-layout .topbar {
    position: fixed !important;
    top: 12px !important;
    left: 12px !important;
    right: auto !important;
    bottom: auto !important;
    z-index: 500 !important;
    display: block !important;
    margin: 0 !important;
  }

  .learning-layout .catalog-toggle {
    display: inline-flex !important;
    width: auto !important;
    min-width: 72px !important;
    min-height: 38px !important;
    border-radius: 999px !important;
    padding: 0 14px !important;
    color: #fff;
    background: var(--brand);
    border-color: var(--brand);
    box-shadow: 0 10px 22px rgba(17, 94, 89, 0.22);
    font-size: 14px !important;
  }

  .learning-layout .catalog-toggle::before {
    content: none !important;
  }

  .learning-layout .study-header {
    align-items: stretch;
    flex-direction: column;
    padding: 56px 14px 10px !important;
  }

  .learning-layout .study-title h2 {
    font-size: 18px;
  }

  .learning-layout .page-controls {
    justify-content: flex-start;
    gap: 6px;
  }

  .learning-layout .page-controls .btn {
    min-height: 31px;
    padding: 5px 8px;
    font-size: 13px;
  }

  .learning-layout .study-body {
    padding: 16px 14px 98px;
  }

  .learning-layout .knowledge-content {
    min-height: calc(100vh - 256px);
    font-size: 16px;
  }

  .learning-layout .study-actions {
    gap: 8px;
    padding: 8px 10px !important;
  }

  .learning-layout .study-actions .btn {
    min-width: 0;
    flex: 1 1 0;
  }

  .profile-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .profile-menu {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0 0 12px;
  }

  .profile-grid,
  .profile-course-row,
  .two-col,
  .three-col,
  .four-col {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .learning-layout .profile-menu {
    grid-template-columns: 1fr;
  }

  .learning-layout .modal {
    width: calc(100vw - 18px);
    padding: 18px;
  }
}

/* Final hard locks for the agreed learning surface. */
.learning-layout #mobileMenuBtn,
.learning-layout .catalog-toggle {
  display: none !important;
}

.learning-layout .question-section,
.learning-layout .question-section *,
.learning-layout #shortQuestions,
.learning-layout #practiceQuestions {
  display: none !important;
}

@media (max-width: 860px) {
  .learning-layout #mobileMenuBtn,
  .learning-layout .catalog-toggle {
    display: inline-flex !important;
  }
}

.learning-layout.sidebar-collapsed {
  grid-template-columns: minmax(0, 1fr) !important;
}

.learning-layout.sidebar-collapsed .learning-sidebar {
  position: fixed !important;
  inset: 0 auto 0 0 !important;
  width: 320px !important;
  transform: translateX(-100%) !important;
  pointer-events: none !important;
}

.learning-layout.sidebar-collapsed .learning-main {
  grid-column: 1 / -1 !important;
}

/* Final desktop reading optimization and global search placement. */
body,
.auth-page,
.admin-shell,
.learning-layout {
  background-image: var(--page-bg-image, none) !important;
  background-repeat: var(--page-bg-repeat, no-repeat) !important;
  background-position: var(--page-bg-position, center) !important;
  background-size: var(--page-bg-size, cover) !important;
  background-attachment: var(--page-bg-attachment, fixed) !important;
}

.auth-page,
.admin-shell,
.learning-layout {
  background-color: rgba(247, 249, 246, 0.9) !important;
}

.learning-layout .sidebar-inner {
  grid-template-rows: auto auto minmax(0, 1fr) auto !important;
  gap: 14px !important;
}

.catalog-search-panel,
.knowledge-search-block {
  display: grid;
  gap: 9px;
}

.catalog-search-panel {
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.search-label,
.knowledge-search-block h4 {
  margin: 0;
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
}

.catalog-search-panel input,
.knowledge-search-block input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  outline: none;
}

.catalog-search-panel input:focus,
.knowledge-search-block input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.catalog-search-results {
  max-height: 240px;
  overflow: auto;
}

.catalog-search-results .muted {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
}

.catalog-search-results .profile-record {
  padding: 8px 9px;
  font-size: 13px;
}

.search-result {
  gap: 4px;
}

.search-result em {
  display: block;
  color: var(--muted);
  font-style: normal;
  line-height: 1.55;
}

.search-result mark {
  border-radius: 3px;
  padding: 0 2px;
  color: inherit;
  background: #fff0a8;
}

.profile-mobile-search {
  display: none !important;
}

.learning-layout .study-header {
  min-height: 58px !important;
  padding: 10px clamp(18px, 3vw, 36px) !important;
}

.learning-layout .study-body {
  width: min(1160px, 100%);
  min-height: calc(100vh - 132px);
  padding: clamp(22px, 3vh, 34px) clamp(22px, 5vw, 68px) 92px !important;
}

.learning-layout .knowledge-content {
  min-height: calc(100vh - 174px) !important;
}

.learning-layout .study-actions {
  display: flex !important;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px !important;
}

.learning-layout .study-actions .page-controls {
  display: flex !important;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center !important;
  gap: 8px;
}

.learning-layout .study-actions .page-indicator {
  min-width: 112px;
}

.learning-layout .page-icon-btn {
  width: 38px !important;
  min-width: 38px !important;
  height: 36px;
  min-height: 36px !important;
  padding: 0 !important;
  font-size: 24px;
  line-height: 1;
}

.learning-layout .display-mode-btn,
.learning-layout .theme-btn {
  min-width: 92px;
}

.tts-word-display {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid rgba(15, 118, 110, 0.16);
  border-radius: 8px;
  padding: clamp(14px, 2.4vw, 22px);
  background: rgba(255, 255, 255, 0.72);
}

.tts-char {
  border-radius: 3px;
  transition: color 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}

.tts-char.active {
  color: #0f3d37;
  background: #f8d96a;
  box-shadow: 0 0 0 2px rgba(248, 217, 106, 0.45);
}

.visual-reading .tts-char {
  color: rgba(31, 41, 51, 0.28);
}

.visual-reading .tts-char.visual-seen {
  color: inherit;
}

.page-turn-next {
  animation: pageTurnNext 260ms ease;
}

.page-turn-prev {
  animation: pageTurnPrev 260ms ease;
}

@keyframes pageTurnNext {
  from {
    opacity: 0.35;
    transform: translateX(18px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes pageTurnPrev {
  from {
    opacity: 0.35;
    transform: translateX(-18px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

body[data-learning-theme="warm"] {
  --bg: #f7f2e8;
  --surface-soft: #fbf4e6;
  --line: #e3d7c6;
  --brand: #9a5b18;
  --brand-strong: #74430e;
  --accent: #0f766e;
}

body[data-learning-theme="paper"] {
  --bg: #eef5ef;
  --surface-soft: #edf7f0;
  --line: #cddfd1;
  --brand: #28745a;
  --brand-strong: #1e5c47;
  --accent: #7c5a10;
}

body[data-learning-theme="warm"] .learning-layout .study-panel,
body[data-learning-theme="warm"] .learning-layout .study-header,
body[data-learning-theme="warm"] .learning-layout .study-actions {
  background: rgba(255, 250, 240, 0.97);
}

body[data-learning-theme="paper"] .learning-layout .study-panel,
body[data-learning-theme="paper"] .learning-layout .study-header,
body[data-learning-theme="paper"] .learning-layout .study-actions {
  background: rgba(248, 253, 248, 0.97);
}

@media (max-width: 860px) {
  .catalog-search-panel {
    display: none !important;
  }

  .profile-mobile-search {
    display: grid !important;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 14px;
  }

  .learning-layout .study-body {
    min-height: calc(100vh - 176px);
    padding: 18px 14px 116px !important;
  }

  .learning-layout .knowledge-content {
    min-height: calc(100vh - 292px) !important;
  }

  .learning-layout .study-actions {
    align-items: stretch;
  }

  .learning-layout .study-actions .page-controls {
    flex: 1 1 100%;
  }

  .learning-layout .study-actions .page-controls .btn {
    flex: 1 1 0;
  }

  .learning-layout .page-icon-btn {
    flex: 0 0 38px !important;
  }

  .learning-layout .display-mode-btn,
  .learning-layout .theme-btn {
    flex: 1 1 88px !important;
    min-width: 88px;
  }
}

/* Final admin polish, subject tabs, copyright, wrong-book page, and mobile speaker control. */
.admin-main {
  padding: 18px !important;
}

.admin-section {
  gap: 12px !important;
}

.panel {
  padding: 14px !important;
}

.table-wrap {
  border: 1px solid var(--line) !important;
  border-radius: 6px !important;
  background: #fff;
}

table {
  border-collapse: separate !important;
  border-spacing: 0 !important;
}

th,
td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 7px 9px !important;
  vertical-align: middle !important;
  line-height: 1.45;
}

th:last-child,
td:last-child {
  border-right: 0;
}

th {
  background: #edf5f2 !important;
}

tr:last-child td {
  border-bottom: 0;
}

.table-actions {
  align-items: center;
  gap: 6px !important;
}

.table-actions .btn {
  min-height: 30px;
  border-radius: 5px;
  padding: 5px 9px;
  font-size: 13px;
}

.subject-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 12px;
}

.subject-tab {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 12px;
  color: var(--ink);
  background: #fff;
}

.subject-tab.active,
.subject-tab:hover {
  color: #fff;
  border-color: var(--brand);
  background: var(--brand);
}

.code-textarea {
  min-height: 110px !important;
  font-family: Consolas, "Courier New", monospace;
}

.copyright-info {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.copyright-info p {
  margin: 0;
}

.admin-shell .copyright-info {
  display: none !important;
}

.learning-layout #copyrightInfo {
  display: none !important;
}

.wrongbook-mode .study-actions .page-controls,
.wrongbook-mode #resetBtn,
.wrongbook-mode #completeBtn {
  display: none !important;
}

.wrongbook-mode .study-actions {
  min-height: 0;
  padding: 0 !important;
  border-top: 0 !important;
}

.wrongbook-page {
  display: block;
}

.wrongbook-list {
  display: grid;
  gap: 14px;
}

.wrongbook-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: rgba(255, 255, 255, 0.96);
}

.wrongbook-head,
.wrongbook-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.wrongbook-head span,
.wrongbook-answer,
.wrongbook-analysis {
  color: var(--muted);
  font-size: 14px;
}

.wrongbook-card p {
  margin: 10px 0;
}

@media (max-width: 860px) {
  .learning-layout #speechBtn {
    position: fixed !important;
    right: 12px;
    bottom: 72px;
    z-index: 420;
    width: 38px !important;
    min-width: 38px !important;
    height: 38px;
    min-height: 38px !important;
    overflow: hidden;
    border-radius: 999px;
    padding: 0 !important;
    color: var(--brand-strong);
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 8px 20px rgba(31, 41, 51, 0.14);
    font-size: 0 !important;
  }

  .learning-layout #speechBtn::before {
    content: "\1F50A";
    font-size: 17px;
    line-height: 1;
  }

  .admin-main {
    padding: 12px !important;
  }

  .table-actions .btn {
    flex: 1 1 auto;
  }
}

/* Stage one, three and four: draggable mobile catalog plus AI Q&A. */
.floating-catalog-btn {
  display: none;
}

.learning-layout .ai-ask-btn {
  min-width: 78px;
  color: #0f4f49;
  border-color: rgba(15, 118, 110, 0.28);
  background: rgba(236, 253, 245, 0.94);
}

.learning-layout .ai-ask-btn:hover {
  color: #fff;
  border-color: var(--brand);
  background: var(--brand);
}

.ai-modal-open .modal {
  width: min(680px, calc(100vw - 28px));
}

.ai-chat-shell {
  display: grid;
  gap: 12px;
}

.ai-context {
  border: 1px solid rgba(15, 118, 110, 0.16);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--muted);
  background: rgba(236, 253, 245, 0.72);
  line-height: 1.7;
}

.ai-question-input {
  width: 100%;
  min-height: 116px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  resize: vertical;
  outline: none;
}

.ai-question-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.ai-toolbar {
  justify-content: flex-end;
}

.ai-answer-box {
  min-height: 84px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.92);
  line-height: 1.85;
}

.ai-answer-box strong {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
}

.ai-answer-box p {
  margin: 0 0 10px;
}

.ai-answer-box p:last-child {
  margin-bottom: 0;
}

.ai-answer-box.error {
  color: #b42318;
  border-color: rgba(180, 35, 24, 0.28);
  background: rgba(255, 247, 245, 0.94);
}

@media (max-width: 860px) {
  .learning-layout #mobileMenuBtn,
  .learning-layout .catalog-toggle {
    display: none !important;
  }

  .floating-catalog-btn {
    position: fixed;
    right: 12px;
    bottom: 124px;
    z-index: 520;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 50%;
    color: #fff;
    background: rgba(15, 118, 110, 0.62);
    box-shadow: 0 10px 26px rgba(17, 94, 89, 0.22);
    backdrop-filter: blur(8px);
    cursor: grab;
    font-size: 21px;
    line-height: 1;
    touch-action: none;
  }

  .floating-catalog-btn:active {
    cursor: grabbing;
  }

  .floating-catalog-btn.is-open {
    background: rgba(180, 83, 9, 0.68);
  }

  .learning-layout .ai-ask-btn {
    flex: 1 1 74px !important;
    min-width: 74px !important;
  }
}

/* DeepSeek multi-turn chat mode. */
.ai-modal-open .modal {
  width: min(760px, calc(100vw - 28px));
}

.ai-chat-shell {
  grid-template-rows: auto minmax(260px, 52vh) auto;
}

.ai-chat-messages {
  display: grid;
  align-content: start;
  gap: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(248, 250, 252, 0.86);
}

.ai-message {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.ai-message.user {
  grid-template-columns: minmax(0, 1fr) 34px;
}

.ai-message-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #fff;
  background: var(--brand);
  font-size: 12px;
  font-weight: 700;
}

.ai-message.user .ai-message-avatar {
  order: 2;
  background: #0052cc;
}

.ai-message-content {
  width: fit-content;
  max-width: min(560px, 100%);
  border: 1px solid rgba(15, 118, 110, 0.14);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  line-height: 1.75;
}

.ai-message.user .ai-message-content {
  justify-self: end;
  color: #fff;
  border-color: #0052cc;
  background: #0052cc;
}

.ai-message.error .ai-message-content {
  color: #b42318;
  border-color: rgba(180, 35, 24, 0.28);
  background: rgba(255, 247, 245, 0.94);
}

.ai-message-content p {
  margin: 0 0 8px;
}

.ai-message-content p:last-child {
  margin-bottom: 0;
}

.ai-message-content strong {
  font-weight: 700;
}

.ai-message-content code {
  border-radius: 4px;
  padding: 1px 4px;
  background: rgba(15, 118, 110, 0.08);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.95em;
}

.ai-chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px;
  gap: 10px;
  align-items: end;
}

.ai-chat-form .ai-question-input {
  min-height: 52px;
  max-height: 130px;
  resize: vertical;
}

.ai-chat-form .btn {
  min-height: 52px;
}

@media (max-width: 860px) {
  .ai-chat-shell {
    grid-template-rows: auto minmax(240px, 50vh) auto;
  }

  .ai-chat-form {
    grid-template-columns: 1fr;
  }

  .ai-chat-form .btn {
    width: 100%;
  }
}

/* AI legal chat window: keep the supplied blue bubble layout. */
.ai-modal-open .modal {
  width: min(750px, calc(100vw - 28px));
  padding: 0 !important;
  overflow: hidden;
  border: 0;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);
}

.ai-modal-open .modal h3 {
  display: none;
}

.ai-modal-open .modal-content {
  padding: 0;
}

.ai-modal-open .modal-close {
  top: 10px;
  right: 10px;
  z-index: 2;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.52);
  background: rgba(255, 255, 255, 0.16);
}

.ai-chat-wrap {
  width: 100%;
  max-width: 750px;
  height: min(650px, calc(100vh - 44px));
  margin: 0 auto;
  background: #fff;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  height: 55px;
  flex: 0 0 55px;
  background: #1677ff;
  color: #fff;
  text-align: center;
  line-height: 55px;
  font-size: 17px;
  font-weight: 500;
}

.chat-main {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background-color: #f9fafb;
}

.chat-main.ai-chat-messages {
  display: block;
  align-content: normal;
  gap: 0;
  border: 0;
  border-radius: 0;
  padding: 20px;
  background-color: #f9fafb;
}

.chat-item {
  display: flex;
  margin-bottom: 18px;
}

.chat-item.ai-message {
  display: flex;
  grid-template-columns: none;
  gap: 0;
  align-items: stretch;
}

.chat-item.user-chat.ai-message {
  grid-template-columns: none;
}

.user-chat {
  justify-content: flex-end;
}

.user-text {
  max-width: 70%;
  background: #1677ff;
  color: #fff;
  padding: 10px 16px;
  border-radius: 18px 18px 4px 18px;
  line-height: 1.6;
  font-size: 14px;
}

.ai-chat {
  justify-content: flex-start;
}

.ai-text {
  max-width: 70%;
  background: #fff;
  border: 1px solid #e5e7eb;
  color: #333;
  padding: 10px 16px;
  border-radius: 18px 18px 18px 4px;
  line-height: 1.6;
  font-size: 14px;
}

.ai-message.pending .ai-text {
  color: #6b7280;
}

.ai-message.pending .ai-text::after {
  content: "";
  display: inline-block;
  width: 1.25em;
  margin-left: 2px;
  text-align: left;
  animation: aiThinkingDots 1.2s steps(4, end) infinite;
}

@keyframes aiThinkingDots {
  0% {
    content: "";
  }
  25% {
    content: ".";
  }
  50% {
    content: "..";
  }
  75%,
  100% {
    content: "...";
  }
}

.chat-footer {
  height: 75px;
  flex: 0 0 75px;
  padding: 15px;
  border-top: 1px solid #eee;
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-input {
  flex: 1;
  height: 42px;
  min-height: 42px;
  max-height: 42px;
  border: 1px solid #dcdcdc;
  border-radius: 21px;
  padding: 0 20px;
  outline: none;
  font-size: 14px;
  resize: none;
}

.chat-input:focus {
  border-color: #1677ff;
  box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.12);
}

.send-btn {
  width: 85px;
  height: 42px;
  min-height: 42px;
  border: none;
  background: #1677ff;
  color: #fff;
  border-radius: 21px;
  cursor: pointer;
  font-size: 14px;
}

.send-btn:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

.learning-layout #copyrightInfo,
.learning-layout .sidebar-footer .copyright-info {
  display: none !important;
}

@media (max-width: 860px) {
  .ai-chat-wrap {
    height: min(620px, calc(100vh - 28px));
  }

  .user-text,
  .ai-text {
    max-width: 82%;
  }
}

/* Mobile-only final learning action layout. PC keeps the original controls. */
@media (max-width: 860px) {
  .learning-layout .study-body {
    min-height: calc(100vh - 142px) !important;
    padding: 14px 12px calc(116px + env(safe-area-inset-bottom)) !important;
  }

  .learning-layout .knowledge-content {
    min-height: calc(100vh - 236px) !important;
  }

  .learning-layout .study-actions {
    position: fixed !important;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 620;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: 40px 48px;
    gap: 8px !important;
    align-items: stretch !important;
    justify-content: stretch !important;
    border-top: 1px solid rgba(209, 213, 219, 0.9) !important;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom)) !important;
    background: rgba(255, 255, 255, 0.98) !important;
    box-shadow: 0 -10px 30px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(12px);
  }

  .learning-layout.has-page-background .study-actions {
    background: rgba(255, 255, 255, 0.92) !important;
  }

  .learning-layout .study-actions .page-controls {
    grid-column: 1 / -1;
    display: grid !important;
    grid-template-columns: 38px 38px 46px repeat(3, 38px) 46px;
    justify-content: space-between;
    gap: 4px;
    align-items: center;
    width: 100%;
    min-width: 0;
    flex: none !important;
  }

  .learning-layout .study-actions .page-controls > * {
    min-width: 0;
  }

  .learning-layout #prevPage {
    order: 1;
  }

  .learning-layout #nextPage {
    order: 2;
  }

  .learning-layout .page-indicator {
    order: 3;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 38px;
    width: 46px;
    border: 1px solid rgba(15, 118, 110, 0.18);
    border-radius: 10px;
    padding: 0 5px;
    color: #34515a;
    background: rgba(248, 250, 252, 0.94);
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
  }

  .learning-layout #themeBtn {
    order: 4;
  }

  .learning-layout #displayModeBtn {
    order: 5;
  }

  .learning-layout #speechBtn {
    order: 6;
    position: static !important;
    right: auto !important;
    bottom: auto !important;
    z-index: auto !important;
    overflow: visible;
    box-shadow: none;
    font-size: 0 !important;
  }

  .learning-layout #resetBtn {
    order: 7;
  }

  .learning-layout #speechBtn::before {
    content: none !important;
  }

  .learning-layout .study-actions .page-controls .btn,
  .learning-layout .study-actions .page-controls #resetBtn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 38px !important;
    min-width: 38px !important;
    height: 38px !important;
    min-height: 38px !important;
    border: 1px solid rgba(15, 118, 110, 0.2);
    border-radius: 10px;
    padding: 0 !important;
    color: #0f766e;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: none;
    flex: 0 0 38px !important;
    touch-action: manipulation;
  }

  .learning-layout .study-actions .page-controls #resetBtn {
    width: 46px !important;
    min-width: 46px !important;
    color: #0f766e;
    font-size: 13px !important;
    font-weight: 700;
  }

  .learning-layout .study-actions .page-controls .btn:disabled {
    color: #a8b4ba;
    border-color: rgba(148, 163, 184, 0.18);
    background: rgba(248, 250, 252, 0.78);
  }

  .learning-layout .page-icon-btn {
    font-size: 24px !important;
    line-height: 1;
  }

  .learning-layout .mobile-action-icon {
    font-size: 0 !important;
  }

  .learning-layout .mobile-action-icon svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.85;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .learning-layout .mobile-action-text {
    display: none;
  }

  .learning-layout .study-actions > #aiAskBtn,
  .learning-layout .study-actions > #completeBtn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 48px !important;
    border-radius: 12px;
    padding: 0 12px !important;
    font-size: 15px;
    font-weight: 700;
    touch-action: manipulation;
  }

  .learning-layout .study-actions > #aiAskBtn {
    grid-column: 1;
    grid-row: 2;
    color: #0f4f49;
    border-color: rgba(15, 118, 110, 0.24);
    background: rgba(236, 253, 245, 0.96);
  }

  .learning-layout .study-actions > #completeBtn {
    grid-column: 2;
    grid-row: 2;
  }

  .mobile-reset-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(15, 23, 42, 0.36);
    backdrop-filter: blur(5px);
  }

  .mobile-reset-backdrop.hidden {
    display: none !important;
  }

  .mobile-reset-dialog {
    width: min(342px, calc(100vw - 32px));
    border: 1px solid rgba(226, 232, 240, 0.95);
    border-radius: 16px;
    padding: 20px;
    color: var(--ink);
    background: #fff;
    box-shadow: 0 22px 60px rgba(15, 23, 42, 0.22);
  }

  .mobile-reset-dialog h3 {
    margin: 0 0 10px;
    font-size: 18px;
    line-height: 1.35;
  }

  .mobile-reset-dialog p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.75;
  }

  .mobile-reset-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 18px;
  }

  .mobile-reset-actions .btn {
    min-width: 0;
    min-height: 42px;
    border-radius: 10px;
    font-weight: 700;
  }
}

@media (min-width: 861px) {
  .mobile-reset-backdrop {
    display: none !important;
  }
}
