/* Mobile layout: turn the desktop sidebar into a compact bottom navigation. */
@media(max-width:860px){
  html,body{max-width:100%;overflow-x:hidden}
  .app-shell{display:block;min-height:100vh}
  .main-content{padding-bottom:68px;min-width:0}
  .sidebar{position:fixed;z-index:40;left:0;right:0;bottom:0;width:100%;height:62px;padding:6px 8px;background:#fff;border:0;border-top:1px solid var(--line);display:block}
  .brand,.workspace-switcher,.sidebar-label,.quick-links,.sidebar-bottom,.workspace-data-tools{display:none!important}
  .nav-list{height:100%;display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:2px}
  .nav-item{position:relative;width:100%;height:50px;display:flex;flex-direction:column;justify-content:center;align-items:center;gap:3px;padding:0!important;border-radius:7px;font-size:9px!important;line-height:1.1;color:#7b8781}
  .nav-item.active{background:#eaf5ee;color:var(--green-dark);box-shadow:none}
  .nav-icon{width:auto;font-size:17px;line-height:1}
  .nav-badge{position:absolute;top:3px;right:calc(50% - 17px);margin:0;padding:1px 4px;font-size:8px;line-height:1.1}
  .topbar{height:58px;padding:0 13px}
  .breadcrumb{font-size:11px}.breadcrumb span{display:none}.top-actions{gap:3px}.top-actions .icon-button{width:30px;height:30px;font-size:18px}.help-button{width:22px;height:22px}
  .view{width:100%;max-width:none;padding:25px 14px 42px}
  .welcome-row,.page-intro{display:block}.welcome-row h1,.page-intro h1{font-size:25px;line-height:1.3}.welcome-row .primary-button,.page-intro .primary-button{width:100%;justify-content:center;margin-top:17px}
  .stats-grid{margin-top:24px}.stat-card{min-height:0;padding:17px}.continue-card{display:block}.video-cover{min-height:175px}.continue-info{padding:19px}.continue-info h3{font-size:18px;margin-top:14px}.continue-footer{gap:9px;align-items:flex-start}.continue-footer .primary-button{flex:none}
  .course-picker{margin-top:28px}.course-picker-head h1{font-size:27px}.course-picker-summary{min-width:0}.picker-section-title{margin-bottom:13px}.course-grid{grid-template-columns:1fr;gap:11px}.course-card{min-height:190px;padding:16px}.course-card h3{font-size:17px}
  .video-layout{display:block;margin-top:23px}.video-main{min-width:0}.player{width:100%;min-height:0;aspect-ratio:16/10}.player video{min-height:0;height:100%}.playlist{margin-top:14px;padding:14px 12px}.chapter{padding:10px 6px}.chapter span{font-size:11px}
  .video-progress-tools{margin-top:13px}.video-progress-actions{grid-template-columns:1fr 1fr}
  .library-toolbar{margin-top:23px}.filter-tabs{display:grid;grid-template-columns:repeat(4,1fr);gap:0;width:100%}.filter-tabs button{padding:9px 0}.file-grid{grid-template-columns:1fr;gap:10px}.file-card{min-width:0}.file-icon{height:92px}
  .notes-layout{display:block;margin-top:22px}.notes-sidebar{margin-bottom:14px;padding-bottom:10px}.note-editor{min-height:470px;padding:17px 15px 64px}.editor-top{align-items:flex-start;gap:8px}.editor-top>div{gap:7px}.title-input{font-size:21px;margin:21px 0 11px}.editor-content{margin-top:20px;font-size:13px}.editor-toolbar{height:auto;min-height:47px;flex-wrap:wrap;gap:7px;padding:8px 12px}.editor-toolbar span{display:none}
  .study-goal-panel{margin-top:20px}.goal-form{grid-template-columns:1fr 1fr}
  .review-enhance-layout{display:block}.review-enhance-stats{grid-template-columns:1fr 1fr}.review-enhance-card{min-height:0}.review-enhance-plan{margin-top:20px}
  .workspace-search-modal,.workspace-restore-modal{z-index:50}.workspace-search-input input{font-size:14px}.workspace-search-footer{display:none}
  .pdf-modal,.resource-modal{z-index:55}
}
@media(max-width:380px){
  .nav-item{font-size:8px!important}.nav-icon{font-size:16px}.top-actions .icon-button[title="通知"],.help-button{display:none}.view{padding-left:11px;padding-right:11px}.course-card{min-height:180px}.video-step-bar.in-player .control-icon{display:none}.video-step-bar.in-player .speed-control select{width:44px}
}

/* Actual notes page markup overrides */
@media(max-width:860px){
  body{-webkit-tap-highlight-color:transparent;overscroll-behavior-x:none}
  .app-shell{display:block;min-height:100vh}
  .main{width:100%;padding-bottom:calc(76px + env(safe-area-inset-bottom))}
  .sidebar{position:fixed;left:0;right:0;bottom:0;width:100%;height:calc(64px + env(safe-area-inset-bottom));padding:5px 8px env(safe-area-inset-bottom);z-index:40;background:rgba(255,255,255,.97);border-top:1px solid var(--line);backdrop-filter:blur(12px)}
  .brand,.workspace,.sidebar-section-title,.sidebar-bottom{display:none!important}
  .nav{height:100%;display:grid;grid-template-columns:repeat(4,1fr);gap:3px}
  .nav-item{height:52px;min-width:44px;padding:5px 2px!important;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;font-size:10px!important;line-height:1.15;border-radius:8px;touch-action:manipulation}
  .nav-item span{font-size:18px;line-height:1}
  .topbar{height:58px;padding:0 12px;position:sticky;top:0;z-index:30;background:var(--surface,#f7faf8)}
  .breadcrumb span,.breadcrumb b{display:none}.top-actions{gap:5px}.top-actions .icon-btn{width:32px;height:32px}.top-actions .primary-btn{padding:8px 10px;font-size:11px}
  .avatar{width:30px;height:30px}
  .view{width:100%;padding:22px 14px 36px}
  .hero{display:block}.hero h1{font-size:28px;line-height:1.28}.focus-box{margin-top:20px;width:100%}
  .overview-grid{grid-template-columns:1fr;gap:10px;margin-top:20px}.overview-card{padding:16px;min-height:0}
  .page-head{display:block}.page-head h1{font-size:27px}.page-head>.primary-btn{width:100%;margin-top:16px;justify-content:center}
  .notes-layout{display:flex;flex-direction:column;gap:14px}.note-list-panel{order:0}.editor-panel{order:1;min-height:440px;padding:15px}.note-list{max-height:230px;overflow:auto}.note-content{min-height:260px}.editor-toolbar{flex-wrap:wrap;gap:6px;padding:8px}.editor-toolbar button{min-height:36px;min-width:36px;padding:6px 9px;touch-action:manipulation}
  .materials-grid{grid-template-columns:1fr}.review-panel{width:100%}
}
@media(max-width:380px){.view{padding-left:11px;padding-right:11px}.top-actions .primary-btn{display:none}.hero h1{font-size:25px}}

/* Final mobile stability overrides. Keep these after the legacy rules above. */
@media(max-width:860px){
  /* clip prevents a horizontal scroll container, so sticky positioning keeps working. */
  html,body{max-width:100%;overflow-x:clip;scroll-padding-top:58px;scroll-padding-bottom:calc(84px + env(safe-area-inset-bottom))}

  .main{min-width:0;padding-bottom:calc(76px + env(safe-area-inset-bottom))}
  .view{padding-bottom:calc(36px + env(safe-area-inset-bottom))}

  /* The top-bar action is intentionally icon-only on narrow screens. */
  .top-actions{min-width:0;gap:5px}
  .top-actions .icon-btn,
  .top-actions .primary-btn{width:44px;height:44px;min-width:44px;min-height:44px;padding:0;flex:0 0 44px;display:grid;place-items:center}
  .top-actions .primary-btn{font-size:0;line-height:1;white-space:nowrap}
  .top-actions .primary-btn::before{content:"+";font-size:25px;font-weight:500;line-height:1}
  .top-actions .icon-btn{font-size:20px}
  .avatar{width:32px;height:32px;flex:0 0 32px}

  /* Keep the action available even on 320px screens; the page-level action remains below. */
  .top-actions .primary-btn{display:grid!important}

  /* Touch targets: key controls are at least 44px high/wide. */
  .page-head>.primary-btn,
  .page-head>.secondary-btn,
  .quick-capture .primary-btn,
  .auth-actions .primary-btn,
  .auth-actions .secondary-btn,
  .reset-form .primary-btn{min-height:44px}
  .filter{min-width:44px;min-height:44px;padding:0 10px}
  .search-field{height:44px}
  .search-field input{height:42px}
  .editor-meta select{min-height:44px;min-width:88px}
  .editor-meta .icon-btn{width:44px;height:44px;min-width:44px}
  .editor-toolbar button{min-width:44px;min-height:44px;padding:7px 10px}
  .nav-item{min-height:52px}

  /* Toasts must sit above the fixed navigation and remain readable. */
  .toast{left:50%;right:auto;bottom:calc(76px + env(safe-area-inset-bottom));z-index:60;max-width:calc(100% - 24px);text-align:center;transform:translate(-50%,8px)}
  .toast.show{transform:translate(-50%,0)}

  /* Lock the page behind the auth gate while allowing the gate itself to scroll. */
  body.signed-out{overflow:hidden}
  .auth-gate.visible{overscroll-behavior:contain}
  .auth-card input{min-height:44px}
  .auth-card button{min-height:44px}
}

/* A short visual viewport is typical while the mobile keyboard is open. */
@media(max-width:860px) and (max-height:560px){
  .auth-gate.visible{place-items:start center;overflow-y:auto;padding:16px 16px calc(16px + env(safe-area-inset-bottom))}
  .auth-card{margin:auto 0}
  body:has(.note-content:focus,.note-title:focus,.search-field input:focus) .sidebar{transform:translateY(110%);pointer-events:none}
  body:has(.note-content:focus,.note-title:focus,.search-field input:focus) .main{padding-bottom:16px}
  .toast{bottom:16px}
}
