/* Shared small-screen shell. Keep desktop rules and authorization in their owners. */
.mobile-nav-toggle { display: none; }
@media (max-width: 600px), (max-width: 1024px) and (max-height: 500px) and (orientation: landscape) {
  :root { --mobile-header-height: 56px; }
  body { padding: calc(var(--mobile-header-height) + env(safe-area-inset-top, 0px)) 0 0; }
  body .container,
  body:has(#ai-image.panel.active) .container,
  body:has(#ai-workbench.panel.active) .container {
    width: 100%; min-width: 0; max-width: 100%; padding: 18px 14px 48px;
  }
  .top-nav { padding-top: env(safe-area-inset-top, 0px); }
  .nav-inner { height: 56px; padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); gap: 10px; justify-content: flex-start; }
  .nav-inner .nav-site-logo { display: inline-flex; width: 34px; height: 44px; flex: 0 0 34px; }
  .nav-inner .nav-site-logo img { width: 26px; height: 26px; }
  .mobile-nav-toggle { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0; margin-right: auto; border: 0; border-radius: 12px; color: var(--text); background: transparent; cursor: pointer; }
  .mobile-nav-toggle:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
  .nav-inner .nav-tabs { display: none; }
  .top-nav .nav-tabs [hidden] { display: none !important; }
  .top-nav.mobile-nav-open .nav-tabs {
    display: flex; flex-direction: column; align-items: stretch; gap: 0;
    position: fixed; inset: calc(56px + env(safe-area-inset-top, 0px)) 0 auto;
    max-height: calc(100dvh - 56px - env(safe-area-inset-top, 0px)); overflow-y: auto;
    padding: 16px 18px max(24px, env(safe-area-inset-bottom)); border-radius: 0 0 20px 20px;
    background: var(--surface); box-shadow: 0 16px 28px #0002; overscroll-behavior: contain;
  }
  /* Keep original category boundaries, with one surface and a grid inside each group.
     Reuse the original links and permission-controlled wrappers. */
  #site-navigation-items :is(.tab-btn-split-shell, .tab-zebra-primary, .tab-zebra-expand, .tab-zebra-expand-body) {
    display: contents !important; background: transparent !important; box-shadow: none !important;
    border: 0 !important; opacity: 1 !important; visibility: visible !important; transform: none !important; pointer-events: auto !important;
  }
  #site-navigation-items :is(.tab-btn-split, .tab-btn-split-shell, .tab-zebra-primary, .tab-zebra-expand, .tab-zebra-expand-body)::before,
  #site-navigation-items :is(.tab-btn-split, .tab-btn-split-shell, .tab-zebra-primary, .tab-zebra-expand, .tab-zebra-expand-body)::after { display: none; }
  #site-navigation-items > .tab-btn-split {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px 8px;
    width: 100%; min-width: 0; padding: 10px 0; border-bottom: 1px solid var(--line);
    background: transparent; box-shadow: none; border-radius: 0; transform: none; transition: none;
  }
  #site-navigation-items > .tab-btn-split:first-child { padding-top: 0; }
  #site-navigation-items > .tab-btn-split:last-child { border-bottom: 0; padding-bottom: 0; }
  #site-navigation-items .tab-btn {
    display: flex; align-items: center; justify-content: center; min-width: 0; width: 100%; height: auto; min-height: 48px;
    margin: 0; padding: 10px 4px; font-size: 14px; font-weight: 550; line-height: 1.5; text-align: center; white-space: normal;
    color: var(--text); background: transparent; border: 0; border-radius: 0; box-shadow: none; transform: none;
  }
  #site-navigation-items > .tab-btn { min-height: 68px; border-bottom: 1px solid var(--line); }
  #site-navigation-items .tab-btn.active { font-weight: 700; box-shadow: inset 0 -2px #ffd43b; }
  #site-navigation-items .tab-btn:focus-visible { outline: 2px solid #ffd43b; outline-offset: -2px; }
  #site-navigation-items .tab-btn:is(:disabled, [aria-disabled="true"]) { opacity: .45; }
  #site-navigation-items .workbench-nav-empty { display: none; }
  #site-navigation-items [hidden] { display: none !important; }
  .nav-inner .nav-ai-quota-btn { position: static; margin-left: auto; min-width: 44px; min-height: 44px; max-width: 80px; }
  .nav-inner .nav-ai-quota-label { display: none; }
  .nav-inner .nav-version-hint { position: static; width: 44px; height: 44px; flex-shrink: 0; }
  .nav-inner .nav-settings { position: static; margin: 0; }
  .nav-inner .nav-settings-btn { width: 44px; height: 44px; }
  .nav-inner .nav-settings-panel, .nav-inner #nav-notice-panel, .nav-inner .nav-ai-quota-panel {
    position: fixed; top: calc(60px + env(safe-area-inset-top, 0px)); right: 12px; left: auto;
    width: min(360px, calc(100vw - 24px)); max-width: calc(100vw - 24px); max-height: calc(100dvh - 80px); overflow-y: auto;
  }
  #nav-weather-root, #nav-smart-upload-root { display: none !important; }
  .panel:not(#ai-image):not(#ai-workbench) { padding: 0; }
  .site-signature { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
  .auth-gate { overflow-y: auto; align-items: safe center; padding: 84px 20px max(24px, env(safe-area-inset-bottom)); }
  .auth-gate-center, .auth-gate .auth-card { width: 100%; max-width: 420px; }
  .auth-gate-center { margin: auto; }
  .auth-gate-welcome { font-size: clamp(21px, 5.5vw, 28px); white-space: normal; }
  .auth-gate-bg { position: fixed; animation: none; }
  .auth-gate-logo { top: max(20px, env(safe-area-inset-top)); }
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), textarea, select { font-size: 16px; }
  button, a, [role="button"] { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
  .growth-learning-segments { width: 100%; overflow-x: auto; }
  #ai-handbook .handbook-home-learn-item { flex: 1 0 auto; min-width: 60px; min-height: 44px; padding: 10px 12px; }
  /* Touch menus use explicit state; desktop hover must never reopen them. */
  .nav-inner .nav-settings-panel { transform: none !important; opacity: 0 !important; visibility: hidden; pointer-events: none !important; border-radius: 18px; }
  .nav-inner .nav-settings.mobile-menu-open .nav-settings-panel { transform: none !important; opacity: 1 !important; visibility: visible; pointer-events: auto !important; }
  .nav-settings-panel .nav-menu-item { min-height: 48px; font-size: 15px; gap: 12px; flex-shrink: 0; }
  .nav-settings-panel .nav-menu-item svg { width: 19px; height: 19px; }
  body .left-float-bar, body:has(#ai-image.panel.active) .left-float-bar { left: auto; right: 14px; top: calc(62px + env(safe-area-inset-top, 0px)); bottom: auto; width: 44px; height: 44px; z-index: 1400; }
  .left-float-trigger-zone { padding: 0; margin: 0; }
  .left-float-main-btn { width: 44px; height: 44px; border-radius: 12px; background: var(--surface); }
  body .left-float-bar .left-float-panel { position: fixed; top: calc(112px + env(safe-area-inset-top, 0px)); right: 14px; display: grid; grid-template-columns: repeat(2, 44px); width: 116px !important; height: auto !important; max-height: calc(var(--mobile-visible-height, 100dvh) - 130px); padding: 10px; gap: 6px; overflow-y: auto; overscroll-behavior: contain; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: 0 16px 40px #0002; transform: none; transition: opacity .15s ease; opacity: 0; visibility: hidden; pointer-events: none; }
  body .left-float-bar.mobile-menu-open .left-float-panel { opacity: 1; visibility: visible; pointer-events: auto; }
  .left-float-panel .left-float-btn { width: 44px; min-height: 44px; height: 44px; padding: 0; flex-shrink: 0; justify-content: center; gap: 0; font-size: 14px; box-shadow: none; background: transparent; }
  .left-float-panel .left-float-btn span { display: none; }
  .shortcut-help-dock, .ai-speed-broadcast { display: none !important; }
  .tool-modal { padding: 12px; }
  .tool-modal-card { max-width: 100%; max-height: calc(100dvh - 24px); overflow-y: auto; }
  .ipc-overlay { padding: 0; }
  .ipc-dialog { width: 100%; height: 100dvh; min-height: 0; max-height: 100dvh; border-radius: 0; }
  .ipc-home { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 190px; gap: 10px; padding: 16px; }
  .ipc-tool-card { min-height: 190px; padding: 16px; }
  .ipc-tool-icon { transform: scale(.7); transform-origin: top left; left: 16px; top: 16px; }
  .ipc-tool-card strong { font-size: 16px; }
}
