﻿/* ==========================================================================
   1. 设计系统与根变量 (Design System & Variables)
   ========================================================================== */
:root {
  /* 自然简约主题色 (Natural theme - Light Sage) */
  --bg-color: #F7F9F6;
  --panel-bg: #FFFFFF;
  --primary-color: #2D5A27;
  --primary-light: #E1ECE2;
  --primary-hover: #1E3F19;
  --accent-color: #4F8549;
  --text-main: #233322;
  --text-muted: #5F745E;
  --border-color: #E2EBE2;
  --danger-color: #A34E36;
  --danger-light: #FCECE8;
  --success-color: #3B7A57;
  --success-light: #E8F4EE;
  
  /* 苹果玻璃质感变量 (Sage Green Style) */
  --glass-bg: rgba(247, 249, 246, 0.55);
  --glass-border: rgba(45, 90, 39, 0.12);
  --blur-radius: 20px;
  --saturate-amount: 190%;
  
  /* 阴影与圆角 (Shadows & Border Radius) */
  --shadow-sm: 0 2px 4px rgba(45, 90, 39, 0.04);
  --shadow-md: 0 8px 16px rgba(45, 90, 39, 0.06);
  --shadow-lg: 0 16px 32px rgba(45, 90, 39, 0.08);
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  
  /* 字体与间距 (Typography & Spacing) */
  --font-main: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-title: 'Outfit', 'Noto Sans SC', sans-serif;
  --transition-speed: 0.3s;
}

/* 深色模式变量 (Dark Sage Theme) */
body.dark-theme {
  --bg-color: #111A10;
  --panel-bg: #1A2519;
  --primary-color: #4F8549;
  --primary-light: #243522;
  --primary-hover: #67AB5E;
  --accent-color: #83B67C;
  --text-main: #E2ECE1;
  --text-muted: #8E9F8D;
  --border-color: #283726;
  
  /* 苹果玻璃质感深色变量 */
  --glass-bg: rgba(22, 33, 21, 0.65);
  --glass-border: rgba(255, 255, 255, 0.08);
  
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 16px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 32px rgba(0, 0, 0, 0.4);
}

/* ==========================================================================
   1.1 动态流光背景样式 (Dynamic Glow Background)
   ========================================================================== */
.glow-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.glow-ball {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.45;
  mix-blend-mode: multiply;
  animation: float 25s infinite alternate ease-in-out;
}

body.dark-theme .glow-ball {
  opacity: 0.22;
  mix-blend-mode: screen;
}

.glow-ball-1 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, var(--primary-color) 0%, transparent 70%);
  top: -10%;
  left: -10%;
  animation-duration: 20s;
}

.glow-ball-2 {
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, var(--accent-color) 0%, transparent 70%);
  bottom: -10%;
  right: -10%;
  animation-duration: 28s;
  animation-delay: -5s;
}

.glow-ball-3 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, #83b67c 0%, transparent 70%);
  top: 40%;
  left: 50%;
  animation-duration: 22s;
  animation-delay: -10s;
}

@keyframes float {
  0% {
    transform: translate(0, 0) scale(1) rotate(0deg);
  }
  50% {
    transform: translate(80px, 50px) scale(1.15) rotate(180deg);
  }
  100% {
    transform: translate(-40px, 80px) scale(0.9) rotate(360deg);
  }
}

/* ==========================================================================
   2. 基础重置与布局 (Reset & Global Styles)
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
  font-family: var(--font-main);
  background-color: var(--bg-color);
  color: var(--text-main);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* 按钮与表单重置 */
button, input {
  font-family: inherit;
}

/* ==========================================================================
   3. 布局结构 (App Layout)
   ========================================================================== */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  position: relative;
}

/* 侧边栏样式 */
.sidebar {
  width: 320px;
  height: 100%;
  background-color: var(--glass-bg);
  backdrop-filter: blur(var(--blur-radius)) saturate(var(--saturate-amount));
  -webkit-backdrop-filter: blur(var(--blur-radius)) saturate(var(--saturate-amount));
  border-right: 1px solid var(--glass-border);
  box-shadow: var(--shadow-sm), inset -1px 0 0 rgba(255, 255, 255, 0.2);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1), margin-left var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
  position: relative;
}

/* 玻璃质感噪点叠加 */
.sidebar::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 99;
  filter: url(#noise-filter);
  opacity: 0.08;
}

.sidebar-header {
  padding: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-img {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

.logo-text h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary-color);
  font-family: var(--font-title);
  letter-spacing: 0.5px;
}

.logo-text span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* 章节列表 */
.chapter-list-container {
  flex-grow: 1;
  overflow-y: auto;
  padding: 8px 16px 24px;
}

.list-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 1px;
  margin-bottom: 12px;
  padding-left: 12px;
}

.chapter-list {
  list-style: none;
}

.chapter-item {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.92rem;
  color: var(--text-main);
  margin-bottom: 4px;
  transition: all var(--transition-speed) ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.chapter-item:hover {
  background-color: var(--bg-color);
  transform: translateX(4px);
}

.chapter-item.active {
  background-color: var(--primary-light);
  color: var(--primary-color);
  font-weight: 500;
}

/* 章节列表中的状态标签 */
.status-badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 500;
}

.status-badge.done {
  background-color: var(--success-light);
  color: var(--success-color);
}

.status-badge.pending {
  background-color: #ECECEC;
  color: #777777;
}

.sidebar-badges {
  display: flex;
  gap: 4px;
  align-items: center;
}

.status-badge.custom-badge {
  background-color: #FFF3E0;
  color: #E65100;
  border: 1px solid #FFE0B2;
}

body.dark-theme .status-badge.custom-badge {
  background-color: #3E2723;
  color: #FFB74D;
  border: 1px solid #5D4037;
}

/* 侧边栏遮罩 */
.sidebar-overlay {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
  z-index: 90;
}

/* 主内容区域 */
.main-content {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 顶部导航栏 */
.top-bar {
  height: 70px;
  padding: 0 24px;
  background-color: var(--glass-bg);
  backdrop-filter: blur(var(--blur-radius)) saturate(var(--saturate-amount));
  -webkit-backdrop-filter: blur(var(--blur-radius)) saturate(var(--saturate-amount));
  border-bottom: 1px solid var(--glass-border);
  box-shadow: var(--shadow-sm), inset 0 -1px 0 rgba(255, 255, 255, 0.2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  position: relative;
}

.top-bar::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 99;
  filter: url(#noise-filter);
  opacity: 0.08;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.current-chapter-info h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.current-chapter-info span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

#current-chapter-pages {
  display: none !important;
}

.toggle-btn {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-main);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  width: 44px;
  min-width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-speed);
}

.toggle-btn:hover {
  background-color: var(--bg-color);
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-mode-tabs {
  position: relative;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  padding: 4px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-color);
}

.top-mode-tab {
  display: inline-flex;
  min-width: 0;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 11px;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color var(--transition-speed), background-color var(--transition-speed), color var(--transition-speed);
}

.top-mode-tab:hover,
.top-mode-tab:focus-visible {
  border-color: var(--border-color);
  color: var(--primary-color);
}

.top-mode-tab.is-active {
  border-color: var(--primary-color);
  background: var(--primary-light);
  color: var(--primary-color);
}

.top-mode-tab[hidden] {
  display: none;
}

.theme-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  width: 44px;
  min-width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-color);
  transition: transform var(--transition-speed);
}

.theme-btn:hover {
  transform: rotate(30deg);
}

/* ==========================================================================
   4. 标签页组件 (Tab Layout)
   ========================================================================== */
.tab-container {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tab-nav {
  display: flex;
  padding: 0 24px;
  background-color: var(--panel-bg);
  border-bottom: 1px solid var(--border-color);
  gap: 8px;
}

.tab-link {
  background: none;
  border: none;
  padding: 16px 20px;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all var(--transition-speed);
  display: flex;
  align-items: center;
  gap: 6px;
}

.tab-link:hover {
  color: var(--primary-color);
}

.tab-link.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
  font-weight: 600;
}

.tab-content-container {
  flex-grow: 1;
  overflow: hidden;
  position: relative;
}

.tab-content {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  padding: 24px;
  overflow-y: auto;
}

.tab-content.active {
  display: block;
}

/* ==========================================================================
   5. 思维导图面板 (Mindmap Tab)
   ========================================================================== */
.mindmap-container {
  width: 100%;
  flex: 1;
  min-height: 0;
  position: relative;
  background-color: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#mindmap-iframe {
  width: 100%;
  flex: 1;
  min-height: 0;
  border: none;
}

.mindmap-version-toggle {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 110;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px;
  border: 1px solid rgba(47, 107, 47, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.10);
}

.mindmap-version-toggle[hidden] {
  display: none !important;
}

.mindmap-version-btn {
  min-width: 34px;
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 750;
  cursor: pointer;
}

.mindmap-version-btn:hover,
.mindmap-version-btn:focus-visible {
  background: rgba(47, 107, 47, 0.10);
  color: var(--primary-color);
}

.mindmap-version-btn.active {
  background: var(--primary-color);
  color: #fff;
  box-shadow: 0 4px 10px rgba(47, 107, 47, 0.22);
}

body.dark-theme .mindmap-version-toggle {
  background: rgba(30, 41, 59, 0.92);
  border-color: rgba(255, 255, 255, 0.15);
}

body.dark-theme .mindmap-version-btn.active {
  background: #86bf7d;
  color: #11210f;
}

.mindmap-actions {
  flex: 0 0 auto;
  flex-shrink: 0;
  position: relative;
  padding: 10px 16px;
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.mindmap-level-controls {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-right: auto;
  padding: 3px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--panel-bg);
}

.mindmap-level-btn {
  min-height: 32px;
  padding: 5px 9px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 650;
  cursor: pointer;
}

.mindmap-level-btn:hover,
.mindmap-level-btn:focus-visible {
  background: var(--primary-light);
  color: var(--primary-color);
}

.mindmap-level-btn[aria-pressed="true"] {
  background: var(--primary-light);
  color: var(--primary-color);
  box-shadow: inset 0 0 0 1px var(--primary-color);
}

.mindmap-actions .btn {
  min-height: 40px;
  padding: 8px 12px;
}

.mindmap-actions svg,
.top-mode-tab svg,
.theme-btn svg,
.settings-btn svg,
.toggle-btn svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.tool-menu {
  position: relative;
}

.tool-menu > summary {
  min-width: 88px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 12px;
  border-radius: 5px;
  background: var(--primary-light);
  color: var(--primary-color);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.tool-menu > summary::-webkit-details-marker {
  display: none;
}

.tool-menu > summary svg,
.tool-menu-item svg {
  width: 17px;
  height: 17px;
}

.tool-menu-popover {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  z-index: 30;
  width: 210px;
  padding: 6px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--panel-bg);
  box-shadow: var(--shadow-md);
}

.tool-menu-item {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-main);
  font: inherit;
  font-size: 0.82rem;
  text-align: left;
  cursor: pointer;
}

.tool-menu-item:hover,
.tool-menu-item:focus-visible {
  background: var(--primary-light);
  color: var(--primary-color);
}

/* ==========================================================================
   6. 3D 闪卡背诵面板 (Flashcard Tab)
   ========================================================================== */
.flashcards-container {
  width: 100%;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 18px 20px 24px;
  overflow-y: auto;
  box-sizing: border-box;
}

.flashcards-active-area {
  width: 100%;
  max-width: 920px;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 12px;
  box-sizing: border-box;
}

.flashcards-active-area.is-csv-editing .card-scene-wrapper,
.flashcards-active-area.is-csv-editing .card-bottom-controls,
.flashcards-active-area.is-inline-editing .card-bottom-controls {
  display: none;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* 闪卡顶部进度 */
.flashcard-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 0 0 auto;
  flex-shrink: 0;
}

.flashcard-header-row {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.flashcard-control-group {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.flashcard-tool-btn,
.flashcard-save-btn,
.flashcard-cancel-btn {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5px 7px;
  border: 1px solid var(--border-color);
  border-radius: 5px;
  background: var(--panel-bg);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.76rem;
  font-weight: 650;
  cursor: pointer;
}

.flashcard-tool-btn svg,
.flashcard-save-btn svg,
.flashcard-cancel-btn svg {
  width: 15px;
  height: 15px;
}

.flashcard-tool-btn:hover,
.flashcard-tool-btn:focus-visible,
.flashcard-cancel-btn:hover,
.flashcard-cancel-btn:focus-visible {
  background: var(--primary-light);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.flashcard-tool-danger:hover,
.flashcard-tool-danger:focus-visible {
  color: var(--danger-color);
  border-color: var(--danger-color);
}

.flashcard-save-btn {
  color: white;
  background: var(--primary-color);
  border-color: var(--primary-color);
}

.flashcard-save-btn:hover,
.flashcard-save-btn:focus-visible {
  filter: brightness(0.94);
}

.flashcard-edit-local {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border: 1px solid var(--border-color);
  border-radius: 5px;
  background: var(--panel-bg);
  color: var(--primary-color);
  font: inherit;
  font-size: 0.76rem;
  font-weight: 650;
  cursor: pointer;
}

.flashcard-edit-local:hover,
.flashcard-edit-local:focus-visible {
  background: var(--primary-light);
  border-color: var(--primary-color);
}

.flashcard-edit-local svg {
  width: 15px;
  height: 15px;
}

/* Question-book cards retain their original ① / （1） numbering. */
.card-answer-text .question-book-answer-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.card-answer-text .question-book-answer-list > li {
  margin: 0 0 0.82em;
  padding: 0;
  line-height: 1.92;
}

.card-answer-text .question-book-answer-list > li.answer-list-level-1,
.card-answer-text .question-book-answer-list > li[data-answer-level="1"] {
  margin-top: 0.95em;
}

.card-answer-text .question-book-answer-list > li.answer-list-level-1:first-child,
.card-answer-text .question-book-answer-list > li[data-answer-level="1"]:first-child {
  margin-top: 0;
}

.card-answer-text .question-book-answer-list > li.answer-list-level-2,
.card-answer-text .question-book-answer-list > li[data-answer-level="2"] {
  margin-left: 1.05em;
  padding-left: 0.78em;
  border-left: 2px solid color-mix(in srgb, var(--primary-color) 24%, transparent);
}

.card-answer-text .question-book-answer-list > li.answer-list-level-3,
.card-answer-text .question-book-answer-list > li[data-answer-level="3"] {
  margin-left: 2em;
  padding-left: 0.72em;
  border-left: 1px dashed color-mix(in srgb, var(--text-muted) 28%, transparent);
}

.card-answer-text .question-book-answer-list > li:last-child {
  margin-bottom: 0;
}

.flashcard-enter-immersive,
.flashcard-exit-immersive {
  width: 40px;
  height: 40px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.flashcard-enter-immersive {
  display: grid;
}

.flashcard-exit-immersive {
  display: none;
}

.flashcard-enter-immersive:hover,
.flashcard-enter-immersive:focus-visible,
.flashcard-exit-immersive:hover,
.flashcard-exit-immersive:focus-visible {
  background: var(--primary-light);
  color: var(--primary-color);
}

.flashcard-enter-immersive svg,
.flashcard-exit-immersive svg {
  width: 18px;
  height: 18px;
}

.progress-info {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 4px;
  font-size: 0.76rem;
  color: var(--text-muted);
  font-weight: 500;
}

.progress-info strong {
  color: var(--primary-color);
  font-size: 0.9rem;
}

.progress-bar-outer {
  width: 100%;
  height: 4px;
  background-color: var(--border-color);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-inner {
  height: 100%;
  width: 0%;
  background-color: var(--primary-color);
  border-radius: 4px;
  transition: width var(--transition-speed) ease;
}

/* 3D 翻转卡片容器 */
.card-scene {
  width: min(100%, 820px);
  margin-inline: auto;
  flex: 1;
  min-height: 200px;
  max-height: 560px;
  height: auto;
  perspective: 1000px; /* 3D 透视深度 */
}

.flashcard {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.42s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.flashcard:focus-visible {
  outline: 3px solid var(--accent-color);
  outline-offset: 4px;
}

.flashcard.is-flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden; /* 隐藏背面以防止重叠 */
  border-radius: 8px;
  padding: 26px 28px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  background-color: var(--panel-bg);
  overflow: hidden;
}

/* 卡片正面与背面配色 */
.card-front {
  justify-content: space-between;
}

.card-back {
  transform: rotateY(180deg); /* 背面翻转 180 度 */
  justify-content: space-between;
}

.card-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.card-tag {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
  padding: 4px 10px;
  background-color: var(--primary-light);
  color: var(--primary-color);
  border-radius: 12px;
  align-self: flex-start;
  white-space: nowrap;
}

.card-front .card-tag {
  display: none !important;
}

.card-front .card-meta-row {
  justify-content: flex-end;
}

.card-back .card-tag {
  background-color: var(--success-light);
  color: var(--success-color);
}

.card-question-text {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.6;
  color: var(--text-main);
  text-align: left;
  flex-grow: 1;
  display: flex;
  align-items: center;
  width: 100%;
  padding: 8px 12px;
  overflow: visible;
}

.card-answer-text-container {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: block;
  padding: 12px 0;
  /* 固定高度卡片内部滚动 */
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  scrollbar-color: transparent transparent;
}

.card-answer-text-container::-webkit-scrollbar {
  display: none;
}

.card-answer-text {
  font-size: 0.98rem;
  line-height: 1.96;
  color: var(--text-main);
  width: 100%;
  text-align: justify;
}

.card-answer-text ul {
  list-style-type: disc;
  padding-left: 20px;
  margin: 10px 0;
}

.card-answer-text ul ul {
  list-style-type: disc; /* Fixed: Enforce solid disc bullet to prevent browser default hollow circle 'o' looking like a Chinese period '。' */
  padding-left: 20px;
  margin: 5px 0;
}

.card-answer-text ol {
  padding-left: 20px;
  margin: 10px 0;
}

.card-answer-text li {
  margin-bottom: 12px;
  line-height: 1.92;
}

.card-question-text sub,
.card-question-text sup,
.card-answer-text sub,
.card-answer-text sup {
  font-size: 0.72em;
  line-height: 0;
}

.card-answer-text p,
.card-answer-text .material-point,
.card-answer-text .material-point-body,
.card-answer-text .answer-subpoint,
.card-answer-text .answer-detail,
.card-answer-text .answer-example {
  line-height: 1.96;
}

.card-answer-text .material-point {
  margin-bottom: 0.72em;
}

.card-answer-text .material-point-level-1 {
  display: block;
  margin: 1.05em 0 0.48em;
}

.card-answer-text .material-point-level-1:first-child {
  margin-top: 0.12em;
}

.card-answer-text .material-point-level-2 {
  display: block;
  margin: 0.26em 0 0.2em 1.12em;
  padding-left: 0.82em;
  border-left: 2px solid color-mix(in srgb, var(--primary-color) 22%, transparent);
}

.card-answer-text .material-point-level-3 {
  display: block;
  margin: 0.22em 0 0.18em 2.05em;
  padding-left: 0.72em;
  border-left: 1px dashed color-mix(in srgb, var(--text-muted) 28%, transparent);
  color: color-mix(in srgb, var(--text-main) 86%, var(--text-muted) 14%);
}

.card-answer-text .material-point-no {
  display: inline-block;
  min-width: 1.7em;
  margin-right: 0.18em;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  background: transparent !important;
}

.card-answer-text .material-point-no-level-1 {
  color: #ea580c;
}

.card-answer-text .material-point-no-level-2 {
  color: var(--primary-color);
}

.card-answer-text .material-point-no-level-3 {
  color: var(--text-muted);
}

.card-answer-text .material-point-title,
.card-answer-text .answer-structure-label {
  color: var(--primary-color);
  font-weight: 820;
}

.card-answer-text li.answer-list-level-2:not(.answer-example) {
  margin-left: 1.08em;
  padding-left: 0.78em;
  border-left: 2px solid color-mix(in srgb, var(--primary-color) 22%, transparent);
}

.card-answer-text li.answer-list-level-3:not(.answer-example) {
  margin-left: 2em;
  padding-left: 0.72em;
  border-left: 1px dashed color-mix(in srgb, var(--text-muted) 28%, transparent);
}

.card-answer-text table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 0.92rem;
  line-height: 1.5;
  background: var(--panel-bg, #fff);
  border-radius: var(--radius-sm, 6px);
  overflow: hidden;
  border: 1px solid var(--border-color, #e2e8f0);
}

.card-answer-text th,
.card-answer-text td {
  border: 1px solid var(--border-color, #e2e8f0);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}

.card-answer-text th,
.card-answer-text tr:first-child td {
  background: var(--bg-secondary, rgba(0, 0, 0, 0.04));
  font-weight: 600;
  color: var(--primary-color, #0284c7);
}

.card-answer-text .answer-section-title {
  margin: 14px 0 6px;
  font-size: 1rem;
  line-height: 1.5;
}

.card-answer-text .answer-section-title:first-child {
  margin-top: 2px;
}

.card-answer-text .answer-hierarchy > .answer-section-title {
  margin: 15px 0 7px;
  padding-bottom: 5px;
  border-bottom: 1px solid color-mix(in srgb, var(--border-color) 78%, transparent);
}

.card-answer-text .answer-hierarchy > .answer-section-title:first-child {
  margin-top: 0;
}

.card-answer-text .answer-section-list {
  margin: 5px 0 12px;
  padding-left: 23px;
}

.card-answer-text .answer-section-list > li {
  margin-bottom: 8px;
}

.card-answer-text .answer-section-list > li.answer-auto-heading {
  list-style: none;
  margin: 12px 0 7px;
  color: var(--primary-color);
  font-weight: 820;
}

.card-answer-text .answer-section-list > li.answer-auto-heading:first-child {
  margin-top: 2px;
}

.card-answer-text .answer-section-list > li.answer-auto-heading-level-2 {
  margin-left: 0.55em;
  color: color-mix(in srgb, var(--primary-color) 84%, var(--text-main) 16%);
}

.card-answer-text li.answer-auto-heading.answer-list-level-2:not(.answer-example),
.card-answer-text li.answer-auto-heading.answer-list-level-3:not(.answer-example) {
  padding-left: 0;
  border-left: 0;
}

.card-answer-text .answer-section-list > li.answer-auto-detail {
  margin-top: 4px;
  margin-bottom: 7px;
}

.card-answer-text .answer-section-list > li.answer-example {
  list-style: none;
  margin: 7px 0 9px 3px;
  padding: 7px 9px;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--text-muted) 6%, transparent);
  border-left: 2px solid color-mix(in srgb, var(--accent-color) 28%, transparent);
  border-radius: 0 4px 4px 0;
}

.card-answer-text .answer-structure-label {
  display: inline;
  margin-right: 3px;
}

.card-answer-text .answer-summary {
  margin: 2px 0 12px;
  padding: 9px 11px;
  border-left: 3px solid var(--accent-color);
  background: color-mix(in srgb, var(--accent-color) 7%, transparent);
  border-radius: 0 4px 4px 0;
  line-height: 1.65;
}

.card-answer-text .answer-major-list {
  margin: 6px 0 0;
  padding-left: 24px;
}

.card-answer-text .answer-major-list > li {
  margin-bottom: 14px;
  padding-left: 3px;
}

.card-answer-text .answer-subpoint,
.card-answer-text .answer-detail,
.card-answer-text .answer-example {
  margin: 6px 0 0;
  line-height: 1.65;
}

.card-answer-text .answer-subpoint {
  padding-left: 10px;
  border-left: 2px solid color-mix(in srgb, var(--accent-color) 22%, transparent);
}

.card-answer-text .answer-example {
  margin-left: 10px;
  padding: 6px 9px;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--text-muted) 6%, transparent);
  border-radius: 4px;
}

.card-answer-text li.answer-example {
  list-style: none;
}

.card-answer-text .answer-subexample,
.card-answer-text li.answer-example,
.card-answer-text p.answer-example,
.card-answer-text div.answer-example {
  border-left: 2px solid color-mix(in srgb, var(--accent-color) 28%, transparent);
}

@media (max-width: 430px) {
  .card-answer-text .answer-summary {
    padding: 8px 9px;
  }

  .card-answer-text .answer-major-list {
    padding-left: 21px;
  }

  .card-answer-text .answer-section-list {
    padding-left: 20px;
  }

  .card-answer-text .answer-subpoint,
  .card-answer-text .answer-example {
    margin-left: 0;
    padding-left: 8px;
  }
}

/* Premium Highlight Badges for Study Key Points */
.card-answer-text span[style*="#0284c7"],
.card-answer-text span[style*="#0d9488"],
.card-answer-text span[style*="#10b981"],
.card-answer-text span[style*="#e11d48"],
.card-answer-text span[style*="#ea580c"] {
  font-weight: inherit;
  padding: 0;
  border-radius: 2px;
  display: inline;
  margin: 0;
}

.card-answer-text span[style*="#0284c7"],
.card-answer-text span[style*="#0d9488"],
.card-answer-text span[style*="#10b981"],
.card-answer-text span[style*="#e11d48"],
.card-answer-text span[style*="#ea580c"] {
  background: transparent !important;
}

.card-answer-text.textbook-answer span[style*="color"] {
  color: inherit !important;
  background: transparent !important;
  padding: 0 !important;
  margin: 0 !important;
  border-radius: 0 !important;
}

.card-answer-text.textbook-answer strong {
  color: var(--text-main);
  font-weight: 820;
}

.card-answer-text.textbook-answer .answer-structure-label,
.card-answer-text.textbook-answer .material-point-title {
  color: var(--primary-color);
  font-weight: 820;
}

.tap-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
  border-top: 1px dashed var(--border-color);
  padding-top: 10px;
}

.tap-hint svg,
.card-page-source svg,
.card-nav svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.card-page-source-icon {
  display: block;
  color: var(--text-muted);
}

.card-nav,
.flashcards-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 0;
  flex: 0 0 auto;
  flex-shrink: 0;
}

.card-nav .btn {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border-color);
  background: var(--panel-bg);
}

/* ==========================================================================
   7. 指南与说明面板 (About Tab)
   ========================================================================== */
.guide-container {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.guide-section {
  background-color: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 28px;
  box-shadow: var(--shadow-sm);
}

.guide-section h3 {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.guide-section p {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* 数据看板 */
.stats-panel {
  display: flex;
  gap: 16px;
  margin: 24px 0 8px;
}

.stat-card {
  flex: 1;
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  text-align: center;
}

.stat-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary-color);
  font-family: var(--font-title);
  margin-bottom: 4px;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* 步骤指南 */
.steps-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.step-item {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.step-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--primary-light);
  color: var(--primary-color);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.step-info {
  font-size: 0.95rem;
  line-height: 1.6;
}

.anki-import-tip {
  background-color: var(--bg-color);
  border-left: 4px solid var(--accent-color);
  padding: 16px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.9rem;
  margin-top: 16px;
}

.anki-import-tip ol {
  margin-left: 20px;
  margin-top: 8px;
}

.anki-import-tip li {
  margin-bottom: 6px;
  line-height: 1.5;
}

.code-box {
  background-color: #1E251D;
  color: #C8E6C9;
  font-family: 'Courier New', Courier, monospace;
  padding: 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  line-height: 1.5;
  margin: 12px 0 20px;
  overflow-x: auto;
}

/* ==========================================================================
   8. 公用 UI 组件 (Button, Status MSG)
   ========================================================================== */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 24px;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-speed) ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-secondary {
  background-color: var(--primary-light);
  color: var(--primary-color);
}

.btn-secondary:hover {
  background-color: var(--border-color);
}

.btn-danger {
  background-color: var(--danger-light);
  color: var(--danger-color);
}

.btn-danger:hover {
  filter: brightness(0.95);
}

.btn-success {
  background-color: var(--success-light);
  color: var(--success-color);
}

.btn-success:hover {
  filter: brightness(0.95);
}

.btn-sm {
  padding: 8px 16px;
  font-size: 0.85rem;
}

/* 未生成提示层 */
.status-msg {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  flex-grow: 1;
  background-color: var(--panel-bg);
}

.status-icon {
  font-size: 3.5rem;
  margin-bottom: 16px;
}

.status-msg h3 {
  font-size: 1.25rem;
  margin-bottom: 8px;
}

.status-msg p {
  color: var(--text-muted);
  font-size: 0.92rem;
  max-width: 380px;
  line-height: 1.6;
}

/* 正在加载骨架 */
.loading-placeholder {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 20px;
}

/* ==========================================================================
   9. 响应式布局媒体查询 (Responsive CSS)
   ========================================================================== */

/* 手机和平板 (屏幕宽度小于 768px) */
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    transform: translateX(-100%); /* 隐藏侧边栏 */
    height: 100%;
    box-shadow: var(--shadow-lg);
  }
  
  .sidebar.open {
    transform: translateX(0); /* 展开侧边栏 */
  }
  
  .sidebar-overlay.open {
    display: block; /* 展示遮罩层 */
  }
  
  .top-bar {
    padding: 0 10px;
    height: 52px;
  }

  .top-bar .logo-text h2,
  .top-bar .current-chapter-info h2 {
    font-size: 0.92rem;
    margin: 0;
    line-height: 1.2;
  }

  .top-bar .current-chapter-info span {
    font-size: 0.68rem;
    display: none;
  }

  .top-mode-tabs {
    display: flex !important;
    overflow-x: auto !important;
    white-space: nowrap !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    max-width: 58vw;
    padding: 2px 4px;
    gap: 3px;
  }

  .top-mode-tabs::-webkit-scrollbar {
    display: none;
  }

  .top-mode-tab {
    flex-shrink: 0 !important;
    padding: 4px 8px !important;
    min-height: 30px !important;
    font-size: 0.75rem !important;
  }

  .main-content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .mindmap-container {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  #mindmap-iframe {
    flex: 1;
    min-height: 0;
  }

  .mindmap-actions {
    flex: 0 0 auto;
    flex-shrink: 0;
    padding: 6px 10px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    gap: 4px;
    overflow-x: auto;
    white-space: nowrap;
  }

  .mindmap-level-btn,
  .mindmap-actions .btn {
    padding: 4px 8px;
    font-size: 0.74rem;
    height: 30px;
    flex-shrink: 0;
  }
  
  .tab-nav {
    padding: 0 16px;
    overflow-x: auto; /* 支持横向滑动 */
    scrollbar-width: none; /* 隐藏 Firefox 滚动条 */
  }
  
  .tab-nav::-webkit-scrollbar {
    display: none; /* 隐藏 Webkit 滚动条 */
  }
  
  .tab-link {
    white-space: nowrap;
    padding: 14px 16px;
  }
  
  .tab-content {
    padding: 16px;
  }
  
  .card-scene {
    flex: 1;
    min-height: 180px;
    max-height: 560px;
    height: auto;
  }
  
  .card-face {
    padding: 16px 18px;
  }
  
  .card-question-text {
    font-size: 1.25rem;
  }
  
  .card-answer-text {
    font-size: 0.95rem;
  }
  
  .stats-panel {
    flex-direction: column;
    gap: 12px;
  }
  
}

/* 手机端收纳顶部模式 (Compact Mobile Header) */
body.compact-header .top-bar {
  height: 38px !important;
  padding: 0 8px !important;
}

body.compact-header .top-bar .logo-img,
body.compact-header .top-bar .current-chapter-info span {
  display: none !important;
}

body.compact-header .top-mode-tab {
  min-height: 26px !important;
  padding: 2px 6px !important;
  font-size: 0.7rem !important;
}

/* 大屏幕电脑适配 (提升视觉留白) */
@media (min-width: 1200px) {
  .flashcards-active-area {
    max-width: 920px;
  }
  
  .card-scene {
    height: 620px;
    min-height: 620px;
    max-height: 620px;
  }
}

/* 隐藏移动端专用元素 */
.mobile-only {
  display: none;
}

@media (max-width: 768px) {
  .mobile-only {
    display: block;
  }
}

/* Flashcard tablets use the chapter list as a drawer so the study card keeps a usable width. */
@media (min-width: 769px) and (max-width: 900px) {
  body.flashcard-page .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    width: min(88vw, 340px);
    height: 100%;
    margin-left: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  body.flashcard-page .sidebar.open {
    transform: translateX(0);
  }

  body.flashcard-page .sidebar-overlay.open {
    display: block;
  }

  body.flashcard-page .sidebar-toggle-trigger {
    display: none !important;
  }

  body.flashcard-page .mobile-only {
    display: block;
  }

  body.flashcard-page .main-content {
    min-width: 0;
  }
}

/* ==========================================================================
   10. 编辑器样式 (Editor Styles)
   ========================================================================== */
.editor-area {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  flex-grow: 1;
  padding: 16px;
  background-color: var(--panel-bg);
}

.editor-area textarea {
  width: 100%;
  height: 100%;
  flex-grow: 1;
  min-height: 250px;
  resize: none;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-family: 'Consolas', 'Courier New', Courier, monospace;
  font-size: 0.95rem;
  line-height: 1.6;
  background-color: var(--bg-color);
  color: var(--text-main);
  outline: none;
  transition: border-color var(--transition-speed);
}

.editor-area textarea:focus {
  border-color: var(--accent-color);
}

.editor-help-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  background-color: var(--primary-light);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  line-height: 1.4;
  border-left: 4px solid var(--primary-color);
}

.editor-title {
  font-weight: 750;
  color: var(--primary-color);
  margin-bottom: 12px;
}

#flashcard-visual-editor {
  gap: 14px;
  overflow: auto;
}

#flashcard-visual-editor label {
  display: grid;
  gap: 7px;
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 680;
}

#flashcard-visual-editor input,
#flashcard-visual-editor textarea,
.visual-editor-rich-input,
.visual-editor-rich-paragraph {
  width: 100%;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-color);
  color: var(--text-main);
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.7;
  outline: none;
  transition: border-color var(--transition-speed), box-shadow var(--transition-speed), background-color var(--transition-speed);
}

#flashcard-visual-editor input,
#flashcard-visual-editor textarea {
  padding: 12px 14px;
}

#visual-editor-list-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#visual-editor-list-container {
  display: grid;
  gap: 9px;
}

.visual-editor-item-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: start;
}

.visual-editor-level-2 {
  padding-left: 28px;
}

.visual-editor-level-3 {
  padding-left: 54px;
}

.visual-editor-item-no {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  min-height: 34px;
  border-radius: 9px;
  background: var(--primary-light);
  color: var(--primary-color);
  font-size: 0.78rem;
  font-weight: 820;
}

.visual-editor-level-2 .visual-editor-item-no {
  background: color-mix(in srgb, #dcfce7 78%, #ffffff 22%);
  color: #047857;
}

.visual-editor-level-3 .visual-editor-item-no {
  background: color-mix(in srgb, #f1f5f9 85%, #ffffff 15%);
  color: var(--text-muted);
}

.visual-editor-rich-input,
.visual-editor-rich-paragraph {
  min-height: 42px;
  padding: 10px 12px;
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: none;
}

.visual-editor-rich-paragraph {
  min-height: 180px;
}

.visual-editor-rich-input:focus,
.visual-editor-rich-paragraph:focus,
#flashcard-visual-editor input:focus,
#flashcard-visual-editor textarea:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-light) 75%, transparent);
}

.visual-editor-rich-input:empty::before,
.visual-editor-rich-paragraph:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  opacity: 0.72;
}

.visual-editor-row-actions {
  display: inline-flex;
  gap: 5px;
}

.visual-row-btn {
  width: 32px;
  min-width: 32px;
  height: 34px;
  padding: 0 !important;
  justify-content: center;
}

.format-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--primary-light);
}

.format-toolbar > span {
  color: var(--text-muted);
  font-size: 0.84rem;
  font-weight: 680;
}

/* 侧边栏折叠规则 (Desktop sidebar collapse) */
@media (min-width: 769px) {
  .sidebar.collapsed {
    margin-left: -320px;
  }
}

/* 设置卡片样式 (Settings card) */
.settings-card {
  padding: 20px;
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-top: 16px;
}
.settings-card h4 {
  font-size: 1.05rem;
  color: var(--primary-color);
  margin-bottom: 8px;
}
.settings-card p {
  font-size: 0.92rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.settings-card[data-global-settings-hub] {
  margin-top: 0;
}

.settings-section-label {
  margin: 18px 0 8px;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.08em;
}

/* details / summary 折叠面板 */
details.guide-details {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: var(--panel-bg);
  box-shadow: var(--shadow-sm);
  margin-top: 16px;
  overflow: hidden;
}
details.guide-details[open] {
  border-color: var(--primary-color);
}
summary.guide-summary {
  padding: 16px 24px;
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--primary-color);
  background-color: var(--primary-light);
  cursor: pointer;
  outline: none;
  user-select: none;
}
summary.guide-summary:hover {
  background-color: var(--border-color);
}
.details-content {
  padding: 24px;
  border-top: 1px solid var(--border-color);
  background-color: var(--panel-bg);
}
.details-content h4 {
  color: var(--primary-color);
  margin-bottom: 12px;
  font-size: 1.05rem;
}
.details-content p {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 16px;
}

/* 设置模态框相关样式 (Global Settings Modal) */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 900;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.settings-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  width: 90%;
  max-width: 700px;
  max-height: 85vh;
  background-color: var(--glass-bg);
  backdrop-filter: blur(var(--blur-radius)) saturate(var(--saturate-amount));
  -webkit-backdrop-filter: blur(var(--blur-radius)) saturate(var(--saturate-amount));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.settings-modal::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 99;
  filter: url(#noise-filter);
  opacity: 0.08;
}
.settings-modal.active {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

/* 旧设置项保留在源码中以兼容早期本地数据，但不再展示给学习者。 */
.settings-modal [hidden] {
  display: none !important;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--bg-color);
}
.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--primary-color);
  display: flex;
  align-items: center;
  gap: 8px;
}
.modal-close-btn {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--transition-speed);
}
.modal-close-btn:hover {
  background-color: var(--border-color);
  color: var(--text-main);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex-grow: 1;
}

.settings-action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.settings-action-grid .btn {
  width: 100%;
  min-height: 42px;
  white-space: normal;
}

/* 移除多余的标签导航之后，为主界面设置内边距修正 */
.single-mode-container {
  box-sizing: border-box;
  width: 100%;
  padding: 24px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* 在顶部工具栏的设置按钮样式 */
.settings-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  width: 44px;
  min-width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-color);
  transition: transform var(--transition-speed);
}
.settings-btn:hover {
  transform: rotate(45deg);
}

.unified-settings-btn {
  flex: 0 0 auto;
}

.global-settings-trigger {
  border: 1px solid var(--border-color);
  background: var(--panel-bg);
  color: var(--text-main);
}

/* ==========================================================================
   11. 书籍选择器与视图切换按钮 (Book Selector & View Switcher Styles)
   ========================================================================== */
.study-navigation {
  padding: 14px 20px 16px;
  border-bottom: 1px solid var(--border-color);
  background: color-mix(in srgb, var(--panel-bg) 88%, transparent);
}

.study-navigation-label {
  display: block;
  margin: 0 0 7px;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.2;
}

.study-navigation .book-select {
  margin-bottom: 0;
}

/* 微信/苹果风双按钮分段学科切换器 */
.subject-toggle-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: var(--bg-color);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.subject-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: calc(var(--radius-sm) - 2px);
  cursor: pointer;
  transition: all var(--transition-speed);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subject-toggle-btn:hover {
  color: var(--text-main);
  background: color-mix(in srgb, var(--primary-light) 40%, transparent);
}

.subject-toggle-btn.active,
.subject-toggle-btn[aria-selected="true"] {
  color: var(--primary-color);
  background: var(--panel-bg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}

/* 真题/模拟题双页模式 (Dual-Column Grid) */
.exam-scroll.dual-column #exam-question-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 18px;
  align-items: start;
}

@media (min-width: 900px) {
  .exam-scroll.dual-column #exam-question-groups {
    grid-template-columns: repeat(2, 1fr);
  }
}

.study-mode-menu {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.study-mode-link {
  display: flex;
  min-width: 0;
  min-height: 40px;
  align-items: center;
  gap: 6px;
  padding: 8px 9px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-color);
  color: var(--text-main);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.25;
  text-decoration: none;
  transition: border-color var(--transition-speed), background-color var(--transition-speed), color var(--transition-speed);
}

.study-mode-link:hover,
.study-mode-link:focus-visible {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.study-mode-link.is-active {
  border-color: var(--primary-color);
  background: var(--primary-light);
  color: var(--primary-color);
}

.study-mode-link[hidden] {
  display: none;
}

body.dark-theme .study-navigation {
  background: color-mix(in srgb, var(--panel-bg) 92%, transparent);
}

body.dark-theme .top-mode-tabs {
  background: var(--panel-bg);
}

.book-selector-container {
  position: relative;
  width: 100%;
  margin-top: 8px;
}

.book-select {
  width: 100%;
  padding: 8px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary-color);
  background-color: var(--primary-light);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='6' fill='%232D5A27'><path d='M0 0h12L6 6z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 28px;
  transition: all var(--transition-speed);
}

body.dark-theme .book-select {
  color: var(--text-main);
  background-color: var(--primary-light);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='6' fill='%23E2ECE1'><path d='M0 0h12L6 6z'/></svg>");
}

.book-select:hover {
  background-color: var(--border-color);
}

.view-switch-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background-color: var(--primary-light);
  color: var(--primary-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition-speed);
  margin-right: 8px;
  min-height: 44px;
}

.pwa-status {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 1000001;
  max-width: min(520px, calc(100vw - 32px));
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--panel-bg);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
  font-size: 0.78rem;
  line-height: 1.45;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity var(--transition-speed), transform var(--transition-speed);
}

.pwa-status.is-visible {
  opacity: 0.96;
  transform: translate(-50%, 0);
}

.pwa-status[data-state="warning"] {
  border-color: #B7791F;
}

.pwa-status[data-state="success"] {
  border-color: #2F855A;
}

.pwa-install-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-color: rgba(45, 90, 39, 0.18);
  background: linear-gradient(135deg, rgba(229, 241, 229, 0.78), rgba(255, 255, 255, 0.92));
}

.pwa-install-card-copy {
  min-width: 0;
}

.pwa-install-card-copy h4 {
  margin-bottom: 5px;
}

.pwa-install-card-copy p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.86rem;
  line-height: 1.55;
}

.install-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
}

.install-btn.is-installable {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: #fff;
  box-shadow: 0 8px 18px rgba(45, 90, 39, 0.18);
}

.install-btn.is-installed {
  background: rgba(47, 133, 90, 0.1);
  border-color: rgba(47, 133, 90, 0.28);
  color: #2f6f45;
}

.pwa-install-guide {
  color: var(--text-main);
}

.pwa-install-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-bottom: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid rgba(45, 90, 39, 0.18);
  background: rgba(229, 241, 229, 0.9);
  color: var(--primary-color);
  font-size: 0.78rem;
  font-weight: 800;
}

.pwa-install-summary {
  margin: 0 0 13px;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.6;
}

.pwa-install-steps {
  margin: 0;
  padding-left: 22px;
  color: var(--text-main);
  font-size: 0.94rem;
  line-height: 1.75;
}

.pwa-install-steps li::marker {
  color: var(--primary-color);
  font-weight: 800;
}

.pwa-install-tip {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 7px;
  background: rgba(247, 250, 247, 0.9);
  color: var(--text-muted);
  font-size: 0.86rem;
  line-height: 1.55;
}

.pwa-native-install-btn {
  width: 100%;
  margin-top: 14px;
}

.pwa-install-more {
  margin-top: 14px;
  border-top: 1px dashed var(--border-color);
  padding-top: 12px;
}

.pwa-install-more summary {
  cursor: pointer;
  color: var(--primary-color);
  font-size: 0.88rem;
  font-weight: 800;
}

.pwa-install-device-grid {
  display: grid;
  gap: 9px;
  margin-top: 10px;
}

.pwa-install-device-grid div {
  padding: 10px 11px;
  border: 1px solid var(--border-color);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.72);
}

.pwa-install-device-grid strong,
.pwa-install-device-grid span {
  display: block;
}

.pwa-install-device-grid strong {
  margin-bottom: 3px;
  color: var(--text-main);
  font-size: 0.86rem;
}

.pwa-install-device-grid span {
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.global-settings-modal {
  max-width: min(460px, calc(100vw - 28px));
}

.global-settings-card {
  margin-top: 14px;
}

.global-settings-card h4 {
  margin-bottom: 10px;
}

.global-settings-link-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.global-settings-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid var(--border-color);
  border-radius: 7px;
  background: var(--panel-bg);
  color: var(--text-main);
  font-size: 0.86rem;
  font-weight: 700;
  text-decoration: none;
}

.global-settings-link:hover,
.global-settings-link.is-active {
  border-color: rgba(45, 90, 39, 0.28);
  background: rgba(229, 241, 229, 0.8);
  color: var(--primary-color);
}

.global-settings-link svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

body.dark-theme .pwa-install-card {
  background: linear-gradient(135deg, rgba(45, 90, 39, 0.16), rgba(17, 24, 39, 0.76));
}

body.dark-theme .install-btn.is-installed {
  color: #9AE6B4;
}

body.dark-theme .pwa-install-tip,
body.dark-theme .pwa-install-device-grid div {
  background: rgba(17, 24, 39, 0.62);
}

body.dark-theme .global-settings-link:hover,
body.dark-theme .global-settings-link.is-active {
  background: rgba(45, 90, 39, 0.22);
}

@media (max-width: 640px) {
  .pwa-install-card {
    align-items: stretch;
    flex-direction: column;
  }

  .pwa-install-card .install-btn {
    width: 100%;
  }

  .global-settings-link-grid {
    grid-template-columns: 1fr;
  }
}

.view-switch-btn:hover {
  background-color: var(--primary-color);
  color: white;
  transform: translateY(-1px);
}

body.dark-theme .view-switch-btn {
  background-color: var(--primary-light);
  color: var(--text-main);
  border-color: var(--border-color);
}

body.dark-theme .view-switch-btn:hover {
  background-color: var(--primary-color);
  color: white;
}
/* ==========================================================================
   Inline Editor Panel (紧凑编辑弹窗)
   ========================================================================== */
.inline-editor-panel {
  position: fixed;
  background: rgba(255,255,255,0.98);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  padding: 14px;
  z-index: 10000002;
  width: 380px;
  max-width: calc(100vw - 16px);
  transform: translate(-50%, 8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
body.dark-theme .inline-editor-panel {
  background: rgba(30,41,59,0.98);
  border-color: rgba(255,255,255,0.1);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.iep-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
}
.iep-btn {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: rgba(0,0,0,0.05);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--text-main, #2d3748);
  transition: background 0.12s ease;
}
.iep-btn:hover { background: rgba(0,0,0,0.1); }
body.dark-theme .iep-btn { background: rgba(255,255,255,0.08); color: #e2e8f0; }
body.dark-theme .iep-btn:hover { background: rgba(255,255,255,0.14); }
.iep-color-red { background: rgba(239,68,68,0.22) !important; color: #dc2626 !important; }
.iep-color-black { background: rgba(17,24,39,0.16) !important; color: #111827 !important; }
.iep-color-green { background: rgba(16,185,129,0.22) !important; color: #059669 !important; }
.iep-color-blue { background: rgba(59,130,246,0.22) !important; color: #2563eb !important; }
.iep-color-yellow { background: rgba(245,158,11,0.22) !important; color: #d97706 !important; }
.iep-editor {
  width: 100%;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: inherit;
  background: rgba(0,0,0,0.02);
  color: var(--text-main, #2d3748);
  outline: none;
  box-sizing: border-box;
  min-height: 80px;
  max-height: 200px;
  overflow-y: auto;
  line-height: 1.6;
  word-break: break-word;
}
.iep-editor:focus { border-color: var(--primary-color, #2b6cb0); }
.iep-editor:empty::before {
  content: attr(placeholder);
  color: rgba(0,0,0,0.3);
}
.iep-editor strong { font-weight: 700; }
body.dark-theme .iep-editor { background: rgba(255,255,255,0.05); border-color: rgba(255,255,255,0.12); color: #e2e8f0; }
body.dark-theme .iep-editor:empty::before { color: rgba(255,255,255,0.3); }
.iep-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.iep-action-btn {
  padding: 8px 20px;
  border: none;
  border-radius: 10px;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.12s ease;
}
.iep-save { background: #3b82f6; color: #fff; }
.iep-save:hover { background: #2563eb; }
.iep-cancel { background: rgba(0,0,0,0.06); color: var(--text-main, #2d3748); }
.iep-cancel:hover { background: rgba(0,0,0,0.1); }
body.dark-theme .iep-cancel { background: rgba(255,255,255,0.08); color: #e2e8f0; }

/* ==========================================================================
   Floating Unified Toolbar (统一浮动工具栏：格式 + 节点操作)
   ========================================================================== */
.floating-format-bar {
  position: fixed;
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 5px 8px;
  background: rgba(255,255,255,0.97);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 22px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15), 0 0 0 0.5px rgba(0,0,0,0.05);
  z-index: 10000001;
  transform: translate(-50%, -8px);
  transition: opacity 0.15s ease, transform 0.2s cubic-bezier(0.16,1,0.3,1);
  user-select: none;
  -webkit-user-select: none;
  white-space: nowrap;
  max-width: calc(100vw - 16px);
  overflow-x: auto;
  scrollbar-width: none;
}
.floating-format-bar::-webkit-scrollbar { display: none; }
.floating-format-bar.show {
  display: flex;
  opacity: 1;
}
body.dark-theme .floating-format-bar {
  background: rgba(30,41,59,0.97);
  border-color: rgba(255,255,255,0.12);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.fmt-btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--text-main, #2d3748);
  transition: background 0.12s ease, transform 0.12s ease;
  flex-shrink: 0;
  line-height: 1;
}
.fmt-btn { position: relative; }
.fmt-btn:hover { background: rgba(0,0,0,0.07); }
.fmt-btn:hover::after {
  content: attr(title);
  position: absolute;
  bottom: -24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: #fff;
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
}
.fmt-btn:active { background: rgba(0,0,0,0.13); transform: scale(0.9); }
.fmt-btn:active::after { display: none; }
body.dark-theme .fmt-btn { color: #e2e8f0; }
body.dark-theme .fmt-btn:hover { background: rgba(255,255,255,0.08); }
body.dark-theme .fmt-btn:active { background: rgba(255,255,255,0.14); }
.fmt-btn-danger { color: #ef4444 !important; }
.fmt-btn-danger:hover { background: rgba(239,68,68,0.12) !important; }
.fmt-divider {
  width: 1px;
  height: 16px;
  background: rgba(0,0,0,0.12);
  margin: 0 3px;
  flex-shrink: 0;
}
body.dark-theme .fmt-divider { background: rgba(255,255,255,0.15); }
.fmt-color-black { color: #111827 !important; background: rgba(17,24,39,0.50) !important; }
.fmt-color-red { color: #dc2626 !important; background: rgba(239,68,68,0.50) !important; }
.fmt-color-green { color: #059669 !important; background: rgba(16,185,129,0.50) !important; }
.fmt-color-blue { color: #2563eb !important; background: rgba(59,130,246,0.50) !important; }
.fmt-color-yellow { color: #d97706 !important; background: rgba(245,158,11,0.50) !important; }
.fmt-color-black:hover { background: rgba(17,24,39,0.65) !important; }
.fmt-color-red:hover { background: rgba(239,68,68,0.65) !important; }
.fmt-color-green:hover { background: rgba(16,185,129,0.65) !important; }
.fmt-color-blue:hover { background: rgba(59,130,246,0.65) !important; }
.fmt-color-yellow:hover { background: rgba(245,158,11,0.65) !important; }

/* ==========================================================================
   Bottom Sheet 底部抽屉样式
   ========================================================================== */
.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 800px; /* 平板和大屏限制宽度 */
  margin: 0 auto;   /* 居中对齐 */
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-bottom: none;
  border-top-left-radius: var(--radius-lg, 20px);
  border-top-right-radius: var(--radius-lg, 20px);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.18);
  z-index: 10000000 !important;
  transform: translateY(105%);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  padding: 16px 20px 24px;
}

.bottom-sheet.active {
  transform: translateY(0) !important;
}

body.dark-theme .bottom-sheet {
  background: rgba(15, 23, 42, 0.96);
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
}

/* 顶部把手 */
.bottom-sheet-drag-handle {
  width: 40px;
  height: 4px;
  background-color: var(--text-muted);
  opacity: 0.3;
  border-radius: 2px;
  margin: 0 auto 12px;
}

.bottom-sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
}

.bottom-sheet-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.bottom-sheet-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.bottom-sheet-close:hover {
  opacity: 1;
}

.bottom-sheet-body {
  position: relative;
}

/* 操作组按钮 */
.bs-action-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.bs-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 1;
  min-width: 110px;
  padding: 12px 16px;
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--panel-bg);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.bs-btn:active {
  transform: scale(0.96);
}

.bs-btn:hover {
  border-color: var(--accent-color);
  background-color: var(--primary-light);
  color: var(--primary-color);
}

.bs-btn-danger {
  color: var(--danger-color);
  border-color: rgba(163, 78, 54, 0.2);
}

.bs-btn-danger:hover {
  background-color: var(--danger-light);
  border-color: var(--danger-color);
  color: var(--danger-color);
}

/* 输入编辑区 */
.bs-input-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bs-input-area textarea {
  width: 100%;
  min-height: 96px;
  max-height: min(42vh, 300px);
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background-color: var(--panel-bg);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.58;
  outline: none;
  resize: vertical;
  overflow-y: auto;
  transition: border-color 0.2s;
}

.bs-input-area textarea:focus {
  border-color: var(--accent-color);
}

.bs-input-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* 颜色面板 */
.bs-color-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.bs-color-title {
  font-size: 0.9rem;
  color: var(--text-main);
  font-weight: 500;
}

.bs-color-palette {
  display: flex;
  gap: 16px;
  margin: 8px 0;
}

.color-dot {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
}

.color-dot:active {
  transform: scale(0.9);
}

.color-dot.selected {
  transform: scale(1.1);
  border-color: var(--accent-color);
}

.color-dot-default { background-color: var(--text-main); }
.color-dot-black { background-color: #111827; }
.color-dot-red { background-color: #ef4444; }
.color-dot-green { background-color: #10b981; }
.color-dot-blue { background-color: #3b82f6; }
.color-dot-yellow { background-color: #f59e0b; }

/* Sidebar Toggle Trigger (Floating handle) */
.sidebar-toggle-trigger {
  position: absolute;
  top: 50%;
  right: -20px;
  transform: translateY(-50%);
  width: 20px;
  height: 60px;
  background-color: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-left: none;
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.05);
  z-index: 101;
  color: var(--text-muted);
}

.bottom-sheet-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.bottom-sheet-close:hover {
  opacity: 1;
}

.bottom-sheet-body {
  position: relative;
}

/* 操作组按钮 */
.bs-action-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.bs-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 1;
  min-width: 110px;
  padding: 12px 16px;
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--panel-bg);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.bs-btn:active {
  transform: scale(0.96);
}

.bs-btn:hover {
  border-color: var(--accent-color);
  background-color: var(--primary-light);
  color: var(--primary-color);
}

.bs-btn-danger {
  color: var(--danger-color);
  border-color: rgba(163, 78, 54, 0.2);
}

.bs-btn-danger:hover {
  background-color: var(--danger-light);
  border-color: var(--danger-color);
  color: var(--danger-color);
}

/* 输入编辑区 */
.bs-input-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bs-input-area textarea {
  width: 100%;
  min-height: 96px;
  max-height: min(42vh, 300px);
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background-color: var(--panel-bg);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.58;
  outline: none;
  resize: vertical;
  overflow-y: auto;
  transition: border-color 0.2s;
}

.bs-input-area textarea:focus {
  border-color: var(--accent-color);
}

.bs-input-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* 颜色面板 */
.bs-color-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.bs-color-title {
  font-size: 0.9rem;
  color: var(--text-main);
  font-weight: 500;
}

.bs-color-palette {
  display: flex;
  gap: 16px;
  margin: 8px 0;
}

.color-dot {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
}

.color-dot:active {
  transform: scale(0.9);
}

.color-dot.selected {
  transform: scale(1.1);
  border-color: var(--accent-color);
}

.color-dot-default { background-color: var(--text-main); }
.color-dot-black { background-color: #111827; }
.color-dot-red { background-color: #ef4444; }
.color-dot-green { background-color: #10b981; }
.color-dot-blue { background-color: #3b82f6; }
.color-dot-yellow { background-color: #f59e0b; }

/* Sidebar Toggle Trigger (Floating handle) */
.sidebar-toggle-trigger {
  position: absolute;
  top: 50%;
  right: -20px;
  transform: translateY(-50%);
  width: 20px;
  height: 60px;
  background-color: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-left: none;
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.05);
  z-index: 101;
  color: var(--text-muted);
  font-size: 0.75rem;
  transition: all var(--transition-speed);
  user-select: none;
}

.sidebar-toggle-trigger:hover {
  background-color: var(--primary-light);
  color: var(--primary-color);
}

.sidebar.collapsed .sidebar-toggle-trigger {
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.15);
}

/* Mobile uses the top-left menu button; desktop keeps the side handle. */
@media (max-width: 768px) {
  .sidebar-toggle-trigger {
    display: none !important;
  }
}

/* Fullscreen / immersive chapter drawer keeps the original pill sidebar handle visible. */
body.fullscreen-mode-active .sidebar,
body.flashcard-immersive .sidebar {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  bottom: 0 !important;
  width: min(86vw, 320px) !important;
  height: 100dvh !important;
  margin-left: 0 !important;
  transform: translateX(-100%) !important;
  z-index: 1000002 !important;
  display: flex !important;
  overflow: visible !important;
}

body.fullscreen-mode-active .sidebar.open,
body.flashcard-immersive .sidebar.open {
  transform: translateX(0) !important;
}

body.fullscreen-mode-active .sidebar.collapsed,
body.flashcard-immersive .sidebar.collapsed {
  margin-left: 0 !important;
  transform: translateX(-100%) !important;
}

body.fullscreen-mode-active .sidebar-overlay,
body.flashcard-immersive .sidebar-overlay {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  z-index: 1000001 !important;
}

body.fullscreen-mode-active .sidebar-overlay.open,
body.flashcard-immersive .sidebar-overlay.open {
  display: block !important;
}

body.fullscreen-mode-active .sidebar-toggle-trigger,
body.flashcard-immersive .sidebar-toggle-trigger {
  display: flex !important;
  right: -22px;
  width: 30px;
  height: 54px;
  z-index: 1000003;
  pointer-events: auto;
}

/* ==========================================================================
   v22 手机 / iPad 学习界面与来源状态
   ========================================================================== */
.glow-container {
  display: none;
}

.card-source-badge {
  align-self: flex-start;
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.source-official {
  color: #166534;
  background: #dcfce7;
  border-color: #86efac;
}

.source-recall {
  color: #1d4ed8;
  background: #dbeafe;
  border-color: #93c5fd;
}

.source-simulation {
  color: #7c2d12;
  background: #ffedd5;
  border-color: #fdba74;
}

.source-textbook {
  color: #374151;
  background: #f3f4f6;
  border-color: #d1d5db;
}

.source-pending {
  color: #854d0e;
  background: #fef9c3;
  border-color: #fde047;
}

.completion-message {
  max-width: 30rem;
  margin: 0 auto;
  text-align: center;
  color: var(--text-muted);
  line-height: 1.7;
}

@supports (height: 100dvh) {
  .app-container {
    height: 100dvh;
  }
}

@media (max-width: 768px) {
  .app-container,
  .main-content {
    min-width: 0;
  }

  .sidebar {
    width: min(88vw, 340px);
    padding-top: env(safe-area-inset-top);
  }

  .top-bar {
    box-sizing: border-box;
    height: calc(116px + env(safe-area-inset-top));
    min-height: calc(116px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 10px 6px;
    gap: 8px;
    flex-wrap: wrap;
    align-content: center;
  }

  .top-bar-left {
    order: 1;
    flex: 1;
    min-width: 0;
    gap: 8px;
  }

  .current-chapter-info {
    min-width: 0;
  }

  .current-chapter-info h2 {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.95rem;
  }

  .current-chapter-info span {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.68rem;
  }

  .top-bar-right {
    order: 2;
    flex: 0 0 auto;
    gap: 4px;
  }

  .top-mode-tabs {
    order: 3;
    flex: 0 0 100%;
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    gap: 3px;
    padding: 3px;
  }

  .top-mode-tab {
    flex: 1 1 0;
    min-height: 38px;
    padding: 6px 4px;
    gap: 4px;
    font-size: 0.72rem;
  }

  .view-switch-btn,
  .install-btn,
  .theme-btn,
  .settings-btn,
  .toggle-btn {
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
    margin: 0;
    border-radius: 6px;
  }

  .view-switch-btn {
    justify-content: center;
    font-size: 1rem;
  }

  .view-label,
  .install-label {
    display: none;
  }

  .single-mode-container {
    box-sizing: border-box;
    width: 100%;
    flex: 1;
    min-height: 0;
    padding: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .mindmap-container {
    border-radius: 6px;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .mindmap-actions {
    flex: 0 0 auto;
    flex-shrink: 0;
    justify-content: flex-start;
    flex-wrap: nowrap;
    gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    overflow-x: auto;
    scrollbar-width: none;
  }

  .mindmap-actions::-webkit-scrollbar {
    display: none;
  }

  .mindmap-level-controls {
    margin-right: 0;
  }

  .mindmap-level-btn {
    min-height: 36px;
    padding: 6px 10px;
  }

  .mindmap-actions .btn {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 9px 12px;
    white-space: nowrap;
    font-size: 0.82rem;
  }

  .flashcards-container {
    width: 100%;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 0;
    overflow-y: auto;
    box-sizing: border-box;
  }

  .flashcards-active-area {
    width: 100%;
    max-width: none;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: env(safe-area-inset-bottom);
    box-sizing: border-box;
  }

  .card-scene {
    flex: 1;
    min-height: 180px;
    max-height: 520px;
    height: auto;
  }

  .card-face {
    padding: 16px;
    border-radius: 6px;
  }

  .card-question-text {
    padding: 8px 2px;
    font-size: 1.08rem;
    line-height: 1.55;
  }

  .flashcard-header-row {
    min-height: 30px;
  }

  .flashcard-enter-immersive,
  .flashcard-exit-immersive {
    width: 32px;
    height: 32px;
  }

  .flashcard-edit-local {
    min-height: 32px;
    padding: 5px 7px;
  }

  .card-answer-text-container {
    padding: 6px 0;
  }

  .card-answer-text {
    font-size: 0.9rem;
    line-height: 1.55;
  }

  .card-nav,
  .flashcards-actions {
    flex: 0 0 auto;
    flex-shrink: 0;
    gap: 6px !important;
    margin: 0 0 8px !important;
  }

  .card-nav .btn {
    min-height: 44px;
    padding: 8px 10px;
  }

  .card-nav .btn span {
    font-size: 0.78rem;
  }

  .settings-modal {
    top: calc(50% + env(safe-area-inset-top) / 2);
    width: calc(100% - 20px);
    max-height: calc(100dvh - 28px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    border-radius: 6px;
  }

  .modal-header,
  .modal-body {
    padding: 16px;
  }

  .bottom-sheet {
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 430px) {
  .install-btn {
    display: none;
  }

  .card-nav #edit-csv-btn,
  .card-nav #delete-fc-btn,
  .card-nav #add-fc-btn {
    display: none;
  }

  .card-nav .btn span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

/* Flashcards use an independent immersive state so mind-map fullscreen remains isolated. */
body.flashcard-immersive {
  overflow-x: hidden;
  overflow-y: hidden;
  background: var(--bg-color);
}

body.flashcard-immersive .app-container,
body.flashcard-immersive .main-content {
  width: 100vw;
  height: auto;
  min-height: 100dvh;
  overflow: visible;
}

body.flashcard-immersive .app-container {
  position: fixed;
  inset: 0;
  height: 100dvh;
  min-height: 100dvh;
  z-index: 10000020;
  background: var(--bg-color);
  isolation: isolate;
}

body.flashcard-immersive .main-content {
  height: 100dvh;
  min-height: 100dvh;
}

body.flashcard-immersive .flashcards-container {
  min-height: 100dvh;
  padding: max(14px, env(safe-area-inset-top)) 20px max(16px, env(safe-area-inset-bottom));
  justify-content: center;
  overflow-y: auto;
}

body.flashcard-immersive .flashcards-active-area {
  flex: 0 1 auto;
  min-height: 0;
  justify-content: center;
}

body.flashcard-immersive .top-bar,
body.flashcard-immersive .glow-container,
body.flashcard-immersive #feedback-trigger-btn,
body.flashcard-immersive .modal-backdrop,
body.flashcard-immersive .mastery-modal,
body.flashcard-immersive .settings-modal,
body.flashcard-immersive .pwa-help-modal {
  display: none !important;
}

@media (max-width: 768px) {
  body.flashcard-immersive .card-scene { width: 100%; min-height: 440px; }
  body.flashcard-immersive .floating-nav-btn { width: 34px; height: 34px; }
  body.flashcard-immersive .floating-nav-prev { left: 0; }
  body.flashcard-immersive .floating-nav-next { right: 0; }
  body.flashcard-immersive .card-face { padding: 18px; }
  body.flashcard-immersive .card-question-text { padding: 8px 0; font-size: 1.15rem; }
  body.flashcard-immersive .card-inline-progress { inset: auto; width: 100%; margin-bottom: 12px; }
}

/* Unified mobile/tablet study navigation. Keep one layout source for the shared top bar. */
@media (max-width: 1400px) {
  .top-bar {
    display: grid !important;
    grid-template-columns: 44px minmax(0, 1fr) max-content !important;
    align-items: center !important;
    align-content: center !important;
    gap: 8px !important;
    flex-wrap: nowrap !important;
    overflow: hidden !important;
  }

  .top-bar-left {
    display: contents !important;
  }

  .top-bar-right {
    grid-column: 3 !important;
    grid-row: 1 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 7px !important;
    min-width: 0 !important;
    width: max-content !important;
    max-width: max-content !important;
    margin-left: 0 !important;
  }

  .top-bar .theme-toggle {
    display: contents !important;
  }

  .top-bar .current-chapter-info,
  .top-bar .exam-page-heading {
    display: none !important;
  }

  .top-bar .toggle-btn,
  .top-bar #menu-btn,
  .top-bar #exam-menu-btn,
  .top-bar #open-prescription-sidebar,
  .top-bar #open-excipient-sidebar {
    grid-column: 1 !important;
    grid-row: 1 !important;
    justify-self: start !important;
    flex: 0 0 44px !important;
    width: 44px !important;
    min-width: 44px !important;
    height: 44px !important;
    padding: 0 !important;
  }

  .top-bar .top-mode-tabs {
    grid-column: 2 !important;
    grid-row: 1 !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    margin: 0 !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    justify-content: flex-start !important;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .top-bar .top-mode-tabs::-webkit-scrollbar {
    display: none;
  }

  .top-bar .top-mode-tab {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
  }

  .top-bar .theme-btn,
  .top-bar .settings-btn,
  .top-bar .account-sync-btn,
  .top-bar .account-profile-trigger {
    grid-column: auto !important;
    grid-row: 1 !important;
    flex: 0 0 auto !important;
    width: auto !important;
    min-width: 44px !important;
    max-width: none !important;
    height: 44px !important;
    min-height: 44px !important;
    padding: 0 11px !important;
    white-space: nowrap !important;
  }
}

@media (max-width: 768px) {
  :root {
    --study-topbar-height: calc(62px + env(safe-area-inset-top));
  }

  .top-bar {
    height: var(--study-topbar-height) !important;
    min-height: var(--study-topbar-height) !important;
    padding: calc(8px + env(safe-area-inset-top)) 8px 8px !important;
    grid-template-columns: 44px minmax(0, 1fr) max-content !important;
  }

  .top-bar .top-mode-tabs {
    padding: 4px !important;
    gap: 3px !important;
    scroll-padding-inline: 8px;
  }

  .top-bar .top-mode-tab {
    min-height: 38px !important;
    padding: 6px 9px !important;
    gap: 4px !important;
    font-size: 0.76rem !important;
  }

  .top-bar .top-mode-tab svg,
  .top-bar .top-mode-tab i {
    width: 16px !important;
    height: 16px !important;
  }

  .top-bar .top-bar-right {
    gap: 6px !important;
  }

  .top-bar .theme-btn,
  .top-bar .settings-btn,
  .top-bar .account-sync-btn,
  .top-bar .account-profile-trigger {
    min-width: 42px !important;
    height: 42px !important;
    min-height: 42px !important;
    padding: 0 10px !important;
  }

  .top-bar #menu-btn i,
  .top-bar #menu-btn svg,
  .top-bar #exam-menu-btn i,
  .top-bar #exam-menu-btn svg,
  .top-bar #open-prescription-sidebar i,
  .top-bar #open-prescription-sidebar svg,
  .top-bar #open-excipient-sidebar i,
  .top-bar #open-excipient-sidebar svg {
    display: none !important;
  }

  .top-bar #menu-btn::before,
  .top-bar #exam-menu-btn::before,
  .top-bar #open-prescription-sidebar::before,
  .top-bar #open-excipient-sidebar::before {
    content: "" !important;
    display: block !important;
    width: 19px !important;
    height: 15px !important;
    border-radius: 2px;
    background:
      linear-gradient(currentColor, currentColor) 0 2px / 19px 2px no-repeat,
      linear-gradient(currentColor, currentColor) 0 7px / 14px 2px no-repeat,
      linear-gradient(currentColor, currentColor) 0 12px / 19px 2px no-repeat;
  }
}

@media (min-width: 769px) and (max-width: 1400px) {
  :root {
    --study-topbar-height: 58px;
  }

  .top-bar {
    height: var(--study-topbar-height) !important;
    min-height: var(--study-topbar-height) !important;
    padding: 7px 12px !important;
  }
}


/* Pure Icon Mindmap Actions & Collapsible Styles */
.mindmap-actions {
  position: absolute;
  bottom: 16px;
  right: 16px;
  top: auto;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 7px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 22px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
  transition: all 0.25s ease;
}

body.dark-theme .mindmap-actions {
  background: rgba(30, 41, 59, 0.92);
  border-color: rgba(255, 255, 255, 0.15);
  color: #f8fafc;
}

.mindmap-actions .btn {
  padding: 8px;
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-main, #334155);
  transition: background 0.18s ease, transform 0.18s ease;
}

.mindmap-actions .btn svg {
  width: 19px !important;
  height: 19px !important;
  stroke-width: 2.2px !important;
}

body.dark-theme .mindmap-actions .btn {
  color: #e2e8f0;
}

.mindmap-actions .btn:hover {
  background: rgba(0, 0, 0, 0.08);
  transform: scale(1.12);
}

body.dark-theme .mindmap-actions .btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.mindmap-actions .btn.is-active {
  background: rgba(47, 107, 47, 0.14);
  color: var(--primary-color, #2f6b2f);
  box-shadow: inset 0 0 0 1px rgba(47, 107, 47, 0.28);
}

body.dark-theme .mindmap-actions .btn.is-active {
  background: rgba(134, 191, 125, 0.18);
  color: #c7f1c2;
  box-shadow: inset 0 0 0 1px rgba(199, 241, 194, 0.28);
}

.mindmap-handwriting-toolbar {
  position: absolute;
  right: 18px;
  bottom: 82px;
  z-index: 105;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px;
  border: 1px solid rgba(47, 107, 47, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
  backdrop-filter: blur(14px);
}

.mindmap-handwriting-toolbar.is-user-positioned {
  position: fixed !important;
  left: var(--hw-toolbar-left, 50%) !important;
  top: var(--hw-toolbar-top, 72px) !important;
  right: auto !important;
  bottom: auto !important;
  transform: none !important;
}

.mindmap-handwriting-toolbar.is-dragging {
  cursor: grabbing;
  user-select: none;
  -webkit-user-select: none;
}

.mindmap-handwriting-toolbar[hidden] {
  display: none !important;
}

body.dark-theme .mindmap-handwriting-toolbar {
  border-color: rgba(199, 241, 194, 0.18);
  background: rgba(30, 41, 59, 0.94);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.26);
}

.hw-tool-btn {
  width: 38px;
  height: 38px;
  min-width: 38px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main, #263824);
  background: transparent;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.hw-drag-handle {
  cursor: grab;
  touch-action: none;
  color: color-mix(in srgb, var(--text-muted, #5f7660) 84%, var(--primary-color, #2f6b2f) 16%);
}

.hw-drag-handle:active,
.mindmap-handwriting-toolbar.is-dragging .hw-drag-handle {
  cursor: grabbing;
}

.hw-tool-chip {
  width: auto;
  min-width: 48px;
  padding: 0 10px;
  border-radius: 999px;
  gap: 4px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
}

.hw-chip-main {
  color: var(--primary-color, #2f6b2f);
}

.hw-chip-sub {
  min-width: 1em;
  color: var(--text-muted, #5f7660);
}

.hw-size-popover {
  position: absolute;
  right: 54px;
  bottom: calc(100% + 10px);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  border: 1px solid rgba(47, 107, 47, 0.18);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
  backdrop-filter: blur(14px);
  touch-action: none;
}

.hw-size-popover[hidden] {
  display: none !important;
}

.hw-width-popover {
  right: 8px;
}

.hw-step-btn {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: rgba(47, 107, 47, 0.1);
  color: var(--primary-color, #2f6b2f);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.hw-size-input {
  width: 58px;
  height: 30px;
  border: 1px solid rgba(47, 107, 47, 0.22);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--text-main, #263824);
  font: 700 0.85rem/1.1 inherit;
  text-align: center;
  outline: none;
  cursor: ns-resize;
}

@media (max-width: 768px) {
  .hw-size-popover {
    right: auto;
    left: 50%;
    bottom: calc(100% + 8px);
    transform: translateX(-50%);
  }

  .hw-width-popover {
    right: auto;
  }
}

.hw-unit {
  padding-right: 2px;
  color: var(--text-muted, #5f7660);
  font-size: 0.74rem;
  font-weight: 700;
}

body.dark-theme .hw-size-popover {
  border-color: rgba(199, 241, 194, 0.18);
  background: rgba(30, 41, 59, 0.98);
}

body.dark-theme .hw-size-input {
  border-color: rgba(199, 241, 194, 0.22);
  background: rgba(15, 23, 42, 0.9);
  color: #e2e8f0;
}

.hw-tool-btn:hover,
.hw-tool-btn.is-active {
  background: rgba(47, 107, 47, 0.13);
  transform: translateY(-1px);
  box-shadow: inset 0 0 0 1px rgba(47, 107, 47, 0.22);
}

body.dark-theme .hw-tool-btn {
  color: #e2e8f0;
}

body.dark-theme .hw-tool-btn:hover,
body.dark-theme .hw-tool-btn.is-active {
  background: rgba(199, 241, 194, 0.14);
  box-shadow: inset 0 0 0 1px rgba(199, 241, 194, 0.22);
}

.hw-tool-btn.hw-danger {
  color: #dc2626;
}

.hw-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14);
}

.hw-swatch-wide {
  width: 22px;
  height: 12px;
  border-radius: 8px;
}

.mindmap-actions.actions-collapsed .action-item {
  display: none !important;
}

.mindmap-actions.actions-collapsed {
  padding: 6px !important;
  border-radius: 50% !important;
  background: rgba(255, 255, 255, 0.92) !important;
}

.mindmap-actions.actions-collapsed #toggle-actions-collapse-btn svg {
  transform: rotate(180deg);
}

body.dark-theme .mindmap-actions.actions-collapsed {
  background: rgba(30, 41, 59, 0.92) !important;
}

/* Mindmap fullscreen is a true viewport overlay, independent from page zoom. */
body.fullscreen-mode-active {
  width: 100vw !important;
  min-width: 100vw !important;
  max-width: 100vw !important;
  height: 100dvh !important;
  min-height: 100dvh !important;
  overflow: hidden !important;
  background: var(--bg-color) !important;
}

@supports (zoom: 1) {
  body.fullscreen-mode-active {
    zoom: 1 !important;
  }
}

body.fullscreen-mode-active .app-container,
body.fullscreen-mode-active .main-content {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  min-width: 100vw !important;
  max-width: 100vw !important;
  height: 100dvh !important;
  min-height: 100dvh !important;
  overflow: hidden !important;
  background: var(--bg-color) !important;
  isolation: isolate;
}

body.fullscreen-mode-active .top-bar,
body.fullscreen-mode-active .sidebar,
body.fullscreen-mode-active .sidebar-overlay,
body.fullscreen-mode-active .glow-container,
body.fullscreen-mode-active #feedback-trigger-btn,
body.fullscreen-mode-active .homepage-announcement-banner,
body.fullscreen-mode-active #pwa-status {
  display: none !important;
}

body.fullscreen-mode-active .single-mode-container {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  padding: 0 !important;
  overflow: hidden !important;
  background: var(--bg-color) !important;
}

body.fullscreen-mode-active .mindmap-container {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: var(--bg-color) !important;
  z-index: 1000000 !important;
}

body.fullscreen-mode-active #mindmap-iframe {
  width: 100vw !important;
  height: 100dvh !important;
  border: 0 !important;
}

body.fullscreen-mode-active .mindmap-actions {
  position: fixed !important;
  bottom: 18px !important;
  right: 18px !important;
  top: auto !important;
  background: rgba(255, 255, 255, 0.94) !important;
  backdrop-filter: blur(14px) !important;
  border: 1px solid rgba(47, 107, 47, 0.18) !important;
  border-radius: 24px !important;
  padding: 6px 8px !important;
  z-index: 1000000 !important;
}

body.fullscreen-mode-active .mindmap-actions .btn {
  color: var(--text-main, #263824) !important;
  width: 40px !important;
  height: 40px !important;
  min-width: 40px !important;
}

body.fullscreen-mode-active .mindmap-actions .btn svg {
  width: 20px !important;
  height: 20px !important;
}

body.fullscreen-mode-active .mindmap-handwriting-toolbar {
  position: fixed !important;
  left: 50% !important;
  right: auto !important;
  bottom: 76px !important;
  transform: translateX(-50%) !important;
  max-width: calc(100vw - 20px) !important;
  overflow-x: auto !important;
  scrollbar-width: none !important;
}

body.fullscreen-mode-active .mindmap-handwriting-toolbar.is-user-positioned {
  left: var(--hw-toolbar-left, 50%) !important;
  top: var(--hw-toolbar-top, 72px) !important;
  right: auto !important;
  bottom: auto !important;
  transform: none !important;
}

body.fullscreen-mode-active .mindmap-handwriting-toolbar::-webkit-scrollbar {
  display: none;
}

@media (max-width: 768px) {
  .mindmap-version-toggle {
    top: 10px;
    right: 10px;
    padding: 3px;
  }

  .mindmap-version-btn {
    min-width: 30px;
    height: 26px;
    padding: 0 8px;
    font-size: 0.74rem;
  }

  .mindmap-actions {
    right: 10px;
    bottom: 10px;
    max-width: calc(100vw - 20px);
    gap: 6px;
    padding: 6px 8px;
    border-radius: 20px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .mindmap-actions .btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    padding: 0;
  }

  .mindmap-actions .btn svg {
    width: 18px !important;
    height: 18px !important;
  }

  body.fullscreen-mode-active .mindmap-actions {
    right: 10px !important;
    bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    max-width: calc(100vw - 20px) !important;
    padding: 5px 6px !important;
  }

  body.fullscreen-mode-active .mindmap-actions .btn {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
  }

  body.fullscreen-mode-active .mindmap-actions .btn svg {
    width: 18px !important;
    height: 18px !important;
  }

  body.fullscreen-mode-active .mindmap-handwriting-toolbar {
    bottom: calc(70px + env(safe-area-inset-bottom)) !important;
    max-width: calc(100vw - 16px) !important;
    padding-inline: 6px !important;
  }
}

/* v130: cleaner iOS-like study controls */
.study-navigation {
  gap: 8px;
}

.subject-toggle-group {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  border: 1px solid color-mix(in srgb, var(--border-color) 80%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg-color) 72%, #ffffff 28%);
  box-shadow: inset 0 1px 1px rgba(31, 54, 38, 0.04);
}

.subject-toggle-btn {
  min-width: 0;
  min-height: 32px;
  gap: 4px;
  padding: 6px 5px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: color-mix(in srgb, var(--text-muted) 86%, var(--primary-color) 14%);
  font-size: 0.76rem;
  font-weight: 680;
  letter-spacing: 0;
}

.subject-toggle-btn i,
.subject-toggle-btn svg {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  stroke-width: 2;
}

.subject-toggle-btn span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subject-toggle-btn:hover {
  background: color-mix(in srgb, var(--primary-light) 56%, transparent);
  color: var(--primary-color);
}

.subject-toggle-btn.active,
.subject-toggle-btn[aria-selected="true"] {
  border-color: rgba(255, 255, 255, 0.72);
  background: rgba(255, 255, 255, 0.92);
  color: var(--primary-color);
  box-shadow: 0 1px 5px rgba(31, 54, 38, 0.12);
}

.subbook-toggle-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
  margin-top: 7px;
  padding: 3px;
  border: 1px solid color-mix(in srgb, var(--border-color) 72%, transparent);
  border-radius: 11px;
  background: color-mix(in srgb, var(--primary-light) 34%, transparent);
}

.subbook-toggle-group[hidden] {
  display: none !important;
}

.subbook-toggle-btn {
  min-height: 28px;
  padding: 5px 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.74rem;
  font-weight: 680;
  white-space: nowrap;
  cursor: pointer;
}

.flashcards-active-area.is-inline-editing .card-scene {
  width: min(100%, 820px);
  height: auto !important;
  max-height: none;
  min-height: 0;
}

.flashcards-active-area.is-inline-editing .flashcard {
  height: auto;
  min-height: 0;
  display: grid;
  gap: 14px;
  transform: none !important;
  cursor: text;
}

.flashcards-active-area.is-inline-editing .card-face {
  position: relative;
  height: auto;
  min-height: 180px;
  transform: none !important;
  backface-visibility: visible;
}

.flashcards-active-area.is-inline-editing .card-front {
  min-height: 160px;
}

.flashcards-active-area.is-inline-editing .card-back {
  min-height: 360px;
}

.flashcards-active-area.is-inline-editing .tap-hint,
.flashcards-active-area.is-inline-editing .floating-nav-btn {
  display: none !important;
}

.card-question-text[contenteditable="true"],
.card-answer-text[contenteditable="true"] {
  outline: 2px dashed color-mix(in srgb, var(--primary-color) 42%, transparent);
  outline-offset: 8px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--primary-light) 20%, transparent);
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.flashcards-active-area.is-inline-editing .flashcard-inline-toolbar,
.flashcards-active-area.is-inline-editing .card-source-badge,
.flashcards-active-area.is-inline-editing .tap-hint {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.subbook-toggle-btn:hover {
  color: var(--primary-color);
}

.subbook-toggle-btn.active,
.subbook-toggle-btn[aria-selected="true"] {
  border-color: rgba(255, 255, 255, 0.78);
  background: rgba(255, 255, 255, 0.9);
  color: var(--primary-color);
  box-shadow: 0 1px 4px rgba(31, 54, 38, 0.1);
}

.mastery-bank-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 38px;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--primary-color) 34%, var(--border-color));
  border-radius: 12px;
  background: color-mix(in srgb, var(--primary-light) 76%, #ffffff 24%);
  color: var(--primary-color);
  font-size: 0.84rem;
  font-weight: 720;
  text-decoration: none;
  box-shadow: 0 1px 4px rgba(31, 54, 38, 0.08);
}

.mastery-bank-btn i,
.mastery-bank-btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}

.mastery-bank-btn:hover {
  background: color-mix(in srgb, var(--primary-light) 64%, #ffffff 36%);
  box-shadow: 0 3px 10px rgba(31, 54, 38, 0.12);
}

body.dark-theme .subject-toggle-group,
body.dark-theme .subbook-toggle-group,
body.dark-theme .card-quick-controls {
  background: rgba(15, 23, 42, 0.38);
  border-color: rgba(148, 163, 184, 0.24);
}

body.dark-theme .subject-toggle-btn.active,
body.dark-theme .subject-toggle-btn[aria-selected="true"],
body.dark-theme .subbook-toggle-btn.active,
body.dark-theme .subbook-toggle-btn[aria-selected="true"] {
  border-color: rgba(148, 163, 184, 0.26);
  background: rgba(30, 41, 59, 0.92);
  color: #d9f99d;
}

body.dark-theme .mastery-bank-btn,
body.dark-theme .card-quick-controls .card-immersive-full-btn,
body.dark-theme .flashcard-exit-immersive {
  background: rgba(30, 41, 59, 0.88);
  border-color: rgba(148, 163, 184, 0.24);
  color: #d9f99d;
}

.card-scene-wrapper {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-inline: 54px;
  box-sizing: border-box;
}

.floating-nav-btn {
  position: absolute;
  top: 50%;
  z-index: 8;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: rgba(45, 90, 39, 0.42);
  box-shadow: none;
  transform: translateY(-50%);
  cursor: pointer;
}

.floating-nav-btn:hover,
.floating-nav-btn:focus-visible {
  background: transparent;
  color: rgba(45, 90, 39, 0.68);
}

.floating-nav-symbol {
  display: block;
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
}

body.dark-theme .floating-nav-btn {
  color: rgba(217, 249, 157, 0.5);
}

body.dark-theme .floating-nav-btn:hover,
body.dark-theme .floating-nav-btn:focus-visible {
  background: transparent;
  color: rgba(217, 249, 157, 0.76);
}

.floating-nav-prev { left: 0; }
.floating-nav-next { right: 0; }

.flashcard-immersive-controls {
  position: absolute;
  top: 12px;
  right: 70px;
  z-index: 12;
  display: none;
}

body.flashcard-immersive .flashcard-immersive-controls {
  display: none;
}

.flashcard-enter-immersive,
.flashcard-exit-immersive {
  border-radius: 999px;
}

body.flashcard-immersive .flashcard-exit-immersive {
  display: grid;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.92);
  color: var(--primary-color);
  box-shadow: 0 5px 16px rgba(31, 54, 38, 0.12);
  backdrop-filter: blur(12px);
}

.card-bottom-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.flashcard-editor-actions {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 1000005;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: min(214px, calc(100vw - 28px));
  padding: 4px;
  border: 1px solid color-mix(in srgb, var(--primary-color) 14%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel-bg) 66%, transparent);
  box-shadow: 0 6px 18px rgba(31, 54, 38, 0.10);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transform: translateX(-50%);
  box-sizing: border-box;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.flashcard-editor-actions.is-dragging {
  cursor: grabbing;
}

.flashcard-editor-actions .btn {
  flex: 0 0 100px;
  width: 100px;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 9px;
  font-size: 0.82rem;
  cursor: pointer;
}

.flashcards-active-area.is-inline-editing,
.flashcards-active-area.is-csv-editing {
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

.flashcard-edit-action-btn {
  flex: 1 1 0;
  min-height: 42px;
  border-radius: 14px;
  gap: 6px;
  font-weight: 760;
}

.flashcard-edit-action-btn svg,
.flashcard-edit-action-btn i {
  width: 18px;
  height: 18px;
}

.flashcard-save-action-btn {
  flex-basis: 1.25fr;
}

.card-quick-controls {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 4px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--primary-light) 48%, transparent);
}

.card-quick-controls .btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 42px;
  min-width: 42px;
  min-height: 40px;
  border-radius: 12px;
  padding: 0 !important;
}

.card-quick-controls .btn svg {
  width: 19px;
  height: 19px;
}

.flashcard-icon-btn[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  z-index: 4;
  min-width: max-content;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(31, 54, 38, 0.92);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 720;
  line-height: 1.2;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition: opacity 0.16s ease, transform 0.16s ease;
  box-shadow: 0 8px 18px rgba(31, 54, 38, 0.18);
}

.flashcard-icon-btn[data-tip]:hover::after,
.flashcard-icon-btn[data-tip]:focus-visible::after,
.flashcard-icon-btn[data-tip]:active::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.card-quick-controls .flashcard-master-btn {
  color: #fff;
  background: linear-gradient(135deg, var(--primary-color), color-mix(in srgb, var(--primary-color) 72%, #10b981 28%));
  box-shadow: 0 6px 16px color-mix(in srgb, var(--primary-color) 24%, transparent);
}

.card-quick-controls .flashcard-master-btn:hover,
.card-quick-controls .flashcard-master-btn:focus-visible {
  filter: brightness(0.98);
  transform: translateY(-1px);
}

.card-quick-controls .flashcard-master-btn svg {
  width: 21px;
  height: 21px;
  stroke-width: 2.4;
}

.card-quick-controls .card-immersive-full-btn {
  width: 42px;
  min-width: 42px;
  padding: 0 !important;
  border: 0;
  background: color-mix(in srgb, var(--primary-light) 72%, #ffffff 28%);
  color: var(--primary-color);
}

.card-quick-controls .card-immersive-full-btn:hover,
.card-quick-controls .card-immersive-full-btn:focus-visible {
  background: color-mix(in srgb, var(--primary-light) 58%, #ffffff 42%);
}

.flashcard-inline-toolbar {
  position: fixed;
  z-index: 1000001;
  display: none;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border: 1px solid color-mix(in srgb, var(--primary-color) 24%, var(--border-color));
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 30px rgba(31, 54, 38, 0.16);
  backdrop-filter: blur(12px);
}

.flashcard-inline-toolbar.is-visible {
  display: inline-flex;
}

.flashcard-inline-toolbar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary-color);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
}

.flashcard-inline-toolbar button:hover,
.flashcard-inline-toolbar button:focus-visible {
  filter: brightness(0.96);
  transform: translateY(-1px);
}

.flashcard-inline-toolbar button span {
  display: block;
  width: 15px;
  height: 15px;
  border-radius: 999px;
}

@media (max-width: 720px) {
  .subject-toggle-btn {
    font-size: 0.74rem;
    gap: 3px;
    padding-inline: 4px;
  }

  .subject-toggle-btn i,
  .subject-toggle-btn svg {
    width: 13px;
    height: 13px;
  }

  .flashcard-immersive-controls {
    top: 10px;
    right: 46px;
  }
}

/* v131: readable sidebar hierarchy and flashcard answer rhythm */
.logo-text .app-brand-title {
  display: flex;
  flex-direction: column;
  max-width: 150px;
  line-height: 1.16;
}

.logo-text .app-brand-title span:first-child {
  font-size: 1rem;
  font-weight: 820;
  letter-spacing: 0;
}

.logo-text .app-brand-title span:last-child {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 680;
  letter-spacing: 0;
}

.subject-toggle-group {
  gap: 4px;
  padding: 4px;
  border-radius: 13px;
}

.subject-toggle-btn {
  flex-direction: column;
  min-height: 48px;
  gap: 3px;
  padding: 6px 3px;
  font-size: 0.73rem;
  line-height: 1.12;
}

.subject-toggle-btn i,
.subject-toggle-btn svg {
  width: 18px;
  height: 18px;
}

.subject-toggle-btn span {
  max-width: 100%;
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
}

.subbook-toggle-group {
  gap: 4px;
  padding: 3px;
  border-radius: 12px;
}

.subbook-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  gap: 4px;
  padding: 4px 6px;
  font-size: 0.72rem;
  line-height: 1.1;
}

.subbook-toggle-btn i,
.subbook-toggle-btn svg {
  width: 12px;
  height: 12px;
  stroke-width: 2;
}

.card-answer-text.regulation-answer {
  line-height: 1.9;
  text-align: left;
}

.card-answer-text.regulation-answer p {
  margin: 0 0 0.82em;
}

.card-answer-text.regulation-answer p + p {
  margin-top: 0.22em;
}

.card-answer-text .answer-paragraph-point {
  position: relative;
  display: block;
  margin-bottom: 0.82em;
}

.card-answer-text .answer-paragraph-level-1 {
  margin-top: 1.05em;
  padding-left: 34px;
}

.card-answer-text .answer-paragraph-level-1:first-child {
  margin-top: 0;
}

.card-answer-text .answer-paragraph-level-2 {
  margin-left: 16px;
  padding-left: 32px;
  border-left: 2px solid color-mix(in srgb, var(--primary-color) 22%, transparent);
}

.card-answer-text .answer-paragraph-level-3 {
  margin-left: 30px;
  padding-left: 30px;
  border-left: 1px dashed color-mix(in srgb, var(--text-muted) 28%, transparent);
}

.card-answer-text .answer-inline-marker {
  position: absolute;
  left: 0;
  top: 0.2em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: auto;
  padding: 0;
  border-radius: 0;
  background: transparent !important;
  color: #ea580c;
  font-size: 0.82rem;
  font-weight: 820;
  line-height: inherit;
  font-variant-numeric: tabular-nums;
}

.card-answer-text .answer-inline-marker-level-2 {
  min-width: 22px;
  height: auto;
  background: transparent !important;
  color: var(--primary-color);
  font-size: 0.78rem;
}

.card-answer-text .answer-inline-marker-level-3 {
  min-width: 20px;
  height: auto;
  background: transparent !important;
  color: var(--text-muted);
  font-size: 0.74rem;
}

.card-answer-text.regulation-answer b,
.card-answer-text.regulation-answer strong {
  color: var(--primary-color);
  font-weight: 820;
}

body.dark-theme .card-answer-text .answer-inline-marker {
  background: transparent !important;
  color: #fed7aa;
}

body.dark-theme .card-answer-text .answer-inline-marker-level-2 {
  background: transparent !important;
  color: #bbf7d0;
}

body.dark-theme .card-answer-text .answer-inline-marker-level-3 {
  background: transparent !important;
  color: #cbd5e1;
}

@media (max-width: 720px) {
  .subject-toggle-btn {
    min-height: 46px;
    font-size: 0.7rem;
  }

  .subject-toggle-btn i,
  .subject-toggle-btn svg {
    width: 17px;
    height: 17px;
  }

  .subbook-toggle-btn {
    font-size: 0.7rem;
  }

  .card-answer-text .answer-paragraph-level-2 {
    margin-left: 10px;
    padding-left: 28px;
  }

  .card-answer-text .answer-paragraph-level-3 {
    margin-left: 18px;
    padding-left: 26px;
  }

  .card-answer-text .material-point-level-2,
  .card-answer-text li.answer-list-level-2:not(.answer-example),
  .card-answer-text .question-book-answer-list > li.answer-list-level-2,
  .card-answer-text .question-book-answer-list > li[data-answer-level="2"] {
    margin-left: 0.82em;
    padding-left: 0.65em;
  }

  .card-answer-text .material-point-level-3,
  .card-answer-text li.answer-list-level-3:not(.answer-example),
  .card-answer-text .question-book-answer-list > li.answer-list-level-3,
  .card-answer-text .question-book-answer-list > li[data-answer-level="3"] {
    margin-left: 1.45em;
    padding-left: 0.6em;
  }
}

/* v138: mobile flashcard, mindmap toolbar, and floating control polish */
@media (max-width: 768px) {
  body.flashcard-page .single-mode-container {
    width: 100%;
    max-width: none;
  }

  body.flashcard-page .flashcards-container {
    width: 100%;
    max-width: none;
    padding: 6px max(2px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(2px, env(safe-area-inset-left));
    overflow-x: hidden;
    gap: 6px;
  }

  body.flashcard-page .flashcards-active-area {
    width: 100%;
    max-width: none;
    gap: 8px;
  }

  body.flashcard-page .card-scene-wrapper {
    width: 100%;
    padding-inline: 2px !important;
    overflow: visible;
  }

  body.flashcard-page .card-scene {
    width: min(100%, calc(100vw - 4px));
    max-width: none;
    max-height: none;
    min-height: clamp(500px, calc(100dvh - 138px), 820px);
    height: clamp(500px, calc(100dvh - 138px), 820px);
  }

  body.flashcard-page .card-face {
    padding: 16px 14px;
  }

  body.flashcard-page .card-answer-text-container,
  body.flashcard-page .card-question-text,
  body.flashcard-page .card-answer-text {
    max-width: none;
  }

  body.flashcard-page .card-bottom-controls {
    min-height: 42px;
    margin-top: 4px;
    padding-bottom: max(2px, env(safe-area-inset-bottom));
  }

  body.flashcard-page .card-quick-controls {
    gap: 5px;
    padding: 3px;
    border-radius: 14px;
  }

  body.flashcard-page .card-quick-controls .btn {
    width: 42px;
    min-width: 42px;
    min-height: 38px;
  }

  body.flashcard-page .card-quick-controls .card-immersive-full-btn {
    width: 42px;
    min-width: 42px;
  }

  body.flashcard-page .floating-nav-prev { left: -2px; }
  body.flashcard-page .floating-nav-next { right: -2px; }

  body.flashcard-page .floating-nav-btn {
    width: 36px;
    height: 36px;
  }

  body.flashcard-page .floating-nav-symbol {
    font-size: 1.55rem;
  }

  body.flashcard-immersive .flashcards-container {
    padding: max(4px, env(safe-area-inset-top)) max(2px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(2px, env(safe-area-inset-left)) !important;
    align-items: stretch;
  }

  body.flashcard-immersive .flashcards-active-area {
    width: 100%;
    max-width: none;
    margin-inline: 0;
  }

  body.flashcard-immersive .card-scene-wrapper {
    padding-inline: 0 !important;
  }

  body.flashcard-immersive .card-scene {
    width: calc(100vw - 4px);
    max-width: none;
    max-height: none;
  }

  body.flashcard-immersive .card-face {
    padding: 16px 13px;
  }

  .mindmap-actions {
    position: fixed !important;
    left: max(10px, env(safe-area-inset-left)) !important;
    right: max(10px, env(safe-area-inset-right)) !important;
    bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    top: auto !important;
    width: auto !important;
    max-width: none !important;
    box-sizing: border-box !important;
    min-height: 0 !important;
    flex-wrap: nowrap !important;
    justify-content: flex-start !important;
    gap: 6px !important;
    padding: 6px 8px !important;
    border-radius: 999px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    scroll-snap-type: x proximity;
  }

  .mindmap-actions::-webkit-scrollbar {
    display: none;
  }

  .mindmap-actions.actions-collapsed .action-item {
    display: none !important;
  }

  .mindmap-actions.actions-collapsed {
    position: fixed !important;
    left: auto !important;
    right: max(10px, env(safe-area-inset-right)) !important;
    bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    width: auto !important;
    min-width: 48px !important;
    max-width: none !important;
    justify-content: center !important;
    padding: 4px !important;
    border-radius: 999px !important;
    background: rgba(255, 255, 255, 0.92) !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15) !important;
    margin-left: auto !important;
    overflow: visible !important;
    touch-action: manipulation;
  }

  .mindmap-actions.actions-collapsed #toggle-actions-collapse-btn svg {
    transform: rotate(180deg);
  }

  .mindmap-actions .btn,
  body.fullscreen-mode-active .mindmap-actions .btn {
    flex: 0 0 auto;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    padding: 0 !important;
    color: var(--text-main, #263824) !important;
    scroll-snap-align: center;
  }

  .mindmap-actions .btn svg,
  body.fullscreen-mode-active .mindmap-actions .btn svg {
    width: 18px !important;
    height: 18px !important;
    stroke-width: 2.15px !important;
  }

  body.fullscreen-mode-active .mindmap-actions {
    position: fixed !important;
    left: max(10px, env(safe-area-inset-left)) !important;
    right: max(10px, env(safe-area-inset-right)) !important;
    bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    width: calc(100vw - max(10px, env(safe-area-inset-left)) - max(10px, env(safe-area-inset-right))) !important;
    max-width: calc(100vw - max(10px, env(safe-area-inset-left)) - max(10px, env(safe-area-inset-right))) !important;
    background: rgba(255, 255, 255, 0.9) !important;
    border-color: rgba(47, 107, 47, 0.16) !important;
  }

  body.fullscreen-mode-active .mindmap-actions.actions-collapsed {
    left: auto !important;
    right: max(10px, env(safe-area-inset-right)) !important;
    width: auto !important;
    min-width: 42px !important;
    max-width: none !important;
    justify-content: center !important;
    padding: 4px !important;
    overflow: visible !important;
  }

  body.dark-theme.fullscreen-mode-active .mindmap-actions {
    background: rgba(30, 41, 59, 0.9) !important;
  }

  body.dark-theme .mindmap-actions .btn,
  body.dark-theme.fullscreen-mode-active .mindmap-actions .btn {
    color: #e2e8f0 !important;
  }
}

@media (min-width: 769px) {
  .sidebar-toggle-trigger {
    right: -14px;
    width: 28px;
    height: 44px;
    border-left: 1px solid rgba(47, 107, 47, 0.08);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.72);
    color: var(--primary-color);
    box-shadow: 0 8px 24px rgba(31, 54, 38, 0.1);
    backdrop-filter: blur(12px);
  }

  .sidebar-toggle-trigger:hover {
    background: rgba(232, 245, 233, 0.88);
    box-shadow: 0 10px 26px rgba(31, 54, 38, 0.16);
  }

  .sidebar-toggle-trigger svg {
    width: 16px;
    height: 16px;
    stroke-width: 2.2;
  }
}

/* Mobile sidebar entry button (#menu-btn) must be visible on mobile screen (max-width: 768px) */
@media (max-width: 768px) {
  .sidebar-toggle-trigger,
  body.fullscreen-mode-active .sidebar-toggle-trigger,
  body.flashcard-immersive .sidebar-toggle-trigger {
    display: none !important;
  }

  #menu-btn,
  #exam-menu-btn,
  #open-prescription-sidebar,
  #open-excipient-sidebar {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    align-items: center !important;
    justify-content: center !important;
    grid-column: 1 !important;
    grid-row: 1 !important;
    position: relative !important;
    z-index: 30 !important;
    flex: 0 0 36px !important;
    flex-shrink: 0 !important;
    width: 36px !important;
    min-width: 36px !important;
    height: 36px !important;
    padding: 0 !important;
    border-radius: 8px !important;
    background: var(--bg-card, rgba(255, 255, 255, 0.85)) !important;
    border: 1px solid var(--border-color, rgba(0, 0, 0, 0.12)) !important;
    color: var(--primary-color, #2b6cb0) !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  }
}

@media (min-width: 769px) {
  #menu-btn,
  #exam-menu-btn,
  #open-prescription-sidebar,
  #open-excipient-sidebar {
    display: none !important;
  }
}

/* v200: enlarge flashcards slightly on desktop and tablet without touching phone layout. */
@media (min-width: 769px) {
  body.flashcard-page .flashcards-container {
    padding: 22px 24px 28px;
  }

  body.flashcard-page .flashcards-active-area {
    max-width: 1040px;
    gap: 14px;
  }

  body.flashcard-page .card-scene {
    width: min(100%, 900px);
    min-height: clamp(600px, calc(100dvh - 190px), 700px);
    height: clamp(600px, calc(100dvh - 190px), 700px);
    max-height: 700px;
  }

  body.flashcard-page .card-face {
    padding: 30px 34px;
  }

  body.flashcard-page .card-question-text {
    font-size: clamp(1.32rem, 1.8vw, 1.72rem);
  }

  body.flashcard-page .card-answer-text {
    font-size: 1.03rem;
  }
}

@media (min-width: 769px) and (max-width: 1180px) {
  body.flashcard-page .flashcards-container {
    padding: 14px 18px 20px;
  }

  body.flashcard-page .flashcards-active-area {
    max-width: min(100%, 940px);
  }

  body.flashcard-page .card-scene {
    width: min(100%, 860px);
    min-height: clamp(560px, calc(100dvh - 150px), 680px);
    height: clamp(560px, calc(100dvh - 150px), 680px);
    max-height: 680px;
  }

  body.flashcard-page .card-face {
    padding: 24px 30px;
  }
}

@media (min-width: 901px) and (max-width: 1180px) {
  body.flashcard-page .sidebar {
    width: 240px;
  }

  body.flashcard-page .card-scene-wrapper {
    padding-inline: 42px;
  }
}

/* v199: glass navigation and mindmap controls polish. */
.top-bar {
  background: rgba(250, 252, 249, 0.72) !important;
  border-bottom: 1px solid rgba(47, 107, 47, 0.12) !important;
  box-shadow: 0 10px 30px rgba(31, 54, 38, 0.08), inset 0 -1px 0 rgba(255, 255, 255, 0.62) !important;
  backdrop-filter: blur(18px) saturate(1.35) !important;
  -webkit-backdrop-filter: blur(18px) saturate(1.35) !important;
}

body.dark-theme .top-bar {
  background: rgba(17, 24, 39, 0.7) !important;
  border-bottom-color: rgba(199, 241, 194, 0.14) !important;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28), inset 0 -1px 0 rgba(255, 255, 255, 0.08) !important;
}

.top-mode-tabs {
  gap: 5px !important;
  padding: 5px !important;
  border: 1px solid rgba(47, 107, 47, 0.14) !important;
  border-radius: 999px !important;
  background: rgba(255, 255, 255, 0.58) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.78), 0 8px 24px rgba(31, 54, 38, 0.08) !important;
  backdrop-filter: blur(16px) saturate(1.25) !important;
  -webkit-backdrop-filter: blur(16px) saturate(1.25) !important;
}

body.dark-theme .top-mode-tabs {
  border-color: rgba(199, 241, 194, 0.16) !important;
  background: rgba(15, 23, 42, 0.58) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 10px 26px rgba(0, 0, 0, 0.22) !important;
}

.top-mode-tab {
  min-height: 36px !important;
  padding: 7px 13px !important;
  border: 0 !important;
  border-radius: 999px !important;
  color: rgba(38, 56, 36, 0.72) !important;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease !important;
}

.top-mode-tab svg {
  width: 17px !important;
  height: 17px !important;
  stroke-width: 2.05px !important;
}

.top-mode-tab:hover,
.top-mode-tab:focus-visible {
  background: rgba(232, 245, 233, 0.72) !important;
  color: var(--primary-color, #2f6b2f) !important;
  transform: translateY(-1px);
}

.top-mode-tab.is-active {
  background: rgba(232, 245, 233, 0.9) !important;
  color: var(--primary-color, #2f6b2f) !important;
  box-shadow: inset 0 0 0 1px rgba(47, 107, 47, 0.16), 0 5px 14px rgba(47, 107, 47, 0.12) !important;
}

body.dark-theme .top-mode-tab {
  color: rgba(226, 232, 240, 0.72) !important;
}

body.dark-theme .top-mode-tab:hover,
body.dark-theme .top-mode-tab:focus-visible,
body.dark-theme .top-mode-tab.is-active {
  background: rgba(56, 74, 54, 0.72) !important;
  color: #c7f1c2 !important;
}

.toggle-btn,
.theme-btn,
.settings-btn {
  border: 1px solid rgba(47, 107, 47, 0.12) !important;
  border-radius: 999px !important;
  background: rgba(255, 255, 255, 0.58) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72), 0 8px 20px rgba(31, 54, 38, 0.08) !important;
  backdrop-filter: blur(14px) saturate(1.25) !important;
  -webkit-backdrop-filter: blur(14px) saturate(1.25) !important;
}

.toggle-btn:hover,
.theme-btn:hover,
.settings-btn:hover {
  background: rgba(232, 245, 233, 0.82) !important;
  color: var(--primary-color, #2f6b2f) !important;
}

body.dark-theme .toggle-btn,
body.dark-theme .theme-btn,
body.dark-theme .settings-btn {
  border-color: rgba(199, 241, 194, 0.14) !important;
  background: rgba(15, 23, 42, 0.58) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 10px 22px rgba(0, 0, 0, 0.24) !important;
}

.mindmap-actions,
.mindmap-handwriting-toolbar {
  border: 1px solid rgba(47, 107, 47, 0.14) !important;
  background: rgba(255, 255, 255, 0.62) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 12px 34px rgba(31, 54, 38, 0.14) !important;
  backdrop-filter: blur(18px) saturate(1.35) !important;
  -webkit-backdrop-filter: blur(18px) saturate(1.35) !important;
}

.mindmap-actions .btn,
.mindmap-handwriting-toolbar .hw-tool-btn {
  background: rgba(255, 255, 255, 0.18) !important;
  border-radius: 999px !important;
}

.mindmap-actions .btn:hover,
.mindmap-handwriting-toolbar .hw-tool-btn:hover {
  background: rgba(232, 245, 233, 0.84) !important;
}

.mindmap-actions.actions-collapsed {
  border-radius: 999px !important;
  padding: 5px !important;
}

body.dark-theme .mindmap-actions,
body.dark-theme .mindmap-handwriting-toolbar {
  border-color: rgba(199, 241, 194, 0.16) !important;
  background: rgba(15, 23, 42, 0.66) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 16px 38px rgba(0, 0, 0, 0.3) !important;
}

.pwa-status {
  border: 1px solid rgba(47, 107, 47, 0.12) !important;
  border-radius: 999px !important;
  background: rgba(255, 255, 255, 0.72) !important;
  box-shadow: 0 10px 30px rgba(31, 54, 38, 0.12) !important;
  backdrop-filter: blur(16px) saturate(1.25) !important;
  -webkit-backdrop-filter: blur(16px) saturate(1.25) !important;
}

body.dark-theme .pwa-status {
  background: rgba(15, 23, 42, 0.78) !important;
  border-color: rgba(199, 241, 194, 0.16) !important;
}

.study-pull-square-indicator {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  z-index: 10000060;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid rgba(47, 107, 47, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--primary-color, #2f6b2f);
  box-shadow: 0 12px 28px rgba(31, 54, 38, 0.14);
  font-size: 0.82rem;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, calc(-110% + var(--study-pull-distance, 0px) * 0.5)) scale(0.96);
  transition: opacity 0.14s ease, transform 0.14s ease, background 0.14s ease;
  backdrop-filter: blur(16px) saturate(1.25);
  -webkit-backdrop-filter: blur(16px) saturate(1.25);
}

.study-pull-square-indicator svg {
  width: 16px;
  height: 16px;
  stroke-width: 2.4;
}

body.study-pull-square-active .study-pull-square-indicator {
  opacity: 1;
  transform: translate(-50%, min(56px, var(--study-pull-distance, 0px) * 0.5)) scale(1);
}

body.study-pull-square-ready .study-pull-square-indicator {
  background: rgba(232, 245, 233, 0.94);
  box-shadow: 0 16px 34px rgba(47, 107, 47, 0.18);
}

body.dark-theme .study-pull-square-indicator {
  border-color: rgba(199, 241, 194, 0.18);
  background: rgba(15, 23, 42, 0.82);
  color: #c7f1c2;
}

@media (max-width: 768px) {
  html,
  body,
  .app-container,
  .main-content {
    max-width: 100%;
    overflow-x: hidden;
  }

  .mindmap-actions {
    left: auto !important;
    right: max(10px, env(safe-area-inset-right)) !important;
    max-width: calc(100vw - 20px) !important;
    padding: 5px !important;
    border-radius: 999px !important;
    justify-content: center !important;
  }

  .mindmap-actions:not(.actions-collapsed) {
    left: max(10px, env(safe-area-inset-left)) !important;
    justify-content: flex-start !important;
    padding: 6px 8px !important;
  }

  .mindmap-actions.actions-collapsed {
    min-width: 46px !important;
    width: auto !important;
    overflow: visible !important;
  }

  .mindmap-actions .btn,
  body.fullscreen-mode-active .mindmap-actions .btn {
    width: 42px !important;
    height: 42px !important;
    min-width: 42px !important;
  }

  .pwa-status[data-state="info"] {
    display: none !important;
  }
}

body.flashcard-page .card-answer-text-container {
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.card-answer-empty {
  margin: 0;
  padding: 18px 16px;
  border: 1px dashed color-mix(in srgb, var(--danger-color) 36%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--danger-light) 64%, transparent);
  color: var(--danger-color);
  font-weight: 700;
  line-height: 1.7;
  text-align: left;
}

.card-quick-controls .flashcard-delete-btn {
  color: var(--danger-color);
  background: color-mix(in srgb, var(--danger-light) 78%, #ffffff 22%);
}

.card-quick-controls .flashcard-delete-btn:hover,
.card-quick-controls .flashcard-delete-btn:focus-visible {
  border-color: color-mix(in srgb, var(--danger-color) 42%, transparent);
  transform: translateY(-1px);
}

@media (max-width: 430px) {
  body.flashcard-page .card-quick-controls {
    width: min(100%, 300px);
    justify-content: space-between;
  }

  body.flashcard-page .card-quick-controls .btn {
    width: 40px !important;
    min-width: 40px !important;
  }
}

@media (max-width: 768px) {
  body.flashcard-page .pwa-status {
    bottom: calc(128px + env(safe-area-inset-bottom)) !important;
    max-width: min(330px, calc(100vw - 40px));
    padding: 7px 12px;
  }
}

/* v212: Anki-like review home and three-grade flashcard controls. */
.flashcard-review-dashboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: min(820px, 100%);
  margin: 0 auto 8px;
}

.review-dashboard-card {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--primary-color) 14%, var(--border-color));
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.66);
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(31, 54, 38, 0.07);
}

.review-dashboard-card span {
  font-size: 0.76rem;
  font-weight: 820;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.review-dashboard-card strong {
  font-size: 1.35rem;
  line-height: 1.05;
  color: var(--primary-color);
}

.review-dashboard-card small {
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.review-dashboard-card.is-active {
  border-color: color-mix(in srgb, var(--primary-color) 42%, var(--border-color));
  background: color-mix(in srgb, var(--primary-light) 72%, #fff 28%);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary-color) 18%, transparent), 0 10px 24px rgba(47, 107, 47, 0.12);
}

.review-dashboard-card.is-empty {
  opacity: 0.62;
}

.card-bottom-controls {
  flex-direction: column;
  gap: 8px;
}

.card-review-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  width: min(420px, 100%);
  padding: 4px;
  border-radius: 16px;
  background: color-mix(in srgb, var(--primary-light) 46%, rgba(255,255,255,0.8) 54%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.62), 0 8px 18px rgba(31, 54, 38, 0.08);
}

.review-rating-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--text-main);
  background: rgba(255,255,255,0.72);
  font-weight: 850;
  cursor: pointer;
}

.review-rating-btn svg,
.review-rating-btn i {
  width: 17px;
  height: 17px;
}

.review-rating-again {
  color: var(--danger-color);
  background: color-mix(in srgb, var(--danger-light) 72%, #fff 28%);
}

.review-rating-hard {
  color: #9a5b00;
  background: color-mix(in srgb, #fff3cd 78%, #fff 22%);
}

.review-rating-good {
  color: #fff;
  background: linear-gradient(135deg, var(--primary-color), color-mix(in srgb, var(--primary-color) 70%, #10b981 30%));
}

.card-recitation-controls {
  display: flex;
  justify-content: center;
  width: min(420px, 100%);
}

.flashcard-recitation-btn {
  min-height: 42px;
  padding-inline: 22px;
  border-radius: 14px;
  font-weight: 850;
  box-shadow: 0 10px 24px rgba(47, 107, 47, 0.16);
}

.card-quick-controls .flashcard-recitation-btn {
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 14px;
  box-shadow: none;
}

.flashcard-recitation-btn.is-added {
  color: var(--primary-color);
  background: color-mix(in srgb, var(--primary-light) 84%, #fff 16%);
  border-color: color-mix(in srgb, var(--primary-color) 34%, var(--border-color));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary-color) 12%, transparent);
}

.inline-confirm-popover {
  position: fixed;
  z-index: 1200;
  width: min(240px, calc(100vw - 20px));
  padding: 10px;
  border: 1px solid color-mix(in srgb, var(--danger-color) 24%, var(--border-color));
  border-radius: 12px;
  background: var(--panel-bg);
  color: var(--text-main);
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.18);
}

.inline-confirm-text {
  font-size: 0.82rem;
  line-height: 1.45;
  font-weight: 760;
}

.inline-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
  margin-top: 9px;
}

.inline-confirm-actions button {
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--text-main);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
}

.inline-confirm-actions .inline-confirm-ok {
  border-color: color-mix(in srgb, var(--danger-color) 36%, transparent);
  background: color-mix(in srgb, var(--danger-light) 78%, #fff 22%);
  color: var(--danger-color);
}

body.dark-theme .review-dashboard-card,
body.dark-theme .card-review-controls,
body.dark-theme .review-rating-btn {
  background: rgba(15, 23, 42, 0.68);
}

@media (max-width: 768px) {
  body.flashcard-page .flashcard-review-dashboard {
    gap: 6px;
    margin: 6px auto 6px;
  }

  body.flashcard-page .review-dashboard-card {
    min-height: 62px;
    padding: 8px 7px;
    border-radius: 12px;
  }

  body.flashcard-page .review-dashboard-card strong {
    font-size: 1.12rem;
  }

  body.flashcard-page .review-dashboard-card small {
    display: none;
  }

  body.flashcard-page .card-scene {
    min-height: clamp(390px, calc(100dvh - 250px), 720px) !important;
    height: clamp(390px, calc(100dvh - 250px), 720px) !important;
  }

  body.flashcard-page .card-bottom-controls {
    gap: 6px;
  }

  body.flashcard-page .card-quick-controls {
    width: min(100%, 250px);
  }

  body.flashcard-page .card-review-controls {
    width: min(100%, 330px);
  }

  body.flashcard-page .card-recitation-controls {
    width: min(100%, 300px);
  }

  body.flashcard-page .card-recitation-controls .flashcard-recitation-btn {
    width: 100%;
  }

  body.flashcard-page .review-rating-btn {
    min-height: 42px;
    font-size: 0.86rem;
  }
}

/* v221: tablet sidebar handle, centered flashcards, and stable theme controls. */
@media (min-width: 769px) {
  .sidebar.collapsed .sidebar-toggle-trigger {
    right: -29px !important;
  }
}

@media (min-width: 901px) and (max-width: 1180px) {
  body.flashcard-page .sidebar.collapsed {
    margin-left: -240px !important;
  }

  body.flashcard-page .sidebar.collapsed .sidebar-toggle-trigger {
    right: -29px !important;
  }
}

/* v238: compact tablet/mobile shell, stable top actions, and page zoom controls. */
:root {
  --study-sidebar-width: 292px;
  --study-sidebar-tablet-width: 246px;
  --study-topbar-height: 58px;
  --study-page-zoom: 1;
}

@supports (zoom: 1) {
  body {
    zoom: var(--study-page-zoom, 1);
    width: calc(100% / var(--study-page-zoom, 1));
    min-height: calc(100dvh / var(--study-page-zoom, 1));
  }
}

.study-page-zoom-card {
  display: grid;
  gap: 10px;
}

.study-page-zoom-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.study-page-zoom-head h4 {
  margin: 0;
}

.study-page-zoom-value {
  flex: 0 0 auto;
  color: var(--primary-color);
  font-size: 0.84rem;
  font-weight: 800;
}

.study-page-zoom-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  gap: 8px;
}

.study-page-zoom-btn {
  min-height: 36px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--panel-bg);
  color: var(--text-main);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 800;
  cursor: pointer;
}

.study-page-zoom-btn.is-active {
  border-color: rgba(47, 107, 47, 0.28);
  background: var(--primary-light);
  color: var(--primary-color);
  box-shadow: inset 0 0 0 1px rgba(47, 107, 47, 0.16);
}

body.flashcard-page .mastery-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 1001;
  display: flex;
  flex-direction: column;
  width: min(560px, calc(100vw - 28px));
  max-height: calc(100dvh - 36px);
  overflow: hidden;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  background: var(--panel-bg);
  box-shadow: 0 24px 70px rgba(31, 54, 38, 0.22);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.96);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}

body.flashcard-page .mastery-modal.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

body.flashcard-page .mastery-modal[aria-hidden="true"]:not(.active) {
  display: none !important;
}

body.flashcard-page .mastery-modal .modal-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sidebar {
  width: var(--study-sidebar-width) !important;
  flex-basis: var(--study-sidebar-width) !important;
}

@media (min-width: 769px) {
  .sidebar.collapsed {
    margin-left: calc(-1 * var(--study-sidebar-width)) !important;
  }
}

.single-mode-container {
  padding-top: 10px !important;
}

.mindmap-container {
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

body.flashcard-page .flashcards-container {
  padding-top: 8px !important;
}

body.flashcard-page .card-answer-text-container,
body.flashcard-page .card-question-text {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(95, 116, 94, 0.35) transparent;
}

body.flashcard-page .card-answer-text-container::-webkit-scrollbar,
body.flashcard-page .card-question-text::-webkit-scrollbar {
  width: 8px;
}

body.flashcard-page .card-answer-text-container::-webkit-scrollbar-thumb,
body.flashcard-page .card-question-text::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(95, 116, 94, 0.35);
}

@media (min-width: 769px) and (max-width: 1180px) {
  :root {
    --study-sidebar-width: var(--study-sidebar-tablet-width);
    --study-topbar-height: 54px;
  }

  .sidebar {
    width: var(--study-sidebar-width) !important;
    flex: 0 0 var(--study-sidebar-width) !important;
  }

  .sidebar-header {
    min-height: 56px !important;
    padding: 10px 12px !important;
  }

  .logo-area {
    gap: 8px !important;
  }

  .logo-img {
    width: 32px !important;
    height: 32px !important;
  }

  .logo-text .app-brand-title {
    max-width: 118px !important;
  }

  .logo-text .app-brand-title span:first-child {
    font-size: 0.9rem !important;
  }

  .logo-text .app-brand-title span:last-child {
    margin-top: 0 !important;
    font-size: 0.64rem !important;
  }

  .study-navigation {
    padding: 8px 10px 10px !important;
  }

  .study-navigation-label,
  .list-title {
    margin-bottom: 5px !important;
    font-size: 0.62rem !important;
  }

  .subject-toggle-group,
  .subbook-toggle-group {
    gap: 4px !important;
  }

  .subject-toggle-btn,
  .subbook-toggle-btn {
    min-height: 32px !important;
    padding: 6px 8px !important;
    font-size: 0.72rem !important;
  }

  .chapter-list-container {
    padding: 6px 10px 18px !important;
  }

  .chapter-item {
    margin-bottom: 3px !important;
    padding: 9px 10px !important;
    font-size: 0.82rem !important;
  }

  .learning-square-top-tab {
    display: none !important;
  }

  .single-mode-container {
    padding: 6px 10px 10px !important;
  }

  body.flashcard-page .flashcards-container {
    padding: 8px 12px 14px !important;
  }

  body.flashcard-page .card-scene-wrapper {
    padding-inline: 26px !important;
  }

  body.flashcard-page .card-scene {
    min-height: clamp(500px, calc(100dvh - 126px), 650px) !important;
    height: clamp(500px, calc(100dvh - 126px), 650px) !important;
  }
}

@media (max-width: 768px) {
  :root {
    --study-topbar-height: 54px;
  }

  .sidebar {
    width: min(86vw, 320px) !important;
    flex-basis: auto !important;
  }

  .sidebar-header {
    min-height: 54px !important;
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px !important;
  }

  .logo-img {
    width: 30px !important;
    height: 30px !important;
  }

  .logo-text .app-brand-title span:first-child {
    font-size: 0.86rem !important;
  }

  .logo-text .app-brand-title span:last-child {
    font-size: 0.6rem !important;
  }

  .learning-square-top-tab {
    display: none !important;
  }

  .single-mode-container {
    padding: 4px 6px calc(6px + env(safe-area-inset-bottom)) !important;
  }

  body.flashcard-page .flashcards-container {
    padding: 5px 4px calc(8px + env(safe-area-inset-bottom)) !important;
  }

  body.flashcard-page .card-scene-wrapper {
    padding-inline: 2px !important;
  }
}

body.flashcard-page .visual-editor-rich-input,
body.flashcard-page .visual-editor-rich-paragraph,
body.flashcard-page #visual-editor-question,
body.flashcard-page #visual-editor-page,
body.flashcard-page #visual-editor-answer-text,
body.flashcard-page #flashcard-textarea,
body.flashcard-page .card-question-text[contenteditable="true"],
body.flashcard-page .card-answer-text[contenteditable="true"] {
  -webkit-touch-callout: none !important;
}

/* v239: corrected scope - card scrolling + stable theme/account actions, without changing module-tab density. */
body.flashcard-page .flashcards-container,
body.flashcard-page .flashcards-active-area {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

body.flashcard-page .card-scene-wrapper,
body.flashcard-page .card-scene,
body.flashcard-page .flashcard,
body.flashcard-page .card-face {
  min-height: 0;
}

body.flashcard-page .card-question-text,
body.flashcard-page .card-answer-text-container {
  max-height: 100%;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.top-bar .theme-btn,
.top-bar .settings-btn,
.top-bar .account-sync-btn,
.top-bar .account-profile-trigger {
  flex-shrink: 0 !important;
}

/* v241: page zoom uses reverse layout compensation, so scaled pages still fill the viewport. */
@supports (zoom: 1) {
  body {
    width: calc(100vw / var(--study-page-zoom, 1)) !important;
    min-width: calc(100vw / var(--study-page-zoom, 1)) !important;
    max-width: calc(100vw / var(--study-page-zoom, 1)) !important;
    min-height: calc(100dvh / var(--study-page-zoom, 1)) !important;
    overflow-x: hidden !important;
  }

  body .app-container {
    width: calc(100vw / var(--study-page-zoom, 1)) !important;
    max-width: calc(100vw / var(--study-page-zoom, 1)) !important;
    height: calc(100dvh / var(--study-page-zoom, 1)) !important;
    min-height: calc(100dvh / var(--study-page-zoom, 1)) !important;
  }

  body .main-content {
    min-height: calc(100dvh / var(--study-page-zoom, 1)) !important;
    max-width: none !important;
  }

  body .top-bar {
    width: 100% !important;
    max-width: 100% !important;
  }

  body .modal-backdrop {
    width: calc(100vw / var(--study-page-zoom, 1)) !important;
    height: calc(100dvh / var(--study-page-zoom, 1)) !important;
  }
}

/* v242: iOS/iPadOS does not handle body zoom consistently in Safari/PWA.
   Keep Android on zoom, but use a transformed app stage for Apple devices. */
@supports (zoom: 1) {
  html.apple-study-device,
  html.apple-study-device body {
    width: 100vw !important;
    min-width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    min-height: 100dvh !important;
    overflow: hidden !important;
  }

  html.apple-study-device body {
    zoom: 1 !important;
  }

  html.apple-study-device body .app-container {
    width: calc(100vw / var(--study-page-zoom, 1)) !important;
    max-width: calc(100vw / var(--study-page-zoom, 1)) !important;
    height: calc(100dvh / var(--study-page-zoom, 1)) !important;
    min-height: calc(100dvh / var(--study-page-zoom, 1)) !important;
    transform: scale(var(--study-page-zoom, 1));
    transform-origin: top left;
    overflow: hidden !important;
  }

  html.apple-study-device body .main-content {
    min-height: calc(100dvh / var(--study-page-zoom, 1)) !important;
  }

  html.apple-study-device body .top-bar {
    width: 100% !important;
    max-width: 100% !important;
  }

  html.apple-study-device body .modal-backdrop,
  html.apple-study-device body .account-sync-backdrop {
    width: 100vw !important;
    height: 100dvh !important;
  }
}

html.apple-study-device .sidebar {
  min-height: 0 !important;
  overflow: hidden !important;
}

html.apple-study-device .chapter-list-container {
  flex: 1 1 0 !important;
  min-height: 0 !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

/* iPad/WebKit viewport guard: keep fixed edge tools inside the real visible viewport at 70-100% page zoom. */
html.ipad-study-device {
  --ipad-visible-width: 100vw;
  --ipad-visible-height: 100dvh;
  --ipad-stage-width: calc(100vw / var(--study-page-zoom, 1));
  --ipad-stage-height: calc(100dvh / var(--study-page-zoom, 1));
  --ipad-stage-right-pad: max(12px, env(safe-area-inset-right));
  --ipad-stage-bottom-pad: max(12px, env(safe-area-inset-bottom));
}

@supports (zoom: 1) {
  html.ipad-study-device body .app-container {
    width: var(--ipad-stage-width) !important;
    max-width: var(--ipad-stage-width) !important;
    height: var(--ipad-stage-height) !important;
    min-height: var(--ipad-stage-height) !important;
  }

  html.ipad-study-device body .main-content {
    min-height: var(--ipad-stage-height) !important;
  }

  html.ipad-study-device body .top-bar {
    width: 100% !important;
    max-width: 100% !important;
    padding-right: calc(var(--ipad-stage-right-pad) + 8px) !important;
    box-sizing: border-box !important;
  }

  html.ipad-study-device body .top-bar-right {
    justify-self: end !important;
    flex-shrink: 0 !important;
    max-width: max-content !important;
    position: relative !important;
    z-index: 40 !important;
  }

  html.ipad-study-device body .mindmap-actions,
  html.ipad-study-device body.fullscreen-mode-active .mindmap-actions {
    right: var(--ipad-stage-right-pad) !important;
    bottom: var(--ipad-stage-bottom-pad) !important;
    max-width: min(560px, calc(var(--ipad-stage-width) - 24px)) !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
  }

  html.ipad-study-device body.fullscreen-mode-active .mindmap-handwriting-toolbar {
    bottom: calc(var(--ipad-stage-bottom-pad) + 58px) !important;
    max-width: calc(var(--ipad-stage-width) - 20px) !important;
  }

  html.ipad-study-device body.fullscreen-mode-active .sidebar,
  html.ipad-study-device body.flashcard-immersive .sidebar {
    width: min(calc(var(--ipad-stage-width) * 0.86), 320px) !important;
    height: var(--ipad-stage-height) !important;
    display: flex !important;
  }

  html.ipad-study-device body.fullscreen-mode-active .sidebar-toggle-trigger,
  html.ipad-study-device body.flashcard-immersive .sidebar-toggle-trigger {
    display: flex !important;
    right: -22px !important;
    z-index: 1000004 !important;
  }
}

@media (min-width: 769px) and (max-width: 1180px) {
  body.flashcard-page .flashcards-active-area {
    gap: 12px !important;
  }

  body.flashcard-page .card-scene {
    min-height: clamp(500px, calc(100dvh - 154px), 620px) !important;
    height: clamp(500px, calc(100dvh - 154px), 620px) !important;
  }

  body.flashcard-page .card-bottom-controls {
    flex: 0 0 auto !important;
    margin-top: 12px !important;
  }
}

body.discussion-page .top-bar,
body.announcement-page .top-bar {
  width: calc(100vw / var(--study-page-zoom, 1)) !important;
  max-width: calc(100vw / var(--study-page-zoom, 1)) !important;
}

@media (max-width: 768px) {
  body.flashcard-page .flashcards-active-area,
  body.flashcard-page .card-scene-wrapper,
  body.flashcard-page .card-scene,
  body.flashcard-page .flashcard,
  body.flashcard-page .card-face,
  body.flashcard-page .card-bottom-controls {
    max-width: 100% !important;
  }
}

/* Mobile flashcard shell: page scroll outside, card text scroll inside, no 3D mirroring on phones. */
@supports (zoom: 1) {
  html {
    min-height: 100dvh;
    background: var(--bg-color);
  }

  body {
    height: auto;
    background: var(--bg-color);
  }

  body.flashcard-page,
  body.mastery-page {
    overflow-y: auto;
    overscroll-behavior-y: contain;
  }

  body.flashcard-page .app-container,
  body.mastery-page .app-container,
  body.flashcard-page .main-content,
  body.mastery-page .main-content {
    height: auto;
    min-height: calc(100dvh / var(--study-page-zoom, 1));
    overflow-x: hidden;
  }
}

body.flashcard-page .single-mode-container {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

body.flashcard-page .flashcards-container {
  flex: 0 0 auto;
  max-height: none;
  align-items: stretch;
  overflow: visible;
}

body.flashcard-page .flashcards-active-area {
  flex: 0 0 auto;
  height: auto;
  overflow: visible;
  gap: 16px;
  padding-bottom: calc(22px + env(safe-area-inset-bottom));
}

body.flashcard-page .card-scene-wrapper {
  flex: 0 0 auto;
  align-items: flex-start;
  overflow: visible;
}

body.flashcard-page .card-scene {
  flex: 0 0 auto;
  max-height: none;
}

body.flashcard-page .flashcard,
body.flashcard-page .card-face {
  min-height: 0;
}

body.flashcard-page .card-question-text,
body.flashcard-page .card-answer-text-container {
  flex: 1 1 0%;
  min-height: 0;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

body.flashcard-page .card-question-text {
  align-items: flex-start;
  justify-content: flex-start;
}

body.flashcard-page .card-bottom-controls {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  margin-top: 14px;
  transform: none;
}

.mastery-top-card-tools .settings-btn,
.mastery-top-card-tools .account-profile-trigger,
.mastery-top-card-tools .account-sync-btn {
  width: 38px !important;
  min-width: 38px !important;
  max-width: 38px !important;
  height: 38px !important;
  min-height: 38px !important;
  padding: 0 !important;
  border-radius: 12px !important;
}

.mastery-top-card-tools .account-profile-trigger > span:not(.account-sync-avatar),
.mastery-top-card-tools .account-sync-btn > span:not(.account-sync-avatar) {
  display: none !important;
}

@media (max-width: 768px) {
  body.flashcard-page .single-mode-container {
    min-height: calc(100dvh - var(--study-topbar-height, 62px));
    padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
    overflow-y: auto;
  }

  body.flashcard-page .flashcards-container {
    width: 100%;
    min-height: calc(100dvh - var(--study-topbar-height, 62px) - 10px);
    max-height: none;
    padding: 4px 2px calc(18px + env(safe-area-inset-bottom));
    overflow: visible;
  }

  body.flashcard-page .flashcards-active-area {
    width: 100%;
    max-width: none;
    min-height: 0;
    gap: 12px;
    overflow: visible;
  }

  body.flashcard-page .card-scene-wrapper {
    padding-inline: 0;
    align-items: stretch;
  }

  body.flashcard-page .card-scene {
    width: 100%;
    height: var(--flashcard-card-height, clamp(430px, calc(100dvh - 184px), 680px));
    min-height: var(--flashcard-card-height, clamp(430px, calc(100dvh - 184px), 680px));
    max-height: none;
    perspective: none;
  }

  body.flashcard-page .flashcard {
    transform: none;
    transform-style: flat;
  }

  body.flashcard-page .card-face {
    inset: 0;
    padding: 22px 18px;
    transform: none;
    backface-visibility: visible;
    transition: opacity 0.16s ease, visibility 0.16s ease;
  }

  body.flashcard-page .card-back {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  body.flashcard-page .flashcard.is-flipped .card-front {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  body.flashcard-page .flashcard.is-flipped .card-back {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  body.flashcard-page .card-question-text,
  body.flashcard-page .card-answer-text-container {
    max-height: 100%;
  }

  body.flashcard-page .card-bottom-controls {
    margin-top: 12px;
    padding-bottom: max(4px, env(safe-area-inset-bottom));
  }

  body.flashcard-page .floating-nav-prev { left: -2px; }
  body.flashcard-page .floating-nav-next { right: -2px; }

  body.flashcard-page .flashcards-active-area.is-inline-editing .card-scene {
    height: auto;
    min-height: 0;
  }

  body.flashcard-page .flashcards-active-area.is-inline-editing .flashcard {
    display: grid;
    gap: 14px;
  }

  body.flashcard-page .flashcards-active-area.is-inline-editing .card-face {
    position: relative;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }
}

/* Flashcard stage layout: the card owns the study area and controls sit below it. */
html.flashcard-shell-page {
  --flashcard-stage-gap: clamp(18px, 2.4dvh, 28px);
  --flashcard-stage-pad-x: clamp(12px, 3vw, 36px);
  height: calc(100dvh / var(--study-page-zoom, 1)) !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

body.flashcard-page {
  height: calc(100dvh / var(--study-page-zoom, 1)) !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

body.flashcard-page .app-container,
body.flashcard-page .main-content {
  height: calc(100dvh / var(--study-page-zoom, 1)) !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

body.flashcard-page .single-mode-container {
  flex: 1 1 auto !important;
  display: flex !important;
  min-height: 0 !important;
  height: auto !important;
  padding: clamp(8px, 1.6dvh, 16px) var(--flashcard-stage-pad-x) clamp(12px, 1.8dvh, 18px) !important;
  overflow: hidden !important;
}

body.flashcard-page .flashcards-container {
  flex: 1 1 auto !important;
  align-items: center !important;
  justify-content: flex-start !important;
  width: 100% !important;
  min-height: 0 !important;
  height: 100% !important;
  max-height: none !important;
  padding: 0 !important;
  overflow: hidden !important;
}

body.flashcard-page .flashcards-active-area {
  flex: 1 1 auto !important;
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) !important;
  grid-template-rows: minmax(0, 1fr) auto !important;
  justify-items: center !important;
  align-items: stretch !important;
  width: min(100%, 1100px) !important;
  max-width: 1100px !important;
  height: 100% !important;
  min-height: 0 !important;
  gap: var(--flashcard-stage-gap) !important;
  padding: 0 !important;
  overflow: hidden !important;
}

body.flashcard-page .card-scene-wrapper {
  justify-self: center !important;
  width: min(100%, 1000px) !important;
  min-width: 0 !important;
  min-height: 0 !important;
  height: auto !important;
  align-self: stretch !important;
  display: flex !important;
  align-items: stretch !important;
  justify-content: center !important;
  padding-inline: clamp(34px, 5vw, 64px) !important;
  overflow: visible !important;
}

body.flashcard-page .card-scene {
  flex: 0 1 860px !important;
  align-self: stretch !important;
  width: min(100%, 860px) !important;
  min-width: 0 !important;
  height: var(--flashcard-card-height, 100%) !important;
  min-height: 0 !important;
  max-height: var(--flashcard-card-height, 100%) !important;
}

body.flashcard-page .flashcard,
body.flashcard-page .card-face {
  min-width: 0 !important;
  min-height: 0 !important;
}

body.flashcard-page .card-question-text,
body.flashcard-page .card-answer-text-container {
  flex: 1 1 0 !important;
  min-width: 0 !important;
  min-height: 0 !important;
  max-height: 100% !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
}

body.flashcard-page .card-bottom-controls {
  justify-self: center !important;
  flex: 0 0 auto !important;
  width: min(100%, 520px) !important;
  min-height: 52px !important;
  margin-top: 0 !important;
  padding-bottom: max(4px, env(safe-area-inset-bottom)) !important;
  overflow: visible !important;
}

body.flashcard-page .card-quick-controls {
  gap: 8px !important;
  min-height: 48px !important;
  padding: 5px !important;
}

body.flashcard-page .card-quick-controls .btn {
  width: 44px !important;
  min-width: 44px !important;
  min-height: 42px !important;
}

body.flashcard-immersive .main-content,
body.flashcard-immersive .single-mode-container,
body.flashcard-immersive .flashcards-container {
  height: calc(100dvh / var(--study-page-zoom, 1)) !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

body.flashcard-immersive .single-mode-container,
body.flashcard-immersive .flashcards-container {
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)) !important;
}

body.flashcard-immersive .flashcards-active-area {
  width: min(100%, 1120px) !important;
  max-width: 1120px !important;
}

body.flashcard-immersive .card-scene-wrapper {
  width: min(100%, 1040px) !important;
}

@media (min-width: 769px) and (max-width: 1180px), (hover: none) and (pointer: coarse) and (min-width: 769px) {
  body.flashcard-page .single-mode-container {
    padding: 8px 18px 12px !important;
  }

  body.flashcard-page .flashcards-active-area {
    width: min(100%, 980px) !important;
    max-width: 980px !important;
    gap: clamp(18px, 2.4dvh, 26px) !important;
  }

  body.flashcard-page .card-scene-wrapper {
    width: min(100%, 920px) !important;
    padding-inline: clamp(38px, 6vw, 72px) !important;
  }

  body.flashcard-page .card-scene {
    flex-basis: 780px !important;
    width: min(100%, 780px) !important;
  }

  body.flashcard-page .card-face {
    padding: 22px 28px !important;
  }
}

@media (max-width: 768px) {
  html.flashcard-shell-page {
    --flashcard-stage-gap: clamp(10px, 1.8dvh, 16px);
    --flashcard-stage-pad-x: 8px;
  }

  body.flashcard-page .single-mode-container {
    min-height: 0 !important;
    height: auto !important;
    padding: 6px var(--flashcard-stage-pad-x) calc(8px + env(safe-area-inset-bottom)) !important;
  }

  body.flashcard-page .flashcards-active-area {
    width: 100% !important;
    max-width: none !important;
  }

  body.flashcard-page .card-scene-wrapper {
    width: 100% !important;
    padding-inline: 2px !important;
  }

  body.flashcard-page .card-scene {
    flex-basis: 100% !important;
    width: 100% !important;
  }

  body.flashcard-page .card-face {
    padding: clamp(14px, 3.6vw, 20px) clamp(12px, 3.2vw, 18px) !important;
  }

  body.flashcard-page .card-bottom-controls {
    width: 100% !important;
    min-height: 46px !important;
    padding-bottom: max(2px, env(safe-area-inset-bottom)) !important;
  }

  body.flashcard-page .card-quick-controls {
    gap: 5px !important;
    min-height: 42px !important;
    padding: 3px !important;
  }

  body.flashcard-page .card-quick-controls .btn {
    width: 40px !important;
    min-width: 40px !important;
    min-height: 38px !important;
  }
}

@media (hover: hover) and (pointer: fine) and (min-width: 769px) {
  html.flashcard-shell-page:not(.touch-study-device):not(:has(body.flashcard-immersive)) {
    height: auto !important;
    min-height: 100% !important;
    overflow: auto !important;
  }

  html:not(.touch-study-device) body.flashcard-page:not(.flashcard-immersive) {
    height: auto !important;
    min-height: 100vh !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  html:not(.touch-study-device) body.flashcard-page:not(.flashcard-immersive) .app-container,
  html:not(.touch-study-device) body.flashcard-page:not(.flashcard-immersive) .main-content {
    height: auto !important;
    min-height: 100vh !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  html:not(.touch-study-device) body.flashcard-page:not(.flashcard-immersive) .single-mode-container {
    flex: 0 0 auto !important;
    height: auto !important;
    min-height: 0 !important;
    padding: 18px 20px 24px !important;
    overflow: visible !important;
  }

  html:not(.touch-study-device) body.flashcard-page:not(.flashcard-immersive) .flashcards-container {
    flex: 0 0 auto !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  html:not(.touch-study-device) body.flashcard-page:not(.flashcard-immersive) .flashcards-active-area {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: auto auto !important;
    justify-items: center !important;
    align-items: start !important;
    height: auto !important;
    min-height: 0 !important;
    width: min(100%, 920px) !important;
    max-width: 920px !important;
    gap: var(--flashcard-stage-gap) !important;
    overflow: visible !important;
  }

  html:not(.touch-study-device) body.flashcard-page:not(.flashcard-immersive) .card-scene-wrapper {
    justify-self: center !important;
    flex: none !important;
    width: min(100%, 900px) !important;
    height: auto !important;
    min-height: 0 !important;
    align-items: center !important;
    overflow: visible !important;
  }

  html:not(.touch-study-device) body.flashcard-page:not(.flashcard-immersive) .card-scene {
    width: min(100%, 820px) !important;
    height: clamp(500px, calc(100dvh - 210px), 700px) !important;
    min-height: clamp(500px, calc(100dvh - 210px), 700px) !important;
    max-height: none !important;
  }

  html:not(.touch-study-device) body.flashcard-page:not(.flashcard-immersive) .card-bottom-controls {
    justify-self: center !important;
    margin-top: 0 !important;
    padding-bottom: 0 !important;
  }
}

/* v243: mastery has a 3-column top bar; keep theme + login/settings as one right-side group. */
@media (min-width: 769px) and (max-width: 1180px) {
  body.mastery-page .mastery-top-bar .top-bar-right {
    display: flex !important;
    grid-column: 3 !important;
    grid-row: 1 !important;
    justify-self: end !important;
    align-self: center !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 8px !important;
    min-width: 0 !important;
    width: max-content !important;
    max-width: max-content !important;
    position: relative !important;
    z-index: 4 !important;
  }

  body.mastery-page .mastery-top-bar .top-bar-right .theme-btn,
  body.mastery-page .mastery-top-bar .top-bar-right .settings-btn,
  body.mastery-page .mastery-top-bar .top-bar-right .account-sync-btn,
  body.mastery-page .mastery-top-bar .top-bar-right .account-profile-trigger {
    grid-column: auto !important;
    grid-row: auto !important;
    justify-self: auto !important;
    flex: 0 0 auto !important;
  }
}

.study-pull-square-hit-zone {
  display: none;
}

@media (hover: none), (pointer: coarse) {
  body:not(.flashcard-page):not(.mastery-page):not(.discussion-page):not(.announcement-page) .study-pull-square-hit-zone {
    display: block;
    position: fixed;
    top: 0;
    left: var(--study-sidebar-tablet-width, 246px);
    right: 0;
    height: 22px;
    z-index: 140;
    background: transparent;
    touch-action: pan-y;
  }
}

@media (max-width: 768px) {
  body:not(.flashcard-page):not(.mastery-page):not(.discussion-page):not(.announcement-page) .study-pull-square-hit-zone {
    left: 0;
  }
}

/* Flashcard editing layout: use a two-panel form instead of a compressible review card. */
body.flashcard-page .flashcards-active-area.is-inline-editing {
  grid-template-rows: auto !important;
  align-content: start !important;
  overflow-y: auto !important;
  padding-bottom: calc(92px + env(safe-area-inset-bottom)) !important;
}

body.flashcard-page .flashcards-active-area.is-inline-editing .card-scene-wrapper {
  height: auto !important;
  align-self: start !important;
}

body.flashcard-page .flashcards-active-area.is-inline-editing .card-scene {
  flex: 0 0 auto !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
}

body.flashcard-page .flashcards-active-area.is-inline-editing .flashcard {
  display: grid !important;
  grid-template-rows: minmax(160px, auto) minmax(360px, auto) !important;
  gap: 14px !important;
  height: auto !important;
  min-height: 534px !important;
  transform: none !important;
  transform-style: flat !important;
}

body.flashcard-page .flashcards-active-area.is-inline-editing .card-face {
  position: relative !important;
  height: auto !important;
  min-height: 0 !important;
  transform: none !important;
  backface-visibility: visible !important;
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

body.flashcard-page .flashcards-active-area.is-inline-editing .card-front {
  min-height: 160px !important;
}

body.flashcard-page .flashcards-active-area.is-inline-editing .card-back {
  min-height: 360px !important;
}

body.flashcard-page .flashcards-active-area.is-inline-editing .card-question-text[contenteditable="true"],
body.flashcard-page .flashcards-active-area.is-inline-editing .card-answer-text[contenteditable="true"] {
  max-height: none !important;
}

/* v0.33: mobile sidebar entry is a plain three-line icon, not a framed button. */
@media (max-width: 768px) {
  .top-bar #menu-btn,
  .top-bar #exam-menu-btn,
  .top-bar #open-prescription-sidebar,
  .top-bar #open-excipient-sidebar {
    width: 44px !important;
    min-width: 44px !important;
    height: 44px !important;
    flex-basis: 44px !important;
    border: 0 !important;
    border-color: transparent !important;
    border-radius: 999px !important;
    background: transparent !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    color: var(--primary-color, #2f6b2f) !important;
  }

  .top-bar #menu-btn:active,
  .top-bar #exam-menu-btn:active,
  .top-bar #open-prescription-sidebar:active,
  .top-bar #open-excipient-sidebar:active {
    background: rgba(47, 107, 47, 0.08) !important;
  }

  .top-bar #menu-btn::before,
  .top-bar #exam-menu-btn::before,
  .top-bar #open-prescription-sidebar::before,
  .top-bar #open-excipient-sidebar::before {
    width: 22px !important;
    height: 18px !important;
    border-radius: 0 !important;
    background:
      linear-gradient(currentColor, currentColor) 0 2px / 22px 2px no-repeat,
      linear-gradient(currentColor, currentColor) 0 8px / 22px 2px no-repeat,
      linear-gradient(currentColor, currentColor) 0 14px / 22px 2px no-repeat !important;
  }
}

/* v0.33: keep the mindmap action dock anchored on tablets when it expands. */
@media (min-width: 769px) and (max-width: 1180px),
       (hover: none) and (pointer: coarse) and (min-width: 769px) {
  .mindmap-actions,
  body.fullscreen-mode-active .mindmap-actions {
    left: auto !important;
    right: max(14px, env(safe-area-inset-right)) !important;
    bottom: calc(14px + env(safe-area-inset-bottom)) !important;
    width: auto !important;
    max-width: min(560px, calc(100vw - 28px)) !important;
    justify-content: flex-end !important;
    margin-left: 0 !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    transform: none !important;
    transform-origin: right center !important;
    scroll-snap-type: none !important;
  }

  .mindmap-actions:not(.actions-collapsed),
  body.fullscreen-mode-active .mindmap-actions:not(.actions-collapsed) {
    padding: 6px 8px !important;
  }

  .mindmap-actions.actions-collapsed,
  body.fullscreen-mode-active .mindmap-actions.actions-collapsed {
    left: auto !important;
    right: max(14px, env(safe-area-inset-right)) !important;
    width: auto !important;
    min-width: 48px !important;
    max-width: none !important;
    justify-content: center !important;
    overflow: visible !important;
  }
}

/* Acceptance fix: keep the chapter drawer handle available in mindmap fullscreen and flashcard immersive modes. */
body.fullscreen-mode-active .sidebar,
body.flashcard-immersive .sidebar {
  display: flex !important;
}

body.fullscreen-mode-active .sidebar-overlay,
body.flashcard-immersive .sidebar-overlay {
  display: none !important;
}

body.fullscreen-mode-active .sidebar-overlay.open,
body.flashcard-immersive .sidebar-overlay.open {
  display: block !important;
}

body.fullscreen-mode-active .sidebar-toggle-trigger,
body.flashcard-immersive .sidebar-toggle-trigger {
  display: flex !important;
}
