/* ===== Teach Site — base ===== */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #38bdf8;
  --sidebar-hover: #334155;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --accent: #0ea5e9;
  --accent-soft: #e0f2fe;
  --success: #059669;
  --success-bg: #ecfdf5;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --danger-soft: #fef2f2;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.04);
  --sidebar-w: 280px;
  --header-h: 56px;
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC",
    system-ui, -apple-system, sans-serif;
  --mono: "SF Mono", "Cascadia Code", "Consolas", "Menlo", monospace;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.65;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ===== Layout ===== */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.25s ease;
  overflow: hidden;
}

.sidebar-brand {
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.sidebar-brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: #f8fafc;
  letter-spacing: 0.02em;
}

.sidebar-brand .sub {
  margin-top: 0.25rem;
  font-size: 0.78rem;
  color: #94a3b8;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.75rem 0.75rem 1.5rem;
}

.course-label {
  font-size: 0.72rem;
  text-transform: none;
  letter-spacing: 0.04em;
  color: #94a3b8;
  padding: 0.5rem 0.75rem 0.35rem;
  font-weight: 600;
}

.nav-unit {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--sidebar-text);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.25rem;
  border-radius: 8px;
  cursor: pointer;
  line-height: 1.4;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.nav-unit:hover {
  background: var(--sidebar-hover);
  color: #f1f5f9;
}

.nav-unit.active {
  background: rgba(56, 189, 248, 0.15);
  color: var(--sidebar-active);
  font-weight: 600;
}

.nav-unit .badge {
  display: inline-block;
  margin-left: 0.35rem;
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: #f59e0b;
  color: #1e293b;
  font-weight: 700;
  vertical-align: middle;
}

.nav-unit .dur {
  display: block;
  font-size: 0.72rem;
  color: #64748b;
  margin-top: 0.15rem;
  font-weight: 400;
}

.nav-unit.active .dur {
  color: #7dd3fc;
}

.sidebar-foot {
  padding: 0.75rem 1rem;
  font-size: 0.72rem;
  color: #64748b;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

/* Main */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
}

.menu-btn {
  display: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.menu-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  position: relative;
}
.menu-btn span::before,
.menu-btn span::after {
  content: "";
  position: absolute;
  left: 0;
  width: 18px;
  height: 2px;
  background: var(--text);
}
.menu-btn span::before {
  top: -5px;
}
.menu-btn span::after {
  top: 5px;
}

.topbar-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.content {
  padding: 1.5rem 1.75rem 3rem;
  max-width: 820px;
  width: 100%;
}

/* Overview / unit cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.1rem;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.25rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.card h3 {
  margin: 0 0 0.6rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.meta-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.meta-list li {
  padding: 0.4rem 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  border-bottom: 1px dashed var(--border);
}
.meta-list li:last-child {
  border-bottom: none;
}
.meta-list strong {
  color: var(--text);
  font-weight: 600;
  margin-right: 0.35rem;
}

.section-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

.tag-obj {
  background: var(--accent-soft);
  color: #0369a1;
}
.tag-key {
  background: #f0fdf4;
  color: #15803d;
}
.tag-pit {
  background: var(--warn-bg);
  color: #b45309;
}
.tag-ex {
  background: #f5f3ff;
  color: #6d28d9;
}

.bullet-list {
  margin: 0;
  padding-left: 1.25rem;
}
.bullet-list li {
  margin-bottom: 0.45rem;
}
.bullet-list li:last-child {
  margin-bottom: 0;
}

.formula {
  font-family: var(--mono);
  font-size: 0.92em;
  background: #f1f5f9;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  white-space: pre-wrap;
  word-break: break-word;
}

.badge-core {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  background: #fef3c7;
  color: #92400e;
}

.unit-header-meta {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: -0.35rem 0 1rem;
}

/* Exercises */
.exercise {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.75rem;
  overflow: hidden;
  background: #fafbfc;
}

.exercise-q {
  padding: 0.85rem 1rem;
  font-size: 0.95rem;
}

.exercise-q .num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  margin-right: 0.5rem;
  flex-shrink: 0;
  vertical-align: middle;
}

.answer-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.55rem 1rem;
  background: #f1f5f9;
  border: none;
  border-top: 1px solid var(--border);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px; /* touch-friendly */
}

.answer-toggle:hover {
  background: #e2e8f0;
  color: var(--text);
}

.answer-toggle .chevron {
  transition: transform 0.2s;
  font-size: 0.75rem;
}

.answer-toggle[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.answer-toggle[aria-expanded="true"] {
  color: var(--success);
  background: var(--success-bg);
}

.answer-body {
  display: none;
  padding: 0.85rem 1rem;
  background: var(--success-bg);
  border-top: 1px solid #a7f3d0;
  color: #065f46;
  font-size: 0.95rem;
}

.answer-body.open {
  display: block;
}

.answer-body .label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #047857;
  margin-bottom: 0.25rem;
}

/* Loading / error */
.state-msg {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.error-msg {
  color: #b91c1c;
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

/* Overlay for mobile sidebar */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 90;
}
.overlay.show {
  display: block;
}

/* ===== Responsive: tablet & phone ===== */
@media (max-width: 1024px) {
  :root {
    --sidebar-w: 260px;
  }
  .content {
    padding: 1.25rem 1.35rem 2.5rem;
  }
}

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main {
    margin-left: 0;
  }
  .menu-btn {
    display: inline-flex;
  }
  .content {
    padding: 1.1rem 1rem 2.5rem;
    max-width: none;
  }
  .card {
    padding: 1.1rem 1.15rem;
  }
}

@media (max-width: 480px) {
  html {
    font-size: 15px;
  }
  .topbar {
    padding: 0 0.75rem;
  }
  .exercise-q {
    padding: 0.75rem 0.85rem;
  }
}

@media (min-width: 768px) and (max-width: 1024px) {
  /* iPad-friendly: comfortable tap targets & readable type */
  .nav-unit {
    padding: 0.8rem 0.9rem;
    font-size: 0.92rem;
    min-height: 48px;
  }
  .answer-toggle {
    min-height: 48px;
  }
  .content {
    max-width: 720px;
    margin: 0 auto;
  }
}

/* Print */
@media print {
  .sidebar,
  .topbar,
  .overlay,
  .answer-toggle {
    display: none !important;
  }
  .main {
    margin-left: 0;
  }
  .answer-body {
    display: block !important;
  }
}

/* ===== Quiz + User (interactive) ===== */
.topbar {
  justify-content: flex-start;
}
.user-bar {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  max-width: 55%;
}
.user-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: none;
}
@media (min-width: 640px) {
  .user-label { display: inline; }
}
.user-name {
  font-size: 0.88rem;
  color: var(--text);
  max-width: 8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-btn {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  min-height: 36px;
  -webkit-tap-highlight-color: transparent;
}
.user-btn.ghost {
  background: transparent;
  color: var(--text-muted);
}
.user-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.65rem 1.2rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}
.btn.primary {
  background: var(--accent);
  color: #fff;
}
.btn.primary:hover {
  background: #0284c7;
}
.btn.ghost {
  background: #f1f5f9;
  color: var(--text-muted);
  border-color: var(--border);
}

.quiz-hint {
  margin: 0 0 0.85rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.q-type {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  margin-right: 0.4rem;
  vertical-align: middle;
}
.q-type.single {
  background: var(--accent-soft);
  color: #0369a1;
}
.q-type.multi {
  background: #f5f3ff;
  color: #6d28d9;
}
.q-result {
  display: inline-block;
  margin-left: 0.5rem;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  vertical-align: middle;
}
.q-result.ok {
  background: var(--success-bg);
  color: var(--success);
}
.q-result.bad {
  background: var(--danger-soft);
  color: #b91c1c;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0 0.85rem 0.9rem;
}
.option {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 0.92rem;
  line-height: 1.45;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, background 0.15s;
}
.option:hover {
  border-color: #7dd3fc;
  background: #f0f9ff;
}
.option input {
  margin-top: 0.2rem;
  width: 1.1rem;
  height: 1.1rem;
  flex-shrink: 0;
  accent-color: var(--accent);
}
.option .opt-key {
  font-weight: 700;
  color: var(--accent);
  min-width: 1.2rem;
}
.option .opt-text {
  flex: 1;
}
.option:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.option.reveal-correct {
  border-color: #34d399;
  background: var(--success-bg);
}
.option.reveal-wrong {
  border-color: #f87171;
  background: var(--danger-soft);
}
.quiz-item.is-correct {
  border-color: #a7f3d0;
}
.quiz-item.is-wrong {
  border-color: #fecaca;
}

.answer-reveal {
  padding: 0.75rem 1rem;
  background: var(--success-bg);
  border-top: 1px solid #a7f3d0;
  color: #065f46;
  font-size: 0.9rem;
}
.answer-reveal .label {
  font-size: 0.72rem;
  font-weight: 700;
  color: #047857;
  margin-bottom: 0.2rem;
}
.answer-reveal .explain {
  margin-top: 0.35rem;
  color: #047857;
  font-size: 0.85rem;
}

.quiz-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
}
.quiz-actions-hint {
  font-size: 0.85rem;
  color: #b45309;
}

.score-banner {
  margin-top: 1rem;
  padding: 0.9rem 1.1rem;
  border-radius: 8px;
  background: #f1f5f9;
  border: 1px solid var(--border);
  font-size: 0.95rem;
}
.score-banner.ok {
  background: var(--success-bg);
  border-color: #a7f3d0;
  color: #065f46;
}
.score-banner.low {
  background: var(--warn-bg);
  border-color: #fcd34d;
  color: #92400e;
}
.score-pill {
  color: #7dd3fc !important;
}

/* Modal */
.modal[hidden] {
  display: none !important;
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
}
.modal-panel {
  position: relative;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.2);
  padding: 1.4rem 1.5rem 1.25rem;
  width: 100%;
  max-width: 400px;
  z-index: 1;
}
.modal-title {
  margin: 0 0 0.4rem;
  font-size: 1.15rem;
}
.modal-desc {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}
#username-input {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  min-height: 44px;
}
#username-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2);
}
.field-error {
  color: #b91c1c;
  font-size: 0.85rem;
  margin: 0 0 0.5rem;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

@media (max-width: 480px) {
  .user-name { max-width: 5rem; }
  .option { padding: 0.55rem 0.65rem; }
}

@media print {
  .user-bar, .modal, .quiz-actions { display: none !important; }
  .answer-reveal { display: block !important; }
}

/* ===== PPT-style slides (v2-thick) ===== */
.slide-card {
  padding: 0;
  overflow: hidden;
}
.slide-deck {
  padding: 1.25rem 1.4rem 1.1rem;
}
.slide-chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}
.slide-counter {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  background: #f1f5f9;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.slide-title {
  margin: 0 0 0.85rem;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text);
}
.slide-body {
  min-height: 12rem;
  font-size: 1.08rem;
  line-height: 1.75;
  color: var(--text);
}
.slide-para {
  margin: 0 0 0.85rem;
}
.slide-para:last-child {
  margin-bottom: 0;
}
.slide-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.slide-nav .btn {
  min-width: 6.5rem;
}
.slide-jump-quiz {
  margin-left: auto;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.slide-jump-quiz:hover {
  text-decoration: none;
  border-color: var(--accent);
  color: var(--accent);
}
.slide-kbd-hint {
  margin: 0.65rem 0 0;
  font-size: 0.78rem;
  color: #94a3b8;
}
.slide-nav .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (min-width: 768px) {
  .slide-body {
    font-size: 1.15rem;
    min-height: 14rem;
  }
  .slide-title {
    font-size: 1.5rem;
  }
  .content {
    max-width: 880px;
  }
}

@media (max-width: 480px) {
  .slide-deck {
    padding: 1.05rem 1rem 1rem;
  }
  .slide-body {
    font-size: 1.02rem;
    min-height: 10rem;
  }
  .slide-jump-quiz {
    margin-left: 0;
    width: 100%;
  }
}

@media print {
  .slide-nav,
  .slide-kbd-hint {
    display: none !important;
  }
  .slide-body {
    min-height: 0;
  }
}


/* ===== Optional slide illustrations ===== */
.slide-main {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.slide-media:empty {
  display: none;
}
.slide-figure {
  margin: 0;
  padding: 0.65rem 0.75rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: center;
}
.slide-img {
  display: block;
  max-width: 100%;
  width: auto;
  height: auto;
  max-height: 280px;
  margin: 0 auto;
  object-fit: contain;
}
.slide-caption {
  margin: 0.45rem 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}
.slide-deck.has-image .slide-body {
  min-height: 0;
}

@media (min-width: 768px) {
  .slide-deck.has-image .slide-main {
    flex-direction: row;
    align-items: flex-start;
    gap: 1rem;
  }
  .slide-deck.has-image .slide-body {
    flex: 1 1 52%;
    min-width: 0;
    font-size: 1.08rem;
  }
  .slide-deck.has-image .slide-media {
    flex: 0 1 46%;
    min-width: 200px;
    max-width: 360px;
  }
  .slide-deck.has-image .slide-img {
    max-height: 260px;
  }
}

@media (max-width: 767px) {
  .slide-img {
    max-height: 220px;
  }
}

@media print {
  .slide-img {
    max-height: 200px;
  }
}
