html.layout-mobile,
body.layout-mobile {
  width: 100%;
  height: 100%;
  /* Preserve the WebView/browser edge-swipe Back gesture. */
  overscroll-behavior-x: auto;
  overscroll-behavior-y: none;
  font-family: var(--mobile-font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1, "liga" 1;
}

/* 矮竖屏手机（如 320×568）：取消欢迎区的上移，保证标题不进入固定顶栏。 */
@media (max-width: 640px) and (max-height: 640px) and (orientation: portrait) {
  html.layout-mobile .chat-panel.is-mobile-empty #chatArea {
    /* Welcome and recommendations can exceed the centered content box. */
    justify-content: flex-start !important;
  }

  html.layout-mobile .chat-panel.is-mobile-empty #mobileWelcomePanel {
    transform: none !important;
    margin-top: 8px !important;
  }
}

html.layout-mobile {
  --mobile-font-sans: "Söhne", "Sohne", "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mobile-font-display: "Söhne", "Sohne", "Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mobile-input-btn-size-md: clamp(38px, 10vw, 42px);
  --mobile-bottom-action-edge-guard: clamp(14px, 4vw, 18px);
  --mobile-input-bottom: calc(env(safe-area-inset-bottom) + var(--mobile-edge-gap));
  --mobile-chat-top-padding: clamp(0px, calc(0.4 * var(--mobile-vh, 1vh)), 4px);
  --mobile-chat-bottom-padding: clamp(10px, calc(2.8 * var(--mobile-vh, 1vh)), 16px);
  --mobile-input-bottom-runtime: var(--mobile-input-bottom);
  --mobile-chat-bottom-padding-runtime: var(--mobile-chat-bottom-padding);
  --mobile-topbar-content-top: max(10px, calc(env(safe-area-inset-top) + 6px));
  --mobile-topbar-control-size: clamp(42px, 11.2vw, 48px);
  --mobile-title-side-reserve: 120px;
}

html.layout-mobile #microcourseCardBtn,
html.layout-mobile #learningDeckLauncherBtn {
  display: none !important;
}

html.layout-mobile .connection-status-indicator {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

html.layout-mobile body,
html.layout-mobile button,
html.layout-mobile input,
html.layout-mobile textarea,
html.layout-mobile select,
html.layout-mobile .message,
html.layout-mobile .modal-content,
html.layout-mobile .mobile-menu-slot,
html.layout-mobile #mobileWelcomePanel,
html.layout-mobile #recommendQuestionsPanel {
  font-family: var(--mobile-font-sans) !important;
}

html.layout-mobile .title,
html.layout-mobile #agentNameDisplay,
html.layout-mobile #mobileWelcomePanel .mobile-welcome-title {
  font-family: var(--mobile-font-display) !important;
}

body.layout-mobile {
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

html.layout-mobile .top-bar {
  margin: 0 !important;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  flex: 0 0 auto;
  z-index: 2500;
}

html.layout-mobile .top-bar .left-aligned-group > #backBtn {
  display: none !important;
}

html.layout-mobile .top-bar .left-aligned-group .btn {
  padding: 6px 8px !important;
  font-size: 12px !important;
}

html.layout-mobile .top-bar .left-aligned-group > #openImageStrategyBtn {
  display: inline-flex !important;
  align-items: center !important;
  line-height: 1.1 !important;
}

html.layout-mobile .top-bar .left-aligned-group > #openImageStrategyBtn i {
  margin: 0 !important;
}

html.layout-mobile .top-bar .left-aligned-group > #openImageStrategyBtn.active {
  border-color: rgba(59, 130, 246, 0.34) !important;
  background: rgba(248, 250, 252, 0.96) !important;
  color: #1d4ed8 !important;
  box-shadow: 0 3px 10px rgba(59, 130, 246, 0.12) !important;
}

html.layout-mobile .top-bar .right-extended-group {
  position: absolute !important;
  right: calc(var(--mobile-topbar-pad-x) + clamp(104px, 26vw, 116px));
  top: var(--mobile-topbar-content-top);
  transform: none;
  display: inline-flex !important;
  align-items: center !important;
  gap: 0 !important;
  z-index: 5;
}

html.layout-mobile .top-bar .right-extended-group .student-profile-area {
  display: none !important;
}

html.layout-mobile #mobileRightDrawerBtn {
  position: absolute;
  right: var(--mobile-topbar-pad-x);
  top: var(--mobile-topbar-content-top);
  transform: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
}

html.layout-mobile #clearBtn.mobile-top-clear-btn {
  position: absolute;
  top: var(--mobile-topbar-content-top);
  transform: none;
  padding: 0 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  line-height: 1 !important;
  z-index: 5;
}

html.layout-mobile #clearBtn.mobile-top-clear-btn i {
  margin: 0 !important;
}

html.layout-mobile .left-aligned-group > #mobileLeftDrawerBtn {
  padding: 0 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  line-height: 1 !important;
  margin-left: 2px !important;
}

html.layout-mobile .student-profile-area {
  padding: 5px 9px !important;
  gap: 6px !important;
}

html.layout-mobile .student-name-grade {
  max-width: clamp(96px, 28vw, 144px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(12px, 3.1vw, 13px) !important;
}

html.layout-mobile .student-profile-card {
  right: var(--mobile-edge-gap) !important;
  left: auto !important;
  max-width: calc(100vw - (var(--mobile-edge-gap) * 2));
}

html.layout-mobile #studentProfileCard {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

html.layout-mobile .main-container {
  flex: 1 1 auto !important;
  min-height: 0;
  transition: padding-bottom 0.22s ease;
  overflow: hidden;
}

html.layout-mobile.mobile-keyboard-open .main-container {
  padding-bottom: var(--mobile-edge-gap) !important;
}

html.layout-mobile .chat-panel {
  position: relative;
  min-height: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  align-content: stretch;
  height: 100%;
}

html.layout-mobile .chat-area {
  min-height: 0 !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 0 !important;
  display: flex !important;
  flex-direction: column !important;
}

/* Mobile-only: chatArea 负责整段滚动，消息项不再内部收缩成“单行条” */
html.layout-mobile #chatArea {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
}

html.layout-mobile #chatArea > .message,
html.layout-mobile #chatArea > .controls,
html.layout-mobile #chatArea > .thinking-panel,
html.layout-mobile #chatArea > .mobile-thinking-panel {
  flex: 0 0 auto !important;
}

/* Mobile-only: 禁止 assistant 气泡内部再做高度裁剪，避免“只剩一条” */
html.layout-mobile #chatArea .message.assistant-message,
html.layout-mobile #chatArea .message.assistant-message > span,
html.layout-mobile #chatArea .message.assistant-message > span > * {
  max-height: none !important;
  overflow-y: visible !important;
}

/* 仍保留横向安全，防止极端内容把页面撑出 */
html.layout-mobile #chatArea .message.assistant-message,
html.layout-mobile #chatArea .message.assistant-message > span {
  overflow-x: hidden !important;
}

/* Mobile-only: 关闭全局内容裁剪，统一交给 chatArea 滚动 */
html.layout-mobile #chatArea .assistant-message .section-content {
  max-height: none !important;
  overflow: visible !important;
}

html.layout-mobile #chatArea > .message:first-of-type,
html.layout-mobile #chatArea > .assistant-message:first-of-type,
html.layout-mobile #chatArea > .user-message:first-of-type {
  margin-top: 0 !important;
}

html.layout-mobile.mobile-keyboard-open {
  --mobile-chat-bottom-padding-runtime: clamp(8px, calc(2.2 * var(--mobile-vh, 1vh)), 14px);
  --mobile-input-bottom-runtime: 0px;
}

html.layout-mobile #mobileBottomDock {
  position: fixed;
  display: flex;
  flex-direction: column;
  z-index: 1210;
  pointer-events: none;
}

html.layout-mobile #mobileBottomDock > * {
  pointer-events: auto;
}

html.layout-mobile #mobileBottomActionRow {
  display: block;
}

html.layout-mobile #mobileBottomActionRow .mobile-menu-slot {
  padding: 7px 4px;
  gap: 0;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}

html.layout-mobile #mobileBottomActionRow .mobile-menu-slot-label {
  text-align: center;
}

html.layout-mobile #mobileBottomActionRow .mobile-menu-slot > .mobile-docked-control {
  display: none !important;
}

html.layout-mobile .editor-tools-floating {
  display: none !important;
}

/* 学习入口由移动工具菜单承载。手机、平板及横屏的输入区均不显示
   尚未归位的原始入口；菜单中的按钮不受这条规则影响。 */
html.layout-mobile .input-area :is(#interactiveInquiryBtn, #learningBoardToggleBtn) {
  display: none !important;
  visibility: hidden !important;
}

html.layout-mobile .input-area {
  position: relative !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
  z-index: auto !important;
  width: 100% !important;
  flex: 0 0 auto !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  transform: none !important;
  flex-wrap: nowrap !important;
  min-height: 0 !important;
  padding-bottom: clamp(5px, 1.5vw, 7px) !important;
}

html.layout-mobile .input-area::before,
html.layout-mobile .input-area::after {
  content: none !important;
  display: none !important;
}

html.layout-mobile .input-area textarea {
  min-height: var(--mobile-input-btn-size) !important;
  max-height: 116px !important;
  height: auto !important;
  padding: 8px 10px !important;
  font-size: 13px !important;
  line-height: 1.4 !important;
  border: none !important;
  background: transparent !important;
  box-sizing: border-box !important;
  overflow-y: auto !important;
  resize: none !important;
}

html.layout-mobile .input-area #userInputEditor.rich-text-editor {
  min-height: var(--mobile-input-btn-size) !important;
  max-height: 116px !important;
  height: auto !important;
  padding: 8px 10px !important;
  border: none !important;
  background: transparent !important;
  font-size: 13px !important;
  line-height: 1.4 !important;
  box-sizing: border-box !important;
}

html.layout-mobile .input-area #userInputEditor {
  display: none !important;
}

html.layout-mobile .input-area #userInput {
  display: block !important;
  width: auto !important;
  margin: 0 !important;
}

/* 桌面端“解题或批改”模式会给输入框加绿色描边与光晕；手机端不需要，去掉避免出现淡绿色边框。 */
html.layout-mobile .input-area textarea.guided-help-mode-active,
html.layout-mobile #mobileComposerBar #userInput.guided-help-mode-active {
  border: none !important;
  box-shadow: none !important;
  outline: none !important;
}

html.layout-mobile .input-area #uploadFileBtn {
  /* Keep the native file input rendered for older Android/HarmonyOS WebViews.
     The visible + button triggers it synchronously from the user's tap. */
  position: fixed !important;
  left: -10000px !important;
  top: 0 !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* 富文本编辑器外壳在手机端已无内容（编辑器与输入框已移入 composer），
   但它仍以 flex:1 参与布局，会在输入条最右侧留下空缺；隐藏后输入条铺满整行。 */
html.layout-mobile .input-area .input-editor-wrap {
  display: none !important;
}

html.layout-mobile .input-area #openCameraBtn,
html.layout-mobile .input-area #mobileQuickPlusBtn,
html.layout-mobile #mobileInputToolbar .mobile-quick-btn {
  width: var(--mobile-input-btn-size) !important;
  height: var(--mobile-input-btn-size) !important;
  min-width: var(--mobile-input-btn-size) !important;
  font-size: 15px !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  padding: 0 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  line-height: 1 !important;
  vertical-align: middle !important;
}

html.layout-mobile .input-area #openCameraBtn,
html.layout-mobile .input-area #mobileQuickPlusBtn,
html.layout-mobile #mobileInputToolbar .mobile-quick-btn:not(.ui-mic-control) {
  border-radius: 999px !important;
  border: none !important;
  background: transparent !important;
  color: #374151 !important;
  box-shadow: none !important;
}

/* 手机端输入按钮只保留图标本身：点击时不出现系统灰色高亮块，也不显示焦点框。 */
html.layout-mobile .input-area #mobileQuickPlusBtn,
html.layout-mobile .input-area #openCameraBtn,
html.layout-mobile #mobileInputToolbar .mobile-quick-btn:not(.ui-mic-control),
html.layout-mobile #mobileComposerBar #sendBtn {
  -webkit-tap-highlight-color: transparent !important;
  tap-highlight-color: transparent !important;
  outline: none !important;
  -webkit-touch-callout: none !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}

html.layout-mobile .input-area #mobileQuickPlusBtn[hidden] {
  display: none !important;
}

html.layout-mobile #mobileInputToolbar #mobileModeSwitchBtn i {
  font-size: 17px !important;
}

html.layout-mobile .input-area #sendBtn {
  min-width: var(--mobile-input-btn-size) !important;
  width: var(--mobile-input-btn-size) !important;
  height: var(--mobile-input-btn-size) !important;
  border-radius: 999px !important;
  padding: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  line-height: 1 !important;
  vertical-align: middle !important;
  border: none !important;
  background: transparent !important;
  color: #374151 !important;
  box-shadow: none !important;
}

html.layout-mobile body:not(.mobile-chat-ready) .input-area #sendBtn,
html.layout-mobile body:not(.mobile-chat-ready) #mobileComposerBar #sendBtn,
html.layout-mobile .input-area #sendBtn.is-mobile-send-pending,
html.layout-mobile #mobileComposerBar #sendBtn.is-mobile-send-pending {
  pointer-events: none !important;
  touch-action: manipulation;
}

html.layout-mobile .input-area #sendBtn::before {
  display: none !important;
  content: none !important;
}

html.layout-mobile .input-area #sendBtn span {
  display: none !important;
}

html.layout-mobile #mobileInputToolbar {
  gap: 4px;
  margin-left: 0;
  margin-right: -3px;
}

html.layout-mobile #mobileDeepThinkingRow {
  display: none !important;
}

/* 桌面端的悬浮状态提示（模式状态、教学流程状态）在手机端会与底部输入栏重叠，
   且淡绿色描边在输入框旁显得突兀；手机端模式状态已由底部快捷栏高亮与占位符体现，直接隐藏。 */

html.layout-mobile #mobileLayoutOverlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 15, 27, 0.35);
  border: none;
  margin: 0;
  padding: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  z-index: 2700;
  pointer-events: none;
}

html.layout-mobile #mobileLayoutOverlay.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

html.layout-mobile #mobileRightDrawer .mobile-panel-title,
html.layout-mobile #mobileLeftDrawer .mobile-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: #4b5563;
  margin-bottom: 8px;
}

html.layout-mobile #mobileRightDrawer,
html.layout-mobile #mobileLeftDrawer {
  position: fixed;
  top: 0;
  width: clamp(216px, 58vw, 248px);
  height: 100vh;
  height: 100dvh;
  padding: max(10px, env(safe-area-inset-top)) clamp(10px, 3vw, 14px) max(12px, env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 0 36px rgba(0, 0, 0, 0.2);
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.24s ease, visibility 0s linear 0.24s;
  z-index: 2850;
  overflow-y: auto;
  box-sizing: border-box;
}

@media (max-width: 374px) {
  html.layout-mobile #mobileRightDrawer,
  html.layout-mobile #mobileLeftDrawer {
    width: clamp(204px, 62vw, 224px);
  }
}

html.layout-mobile #mobileRightDrawer {
  right: 0;
  border-left: 1px solid rgba(0, 0, 0, 0.08);
  transform: translateX(100%);
}

html.layout-mobile #mobileRightDrawer.is-open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

html.layout-mobile #mobileLeftDrawer {
  left: 0;
  border-right: 1px solid rgba(0, 0, 0, 0.08);
  transform: translateX(-100%);
}

html.layout-mobile #mobileLeftDrawer.is-open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

html.layout-mobile #mobileRightDrawer .mobile-drawer-header,
html.layout-mobile #mobileLeftDrawer .mobile-drawer-header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

html.layout-mobile #mobileRightDrawer .mobile-drawer-header {
  width: 100%;
  margin-left: 0;
}

html.layout-mobile #mobileLeftDrawer .mobile-drawer-header {
  width: 100%;
  margin-right: 0;
}

html.layout-mobile #mobileRightDrawer .mobile-drawer-header .mobile-panel-title,
html.layout-mobile #mobileLeftDrawer .mobile-drawer-header .mobile-panel-title {
  display: none !important;
}

html.layout-mobile #mobileDrawerProfile {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.05);
}

html.layout-mobile #mobileDrawerProfileAvatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.12);
  color: #2563eb;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

html.layout-mobile #mobileDrawerProfileText {
  min-width: 0;
}

html.layout-mobile #mobileDrawerProfileName {
  font-size: 12px;
  font-weight: 700;
  color: #111827;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

html.layout-mobile .mobile-menu-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

html.layout-mobile .mobile-menu-slot {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: clamp(40px, 10.2vw, 46px);
  padding: clamp(5px, 1.6vw, 7px);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.04);
}

html.layout-mobile .mobile-menu-slot.is-primary {
  background: rgba(249, 115, 22, 0.12);
}

html.layout-mobile .mobile-menu-slot-label {
  flex: 1;
  font-size: clamp(13px, 3.6vw, 14px);
  color: #1f2937;
  font-weight: 600;
}

html.layout-mobile .mobile-menu-slot > .mobile-docked-control {
  flex-shrink: 0;
  margin: 0 !important;
}

html.layout-mobile .mobile-menu-slot > .icon-btn.mobile-docked-control,
html.layout-mobile .mobile-menu-slot > #workflowToggleBtn.mobile-docked-control,
html.layout-mobile .mobile-menu-slot > #modelToggleBtn.mobile-docked-control,
html.layout-mobile .mobile-menu-slot > #learningBoardToggleBtn.mobile-docked-control,
html.layout-mobile .mobile-menu-slot > #mathFormulaBtn.mobile-docked-control,
html.layout-mobile .mobile-menu-slot > #chemistryFormulaBtn.mobile-docked-control,
html.layout-mobile .mobile-menu-slot > #physicsFormulaBtn.mobile-docked-control,
html.layout-mobile .mobile-menu-slot > #mindmapBtn.mobile-docked-control {
  width: clamp(32px, 8.6vw, 36px) !important;
  height: clamp(32px, 8.6vw, 36px) !important;
  min-width: clamp(32px, 8.6vw, 36px) !important;
  border-radius: 10px !important;
  margin: 0 !important;
  box-shadow: none !important;
}

html.layout-mobile .mobile-menu-slot > #mathFormulaBtn.mobile-docked-control i,
html.layout-mobile .mobile-menu-slot > #chemistryFormulaBtn.mobile-docked-control i,
html.layout-mobile .mobile-menu-slot > #physicsFormulaBtn.mobile-docked-control i,
html.layout-mobile .mobile-menu-slot > #mindmapBtn.mobile-docked-control i {
  font-size: 15px !important;
  margin: 0 !important;
}

html.layout-mobile .mobile-menu-slot > .btn.mobile-docked-control {
  width: clamp(32px, 8.6vw, 36px) !important;
  height: clamp(32px, 8.6vw, 36px) !important;
  min-width: clamp(32px, 8.6vw, 36px) !important;
  border-radius: 10px !important;
  padding: 0 !important;
  font-size: 0 !important;
  justify-content: center !important;
  gap: 0 !important;
}

html.layout-mobile .mobile-menu-slot > .card-button.mobile-docked-control {
  width: clamp(32px, 8.6vw, 36px) !important;
  height: clamp(32px, 8.6vw, 36px) !important;
  min-width: clamp(32px, 8.6vw, 36px) !important;
  display: inline-flex !important;
  align-items: center !important;
  border-radius: 10px !important;
  padding: 0 !important;
  font-size: 0 !important;
  justify-content: center !important;
  gap: 0 !important;
  border: 1px solid rgba(0, 0, 0, 0.08) !important;
}

html.layout-mobile .mobile-menu-slot > .btn.mobile-docked-control i {
  font-size: 15px !important;
  margin: 0 !important;
}

html.layout-mobile .mobile-menu-slot > .card-button.mobile-docked-control i {
  font-size: 15px !important;
  margin: 0 !important;
}

/* Mobile side drawer: minimalist text-only style */
html.layout-mobile #mobileRightDrawer .mobile-menu-list,
html.layout-mobile #mobileLeftDrawer .mobile-menu-list {
  gap: 0;
  margin-top: 2px;
}

html.layout-mobile #mobileRightDrawer .mobile-menu-list {
  width: 100%;
  margin-left: 0;
}

html.layout-mobile #mobileLeftDrawer .mobile-menu-list {
  width: 100%;
  margin-right: 0;
}

html.layout-mobile #mobileRightDrawer .mobile-menu-slot,
html.layout-mobile #mobileRightDrawer .mobile-menu-slot.is-primary,
html.layout-mobile #mobileLeftDrawer .mobile-menu-slot,
html.layout-mobile #mobileLeftDrawer .mobile-menu-slot.is-primary {
  background: transparent !important;
  border-radius: 0 !important;
  min-height: 0 !important;
  width: 100%;
  padding: 9px 0 !important;
  gap: 0 !important;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  justify-content: flex-start;
}

html.layout-mobile #mobileRightDrawer .mobile-menu-slot:last-child,
html.layout-mobile #mobileLeftDrawer .mobile-menu-slot:last-child {
  border-bottom: none;
}

html.layout-mobile #mobileRightDrawer .mobile-menu-slot-label,
html.layout-mobile #mobileLeftDrawer .mobile-menu-slot-label {
  color: #111111 !important;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

html.layout-mobile #mobileRightDrawer .mobile-menu-slot > .mobile-docked-control,
html.layout-mobile #mobileLeftDrawer .mobile-menu-slot > .mobile-docked-control {
  display: none !important;
}

html.layout-mobile #mobileRightDrawer #mobileDrawerProfile {
  background: transparent !important;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  margin-left: 0;
  margin-right: 0;
}

html.layout-mobile #mobileRightDrawer #mobileDrawerProfileAvatar {
  display: none !important;
}

html.layout-mobile #mobileRightDrawer #mobileDrawerProfileName {
  color: #111111 !important;
  text-align: center;
}

html.layout-mobile .mobile-menu-slot [data-rotating-label]::after {
  display: none !important;
}

html.layout-mobile [data-rotating-label]::after {
  display: none !important;
  content: none !important;
}

html.layout-mobile #modeStatusIndicator,
html.layout-mobile #workflowStatusIndicator {
  display: none !important;
}

/* 手机端使用 recommendQuestionsPanel，桌面 suggestions 容器不应占位 */
html.layout-mobile .suggestions-container,
html.layout-mobile #suggestionsContainer {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  height: 0 !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  pointer-events: none !important;
}

html.layout-mobile .assistant-message + .controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start !important;
  align-items: flex-start;
  column-gap: 8px;
  row-gap: 6px;
  clear: both;
  position: static !important;
  z-index: auto !important;
  margin: 10px 0 14px 0 !important;
  padding-right: 0 !important;
  padding-left: 2px !important;
  align-self: stretch !important;
}

html.layout-mobile .assistant-message + .controls button {
  padding: 6px 4px !important;
  min-width: 58px !important;
  min-height: 44px !important;
  gap: 4px !important;
  background: transparent !important;
  box-shadow: none !important;
}

html.layout-mobile .assistant-message + .controls button i {
  font-size: 15px !important;
}

html.layout-mobile .assistant-message + .controls .control-btn-label {
  font-size: 11px !important;
  line-height: 1.05 !important;
}

html.layout-mobile .assistant-message + .controls .enhanced-control-button {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
}

html.layout-mobile .assistant-message + .controls .assistant-control-fold__panel {
  max-width: calc(100vw - 40px);
  flex-wrap: wrap;
}

html.layout-mobile .controls > .next-step-host--compact {
  order: -30 !important;
  flex-basis: 100% !important;
  width: 100% !important;
  margin-inline: 0 !important;
}

html.layout-mobile .controls > .next-step-host--compact .next-step-island {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
}

html.layout-mobile .controls > .next-step-host--compact .next-step-island__launcher {
  min-height: 44px !important;
}

/* Mobile guidance is normal-flow content at every width, including tablets.
   Absolute desktop positioning would place the route outside its full row. */
html.layout-mobile .controls > .next-step-host--compact .next-step-island__panel {
  position: static;
  transform: none;
  flex: 0 1 auto;
  width: auto;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

html.layout-mobile .controls > .next-step-host--compact .next-step-island__panel:not([hidden]) {
  opacity: 1;
  pointer-events: auto;
}

html.layout-mobile .controls > .next-step-host--compact .next-step-island__guidance,
html.layout-mobile .controls > .next-step-host--compact .next-step-island__collapse {
  display: none !important;
}

html.layout-mobile .controls > .next-step-host--compact .next-step-island__route {
  min-width: 0 !important;
  max-width: 100%;
  height: auto !important;
  min-height: 44px !important;
  padding: 8px 14px !important;
  border: 1px solid rgba(249, 115, 22, 0.34) !important;
  border-radius: 14px !important;
  color: #9a3412 !important;
  background: #fff7ed !important;
  box-shadow: none !important;
  pointer-events: auto !important;
  touch-action: manipulation !important;
}

html.layout-mobile .controls > .next-step-host--compact .next-step-island__route-prefix {
  flex: none;
  white-space: nowrap;
}

html.layout-mobile .controls > .next-step-host--compact .next-step-island__route-label {
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.4;
}

html.layout-mobile .assistant-message + .controls .assistant-control-fold__main {
  gap: 0 !important;
}

html.layout-mobile .assistant-message + .controls .assistant-control-fold__toggle--nodes {
  min-width: 42px !important;
  width: 42px !important;
  min-height: 42px !important;
  padding: 6px !important;
  border-radius: 15px !important;
}

html.layout-mobile .assistant-message + .controls .assistant-control-fold__toggle-icon-wrap,
html.layout-mobile .assistant-message + .controls .assistant-control-fold__toggle-icon {
  width: 24px !important;
  height: 24px !important;
}

html.layout-mobile .assistant-message + .controls .assistant-control-fold__arrow {
  min-width: 22px !important;
  width: 22px !important;
  min-height: 44px !important;
  padding: 6px 0 !important;
}

html.layout-mobile .assistant-message + .controls .assistant-control-fold__arrow i {
  font-size: 11px !important;
}

html.layout-mobile .message.assistant-message[data-mobile-greeting="1"] {
  width: 94% !important;
  max-width: 94% !important;
  padding: 10px 12px !important;
}

html.layout-mobile .message.assistant-message[data-mobile-greeting="1"] > span,
html.layout-mobile .message.assistant-message[data-mobile-greeting="1"] p,
html.layout-mobile .message.assistant-message[data-mobile-greeting="1"] p:first-child {
  font-size: 13px !important;
  line-height: 1.45 !important;
  letter-spacing: 0 !important;
  margin: 0 !important;
}

html.layout-mobile #recommendQuestionsPanel {
  padding: 0 clamp(8px, 2.3vw, 10px) 0 !important;
  margin-top: auto !important;
  margin-bottom: clamp(4px, 1.4vw, 8px) !important;
  align-self: stretch !important;
  position: relative !important;
  z-index: 2 !important;
}

html.layout-mobile #recommendQuestionsPanel .recommend-questions-wrap {
  max-width: 100%;
  margin-bottom: 0 !important;
}

html.layout-mobile #recommendQuestionsPanel .recommend-questions-label {
  font-size: clamp(11px, 2.9vw, 12px);
  margin-bottom: 2px;
}

html.layout-mobile #recommendQuestionsPanel .recommend-questions-grid {
  grid-template-columns: 1fr !important;
  gap: clamp(4px, 1vw, 6px);
}

html.layout-mobile #recommendQuestionsPanel .recommend-questions-btn {
  color: #64748b;
  font-size: clamp(11px, 3vw, 13px);
  line-height: 1.28;
  min-height: 30px;
  padding: 2px 6px;
  white-space: normal !important;
  overflow: visible !important;
  text-overflow: clip !important;
  text-align: left !important;
}

@media (max-width: 390px) {
  html.layout-mobile .top-bar .left-aligned-group .btn {
    padding: 5px 7px !important;
    font-size: 11px !important;
  }

  html.layout-mobile {
    --mobile-edge-gap: 6px;
  }
}

@media (min-width: 430px) {
  html.layout-mobile {
    --mobile-chat-bottom-padding: clamp(10px, calc(2.6 * var(--mobile-vh, 1vh)), 16px);
  }

  html.layout-mobile .student-name-grade {
    max-width: 168px;
  }
}

@media (max-height: 740px) {
  html.layout-mobile {
    --mobile-chat-top-padding: 0px;
    --mobile-chat-bottom-padding: 10px;
    --mobile-input-btn-size: 36px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  html.layout-mobile {
    --mobile-chat-top-padding: 0px;
    --mobile-chat-bottom-padding: 8px;
    --mobile-input-bottom: calc(env(safe-area-inset-bottom) + 44px);
  }

  html.layout-mobile #mobileDeepThinkingRow {
    justify-content: flex-end;
  }

  html.layout-mobile #mobileRightDrawer,
  html.layout-mobile #mobileLeftDrawer {
    width: min(52vw, 312px);
  }

}

/* Ensure existing tool popovers stay above mobile input chrome */
html.layout-mobile .science-tools-drawer {
  z-index: 2910 !important;
}

/* 手机端：模型选择/工作流选择弹窗贴近底部按钮区域 */
html.layout-mobile .model-panel,
html.layout-mobile .workflow-panel {
  position: fixed !important;
  left: 50% !important;
  top: auto !important;
  right: auto !important;
  bottom: calc(var(--mobile-input-height-runtime) + var(--mobile-input-bottom-runtime) + 4px) !important;
  transform: translateX(-50%) !important;
  width: min(92vw, 380px) !important;
  max-height: min(58vh, 520px) !important;
  max-height: min(58dvh, 520px) !important;
  overflow: hidden !important;
  z-index: 1206 !important;
}

html.layout-mobile .model-panel .model-panel__list {
  max-height: min(54vh, 420px) !important;
  max-height: min(54dvh, 420px) !important;
  overflow: auto !important;
}

html.layout-mobile .workflow-panel .workflow-panel__grid {
  max-height: min(46vh, 360px) !important;
  max-height: min(46dvh, 360px) !important;
  overflow: auto !important;
  padding-right: 2px !important;
}

/* Mobile: learning board entry panel should behave like a full-screen page */
html.layout-mobile .learning-board-mount--floating {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-width: none !important;
  left: 0 !important;
  top: 0 !important;
  right: auto !important;
  bottom: auto !important;
  padding: 0 !important;
  z-index: 2930 !important;
}

html.layout-mobile .learning-board-mount--floating .learning-board--floating {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  margin: 0 !important;
  border-radius: 0 !important;
  border: none !important;
  box-shadow: none !important;
  display: flex;
  flex-direction: column;
  overflow: auto;
}

html.layout-mobile .learning-board-mount--floating .learning-board__skip-btn {
  display: inline-flex !important;
  position: sticky;
  top: 0;
  align-self: flex-end;
  z-index: 2;
}

html.layout-mobile #interactiveWebViewer .interactive-web-viewer-header {
  min-height: calc(env(safe-area-inset-top) + 50px);
  padding: calc(env(safe-area-inset-top) + 8px) 10px 8px;
  gap: 8px;
  box-sizing: border-box;
  background: rgba(2, 6, 23, 0.90);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

html.layout-mobile #interactiveWebViewer,
html.layout-mobile #mediaFullscreenOverlay {
  z-index: 3048 !important;
}

html.layout-mobile #interactiveWebViewer .interactive-web-viewer-title,
html.layout-mobile #mediaFullscreenOverlay .media-fullscreen-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html.layout-mobile #interactiveWebViewer .interactive-web-viewer-back,
html.layout-mobile #interactiveWebViewer .interactive-web-ai-btn {
  height: 34px;
  padding: 0 10px;
  border-radius: 10px;
  font-size: 12px;
}

html.layout-mobile #mediaFullscreenOverlay .media-fullscreen-header {
  min-height: calc(env(safe-area-inset-top) + 52px);
  padding: calc(env(safe-area-inset-top) + 8px) 10px 8px;
  gap: 8px;
  box-sizing: border-box;
}

/* Mobile: 构建化板块入口改为紧凑纯文字条目（仅入口，不影响各子弹层功能） */
html.layout-mobile .learning-board-mount--floating .learning-board--floating {
  gap: 6px;
  padding:
    calc(env(safe-area-inset-top) + clamp(8px, 2.4vw, 12px))
    clamp(10px, 2.8vw, 13px)
    calc(env(safe-area-inset-bottom) + clamp(10px, 2.6vw, 13px)) !important;
}

html.layout-mobile .learning-board-mount--floating .learning-board__skip-btn {
  padding: 4px 10px !important;
  font-size: 12px !important;
}

html.layout-mobile .learning-board-mount--floating .learning-board__grid {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: clamp(4px, 1.4vw, 7px) clamp(9px, 2.5vw, 12px) !important;
}

html.layout-mobile .learning-board-mount--floating .learning-board__card {
  min-height: 0 !important;
  aspect-ratio: auto !important;
  padding: clamp(7px, 2vw, 9px) clamp(3px, 1vw, 6px) !important;
  border: none !important;
  border-bottom: 1px solid rgba(15, 23, 42, 0.12) !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  overflow: visible !important;
  align-items: flex-start !important;
  justify-content: flex-start !important;
  text-align: left !important;
}

html.layout-mobile .learning-board-mount--floating .learning-board__card::before,
html.layout-mobile .learning-board-mount--floating .learning-board__card::after {
  display: none !important;
}

html.layout-mobile .learning-board-mount--floating .learning-board__title {
  width: 100%;
  align-items: flex-start !important;
  text-align: left !important;
  font-size: clamp(13px, 3.7vw, 15px) !important;
  font-weight: 700 !important;
  line-height: 1.32 !important;
}

html.layout-mobile .learning-board-mount--floating .learning-board__title-main {
  width: auto !important;
  text-align: left !important;
}

html.layout-mobile .learning-board-mount--floating .learning-board__tag,
html.layout-mobile .learning-board-mount--floating .learning-board__title-en,
html.layout-mobile .learning-board-mount--floating .learning-board__placeholder {
  display: none !important;
}

html.layout-mobile .learning-board-mount--floating .learning-board__card:active .learning-board__title {
  color: #2563eb !important;
}

@media (max-width: 360px) {
  html.layout-mobile .learning-board-mount--floating .learning-board__grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

/* Mobile-only: 知识图解保留展示台优先入口，其他构建化板块跟随桌面端逻辑。 */
html.layout-mobile #knowledgeGraphModal #knowledgeGraphAiViewBtn,
html.layout-mobile #knowledgeGraphModal #knowledgeGraphAiView,
html.layout-mobile #knowledgeGraphModal #knowledgeGraphHeaderCenter,
html.layout-mobile #knowledgeGraphModal #knowledgeGraphShowcaseView .learning-board-showcase-empty-action[data-showcase-action="go-ai"] {
  display: none !important;
}

/* 互动探究的视图显隐由 learning-board.css 和组件 hidden 状态共同管理。
   这里只隐藏移动端不使用的辅助入口，不再先隐藏、后恢复 AI 创作。 */
html.layout-mobile #knowledgeChartModal #knowledgeChartHeaderCenter,
html.layout-mobile #knowledgeChartModal #knowledgeChartResetBtn,
html.layout-mobile #knowledgeChartModal #knowledgeChartShowcaseView .learning-board-showcase-empty-action[data-showcase-action="go-ai"] {
  display: none !important;
}

html.layout-mobile #knowledgeChartModal #knowledgeChartShowcaseViewBtn {
  width: 100% !important;
  justify-content: center !important;
}

/* Mobile-only: 输入区上方附件容器按需显示，避免出现“多一层空白条” */
html.layout-mobile #thumbnailContainer {
  display: none !important;
  position: static !important;
  flex: 0 0 auto !important;
  min-height: 0 !important;
  max-width: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  overflow: hidden !important;
}

html.layout-mobile .input-area #thumbnailContainer.has-thumbnails {
  display: inline-flex !important;
  position: relative !important;
  z-index: auto !important;
  width: auto !important;
  max-width: min(28vw, 96px) !important;
  min-width: calc(var(--mobile-input-btn-size) - 6px) !important;
  height: var(--mobile-input-btn-size) !important;
  min-height: var(--mobile-input-btn-size) !important;
  max-height: var(--mobile-input-btn-size) !important;
  flex: 0 1 auto !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  justify-content: flex-start !important;
  align-self: center !important;
  gap: 4px !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  margin: 0 2px 0 0 !important;
  padding: 3px !important;
  border: 1px solid rgba(15, 23, 42, 0.08) !important;
  border-radius: 12px !important;
  background: rgba(248, 250, 252, 0.96) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7) !important;
  scrollbar-width: none !important;
}

html.layout-mobile .input-area #thumbnailContainer.has-thumbnails::-webkit-scrollbar {
  display: none !important;
}

html.layout-mobile .input-area #thumbnailContainer.has-thumbnails[data-attachment-count]:not([data-attachment-count="1"])::after {
  content: attr(data-attachment-count);
  position: absolute;
  right: 2px;
  bottom: 1px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: 999px;
  background: #2563eb;
  color: #fff;
  font-size: 9px;
  line-height: 14px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(37, 99, 235, 0.28);
}

html.layout-mobile .input-area #thumbnailContainer.has-thumbnails > div {
  flex: 0 0 auto !important;
  width: calc(var(--mobile-input-btn-size) - 10px) !important;
  min-width: calc(var(--mobile-input-btn-size) - 10px) !important;
  height: calc(var(--mobile-input-btn-size) - 6px) !important;
  margin: 0 !important;
  gap: 1px !important;
  align-items: center !important;
  justify-content: flex-start !important;
  flex-direction: column !important;
}

html.layout-mobile .input-area #thumbnailContainer .thumb-media {
  width: calc(var(--mobile-input-btn-size) - 16px) !important;
  min-width: calc(var(--mobile-input-btn-size) - 16px) !important;
  height: calc(var(--mobile-input-btn-size) - 20px) !important;
  min-height: calc(var(--mobile-input-btn-size) - 20px) !important;
  flex: 0 0 calc(var(--mobile-input-btn-size) - 20px) !important;
  border-radius: 8px !important;
  background: rgba(15, 23, 42, 0.05) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

html.layout-mobile .input-area #thumbnailContainer .thumb-media img,
html.layout-mobile .input-area #thumbnailContainer .thumb-media video,
html.layout-mobile .input-area #thumbnailContainer .thumb-media canvas,
html.layout-mobile .input-area #thumbnailContainer .thumb-media .file-icon {
  width: 100% !important;
  height: 100% !important;
}

html.layout-mobile .input-area #thumbnailContainer .thumb-media .file-icon {
  padding: 0 !important;
  border-radius: 8px !important;
  box-shadow: none !important;
}

html.layout-mobile .input-area #thumbnailContainer .thumb-media .file-icon i {
  font-size: 15px !important;
}

html.layout-mobile .input-area #thumbnailContainer .thumb-mobile-status {
  display: block !important;
  width: 100% !important;
  min-height: 10px !important;
  max-height: 10px !important;
  overflow: hidden !important;
  font-size: 8px !important;
  line-height: 10px !important;
  text-align: center !important;
  color: #64748b !important;
  white-space: nowrap !important;
  text-overflow: ellipsis !important;
}

html.layout-mobile .input-area #thumbnailContainer .thumb-mobile-status[data-state="pending"] {
  color: #d97706 !important;
}

html.layout-mobile .input-area #thumbnailContainer .thumb-mobile-status[data-state="ready"] {
  color: #059669 !important;
}

html.layout-mobile .input-area #thumbnailContainer .thumb-mobile-status[data-state="warning"] {
  color: #d97706 !important;
}

html.layout-mobile .input-area #thumbnailContainer .thumb-mobile-status[data-state="error"] {
  color: #dc2626 !important;
}

html.layout-mobile .input-area #thumbnailContainer .thumb-side {
  width: 0 !important;
  min-width: 0 !important;
  flex: 0 0 0 !important;
  gap: 0 !important;
  padding-top: 0 !important;
  overflow: visible !important;
}

html.layout-mobile .input-area #thumbnailContainer .thumb-side > span:first-child,
html.layout-mobile .input-area #thumbnailContainer .thumb-side > div:first-of-type {
  display: none !important;
}

html.layout-mobile .input-area #thumbnailContainer .thumb-actions {
  width: 0 !important;
  min-width: 0 !important;
  gap: 0 !important;
}

html.layout-mobile .input-area #thumbnailContainer .thumb-actions .parse-retry-btn,
html.layout-mobile .input-area #thumbnailContainer .thumb-actions .preparse-summary-btn {
  position: absolute !important;
  top: -4px !important;
  right: -4px !important;
  z-index: 3 !important;
  display: grid !important;
  place-items: center !important;
  width: 18px !important;
  min-width: 18px !important;
  height: 18px !important;
  padding: 0 !important;
  border: 1px solid #fff !important;
  border-radius: 50% !important;
  font-size: 0 !important;
}

html.layout-mobile .input-area #thumbnailContainer .thumb-actions .parse-retry-btn::before {
  content: '↻';
  font-size: 15px;
}

html.layout-mobile .input-area #thumbnailContainer .thumb-actions .preparse-summary-btn::before {
  content: '摘';
  font-size: 11px;
}

html.layout-mobile .input-area #thumbnailContainer > div.selected::after,
html.layout-mobile .input-area #thumbnailContainer > div.selected::before {
  display: none !important;
}

html.layout-mobile .input-area #thumbnailContainer .delete-btn {
  width: 16px !important;
  height: 16px !important;
  top: -4px !important;
  left: -4px !important;
  padding: 0 !important;
  font-size: 8px !important;
}

html.layout-mobile .input-area #thumbnailContainer > div[data-upload-status="pending"] .thumb-media,
html.layout-mobile .input-area #thumbnailContainer > div[data-parse-status="pending"] .thumb-media,
html.layout-mobile .input-area #thumbnailContainer > div[data-kb-status="pending"] .thumb-media {
  box-shadow: inset 0 0 0 1.5px rgba(217, 119, 6, 0.62) !important;
}

html.layout-mobile .input-area #thumbnailContainer > div[data-upload-status="error"] .thumb-media,
html.layout-mobile .input-area #thumbnailContainer > div[data-parse-status="error"] .thumb-media,
html.layout-mobile .input-area #thumbnailContainer > div[data-kb-status="error"] .thumb-media {
  box-shadow: inset 0 0 0 1.5px rgba(220, 38, 38, 0.72) !important;
}

html.layout-mobile .input-area #thumbnailContainer > div[data-upload-status="success"]:not([data-parse-status="pending"]):not([data-parse-status="error"]):not([data-kb-status="pending"]):not([data-kb-status="error"]) .thumb-media,
html.layout-mobile .input-area #thumbnailContainer > div[data-parse-status="success"]:not([data-upload-status="error"]) .thumb-media,
html.layout-mobile .input-area #thumbnailContainer > div[data-kb-status="ready"]:not([data-upload-status="error"]) .thumb-media {
  box-shadow: inset 0 0 0 1.5px rgba(5, 150, 105, 0.58) !important;
}

/* Mobile-only: 数学/化学/物理公式编辑器改为全屏弹层，避免被底部输入栏遮挡 */
html.layout-mobile #mathFormulaModal,
html.layout-mobile #chemistryFormulaModal,
html.layout-mobile #physicsFormulaModal {
  --mobile-formula-accent: #4f7cff;
  --mobile-formula-accent-soft: #edf2ff;
  --mobile-formula-accent-muted: #5f79d8;
  --mobile-formula-accent-border: rgba(79, 124, 255, 0.22);
  --mobile-formula-accent-shadow: rgba(79, 124, 255, 0.22);
  --mobile-formula-card-bg: #ffffff;
  --mobile-formula-shell-bg: #fbfcfd;
  --mobile-formula-editor-height: clamp(72px, 12vh, 112px);
  z-index: 2972 !important;
  align-items: stretch !important;
  justify-content: stretch !important;
  padding: 0 !important;
}

html.layout-mobile #chemistryFormulaModal {
  --mobile-formula-accent: #56c775;
  --mobile-formula-accent-soft: #eaf8ef;
  --mobile-formula-accent-muted: #55ad6e;
  --mobile-formula-accent-border: rgba(86, 199, 117, 0.24);
  --mobile-formula-accent-shadow: rgba(86, 199, 117, 0.22);
}

html.layout-mobile #mathFormulaModal .modal-content,
html.layout-mobile #chemistryFormulaModal .modal-content,
html.layout-mobile #physicsFormulaModal .modal-content {
  width: 100vw !important;
  max-width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  min-height: 100vh !important;
  min-height: 100dvh !important;
  max-height: 100vh !important;
  max-height: 100dvh !important;
  margin: 0 !important;
  border-radius: 0 !important;
  border: none !important;
  padding: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  background: var(--mobile-formula-shell-bg) !important;
}

html.layout-mobile #mathFormulaModal .modal-header,
html.layout-mobile #chemistryFormulaModal .modal-header,
html.layout-mobile #physicsFormulaModal .modal-header {
  position: sticky !important;
  top: 0 !important;
  z-index: 8 !important;
  min-height: 64px !important;
  padding: calc(env(safe-area-inset-top) + 9px) 16px 10px !important;
  background: rgba(255, 255, 255, 0.98) !important;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08) !important;
  backdrop-filter: blur(10px) !important;
  -webkit-backdrop-filter: blur(10px) !important;
}

html.layout-mobile #mathFormulaModal .modal-title,
html.layout-mobile #chemistryFormulaModal .modal-title,
html.layout-mobile #physicsFormulaModal .modal-title {
  margin: 0 !important;
  font-size: 23px !important;
  line-height: 1.2 !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 10px !important;
  font-weight: 800 !important;
  letter-spacing: 0 !important;
}

html.layout-mobile #mathFormulaModal .modal-title i,
html.layout-mobile #chemistryFormulaModal .modal-title i,
html.layout-mobile #physicsFormulaModal .modal-title i {
  width: 34px !important;
  height: 34px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  border-radius: 12px !important;
  background: var(--mobile-formula-accent) !important;
  color: #ffffff !important;
  font-size: 16px !important;
  line-height: 1 !important;
  box-shadow: 0 8px 18px var(--mobile-formula-accent-shadow) !important;
}

html.layout-mobile #mathFormulaModal .math-formula-content,
html.layout-mobile #chemistryFormulaModal .chemistry-formula-content,
html.layout-mobile #physicsFormulaModal .physics-formula-content {
  flex: 1 1 auto !important;
  display: grid !important;
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr) !important;
  grid-template-rows: auto auto minmax(0, 1fr) auto !important;
  gap: 10px !important;
  width: 100% !important;
  min-height: 0 !important;
  height: 100% !important;
  max-height: 100% !important;
  overflow: hidden !important;
  padding: 10px 12px 0 !important;
  background: var(--mobile-formula-shell-bg) !important;
}

html.layout-mobile #mathFormulaModal .math-editor-section,
html.layout-mobile #chemistryFormulaModal .chemistry-editor-section,
html.layout-mobile #physicsFormulaModal .physics-editor-section {
  overflow: visible !important;
  min-height: 0 !important;
  gap: 6px !important;
  display: flex !important;
  flex-direction: column !important;
  padding: 10px 12px !important;
  border: 1px solid var(--mobile-formula-accent-border) !important;
  border-radius: 16px !important;
  background: var(--mobile-formula-card-bg) !important;
  box-shadow: 0 4px 14px rgba(16, 24, 40, 0.05) !important;
}

html.layout-mobile #mathFormulaModal .math-editor-section:nth-of-type(1),
html.layout-mobile #chemistryFormulaModal .chemistry-editor-section:nth-of-type(1),
html.layout-mobile #physicsFormulaModal .physics-editor-section:nth-of-type(1) {
  grid-column: 1 / 2 !important;
  grid-row: 1 !important;
}

html.layout-mobile #mathFormulaModal .math-editor-section:nth-of-type(2),
html.layout-mobile #chemistryFormulaModal .chemistry-editor-section:nth-of-type(2),
html.layout-mobile #physicsFormulaModal .physics-editor-section:nth-of-type(2) {
  grid-column: 2 / 3 !important;
  grid-row: 1 !important;
}

html.layout-mobile #mathFormulaModal .math-editor-label,
html.layout-mobile #chemistryFormulaModal .chemistry-editor-label,
html.layout-mobile #physicsFormulaModal .physics-editor-label {
  margin-bottom: 0 !important;
  font-size: 12px !important;
  line-height: 1.25 !important;
  color: #344054 !important;
  font-weight: 800 !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

html.layout-mobile #mathFormulaModal .editable-hint,
html.layout-mobile #chemistryFormulaModal .editable-hint,
html.layout-mobile #physicsFormulaModal .editable-hint {
  display: none !important;
}

html.layout-mobile #mathFormulaModal .math-input-area,
html.layout-mobile #chemistryFormulaModal .chemistry-input-area,
html.layout-mobile #physicsFormulaModal .physics-input-area {
  min-height: var(--mobile-formula-editor-height) !important;
  height: var(--mobile-formula-editor-height) !important;
  max-height: var(--mobile-formula-editor-height) !important;
  font-size: 14px !important;
  line-height: 1.35 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  resize: none !important;
}

html.layout-mobile #mathFormulaModal .math-preview-section,
html.layout-mobile #chemistryFormulaModal .chemistry-preview-section,
html.layout-mobile #physicsFormulaModal .physics-preview-section {
  min-height: var(--mobile-formula-editor-height) !important;
  height: var(--mobile-formula-editor-height) !important;
  max-height: var(--mobile-formula-editor-height) !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  align-items: flex-start !important;
  justify-content: center !important;
  overflow: auto !important;
}

html.layout-mobile #mathFormulaModal .math-preview-content,
html.layout-mobile #chemistryFormulaModal .chemistry-preview-content,
html.layout-mobile #physicsFormulaModal .physics-preview-content {
  font-size: 13px !important;
  line-height: 1.35 !important;
  width: 100% !important;
  min-height: 100% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center !important;
  overflow: hidden !important;
}

html.layout-mobile #mathFormulaModal .grade-switch,
html.layout-mobile #chemistryFormulaModal .grade-switch,
html.layout-mobile #physicsFormulaModal .grade-switch {
  grid-column: 1 / -1 !important;
  grid-row: 2 !important;
  height: 42px !important;
  min-height: 42px !important;
  padding: 3px !important;
  gap: 3px !important;
  margin: 0 !important;
  border-radius: 15px !important;
  background: #f3f5f6 !important;
  border: 1px solid rgba(16, 24, 40, 0.08) !important;
  box-shadow: inset 0 1px 2px rgba(16, 24, 40, 0.04) !important;
}

html.layout-mobile #mathFormulaModal .grade-btn,
html.layout-mobile #chemistryFormulaModal .grade-btn,
html.layout-mobile #physicsFormulaModal .grade-btn {
  min-height: 34px !important;
  padding: 0 10px !important;
  font-size: 14px !important;
  border-radius: 12px !important;
  line-height: 1.15 !important;
  color: var(--mobile-formula-accent-muted) !important;
  font-weight: 800 !important;
  background: transparent !important;
  border: 0 !important;
}

html.layout-mobile #mathFormulaModal .grade-btn.active,
html.layout-mobile #chemistryFormulaModal .grade-btn.active,
html.layout-mobile #physicsFormulaModal .grade-btn.active {
  color: #ffffff !important;
  background: var(--mobile-formula-accent) !important;
  box-shadow: 0 8px 18px var(--mobile-formula-accent-shadow) !important;
}

html.layout-mobile #mathFormulaModal .math-symbols-panel,
html.layout-mobile #chemistryFormulaModal .chemistry-symbols-panel,
html.layout-mobile #physicsFormulaModal .physics-symbols-panel {
  grid-column: 1 / -1 !important;
  grid-row: 3 !important;
  display: flex !important;
  flex-direction: column !important;
  max-height: none !important;
  min-height: 0 !important;
  overflow: hidden !important;
  padding: 10px !important;
  border-radius: 18px !important;
  border: 1px solid rgba(15, 23, 42, 0.08) !important;
  background: rgba(255, 255, 255, 0.74) !important;
}

html.layout-mobile #mathFormulaModal .math-symbols-tabs,
html.layout-mobile #chemistryFormulaModal .chemistry-symbols-tabs,
html.layout-mobile #physicsFormulaModal .physics-symbols-tabs {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  display: flex !important;
  flex-wrap: nowrap !important;
  gap: 8px !important;
  margin-bottom: 10px !important;
  padding: 1px 10px 3px 0 !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  scrollbar-width: none !important;
  -webkit-overflow-scrolling: touch !important;
  overscroll-behavior: contain !important;
  overscroll-behavior-x: contain !important;
  touch-action: pan-x pan-y !important;
  scroll-snap-type: x proximity !important;
  scroll-padding-left: 0 !important;
}

html.layout-mobile #mathFormulaModal .math-symbols-tabs::-webkit-scrollbar,
html.layout-mobile #chemistryFormulaModal .chemistry-symbols-tabs::-webkit-scrollbar,
html.layout-mobile #physicsFormulaModal .physics-symbols-tabs::-webkit-scrollbar {
  display: none !important;
}

html.layout-mobile #mathFormulaModal .math-tab-btn,
html.layout-mobile #chemistryFormulaModal .chemistry-tab-btn,
html.layout-mobile #physicsFormulaModal .physics-tab-btn {
  flex: 0 0 auto !important;
  min-height: 34px !important;
  height: 34px !important;
  padding: 0 14px !important;
  font-size: 13px !important;
  border-radius: 999px !important;
  color: var(--mobile-formula-accent-muted) !important;
  background: var(--mobile-formula-accent-soft) !important;
  border: 1px solid var(--mobile-formula-accent-border) !important;
  font-weight: 800 !important;
  white-space: nowrap !important;
  scroll-snap-align: start !important;
  touch-action: manipulation !important;
}

html.layout-mobile #mathFormulaModal .math-tab-btn.active,
html.layout-mobile #chemistryFormulaModal .chemistry-tab-btn.active,
html.layout-mobile #physicsFormulaModal .physics-tab-btn.active {
  color: #ffffff !important;
  background: var(--mobile-formula-accent) !important;
  border-color: transparent !important;
}

html.layout-mobile #mathFormulaModal .math-symbols-grid,
html.layout-mobile #chemistryFormulaModal .chemistry-symbols-grid,
html.layout-mobile #physicsFormulaModal .physics-symbols-grid {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  grid-auto-rows: minmax(88px, auto) !important;
  align-items: stretch !important;
  justify-items: stretch !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  padding: 0 1px 1px !important;
  gap: 8px !important;
  align-content: start !important;
}

html.layout-mobile #mathFormulaModal .math-symbols-grid.layout-compact,
html.layout-mobile #chemistryFormulaModal .chemistry-symbols-grid.layout-compact,
html.layout-mobile #physicsFormulaModal .physics-symbols-grid.layout-compact {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

html.layout-mobile #mathFormulaModal .math-symbols-grid.layout-extra-wide,
html.layout-mobile #chemistryFormulaModal .chemistry-symbols-grid.layout-extra-wide,
html.layout-mobile #physicsFormulaModal .physics-symbols-grid.layout-extra-wide {
  grid-template-columns: minmax(0, 1fr) !important;
}

html.layout-mobile #mathFormulaModal .math-symbol-btn,
html.layout-mobile #chemistryFormulaModal .chemistry-symbol-btn,
html.layout-mobile #physicsFormulaModal .physics-symbol-btn {
  width: 100% !important;
  min-width: 0 !important;
  height: auto !important;
  min-height: 88px !important;
  max-width: 100% !important;
  padding: 9px 8px !important;
  display: grid !important;
  grid-template-rows: auto auto !important;
  align-content: center !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 4px !important;
  border-radius: 14px !important;
  white-space: normal !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
  aspect-ratio: auto !important;
  background: #ffffff !important;
  border: 1px solid rgba(16, 24, 40, 0.08) !important;
  box-shadow: 0 4px 12px rgba(16, 24, 40, 0.06) !important;
}

html.layout-mobile #mathFormulaModal .math-symbol-btn.btn-compact,
html.layout-mobile #chemistryFormulaModal .chemistry-symbol-btn.btn-compact,
html.layout-mobile #physicsFormulaModal .physics-symbol-btn.btn-compact {
  min-width: 0 !important;
  height: auto !important;
  min-height: 84px !important;
}

html.layout-mobile #mathFormulaModal .math-symbol-btn.btn-medium,
html.layout-mobile #chemistryFormulaModal .chemistry-symbol-btn.btn-medium,
html.layout-mobile #physicsFormulaModal .physics-symbol-btn.btn-medium {
  min-width: 0 !important;
  height: auto !important;
  min-height: 88px !important;
}

html.layout-mobile #mathFormulaModal .math-symbol-btn.btn-wide,
html.layout-mobile #chemistryFormulaModal .chemistry-symbol-btn.btn-wide,
html.layout-mobile #physicsFormulaModal .physics-symbol-btn.btn-wide {
  min-width: 0 !important;
  height: auto !important;
  min-height: 96px !important;
  flex: none !important;
}

html.layout-mobile #mathFormulaModal .math-symbol-btn.btn-extra-wide,
html.layout-mobile #chemistryFormulaModal .chemistry-symbol-btn.btn-extra-wide,
html.layout-mobile #physicsFormulaModal .physics-symbol-btn.btn-extra-wide {
  min-width: 0 !important;
  height: auto !important;
  min-height: 104px !important;
  flex: none !important;
}

html.layout-mobile #mathFormulaModal .formula-symbol-overflow,
html.layout-mobile #chemistryFormulaModal .formula-symbol-overflow,
html.layout-mobile #physicsFormulaModal .formula-symbol-overflow {
  grid-column: 1 / -1 !important;
}

html.layout-mobile .formula-symbol-main {
  font-size: 15px !important;
  line-height: 1.12 !important;
  min-height: 0 !important;
  overflow: visible !important;
  text-overflow: clip !important;
  white-space: normal !important;
  align-self: center !important;
}

html.layout-mobile .formula-symbol-main :is(svg, .mjx-svg, mjx-container) {
  max-width: 100% !important;
  max-height: none !important;
  overflow: visible !important;
}

html.layout-mobile .formula-symbol-main :is(mjx-container, mjx-container[display="true"], .MathJax) {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: auto !important;
  min-width: 0 !important;
  min-height: 0 !important;
  margin: 0 !important;
  line-height: 1 !important;
  vertical-align: middle !important;
}

html.layout-mobile .formula-symbol-main :is(svg, .mjx-svg) {
  display: block !important;
  margin: 0 auto !important;
  vertical-align: middle !important;
}

html.layout-mobile .formula-symbol-main mjx-assistive-mml {
  display: none !important;
}

html.layout-mobile .formula-symbol-label {
  font-size: 10.5px !important;
  line-height: 1.1 !important;
  color: #667085 !important;
  font-weight: 700 !important;
  min-height: 12px !important;
  max-height: 24px !important;
  overflow: hidden !important;
  text-overflow: clip !important;
  white-space: normal !important;
  align-self: end !important;
}

html.layout-mobile #mathFormulaModal .math-actions,
html.layout-mobile #chemistryFormulaModal .chemistry-actions,
html.layout-mobile #physicsFormulaModal .physics-actions {
  grid-column: 1 / -1 !important;
  grid-row: 4 !important;
  position: relative !important;
  bottom: auto !important;
  z-index: 6 !important;
  display: grid !important;
  grid-template-columns: 1fr 1fr 1.25fr !important;
  gap: 8px !important;
  margin: 0 -12px !important;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 12px) !important;
  border-top: 1px solid rgba(15, 23, 42, 0.08) !important;
  background: rgba(255, 255, 255, 0.98) !important;
}

html.layout-mobile #mathFormulaModal .math-action-btn,
html.layout-mobile #chemistryFormulaModal .chemistry-action-btn,
html.layout-mobile #physicsFormulaModal .physics-action-btn {
  flex: none !important;
  min-height: 48px !important;
  padding: 0 8px !important;
  font-size: 15px !important;
  border-radius: 15px !important;
  font-weight: 800 !important;
}

html.layout-mobile #mathFormulaModal .math-action-btn.secondary,
html.layout-mobile #chemistryFormulaModal .chemistry-action-btn.secondary,
html.layout-mobile #physicsFormulaModal .physics-action-btn.secondary {
  color: var(--mobile-formula-accent-muted) !important;
  border: 1px solid var(--mobile-formula-accent-border) !important;
  background: var(--mobile-formula-accent-soft) !important;
}

html.layout-mobile #mathFormulaModal .math-action-btn.primary,
html.layout-mobile #chemistryFormulaModal .chemistry-action-btn.primary,
html.layout-mobile #physicsFormulaModal .physics-action-btn.primary {
  color: #ffffff !important;
  border-color: transparent !important;
  background: var(--mobile-formula-accent) !important;
  box-shadow: 0 8px 18px var(--mobile-formula-accent-shadow) !important;
}

@media (max-height: 760px) {
	  html.layout-mobile #mathFormulaModal,
	  html.layout-mobile #chemistryFormulaModal,
	  html.layout-mobile #physicsFormulaModal {
	    --mobile-formula-editor-height: clamp(56px, 12vh, 88px);
	  }

	  html.layout-mobile #mathFormulaModal .math-formula-content,
	  html.layout-mobile #chemistryFormulaModal .chemistry-formula-content,
	  html.layout-mobile #physicsFormulaModal .physics-formula-content {
	    gap: 8px !important;
	    padding: 8px 10px 0 !important;
	  }

	  html.layout-mobile #mathFormulaModal .math-editor-section,
	  html.layout-mobile #chemistryFormulaModal .chemistry-editor-section,
	  html.layout-mobile #physicsFormulaModal .physics-editor-section {
	    padding: 8px 10px !important;
	  }

	  html.layout-mobile #mathFormulaModal .math-symbols-grid,
	  html.layout-mobile #chemistryFormulaModal .chemistry-symbols-grid,
	  html.layout-mobile #physicsFormulaModal .physics-symbols-grid {
	    grid-auto-rows: minmax(80px, auto) !important;
	    max-height: none !important;
	  }

  html.layout-mobile #mathFormulaModal .grade-switch,
  html.layout-mobile #chemistryFormulaModal .grade-switch,
  html.layout-mobile #physicsFormulaModal .grade-switch {
    height: 40px !important;
    min-height: 40px !important;
  }

	  html.layout-mobile #mathFormulaModal .grade-btn,
	  html.layout-mobile #chemistryFormulaModal .grade-btn,
	  html.layout-mobile #physicsFormulaModal .grade-btn {
	    min-height: 32px !important;
	    padding: 0 8px !important;
	    font-size: 12px !important;
	  }

	  html.layout-mobile #mathFormulaModal .math-symbol-btn,
	  html.layout-mobile #chemistryFormulaModal .chemistry-symbol-btn,
	  html.layout-mobile #physicsFormulaModal .physics-symbol-btn {
	    min-height: 80px !important;
	  }

	  html.layout-mobile #mathFormulaModal .math-actions,
	  html.layout-mobile #chemistryFormulaModal .chemistry-actions,
	  html.layout-mobile #physicsFormulaModal .physics-actions {
	    margin: 0 -10px !important;
	    padding: 8px 10px calc(env(safe-area-inset-bottom) + 10px) !important;
	  }

	  html.layout-mobile #mathFormulaModal .math-action-btn,
	  html.layout-mobile #chemistryFormulaModal .chemistry-action-btn,
	  html.layout-mobile #physicsFormulaModal .physics-action-btn {
	    min-height: 44px !important;
	  }
	}

/* Mobile-only: unify all clickable popup dialogs (excluding dedicated formula full-screen modals). */
html.layout-mobile .modal-overlay:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) {
  z-index: 3020 !important;
  padding: max(8px, env(safe-area-inset-top)) var(--mobile-edge-gap)
    max(8px, env(safe-area-inset-bottom)) !important;
  align-items: stretch !important;
  justify-content: center !important;
}

html.layout-mobile .modal-overlay:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) .modal-content {
  width: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
  height: auto !important;
  max-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px) !important;
  max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px) !important;
  margin: 0 !important;
  padding: 0 !important;
  border-radius: 16px !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
}

html.layout-mobile .modal-overlay:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) .modal-header {
  position: sticky !important;
  top: 0 !important;
  z-index: 6 !important;
  margin: 0 !important;
  padding: 10px 12px !important;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08) !important;
  background: rgba(255, 255, 255, 0.98) !important;
  backdrop-filter: blur(10px) !important;
  -webkit-backdrop-filter: blur(10px) !important;
}

html.layout-mobile .modal-overlay:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) .modal-body,
html.layout-mobile .modal-overlay:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) .library-list,
html.layout-mobile .modal-overlay:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) .library-detail-content,
html.layout-mobile .modal-overlay:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) .subject-stats-body,
html.layout-mobile .modal-overlay:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) .chat-records-admin,
html.layout-mobile .modal-overlay:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) .chat-records-admin__folder-grid,
html.layout-mobile .modal-overlay:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) .chat-records-admin__messages,
html.layout-mobile .modal-overlay:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) .chat-records-admin__detail {
  min-height: 0 !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch !important;
}

html.layout-mobile .modal-overlay:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) .modal-footer,
html.layout-mobile .modal-overlay:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) .preferences-modal-footer,
html.layout-mobile .modal-overlay:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) .library-detail-footer {
  position: sticky !important;
  bottom: 0 !important;
  z-index: 6 !important;
  margin: 0 !important;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 8px) !important;
  border-top: 1px solid rgba(15, 23, 42, 0.08) !important;
  background: rgba(255, 255, 255, 0.98) !important;
  backdrop-filter: blur(10px) !important;
  -webkit-backdrop-filter: blur(10px) !important;
}

/* Mobile-only: route strategy */
html.layout-mobile #imageStrategyModal .modal-body {
  padding: 12px !important;
}

html.layout-mobile #imageStrategyModal #imageStrategyOptions {
  gap: 8px !important;
}

/* Mobile-only: library and detail dialogs */
html.layout-mobile #myLibraryModal .library-modal-header {
  align-items: flex-start !important;
  gap: 10px !important;
}

html.layout-mobile #myLibraryModal .library-modal-subtitle {
  font-size: 12px !important;
  line-height: 1.4 !important;
  margin-top: 3px !important;
}

html.layout-mobile #myLibraryModal .library-tabs {
  position: sticky !important;
  top: 0 !important;
  z-index: 5 !important;
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  margin: 8px 10px 0 !important;
  padding: 5px !important;
  overflow: visible !important;
  gap: 5px !important;
}

html.layout-mobile #myLibraryModal .library-notes-drawing-entry {
  min-width: 0 !important;
}

html.layout-mobile #myLibraryModal .library-notes-drawing-btn {
  width: 100% !important;
  min-width: 0 !important;
  min-height: 38px !important;
  font-size: 12px !important;
  padding: 7px 6px !important;
}

html.layout-mobile #myLibraryModal .library-tab-btn {
  min-width: 0 !important;
  min-height: 38px !important;
  font-size: 12px !important;
  padding: 7px 6px !important;
  white-space: nowrap !important;
}

html.layout-mobile #myLibraryModal .library-tab-count {
  min-width: 22px !important;
  height: 22px !important;
  font-size: 11px !important;
}

html.layout-mobile #myLibraryModal .library-controls {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) !important;
  gap: 8px !important;
  margin: 10px !important;
  padding: 10px !important;
}

html.layout-mobile #myLibraryModal .library-search-wrap,
html.layout-mobile #myLibraryModal .library-sort-wrap {
  width: 100% !important;
}

html.layout-mobile #myLibraryModal #addLibraryItemBtn {
  justify-content: center !important;
  width: 100% !important;
}

html.layout-mobile #myLibraryModal #libraryContentArea {
  padding: 0 10px 12px !important;
}

html.layout-mobile #myLibraryModal .library-list-item {
  padding: 12px !important;
  gap: 10px !important;
  min-height: 104px !important;
}

html.layout-mobile #myLibraryModal .item-thumbnail {
  width: 48px !important;
  height: 48px !important;
  border-radius: 10px !important;
}

html.layout-mobile #myLibraryModal .item-header-row {
  align-items: flex-start !important;
  gap: 8px !important;
}

html.layout-mobile #myLibraryModal .item-type-chip {
  max-width: 58% !important;
  font-size: 11px !important;
}

html.layout-mobile #myLibraryModal .item-title {
  font-size: 14px !important;
}

html.layout-mobile #myLibraryModal .item-preview,
html.layout-mobile #myLibraryModal .item-meta-line {
  font-size: 12px !important;
}

html.layout-mobile #myLibraryModal .delete-item-btn {
  width: 34px !important;
  height: 34px !important;
  border-radius: 10px !important;
}

html.layout-mobile #myLibraryModal .library-empty-state {
  min-height: 220px !important;
  padding: 28px 16px !important;
}

html.layout-mobile #libraryItemDetailModal #libraryItemDetailContent {
  padding: 12px !important;
}

html.layout-mobile #libraryItemDetailModal .note-detail-head,
html.layout-mobile #libraryItemDetailModal .note-content-preview {
  padding: 16px !important;
  border-radius: 12px !important;
}

html.layout-mobile #libraryItemDetailModal .note-detail-title {
  font-size: 21px !important;
}

html.layout-mobile #libraryItemDetailModal .note-detail-meta,
html.layout-mobile #libraryItemDetailModal .note-meta-display {
  gap: 8px 12px !important;
  font-size: 12px !important;
}

html.layout-mobile #libraryItemDetailModal .note-content-preview {
  min-height: 220px !important;
  font-size: 14px !important;
  line-height: 1.72 !important;
}

html.layout-mobile #libraryItemDetailModal .note-editor-container textarea {
  min-height: 240px !important;
  max-height: none !important;
}

html.layout-mobile #libraryItemDetailModal #libraryItemDetailFooter {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 8px !important;
}

html.layout-mobile #libraryItemDetailModal #libraryItemDetailFooter > *:only-child {
  grid-column: 1 / -1 !important;
}

html.layout-mobile #libraryItemDetailModal #libraryItemDetailFooter .btn,
html.layout-mobile #libraryItemDetailModal #libraryItemDetailFooter .btn-filled {
  width: 100% !important;
}

html.layout-mobile #libraryItemDetailModal .library-ai-detail {
  gap: 14px !important;
}

html.layout-mobile #libraryItemDetailModal .library-ai-detail-section {
  padding: 16px !important;
  border-radius: 16px !important;
}

html.layout-mobile #libraryItemDetailModal .library-ai-rich.has-markmap .mindmap-bubble__header {
  flex-direction: column !important;
  align-items: flex-start !important;
}

html.layout-mobile #libraryItemDetailModal .library-ai-rich.has-markmap .mindmap-bubble__actions {
  width: 100% !important;
  justify-content: flex-start !important;
}

/* Mobile-only: drawing board dialog */
html.layout-mobile .modal-overlay#drawingBoardModal:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) {
  align-items: stretch !important;
  justify-content: stretch !important;
  overscroll-behavior: none !important;
  touch-action: none !important;
}

html.layout-mobile .modal-overlay#drawingBoardModal:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) .modal-content.drawing-modal-content {
  padding: 0 !important;
  height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px) !important;
  height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px) !important;
  max-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px) !important;
  max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px) !important;
  display: grid !important;
  grid-template-rows: auto minmax(180px, 1fr) auto !important;
  overflow: hidden !important;
}

html.layout-mobile #drawingBoardModal .drawing-canvas-wrap {
  min-height: 0 !important;
  height: 100% !important;
  box-sizing: border-box !important;
  margin: 0 !important;
  padding: 10px max(36px, env(safe-area-inset-right)) 10px max(36px, env(safe-area-inset-left)) !important;
  overflow: hidden !important;
  contain: layout paint !important;
  -webkit-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
  overscroll-behavior: none !important;
  touch-action: none !important;
}

html.layout-mobile #drawingBoardModal #drawingCanvas {
  display: block !important;
  box-sizing: border-box !important;
  width: 100% !important;
  height: 100% !important;
  min-height: 0 !important;
  max-height: none !important;
  margin: 0 auto !important;
  border-radius: 12px !important;
  align-self: stretch !important;
  justify-self: center !important;
  -webkit-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
  touch-action: none !important;
  overscroll-behavior: none !important;
}

html.layout-mobile #drawingBoardModal .drawing-controls {
  position: relative !important;
  z-index: 6 !important;
  display: grid !important;
  grid-template-columns: 1fr !important;
  grid-auto-rows: auto !important;
  gap: 8px !important;
  margin: 0 !important;
  border-radius: 0 !important;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px) !important;
  overflow: visible !important;
  align-items: stretch !important;
  justify-content: stretch !important;
}

html.layout-mobile #drawingBoardModal .drawing-controls > * {
  min-width: 0 !important;
}

html.layout-mobile #drawingBoardModal .drawing-control-group {
  width: 100% !important;
  display: grid !important;
  gap: 8px !important;
  justify-content: stretch !important;
  margin-left: 0 !important;
}

html.layout-mobile #drawingBoardModal .drawing-style-group {
  grid-template-columns: minmax(48px, 0.45fr) minmax(0, 1fr) !important;
}

html.layout-mobile #drawingBoardModal .drawing-history-group {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

html.layout-mobile #drawingBoardModal .drawing-tool-group {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

html.layout-mobile #drawingBoardModal .drawing-line-tool-group {
  grid-template-columns: minmax(0, 1fr) !important;
}

html.layout-mobile #drawingBoardModal .drawing-eraser-size-group {
  grid-template-columns: minmax(0, 1fr) !important;
}

html.layout-mobile #drawingBoardModal .drawing-eraser-size-group .eraser-size-selector,
html.layout-mobile #drawingBoardModal .drawing-eraser-size-group select {
  width: 100% !important;
}

html.layout-mobile #drawingBoardModal .drawing-output-group {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

html.layout-mobile #drawingBoardModal .drawing-controls .tool-selector {
  height: 36px !important;
  min-height: 36px !important;
  padding: 0 8px !important;
  border-radius: 10px !important;
  background: rgba(248, 250, 252, 0.92) !important;
  border: 1px solid rgba(15, 23, 42, 0.08) !important;
  justify-content: center !important;
}

html.layout-mobile #drawingBoardModal .drawing-controls input[type="color"] {
  width: 28px !important;
  height: 28px !important;
}

html.layout-mobile #drawingBoardModal .drawing-controls input[type="range"] {
  width: 100% !important;
}

html.layout-mobile #drawingBoardModal .drawing-controls .tool-button,
html.layout-mobile #drawingBoardModal .drawing-controls #uploadDrawingBtn,
html.layout-mobile #drawingBoardModal .drawing-controls #saveDrawingBtn {
  width: 100% !important;
  min-height: 36px !important;
  height: 36px !important;
  margin: 0 !important;
  padding: 0 8px !important;
  border-radius: 10px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 4px !important;
  font-size: 12px !important;
  line-height: 1 !important;
  white-space: nowrap !important;
}

html.layout-mobile #drawingBoardModal .drawing-controls #uploadDrawingBtn,
html.layout-mobile #drawingBoardModal .drawing-controls #saveDrawingBtn {
  min-height: 40px !important;
  height: 40px !important;
  font-weight: 700 !important;
}

html.layout-mobile #drawingBoardModal .drawing-controls #uploadDrawingBtn {
  order: 20 !important;
}

html.layout-mobile #drawingBoardModal .drawing-controls #saveDrawingBtn {
  order: 21 !important;
}

/* Mobile-only: mindmap editor dialog */
html.layout-mobile #mindmapModal .mindmap-modal-content {
  width: 100% !important;
  max-width: none !important;
  height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px) !important;
  height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px) !important;
  max-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px) !important;
  max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px) !important;
  padding: 0 !important;
}

html.layout-mobile #mindmapModal .mindmap-toolbar {
  top: 0 !important;
  z-index: 6 !important;
  -webkit-overflow-scrolling: touch !important;
}

html.layout-mobile #mindmapModal .mindmap-tools-group,
html.layout-mobile #mindmapModal .mindmap-templates-group,
html.layout-mobile #mindmapModal .mindmap-history-group,
html.layout-mobile #mindmapModal .mindmap-zoom-group,
html.layout-mobile #mindmapModal .mindmap-export-group,
html.layout-mobile #mindmapModal .mindmap-clear-group {
  flex-wrap: nowrap !important;
  gap: 6px !important;
}

html.layout-mobile #mindmapModal .mindmap-toolbar .mindmap-tool-btn,
html.layout-mobile #mindmapModal .mindmap-action-btn,
html.layout-mobile #mindmapModal .mindmap-template-select {
  width: auto !important;
  min-width: 44px !important;
  height: 36px !important;
  min-height: 36px !important;
  padding: 0 9px !important;
  font-size: 12px !important;
  white-space: nowrap !important;
}

html.layout-mobile #mindmapModal .mindmap-template-select {
  min-width: 120px !important;
}

html.layout-mobile #mindmapModal .mindmap-content-area {
  flex-direction: column !important;
}

html.layout-mobile #mindmapModal .mindmap-preview-panel {
  display: none !important;
}

html.layout-mobile #mindmapModal .mindmap-canvas-container {
  flex: 1 1 auto !important;
  border-right: none !important;
  overscroll-behavior: none !important;
  touch-action: none !important;
}

/* Mobile-only: chat records dialog */
html.layout-mobile #chatRecordsModal .chat-records-modal {
  padding: 0 !important;
  height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px) !important;
  height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px) !important;
  max-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px) !important;
  max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px) !important;
}

html.layout-mobile #chatRecordsModal .chat-records-admin {
  height: 100% !important;
  min-height: 0 !important;
  padding: 12px !important;
  gap: 10px !important;
}

html.layout-mobile #chatRecordsModal .chat-records-admin__header {
  position: sticky !important;
  top: 0 !important;
  z-index: 6 !important;
  display: flex !important;
  flex-wrap: wrap !important;
  gap: 8px !important;
  padding-bottom: 8px !important;
  background: inherit !important;
}

html.layout-mobile #chatRecordsModal .chat-records-admin__actions {
  width: 100% !important;
  gap: 8px !important;
}

html.layout-mobile #chatRecordsModal .chat-records-admin__actions .admin-btn {
  flex: 1 1 calc(33.333% - 8px) !important;
  min-width: 0 !important;
  font-size: 12px !important;
  padding: 8px 10px !important;
}

html.layout-mobile #chatRecordsModal .chat-records-admin__folder-grid {
  grid-template-columns: 1fr !important;
  gap: 8px !important;
}

html.layout-mobile #chatRecordsModal .chat-records-admin__detail {
  padding: 10px !important;
}

html.layout-mobile #chatRecordsModal .chat-records-admin__detail-header {
  flex-direction: column !important;
  gap: 8px !important;
}

html.layout-mobile #chatRecordsModal .chat-records-admin__detail-actions {
  width: 100% !important;
}

html.layout-mobile #chatRecordsModal .chat-records-admin__detail-actions .admin-btn {
  flex: 1 1 0 !important;
}

html.layout-mobile #chatRecordsModal .chat-records-admin__messages {
  padding-bottom: calc(env(safe-area-inset-bottom) + 6px) !important;
}

/* Mobile-only: subject stats dialog */
html.layout-mobile #subjectStatsModal .subject-stats-modal-content {
  padding: 0 !important;
  border-radius: 18px !important;
  background: var(--bg-light) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-body {
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px) !important;
  gap: 10px !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-range-tabs {
  position: sticky !important;
  top: 0 !important;
  z-index: 5 !important;
  width: 100% !important;
  display: grid !important;
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  gap: 5px !important;
  padding-bottom: 6px !important;
  background: inherit !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-toolbar {
  align-items: stretch !important;
  padding: 10px !important;
  border-radius: 14px !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-range-tab {
  width: 100% !important;
  justify-content: center !important;
  min-height: 36px !important;
  padding: 7px 5px !important;
  font-size: 12px !important;
  white-space: nowrap !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-tool-actions {
  width: 100% !important;
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 8px !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-history-toggle-btn,
html.layout-mobile #subjectStatsModal .subject-stats-regenerate-btn {
  width: 100% !important;
  min-height: 40px !important;
  padding: 0 8px !important;
  font-size: 12px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-report-meta {
  gap: 6px !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-report-chip {
  font-size: 12px !important;
  padding: 5px 9px !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-history {
  padding: 8px 10px !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-history-list {
  display: grid !important;
  grid-template-columns: 1fr !important;
  gap: 6px !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-history-item {
  min-width: 0 !important;
  padding: 7px 9px !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-teacher-card,
html.layout-mobile #subjectStatsModal .subject-stats-feedback-card,
html.layout-mobile #subjectStatsModal .subject-stats-teacher-note {
  padding: 14px !important;
  border-radius: 16px !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-teacher-title {
  font-size: 20px !important;
  line-height: 1.28 !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-key-point p,
html.layout-mobile #subjectStatsModal .subject-stats-feedback-item,
html.layout-mobile #subjectStatsModal .subject-stats-action-text,
html.layout-mobile #subjectStatsModal .subject-stats-teacher-note p {
  font-size: 14px !important;
  line-height: 1.72 !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-key-point {
  grid-template-columns: 1fr !important;
  gap: 8px !important;
  padding: 12px 13px !important;
  border-radius: 15px !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-feedback-copy h4,
html.layout-mobile #subjectStatsModal .subject-stats-teacher-note h4 {
  font-size: 16px !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-feedback-icon {
  width: 40px !important;
  height: 40px !important;
  flex-basis: 40px !important;
  border-radius: 14px !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-feedback-grid,
html.layout-mobile #subjectStatsModal .subject-stats-action-list,
html.layout-mobile #subjectStatsModal .subject-stats-detail-grid {
  grid-template-columns: 1fr !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-feedback-card {
  min-height: 0 !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-detail-section {
  padding: 12px !important;
}

html.layout-mobile #subjectStatsModal .subject-stats-detail-section ul {
  font-size: 13px !important;
  line-height: 1.72 !important;
}

/* Mobile-only: intelligent result dialog */
html.layout-mobile #intelligentDialog {
  z-index: 3035 !important;
  padding: max(8px, env(safe-area-inset-top)) var(--mobile-edge-gap)
    max(8px, env(safe-area-inset-bottom)) !important;
  align-items: stretch !important;
}

html.layout-mobile #intelligentDialog .modal-content {
  width: 100% !important;
  max-width: none !important;
  max-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px) !important;
  max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px) !important;
  border-radius: 16px !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
}

html.layout-mobile #intelligentDialog .dialog-content {
  min-height: 0 !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch !important;
  padding: 12px !important;
}

html.layout-mobile #intelligentDialog .dialog-actions {
  position: sticky !important;
  bottom: 0 !important;
  z-index: 5 !important;
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 8px !important;
  margin: 0 !important;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 8px) !important;
  background: rgba(255, 255, 255, 0.98) !important;
  border-top: 1px solid rgba(15, 23, 42, 0.08) !important;
}

html.layout-mobile #intelligentDialog .dialog-actions .btn,
html.layout-mobile #intelligentDialog .dialog-actions .btn-filled {
  width: 100% !important;
  min-width: 0 !important;
}

/* Mobile-only: attachment preview popup */
html.layout-mobile #attachmentPreviewModal {
  z-index: 3044 !important;
  padding: 10px var(--mobile-edge-gap) calc(env(safe-area-inset-bottom) + 10px) !important;
}

html.layout-mobile #attachmentPreviewModal .attachment-preview-card {
  width: 100% !important;
  max-width: none !important;
  max-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 20px) !important;
  max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 20px) !important;
  padding: 10px !important;
  border-radius: 14px !important;
}

html.layout-mobile #attachmentPreviewModal .attachment-preview-body,
html.layout-mobile #attachmentPreviewModal .attachment-preview-media {
  max-width: 100% !important;
  max-height: calc(100vh - 180px) !important;
  max-height: calc(100dvh - 180px) !important;
}

/* Mobile: learning preferences copy readability */
html.layout-mobile #learningPreferencesModal .preference-option,
html.layout-mobile #learningPreferencesModal .ai-role-card {
  align-items: flex-start !important;
}

html.layout-mobile #learningPreferencesModal .preference-option-copy,
html.layout-mobile #learningPreferencesModal .ai-role-copy {
  gap: 3px !important;
}

html.layout-mobile #learningPreferencesModal .preference-option-desc,
html.layout-mobile #learningPreferencesModal .ai-role-desc {
  font-size: 12px !important;
  line-height: 1.35 !important;
}

/* Mobile: keep preferences modal fully aligned and readable */
html.layout-mobile #studentInfoModal .preferences-modal-content,
html.layout-mobile #learningPreferencesModal .preferences-modal-content,
html.layout-mobile #studentSkillTagModal .preferences-modal-content,
html.layout-mobile #ttsVoiceModal .preferences-modal-content {
  width: calc(100vw - 12px) !important;
  max-width: calc(100vw - 12px) !important;
  max-height: calc(100vh - 12px) !important;
  max-height: calc(100dvh - 12px) !important;
  padding: 0 !important;
  border-radius: 14px !important;
}

html.layout-mobile #studentInfoModal .modal-header,
html.layout-mobile #learningPreferencesModal .modal-header,
html.layout-mobile #studentSkillTagModal .modal-header,
html.layout-mobile #ttsVoiceModal .modal-header {
  min-height: 54px !important;
  padding: 9px 12px !important;
}

html.layout-mobile #studentInfoModal .modal-body,
html.layout-mobile #learningPreferencesModal .modal-body,
html.layout-mobile #studentSkillTagModal .modal-body,
html.layout-mobile #ttsVoiceModal .modal-body {
  padding: 10px 12px !important;
  max-height: none !important;
}

html.layout-mobile #studentInfoModal .preferences-modal-footer,
html.layout-mobile #learningPreferencesModal .preferences-modal-footer,
html.layout-mobile #studentSkillTagModal .preferences-modal-footer,
html.layout-mobile #ttsVoiceModal .preferences-modal-footer {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 8px !important;
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px) !important;
}

html.layout-mobile #studentInfoModal .preferences-modal-footer .btn,
html.layout-mobile #learningPreferencesModal .preferences-modal-footer .btn,
html.layout-mobile #studentSkillTagModal .preferences-modal-footer .btn,
html.layout-mobile #ttsVoiceModal .preferences-modal-footer .btn,
html.layout-mobile #studentInfoModal .preferences-modal-footer .btn-filled,
html.layout-mobile #learningPreferencesModal .preferences-modal-footer .btn-filled,
html.layout-mobile #studentSkillTagModal .preferences-modal-footer .btn-filled,
html.layout-mobile #ttsVoiceModal .preferences-modal-footer .btn-filled {
  width: 100% !important;
  min-height: 42px !important;
  padding: 0 10px !important;
  justify-content: center !important;
}

html.layout-mobile #learningPreferencesModal .preference-label {
  margin-top: 12px !important;
  margin-bottom: 7px !important;
}

html.layout-mobile #studentInfoModal .full-width-input,
html.layout-mobile #studentInfoModal .full-width-select,
html.layout-mobile #learningPreferencesModal .full-width-input,
html.layout-mobile #learningPreferencesModal .full-width-select {
  margin-bottom: 10px !important;
}

html.layout-mobile #learningPreferencesModal .preference-options-group,
html.layout-mobile #learningPreferencesModal #learningStyleOptions,
html.layout-mobile #learningPreferencesModal #difficultyLevelOptions,
html.layout-mobile #learningPreferencesModal #aiRoleOptions,
html.layout-mobile #ttsVoiceModal .tts-voice-options,
html.layout-mobile #studentSkillTagModal .student-skill-tag-options {
  grid-template-columns: 1fr !important;
  gap: 8px !important;
}

html.layout-mobile #myPetModal .my-pet-modal-content {
  width: min(96vw, 680px) !important;
  max-height: 88vh !important;
  padding: 18px !important;
}

html.layout-mobile .pet-settings-switch-row {
  gap: 10px;
  min-height: 68px;
  padding: 11px 12px;
}

html.layout-mobile .pet-settings-switch-row strong {
  font-size: 14px;
}

html.layout-mobile .pet-settings-switch-row small {
  font-size: 12px;
}

html.layout-mobile .pet-settings-switch-control {
  gap: 7px;
}

html.layout-mobile .pet-settings-option {
  grid-template-columns: 50px minmax(0, 1fr) auto;
  gap: 10px;
  min-height: 72px;
  padding: 10px;
}

html.layout-mobile .pet-settings-avatar {
  width: 50px;
  height: 50px;
}

html.layout-mobile .pet-settings-copy strong {
  font-size: 14px;
}

html.layout-mobile .pet-settings-copy > span {
  font-size: 12px;
}

html.layout-mobile .pet-settings-action {
  min-width: 46px;
  padding: 6px 8px;
  font-size: 12px;
}

/* Mobile home redesign: study-first layout matching the reference composition */
html.layout-mobile {
  --mobile-edge-gap: clamp(12px, 3.6vw, 16px);
  --mobile-topbar-pad-x: clamp(12px, 3.6vw, 16px);
  --mobile-input-btn-size: clamp(38px, 10.2vw, 42px);
  --mobile-input-radius: 999px;
  --mobile-topbar-height-runtime: clamp(66px, calc(9.8 * var(--mobile-vh, 1vh)), 78px);
  --mobile-input-height-runtime: clamp(120px, calc(17.8 * var(--mobile-vh, 1vh)), 148px);
  --mobile-input-bar-height-runtime: clamp(52px, 13.2vw, 56px);
  background: #f7f8fa;
}

html.layout-mobile body.layout-mobile {
  background:
    radial-gradient(circle at 50% 24%, rgba(255, 255, 255, 0.98) 0, rgba(255, 255, 255, 0.72) 28%, rgba(247, 248, 250, 0) 56%),
    #f7f8fa !important;
}

html.layout-mobile .top-bar {
  min-height: max(clamp(66px, 9.8vh, 78px), calc(var(--mobile-topbar-content-top) + var(--mobile-topbar-control-size) + 9px)) !important;
  min-height: max(clamp(66px, 9.8dvh, 78px), calc(var(--mobile-topbar-content-top) + var(--mobile-topbar-control-size) + 9px)) !important;
  padding: var(--mobile-topbar-content-top) calc(var(--mobile-topbar-pad-x) + 156px) 9px var(--mobile-topbar-pad-x) !important;
  transition: none !important;
  gap: clamp(4px, 1.4vw, 7px) !important;
  background: transparent !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  animation: none !important;
}

html.layout-mobile .top-bar .left-aligned-group {
  position: absolute !important;
  top: var(--mobile-topbar-content-top);
  left: var(--mobile-topbar-pad-x);
  gap: clamp(5px, 1.5vw, 7px) !important;
  min-width: 0;
  flex: 0 1 auto !important;
  z-index: 6;
}

html.layout-mobile .title {
  font-size: clamp(15px, 4.2vw, 20px) !important;
  line-height: 1.05 !important;
  font-weight: 800 !important;
  color: #111827 !important;
  letter-spacing: 0 !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 4;
}

html.layout-mobile .left-aligned-group > #mobileLeftDrawerBtn,
html.layout-mobile .left-aligned-group > #mobileStudentNotesBtn,
html.layout-mobile #clearBtn.mobile-top-clear-btn,
html.layout-mobile #mobileRightDrawerBtn,
html.layout-mobile .top-bar .right-extended-group .homework-entry-btn {
  width: clamp(42px, 11.2vw, 48px) !important;
  height: clamp(42px, 11.2vw, 48px) !important;
  min-width: clamp(42px, 11.2vw, 48px) !important;
  /* Fixed icon targets must not inherit the global button's 24px side padding. */
  padding: 0 !important;
  border-radius: 16px !important;
  border: 1px solid rgba(255, 255, 255, 0.72) !important;
  background: rgba(255, 255, 255, 0.92) !important;
  color: #0f172a !important;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.08) !important;
}

html.layout-mobile .left-aligned-group > #mobileLeftDrawerBtn i,
html.layout-mobile .left-aligned-group > #mobileStudentNotesBtn i,
html.layout-mobile #clearBtn.mobile-top-clear-btn i,
html.layout-mobile #mobileRightDrawerBtn i,
html.layout-mobile .top-bar .right-extended-group .homework-entry-btn i {
  font-size: clamp(18px, 5.2vw, 23px) !important;
}

html.layout-mobile .top-bar .left-aligned-group > #openImageStrategyBtn {
  height: clamp(42px, 11.2vw, 48px) !important;
  max-width: clamp(102px, 29vw, 118px) !important;
  min-width: 0 !important;
  padding: 0 clamp(9px, 2.6vw, 13px) !important;
  border-radius: 999px !important;
  border: 1px solid rgba(255, 255, 255, 0.72) !important;
  background: rgba(255, 255, 255, 0.94) !important;
  color: #1677ff !important;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.08) !important;
  font-size: clamp(12px, 3.4vw, 15px) !important;
  font-weight: 800 !important;
  gap: 7px !important;
}

html.layout-mobile .top-bar .left-aligned-group > #openImageStrategyBtn i {
  color: #1677ff !important;
  font-size: clamp(16px, 4.7vw, 20px) !important;
}

html.layout-mobile .top-bar .left-aligned-group > #openImageStrategyBtn .btn-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

html.layout-mobile #clearBtn.mobile-top-clear-btn {
  right: calc(var(--mobile-topbar-pad-x) + clamp(52px, 13vw, 58px)) !important;
}

html.layout-mobile .main-container {
  padding: calc(var(--mobile-topbar-height-runtime) + 2px) 0 0 !important;
  background: transparent !important;
}

html.layout-mobile .chat-panel {
  gap: 0 !important;
  background: transparent !important;
}

html.layout-mobile .chat-area {
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
  padding: 0 var(--mobile-edge-gap)
    calc(var(--mobile-input-height-runtime) + env(safe-area-inset-bottom) + 18px)
    var(--mobile-edge-gap) !important;
  gap: 10px !important;
}

html.layout-mobile .chat-panel.is-mobile-empty .chat-area {
  justify-content: center;
  padding-bottom: calc(var(--mobile-input-height-runtime) + env(safe-area-inset-bottom) + 24px) !important;
}

html.layout-mobile #chatArea > .message[data-mobile-greeting="1"],
html.layout-mobile #chatArea > .message[data-mobile-greeting="1"] + .controls,
html.layout-mobile #chatArea > .assistant-welcome-message,
html.layout-mobile #chatArea > .assistant-welcome-message + .controls {
  display: none !important;
}

html.layout-mobile #mobileWelcomePanel {
  display: none;
}

html.layout-mobile .chat-panel.is-mobile-empty #mobileWelcomePanel {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  transform: translateY(clamp(-28px, -4vh, -16px));
  transform: translateY(clamp(-28px, -4dvh, -16px));
}

html.layout-mobile .mobile-welcome-title {
  margin: 0;
  color: #0b0f19;
  font-size: clamp(28px, 9vw, 42px);
  line-height: 1.08;
  font-weight: 900;
  letter-spacing: 0;
  text-align: center;
}

html.layout-mobile .mobile-welcome-subtitle {
  margin: clamp(10px, 3vw, 16px) 0 clamp(22px, 5vh, 42px);
  margin: clamp(10px, 3vw, 16px) 0 clamp(22px, 5dvh, 42px);
  color: #5f6b7a;
  font-size: clamp(15px, 4vw, 20px);
  line-height: 1.35;
  font-weight: 500;
  letter-spacing: 0;
  text-align: center;
}

html.layout-mobile #mobileBottomDock {
  /* 底部输入区左右留白收窄，让加号贴近屏幕边缘、输入条更宽 */
  left: clamp(4px, 1.6vw, 8px);
  right: clamp(4px, 1.6vw, 8px);
  bottom: calc(env(safe-area-inset-bottom) + clamp(12px, 3vw, 16px));
  gap: clamp(12px, 3.2vw, 16px);
}

html.layout-mobile .chat-panel.is-mobile-empty #recommendQuestionsPanel.is-visible {
  display: block;
  width: 100% !important;
  max-width: 680px;
  margin: 0 auto !important;
  padding: 0 !important;
  align-self: center !important;
  z-index: 2 !important;
  transform: translateY(clamp(12px, 2.5vh, 22px)) !important;
  transform: translateY(clamp(12px, 2.5dvh, 22px)) !important;
}

html.layout-mobile .chat-panel.is-mobile-empty #recommendQuestionsPanel .recommend-questions-wrap {
  width: 100%;
  max-width: 100%;
  margin: 0 auto !important;
}

html.layout-mobile .chat-panel.is-mobile-empty #recommendQuestionsPanel .recommend-questions-label {
  position: static !important;
  transform: none !important;
  justify-content: center !important;
  height: auto !important;
  margin: 0 0 clamp(10px, 2.8vw, 14px) !important;
  color: #9aa3af;
  font-size: clamp(13px, 3.6vw, 16px);
  font-weight: 700;
  line-height: 1.2;
}

html.layout-mobile .chat-panel.is-mobile-empty #recommendQuestionsPanel .recommend-questions-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: clamp(12px, 3.8vw, 18px) !important;
}

html.layout-mobile .chat-panel.is-mobile-empty #recommendQuestionsPanel .recommend-questions-btn {
  min-height: clamp(52px, 13vw, 66px);
  padding: 0 clamp(14px, 4vw, 22px);
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.82);
  color: #64748b;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 8px 24px rgba(15, 23, 42, 0.04);
  font-size: clamp(14px, 3.9vw, 18px);
  line-height: 1.18;
  font-weight: 600;
  letter-spacing: 0;
  text-align: center !important;
  justify-content: center;
  white-space: normal;
}

html.layout-mobile .chat-panel.is-mobile-empty #recommendQuestionsPanel .recommend-questions-btn:active {
  transform: scale(0.985);
  color: #1677ff;
}

html.layout-mobile #mobileBottomActionRow .mobile-menu-slot {
  box-sizing: border-box;
  padding-block: 0;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.78);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.075);
}

html.layout-mobile #mobileBottomActionRow .mobile-menu-slot-icon {
  display: none !important;
}

html.layout-mobile #mobileBottomActionRow .mobile-menu-slot-icon i {
  font-size: clamp(17px, 4.6vw, 21px);
}

html.layout-mobile #mobileBottomActionRow .mobile-menu-slot[data-tone="green"] .mobile-menu-slot-icon {
  color: #18c33f;
}

html.layout-mobile #mobileBottomActionRow .mobile-menu-slot[data-tone="orange"] .mobile-menu-slot-icon {
  color: #ff7a1a;
}

html.layout-mobile #mobileBottomActionRow .mobile-menu-slot[data-tone="blue"] .mobile-menu-slot-icon {
  color: #15a7f5;
}

html.layout-mobile #mobileBottomActionRow .mobile-menu-slot[data-tone="violet"] .mobile-menu-slot-icon {
  color: #6f63ff;
}

html.layout-mobile #mobileBottomActionRow .mobile-menu-slot-label {
  flex: 1 1 auto;
  width: 100% !important;
  min-width: 0;
  white-space: nowrap !important;
  color: #263449;
  font-weight: 650;
}

html.layout-mobile #mobileBottomActionRow .mobile-menu-slot.is-active {
  background: linear-gradient(180deg, rgba(239, 246, 255, 0.98), rgba(219, 234, 254, 0.98));
  border-color: rgba(96, 165, 250, 0.46);
  box-shadow:
    0 10px 24px rgba(37, 99, 235, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.86);
}

html.layout-mobile #mobileBottomActionRow .mobile-menu-slot.is-active .mobile-menu-slot-label {
  color: #1d4ed8;
  font-weight: 800;
}

html.layout-mobile .input-area {
  display: flex !important;
  align-items: center !important;
  gap: clamp(2px, 0.6vw, 3px) !important;
  padding: 0 !important;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0 !important;
}

html.layout-mobile #mobileComposerBar {
  flex: 1 1 auto;
  min-width: 0;
  height: var(--mobile-input-bar-height-runtime);
  min-height: var(--mobile-input-bar-height-runtime);
  display: flex;
  gap: clamp(2px, 0.6vw, 3px);
  padding: 5px 0 5px clamp(4px, 1.2vw, 6px);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.78);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

html.layout-mobile .input-area #mobileQuickPlusBtn {
  /* This button sits outside the composer. Match its content bottom, including
     padding and border; portrait phones and tablets own their inset token. */
  margin-bottom: var(--mobile-composer-control-inset, 6px) !important;
  flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.94) !important;
  color: #0b0f19 !important;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08) !important;
  transform: none !important;
}

html.layout-mobile .input-area #mobileQuickPlusBtn i {
  font-size: 19px !important;
  font-weight: 700;
}

html.layout-mobile #mobileComposerBar #openCameraBtn {
  width: var(--mobile-input-btn-size) !important;
  height: var(--mobile-input-btn-size) !important;
  min-width: var(--mobile-input-btn-size) !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
  border-radius: 999px !important;
  background: transparent !important;
  color: #374151 !important;
}

html.layout-mobile #mobileComposerBar #mobileInputToolbar .mobile-quick-btn {
  width: var(--mobile-input-btn-size-md) !important;
  height: var(--mobile-input-btn-size-md) !important;
  min-width: var(--mobile-input-btn-size-md) !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
}

html.layout-mobile #mobileComposerBar #mobileInputToolbar .mobile-quick-btn:not(.ui-mic-control) {
  border-radius: 999px !important;
  background: transparent !important;
  color: #374151 !important;
}

html.layout-mobile #mobileComposerBar #openCameraBtn i {
  font-size: 18px !important;
}

html.layout-mobile #mobileComposerBar #mobileInputToolbar .mobile-quick-btn i {
  font-size: 17px !important;
}

html.layout-mobile .input-area #userInput {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  min-height: 38px !important;
  max-height: 96px !important;
  padding: 8px 1px !important;
  color: #1f2937 !important;
  font-size: clamp(13px, 3.6vw, 16px) !important;
  line-height: 1.25 !important;
  overflow: hidden !important;
  resize: none !important;
}

html.layout-mobile .input-area #userInput::placeholder {
  color: #9aa1ad !important;
  font-size: clamp(12px, 3.08vw, 14px);
  font-weight: 500;
}

html.layout-mobile #mobileInputToolbar {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

html.layout-mobile #mobileComposerBar #sendBtn {
  flex: 0 0 auto;
  min-width: var(--mobile-input-btn-size-md) !important;
  width: var(--mobile-input-btn-size-md) !important;
  height: var(--mobile-input-btn-size-md) !important;
  margin-left: -8px;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
  border-radius: 999px !important;
  background: transparent !important;
  color: #374151 !important;
  box-shadow: none !important;
}

html.layout-mobile #mobileComposerBar #sendBtn i {
  font-size: 18px !important;
}

html.layout-mobile #mobileComposerBar #sendBtn[disabled],
html.layout-mobile #mobileComposerBar #sendBtn.is-disabled,
html.layout-mobile #mobileComposerBar #sendBtn.is-mobile-send-disabled,
html.layout-mobile #mobileComposerBar #sendBtn[data-mobile-send-visual="disabled"] {
  opacity: 1 !important;
  background: transparent !important;
  color: rgba(15, 23, 42, 0.32) !important;
  pointer-events: none !important;
  cursor: not-allowed !important;
}

html.layout-mobile #mobileComposerBar #sendBtn:not([disabled]):not(.is-disabled):not(.is-mobile-send-disabled),
html.layout-mobile #mobileComposerBar #sendBtn[data-mobile-send-visual="ready"] {
  background: transparent !important;
  color: #374151 !important;
}

html.layout-mobile #mobileRightDrawer .mobile-menu-slot-icon,
html.layout-mobile #mobileLeftDrawer .mobile-menu-slot-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  color: #1677ff;
}

html.layout-mobile #mobileRightDrawer .mobile-menu-slot,
html.layout-mobile #mobileLeftDrawer .mobile-menu-slot {
  min-height: 46px;
  gap: 10px;
  border-radius: 12px;
}

html.layout-mobile #mobileRightDrawer .mobile-menu-slot-label,
html.layout-mobile #mobileLeftDrawer .mobile-menu-slot-label {
  text-align: left;
}

@media (max-width: 374px) {
  html.layout-mobile .top-bar .left-aligned-group > #openImageStrategyBtn {
    font-size: 12px !important;
  }

  html.layout-mobile #mobileBottomActionRow .mobile-menu-slot {
    padding: 0 4px;
    gap: 0;
  }

  html.layout-mobile #mobileBottomActionRow .mobile-menu-slot-label {
    font-size: 14px;
  }
}

/* ===== 原生拍照入口：手机与平板保留在输入条中；桌面端样式不受影响。 ===== */
html.layout-mobile .input-area #openCameraBtn,
html.layout-mobile #mobileComposerBar #openCameraBtn {
  display: inline-flex !important;
  visibility: visible !important;
}

/* ============================================================
   手机版排版优化 V1
   仅作用于 layout-mobile；桌面版、登录页与 agents 页均不命中。
============================================================ */

/* 四个高频对话模式固定展示，手机上无需横向拖动才能发现功能。 */
html.layout-mobile #mobileBottomActionRow .mobile-menu-list {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  gap: 6px !important;
  width: 100% !important;
  padding: 0 2px 2px !important;
  overflow: visible !important;
  scroll-snap-type: none !important;
  touch-action: manipulation !important;
  user-select: none;
  -webkit-user-select: none;
}

html.layout-mobile #mobileBottomActionRow .mobile-menu-slot {
  min-width: 0 !important;
  width: 100% !important;
  flex: none !important;
  min-height: 42px !important;
  padding-inline: 4px !important;
  border-radius: 14px !important;
}

html.layout-mobile #mobileBottomActionRow .mobile-menu-slot-label {
  font-size: clamp(11px, 3vw, 13px) !important;
  line-height: 1.15 !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

/* 输入框支持自然换行并随内容增高，最高仍限制在 96px。 */
html.layout-mobile #mobileComposerBar {
  transition: height 120ms ease, min-height 120ms ease !important;
}

html.layout-mobile .input-area #userInput {
  height: auto;
  white-space: pre-wrap !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
}

/* 思维导图编辑器改为真正的手机全屏，工具栏保持单行横向滚动。 */
html.layout-mobile #mindmapModal.modal-overlay:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) {
  align-items: stretch !important;
  justify-content: flex-start !important;
  padding: 0 !important;
}

html.layout-mobile #mindmapModal.modal-overlay:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) .mindmap-modal-content {
  width: 100vw !important;
  max-width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  min-height: 100vh !important;
  min-height: 100dvh !important;
  max-height: none !important;
  border-radius: 0 !important;
}

html.layout-mobile #mindmapModal.modal-overlay:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) .modal-header {
  flex: 0 0 auto !important;
  min-height: 58px !important;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px !important;
}

html.layout-mobile #mindmapModal.modal-overlay:not(.learning-board-modal):not(#mathFormulaModal):not(#chemistryFormulaModal):not(#physicsFormulaModal) .modal-header h2 {
  font-size: 18px !important;
  line-height: 1.2 !important;
}

html.layout-mobile #mindmapModal .mindmap-editor-container {
  height: 100% !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

html.layout-mobile #mindmapModal .mindmap-toolbar {
  position: relative !important;
  display: flex !important;
  flex-direction: row !important;
  flex: 0 0 auto !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  justify-content: flex-start !important;
  width: 100% !important;
  min-height: 54px !important;
  max-height: 54px !important;
  padding: calc(env(safe-area-inset-top) + 8px) 10px 8px !important;
  gap: 8px !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  overscroll-behavior-x: contain !important;
  scroll-snap-type: x proximity !important;
}

html.layout-mobile #mindmapModal :is(
  .mindmap-tools-group,
  .mindmap-templates-group,
  .mindmap-history-group,
  .mindmap-zoom-group,
  .mindmap-export-group,
  .mindmap-clear-group
) {
  display: flex !important;
  flex: 0 0 auto !important;
  flex-wrap: nowrap !important;
  gap: 6px !important;
  scroll-snap-align: start !important;
}

html.layout-mobile #mindmapModal .mindmap-content-area {
  flex: 1 1 auto !important;
  min-height: 0 !important;
}

html.layout-mobile #mindmapModal .mindmap-canvas-container {
  min-height: 0 !important;
  height: 100% !important;
}

/* MOBILE_NOTIFICATION_TOP_RIGHT_V1: all mobile/tablet status messages use the
   same top-right anchor, including voice and learning-board notifications.
   Keep both safe-area edges and long messages within the viewport. */
html.layout-mobile body > .notification {
  top: max(12px, env(safe-area-inset-top)) !important;
  right: max(12px, env(safe-area-inset-right)) !important;
  bottom: auto !important;
  left: auto !important;
  width: max-content !important;
  max-width: min(360px, calc(100vw - 24px - env(safe-area-inset-left) - env(safe-area-inset-right))) !important;
  box-sizing: border-box;
  min-height: 44px !important;
  padding: 10px 12px !important;
  border-radius: 14px !important;
  font-size: 12px !important;
  line-height: 1.35 !important;
  overflow-wrap: anywhere;
}

html.layout-mobile body > .notification .notification-icon {
  flex: 0 0 auto !important;
  margin-right: 8px !important;
  font-size: 16px !important;
}

/* 矮屏横向手机：缩短欢迎区，避免标题被顶部栏遮挡。 */
@media (orientation: landscape) and (max-height: 560px) {
  html.layout-mobile .chat-panel.is-mobile-empty #mobileWelcomePanel {
    transform: none !important;
  }

  html.layout-mobile .mobile-welcome-title {
    font-size: clamp(22px, 6.5vw, 30px) !important;
  }

  html.layout-mobile .mobile-welcome-subtitle {
    margin: 6px 0 12px !important;
    font-size: 13px !important;
  }

  html.layout-mobile .chat-panel.is-mobile-empty #recommendQuestionsPanel.is-visible {
    transform: none !important;
  }

  html.layout-mobile .chat-panel.is-mobile-empty #recommendQuestionsPanel .recommend-questions-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  html.layout-mobile .chat-panel.is-mobile-empty #recommendQuestionsPanel .recommend-questions-btn {
    min-height: 42px !important;
    padding-inline: 8px !important;
    font-size: 12px !important;
  }
}

/* ============================================================
   手机版排版优化 V2
   仅作用于 layout-mobile；不改变桌面版结构或业务事件。
============================================================ */

/* 桌面宠物浮窗在手机横竖屏都会遮挡学习操作，手机版只隐藏、不删除。 */
html.layout-mobile #pet-widget {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* 窄屏顶部只保留路由图标，确保入口仍是标准触控尺寸。 */
@media (max-width: 374px) {
  html.layout-mobile .top-bar .left-aligned-group > #openImageStrategyBtn {
    flex: 0 0 42px !important;
    width: 42px !important;
    min-width: 42px !important;
    max-width: 42px !important;
    height: 42px !important;
    padding: 0 !important;
    justify-content: center !important;
    border-radius: 14px !important;
  }

  html.layout-mobile .top-bar .left-aligned-group > #openImageStrategyBtn .btn-text {
    display: none !important;
  }

  html.layout-mobile .top-bar .left-aligned-group > #openImageStrategyBtn i {
    font-size: 18px !important;
  }

}

/* 手机公式编辑器将“输入 / 预览”改为上下排列，长公式不再挤在半屏列中。 */
@media (max-width: 480px) {
  html.layout-mobile #mathFormulaModal .math-formula-content,
  html.layout-mobile #chemistryFormulaModal .chemistry-formula-content,
  html.layout-mobile #physicsFormulaModal .physics-formula-content {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: auto auto auto minmax(0, 1fr) auto !important;
  }

  html.layout-mobile #mathFormulaModal .math-editor-section:nth-of-type(1),
  html.layout-mobile #chemistryFormulaModal .chemistry-editor-section:nth-of-type(1),
  html.layout-mobile #physicsFormulaModal .physics-editor-section:nth-of-type(1) {
    grid-column: 1 !important;
    grid-row: 1 !important;
  }

  html.layout-mobile #mathFormulaModal .math-editor-section:nth-of-type(2),
  html.layout-mobile #chemistryFormulaModal .chemistry-editor-section:nth-of-type(2),
  html.layout-mobile #physicsFormulaModal .physics-editor-section:nth-of-type(2) {
    grid-column: 1 !important;
    grid-row: 2 !important;
  }

  html.layout-mobile #mathFormulaModal .grade-switch,
  html.layout-mobile #chemistryFormulaModal .grade-switch,
  html.layout-mobile #physicsFormulaModal .grade-switch {
    grid-row: 3 !important;
  }

  html.layout-mobile #mathFormulaModal .math-symbols-panel,
  html.layout-mobile #chemistryFormulaModal .chemistry-symbols-panel,
  html.layout-mobile #physicsFormulaModal .physics-symbols-panel {
    grid-row: 4 !important;
  }

  html.layout-mobile #mathFormulaModal .math-actions,
  html.layout-mobile #chemistryFormulaModal .chemistry-actions,
  html.layout-mobile #physicsFormulaModal .physics-actions {
    grid-row: 5 !important;
  }

  html.layout-mobile #mathFormulaModal .math-preview-section,
  html.layout-mobile #chemistryFormulaModal .chemistry-preview-section,
  html.layout-mobile #physicsFormulaModal .physics-preview-section,
  html.layout-mobile #mathFormulaModal .math-preview-content,
  html.layout-mobile #chemistryFormulaModal .chemistry-preview-content,
  html.layout-mobile #physicsFormulaModal .physics-preview-content {
    overflow-x: auto !important;
    overflow-y: auto !important;
    justify-content: flex-start !important;
  }
}

/* ============================================================
   手机版竖屏排版优化 V3
   仅命中 portrait phone + layout-mobile；不改变桌面端结构和事件。
============================================================ */
@media (max-width: 640px) and (orientation: portrait) {
  html.layout-mobile {
    --mobile-topbar-pad-x: 12px;
    --mobile-topbar-content-top: max(8px, calc(env(safe-area-inset-top) + 5px));
    --mobile-topbar-control-size: 44px;
    /* The portrait composer has no border or padding of its own. */
    --mobile-composer-control-inset: 0px;
    --mobile-v3-surface: rgba(255, 255, 255, 0.96);
    --mobile-v3-surface-soft: #f4f7fb;
    --mobile-v3-border: rgba(15, 23, 42, 0.09);
    --mobile-v3-blue: #1677ff;
    --mobile-v3-blue-soft: #eaf3ff;
    --mobile-v3-radius: 18px;
    --mobile-v3-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
  }

  /* 顶部以中间标题为视觉锚点，路由入口只保留图标，避免 375/390 宽度截断。 */
  html.layout-mobile .top-bar {
    min-height: max(64px, calc(var(--mobile-topbar-content-top) + var(--mobile-topbar-control-size) + 8px)) !important;
    padding: var(--mobile-topbar-content-top) 12px 8px !important;
  }

  html.layout-mobile .top-bar .left-aligned-group > #openImageStrategyBtn {
    flex: 0 0 44px !important;
    width: 44px !important;
    min-width: 44px !important;
    max-width: 44px !important;
    height: 44px !important;
    padding: 0 !important;
    justify-content: center !important;
    border-radius: 15px !important;
  }

  html.layout-mobile .top-bar .left-aligned-group > #openImageStrategyBtn .btn-text {
    display: none !important;
  }

  html.layout-mobile .top-bar .left-aligned-group > #openImageStrategyBtn i {
    font-size: 18px !important;
  }

  html.layout-mobile .title {
    font-size: clamp(18px, 5vw, 20px) !important;
    line-height: 1.08 !important;
  }

  html.layout-mobile .left-aligned-group > #mobileLeftDrawerBtn,
  html.layout-mobile .left-aligned-group > #mobileStudentNotesBtn,
  html.layout-mobile #clearBtn.mobile-top-clear-btn,
  html.layout-mobile #mobileRightDrawerBtn,
  html.layout-mobile .top-bar .right-extended-group .homework-entry-btn {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    border-radius: 15px !important;
  }

  /* 四个高频对话模式保持独立按钮，避免产生整体包裹感。 */
  html.layout-mobile #mobileBottomActionRow .mobile-menu-list {
    gap: 6px !important;
    padding: 0 2px 2px !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  html.layout-mobile #mobileBottomActionRow .mobile-menu-slot,
  html.layout-mobile #mobileBottomActionRow .mobile-menu-slot.is-active {
    min-height: 44px !important;
    padding-inline: 3px !important;
    border: 1px solid rgba(255, 255, 255, 0.8) !important;
    border-radius: 14px !important;
    background: var(--mobile-v3-surface) !important;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06) !important;
  }

  html.layout-mobile #mobileBottomActionRow .mobile-menu-slot.is-active {
    background: var(--mobile-v3-blue-soft) !important;
    border-color: rgba(22, 119, 255, 0.24) !important;
    box-shadow: 0 8px 20px rgba(22, 119, 255, 0.11) !important;
  }

  html.layout-mobile #mobileBottomActionRow .mobile-menu-slot-label {
    color: #475569 !important;
    font-size: clamp(11px, 3vw, 12px) !important;
    font-weight: 650 !important;
  }

  html.layout-mobile #mobileBottomActionRow .mobile-menu-slot.is-active .mobile-menu-slot-label {
    color: #145dcc !important;
    font-weight: 800 !important;
  }

  /* 加号、输入框和语音/发送按钮收进同一输入胶囊，减少漂浮按钮的碎片感。 */
  html.layout-mobile .input-area {
    gap: 2px !important;
    padding: 4px !important;
    border: 1px solid var(--mobile-v3-border) !important;
    border-radius: var(--mobile-v3-radius) !important;
    background: var(--mobile-v3-surface) !important;
    box-shadow: var(--mobile-v3-shadow) !important;
  }

  html.layout-mobile #mobileComposerBar {
    gap: 2px !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 14px !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  html.layout-mobile .input-area #mobileQuickPlusBtn {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    border-radius: 14px !important;
    background: var(--mobile-v3-surface-soft) !important;
    color: #334155 !important;
    box-shadow: none !important;
    transform: none !important;
  }

  html.layout-mobile .input-area #mobileQuickPlusBtn.is-disabled[aria-disabled="true"] {
    color: #94a3b8 !important;
    background: #f1f5f9 !important;
    opacity: 0.72 !important;
  }

  html.layout-mobile #mobileComposerBar #mobileInputToolbar .mobile-quick-btn,
  html.layout-mobile #mobileComposerBar #sendBtn {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    margin-left: 0 !important;
    border-radius: 14px !important;
  }

  html.layout-mobile .input-area #userInput {
    min-height: 44px !important;
    padding: 10px 4px !important;
  }

  /* 工具抽屉扩大有效阅读宽度，并按手机任务优先级分组。 */
  html.layout-mobile #mobileRightDrawer,
  html.layout-mobile #mobileLeftDrawer {
    width: min(82vw, 320px) !important;
    padding: max(10px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom)) !important;
    background: #ffffff !important;
    box-shadow: 18px 0 50px rgba(15, 23, 42, 0.20) !important;
  }

  html.layout-mobile #mobileRightDrawer .mobile-menu-list,
  html.layout-mobile #mobileLeftDrawer .mobile-menu-list {
    gap: 4px !important;
  }

  html.layout-mobile #mobileRightDrawer .mobile-menu-slot,
  html.layout-mobile #mobileRightDrawer .mobile-menu-slot.is-primary,
  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot,
  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot.is-primary {
    position: relative;
    min-height: 48px !important;
    padding: 0 10px !important;
    gap: 10px !important;
    border: 0 !important;
    border-radius: 12px !important;
    background: transparent !important;
  }

  html.layout-mobile #mobileRightDrawer .mobile-menu-slot:active,
  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot:active {
    background: var(--mobile-v3-blue-soft) !important;
  }

  html.layout-mobile #mobileRightDrawer .mobile-menu-slot-icon,
  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot-icon {
    width: 28px !important;
    color: #55708f !important;
  }

  html.layout-mobile #mobileRightDrawer .mobile-menu-slot-label,
  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot-label {
    font-size: 14px !important;
    font-weight: 600 !important;
  }

  html.layout-mobile #mobileLeftDrawer .mobile-menu-list::before,
  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-slot-id="interactiveInquiryBtn"]::before,
  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-slot-id="mathFormulaBtn"]::before {
    color: #94a3b8;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    line-height: 1.2;
    pointer-events: none;
  }

  html.layout-mobile #mobileLeftDrawer .mobile-menu-list::before {
    content: "学习内容";
    order: 0;
    padding: 4px 10px 3px;
  }

  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-slot-id="interactiveInquiryBtn"]::before,
  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-slot-id="mathFormulaBtn"]::before {
    position: absolute;
    top: -22px;
    left: 10px;
  }

  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-slot-id="interactiveInquiryBtn"] {
    order: 5;
    margin-top: 28px;
  }

  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-slot-id="interactiveInquiryBtn"]::before {
    content: "探究与练习";
  }

  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-slot-id="mathFormulaBtn"] {
    order: 9;
    margin-top: 28px;
  }

  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-slot-id="mathFormulaBtn"]::before {
    content: "学科工具";
  }

  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-module-id="advanced-practice"] { order: 1; }
  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-module-id="flashcard"] { order: 2; }
  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-module-id="mindmap"] { order: 3; }
  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-module-id="expert-challenge"] { order: 4; }
  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-slot-id="board-module-interactive-experiment"] { order: 6; }
  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-module-id="subject-reasoning"] { order: 7; }
  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-module-id="qa"] { order: 8; }
  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-module-id="basic-practice"] { order: 9; }
  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-slot-id="mathFormulaBtn"] { order: 10; }
  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-slot-id="chemistryFormulaBtn"] { order: 11; }
  html.layout-mobile #mobileLeftDrawer .mobile-menu-slot[data-slot-id="physicsFormulaBtn"] { order: 12; }

  /* 高频弹窗的触控目标统一到 44px；仅改变竖屏手机版命中面积。 */

  html.layout-mobile :is(
    #mathFormulaModal,
    #chemistryFormulaModal,
    #physicsFormulaModal
  ) .grade-switch {
    height: auto !important;
    min-height: 50px !important;
  }

  html.layout-mobile :is(
    #mathFormulaModal,
    #chemistryFormulaModal,
    #physicsFormulaModal
  ) .grade-btn,
  html.layout-mobile #mathFormulaModal .math-tab-btn,
  html.layout-mobile #chemistryFormulaModal .chemistry-tab-btn,
  html.layout-mobile #physicsFormulaModal .physics-tab-btn {
    height: 44px !important;
    min-height: 44px !important;
  }

  html.layout-mobile #chatRecordsModal .chat-records-admin__actions .admin-btn,
  html.layout-mobile #chatRecordsModal .chat-records-admin__detail-actions .admin-btn,
  html.layout-mobile #chatRecordsModal .personal-chat-calendar__nav,
  html.layout-mobile :is(
    #studentInfoModal,
    #learningPreferencesModal,
    #studentSkillTagModal,
    #ttsVoiceModal
  ) .preferences-modal-footer :is(.btn, .btn-filled),
  html.layout-mobile #myLibraryModal :is(.library-tab-btn, .library-notes-drawing-btn) {
    min-height: 44px !important;
  }

  html.layout-mobile #chatRecordsModal .personal-chat-calendar__nav {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
  }

  html.layout-mobile #myLibraryModal .delete-item-btn,
  html.layout-mobile #myLibraryModal .library-clear-search-btn {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
  }

  html.layout-mobile #mindmapModal :is(
    .mindmap-toolbar .mindmap-tool-btn,
    .mindmap-action-btn,
    .mindmap-template-select
  ) {
    height: 44px !important;
    min-height: 44px !important;
  }
}

/* Keep the title on the same safe-area row as both button groups. Reserve
   the real two-button footprint on phones and the wider route label on tablets. */
html.layout-mobile .top-bar > .title {
  position: absolute !important;
  top: calc(var(--mobile-topbar-content-top) + var(--mobile-topbar-control-size) / 2) !important;
  left: 50% !important;
  width: min(420px, calc(100vw - var(--mobile-title-side-reserve) - var(--mobile-title-side-reserve))) !important;
  max-width: calc(100vw - var(--mobile-title-side-reserve) - var(--mobile-title-side-reserve)) !important;
  min-width: 0 !important;
  margin: 0 !important;
  transform: translate(-50%, -50%) !important;
  text-align: center !important;
  pointer-events: none;
}

/* Keep phone titles beside the controls. Long agent names can use two lines
   within the same 44px control row instead of shrinking or dropping below it. */
@media (max-width: 640px) and (orientation: portrait) {
  html.layout-mobile .top-bar > .title {
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
    overflow-wrap: anywhere;
  }
}

@media (min-width: 641px) {
  html.layout-mobile {
    --mobile-title-side-reserve: 205px;
  }
}

/* An extra task button needs a dedicated title row. */
@media (max-width: 640px) {
  html.layout-mobile .top-bar.has-homework-entry {
    min-height: calc(var(--mobile-topbar-content-top) + var(--mobile-topbar-control-size) + 34px) !important;
  }
  html.layout-mobile .top-bar.has-homework-entry > .title {
    top: calc(var(--mobile-topbar-content-top) + var(--mobile-topbar-control-size) + 5px) !important;
    left: 12px !important;
    width: calc(100vw - 24px) !important;
    max-width: calc(100vw - 24px) !important;
    transform: none !important;
  }
}
