/* ============================================================
   宇宙 · 手机竖屏全屏 App 形态
   电脑端(>820px) 完全沿用 app.css / pages.css 的桌面布局；
   本文件只在手机竖屏生效，把站点变成「打开即全屏、底部标签切换」
   的原生 App 观感。放在最后加载，优先级最高。
   ============================================================ */

/* 默认（桌面/宽屏）：手机专用元素全部隐藏，不改变原布局 */
.mobile-topbar{display:none!important}
.nav-toggle,.nav-mask{display:none}

@media (max-width:820px){
  /* ---------- 真·全屏基础 ---------- */
  html,body{
    height:100%;height:100dvh;
    width:100%;
    overflow:hidden;
    overscroll-behavior:none;               /* 禁下拉橡皮筋 */
    -webkit-tap-highlight-color:transparent;/* 去点击高亮 */
  }
  body{
    padding-bottom:calc(58px + env(safe-area-inset-bottom,0px)); /* 给底部标签栏留位 */
  }
  .app{
    height:100dvh;
    padding-left:0!important;
    padding-top:0;                     /* 安全区由顶部选卡负责，别叠加两次 */
  }
  #stars,.vignette{position:fixed;inset:0}

  /* ---------- 顶部：极简状态条（时钟 + 层名） ---------- */
  header{
    padding:6px 12px;
    gap:8px;min-height:44px;
    background:linear-gradient(180deg,rgba(4,8,18,.96),rgba(4,8,18,.55));
  }
  .logo{width:26px;height:26px;font-size:12px}
  .brand h1{font-size:14px;letter-spacing:2px}
  .brand p{display:none}
  .status{display:none}
  .clock{margin-left:auto;flex:0 0 auto;white-space:nowrap}
  .clock .t{font-size:13px}
  .clock .d{font-size:8px}
  .brand{flex:0 0 auto}

  /* 星图整屏时顶栏照常收起（沿用 stage-full），全给星图 */
  body.stage-full header{display:none!important}

  /* ---------- 主体：单列铺满 ---------- */
  .shell{padding:0;gap:0;flex:1 1 auto;min-height:0}
  #main{padding:0;flex:1 1 auto;min-height:0}
  .page{flex:1 1 auto;min-height:0;padding:0;gap:0}
  .page-h{display:none}                      /* 页标题交给底部标签/顶部，省竖向空间 */
  main{display:flex;overflow-y:auto;-webkit-overflow-scrolling:touch;overscroll-behavior:contain}
  /* 除星图外的页面：内容自然往下排、整页滚动（原来被 280px 的面板高度切成两半） */
  /* #main 原本是 display:flex 行容器，align-items:stretch 会把 .page 钉在视口高（764px），
     面板里超出的内容落在 page 外面，既不进滚动区、padding-bottom 也白留 ——
     表现就是「已经滚到底了，下半截还被底部导航压着」。改成块级流，page 高度按内容算。 */
  #main{display:block;height:100%}   /* height 必须显式给，否则 .page 的 min-height:100% 解析不到基准，短页面底部会露背景 */
  .page:not([data-page="orbit"]){height:auto!important;min-height:100%;
    padding-bottom:calc(66px + env(safe-area-inset-bottom,0px))}
  /* 必须连 .panel.grow 一起压平：`.panel.grow{flex:1 1 auto}` 特异性(0,2,0) 高于
     `.page:not() .panel`(0,1,1)，只写前一条的话面板仍被定成 764px 固定高，
     面板里的表单溢出到面板外面、撑不开 #main 的 scrollHeight ——
     表现就是「滚到底了，下半截内容被底部导航压着，永远看不到」。 */
  .page:not([data-page="orbit"]) .panel,
  .page:not([data-page="orbit"]) .panel.grow{
    height:auto!important;flex:0 0 auto!important;max-height:none!important}
  .page:not([data-page="orbit"]) .panel-b{flex:0 0 auto!important;overflow:visible!important}
  /* 我的宇宙：外层也不能锁 height:100%，否则整块按视口高算、内容照样溢出 */
  .page:not([data-page="orbit"]) .mine-wrap{height:auto!important;min-height:0}
  /* 窄屏那条 .panel{max-height:280px} 会把内容切成两半（我的宇宙表单直接被裁掉），
     手机上让面板撑满整页高度，内容自己内部滚动 */
  .panel{border-radius:0;border-left:0;border-right:0;background:rgba(8,16,32,.5);max-height:none!important}
  /* 栅格里的 auto 行会被拉平成等高，内容多的那块就被切了；手机上直接排成一列 */
  .grid-2{display:flex!important;flex-direction:column;gap:0;height:auto;flex:0 0 auto!important}
  .grid-2 > .panel{max-height:none}

  /* ---------- 星图页：整屏竖满，指令台浮在底部标签栏之上 ---------- */
  .page[data-page="orbit"]{height:100%}
  .page[data-page="orbit"] .panel.grow{max-height:none;height:100%}
  .stage{height:100%}
  #orbit{height:100%}
  .legend{right:10px;top:8px;font-size:9px}
  .legend .lg-note{font-size:8px;max-width:none;white-space:nowrap;opacity:.7}
  /* 竖屏也要留一行提示：缩到地球能进地图是这个星图最主要的出口，
     全藏起来用户根本不知道。文字由 updateHint() 出短版。
     位置要点：① 不能贴底 —— 指令台盖在 stage 底部，会被整块挡住；
     ② 左边必须让开 118px，否则和左侧层级条的高亮层名（约 y=162）叠字。 */
  .stage-hint{
    display:block;top:112px;bottom:auto;left:118px;right:10px;padding:0;
    font-size:10px;line-height:1.45;letter-spacing:0;opacity:.75;
    white-space:normal;overflow:hidden;
  }
  /* 详情面板：用 dvh 而不是 %，否则父容器比视口高时 max-height 会算飞（实测遮住底部按钮） */
  .detail{left:8px;right:8px;top:auto;bottom:calc(122px + env(safe-area-inset-bottom,0px));
          width:auto;max-height:calc(100dvh - 186px);font-size:12px;z-index:30;
          -webkit-overflow-scrolling:touch;
          /* 手机上改成从下滑入：桌面那套 translateX(12px) 会让右侧溢出错觉 */
          transform:translateY(12px)}
  .detail.on{transform:translateY(0)}
  /* 指令台：贴着底部标签栏上方，收起时只露一条
     用 body.stage-full 前缀压过 pages.css 里桌面的 left:88px/bottom:10px */
  .cmd-dock,
  body.stage-full .cmd-dock{
    left:6px!important;right:6px!important;
    bottom:calc(62px + env(safe-area-inset-bottom,0px))!important;
    z-index:20!important;
    padding:6px 8px 8px;
    background:rgba(6,14,28,.92);
  }
  #log{max-height:78px;font-size:11px;line-height:1.6}
  .input-row{gap:5px}
  #cmd{font-size:13px;padding:8px}
  .btn{font-size:12px;padding:7px 12px}
  .quick{max-height:112px;overflow-y:auto}
  /* app.css 在窄屏把 .quick 默认藏了（只留指令台里可展开的那份），指令台页的快捷指令要常显 */
  #quick2{display:flex!important;flex-wrap:wrap;gap:6px}

  /* ---------- 层名闪屏：居中偏上，避开指令台 ---------- */
  .layer-flash .lf-nm{font-size:30px}
  .layer-flash{transform:translateY(-16%)}

  /* ---------- 我的宇宙：竖屏改成「工具条 → 列表 → 画布 → 表单」四段flex ----------
     原来用 grid 的 minmax(…,1fr) + auto，表单被挤成一条缝、内容全看不见。 */
  .mine-wrap{display:flex!important;flex-direction:column;height:100%;padding:8px;gap:8px}
  .mine-side{flex:0 0 auto;max-height:none;gap:6px}
  .mine-tools{width:100%}
  /* 列表在手机上限高是为了「有作品时不把画布顶下去」；
     空态那段引导文字比较长（5 行），88px 会把它截断出内部滚动条，所以放宽到 148px。 */
  .mine-list{width:100%;flex:0 0 auto;max-height:148px;overflow-y:auto;display:block}
  .mine-empty{font-size:11.5px;line-height:1.7}
  .mine-main{flex:1 1 auto;display:flex!important;flex-direction:column;gap:8px;min-height:0}
  #mineCanvas{flex:1 1 auto;width:100%;height:auto;min-height:210px}
  .mine-form{flex:0 0 auto;max-height:none;overflow:visible}   /* 整页滚动，不再套一层滚动条 */

  /* ---------- 其它页：单列滚动，触摸友好 ---------- */
  .panel-b,.deep-wrap,.conj,#tasks{overflow-y:auto;-webkit-overflow-scrolling:touch}
  .deep-card,.dsn,.task{padding:11px}
  /* 深空卡片：轨道动画与里程碑在手机上改成上下排，否则右边只剩一条缝 */
  .deep-body{flex-direction:column;gap:10px}
  .deep-orb{flex:0 0 auto;width:100%;height:132px}
  .deep-tl{flex-direction:column;gap:8px;overflow-x:visible}
  .dn{min-width:0}
  .deep-h{flex-wrap:wrap;gap:8px}
  .deep-meta{margin-left:0;width:100%;justify-content:space-between}
  .conj{padding:10px}

  /* ---------- 底部标签栏（App 式，替代左侧抽屉） ---------- */
  .nav-toggle,.nav-mask{display:none!important}
  .nav{
    position:fixed!important;
    left:0;right:0;bottom:0;top:auto!important;
    width:100%!important;height:calc(56px + env(safe-area-inset-bottom,0px));
    padding:0 1px env(safe-area-inset-bottom,0px)!important;
    display:flex!important;flex-direction:row!important;
    justify-content:flex-start;align-items:stretch;
    gap:0!important;
    transform:none!important;                /* 覆盖抽屉位移 */
    background:rgba(4,10,22,.97)!important;
    border-top:1px solid var(--line);
    box-shadow:0 -6px 22px rgba(0,0,0,.55);
    backdrop-filter:blur(12px);
    z-index:30!important;
    overflow-x:auto;overflow-y:hidden;        /* 极窄屏可滑动，标签永不丢失 */
    scrollbar-width:none;
  }
  .nav::-webkit-scrollbar{display:none}
  .nav-i{
    flex:1 0 auto;min-width:calc(100% / 7);max-width:calc(100% / 7 + 8px);
    flex-direction:column!important;justify-content:center;align-items:center;
    gap:2px;padding:5px 1px 3px!important;
    font-size:10px!important;letter-spacing:0!important;
    color:var(--dim);border-radius:0;position:relative;
  }
  .nav-i i{
    width:22px!important;height:22px!important;font-size:11px!important;
    border-radius:6px;
    background:rgba(90,170,255,.08);
    border:1px solid transparent;
  }
  .nav-i span{white-space:nowrap;line-height:1.2;font-size:10px}
  .nav-i.on{color:var(--cyan)!important}
  .nav-i.on i{
    background:rgba(79,209,255,.18)!important;
    border-color:rgba(79,209,255,.7)!important;
    box-shadow:0 0 12px rgba(79,209,255,.45);
  }
  .nav-i.on::before{
    content:"";position:absolute;top:0;left:32%;right:32%;height:2px;border-radius:2px;
    background:var(--cyan);box-shadow:0 0 8px var(--cyan);
  }
}

/* 极矮屏（横屏/小屏）：压缩底部栏与指令台 */
@media (max-width:820px) and (max-height:480px){
  .nav{height:calc(46px + env(safe-area-inset-bottom,0px))}
  .nav-i i{width:20px!important;height:20px!important;font-size:10px!important}
  #log{max-height:46px}
  .mine-form{max-height:60vh}
}
