/* ============================================================
   手机界面
   ------------------------------------------------------------
   基准 390×844（iPhone 14 / 主流安卓）。这一份只做覆盖，
   不改 layout.css 里的桌面规则——桌面上三栏并排是对的，
   手机上并排就是三个都看不清。

   几条硬约束：
     · 高度用 100dvh。iOS 的地址栏会伸缩，100vh 会把底部输入框
       顶到屏幕外面，玩家一打字整页跳一下
     · 安全区。刘海和底部横条要留出来，不然输入框压在手势区上
     · 输入框 16px。低于 16px，iOS 一聚焦就自动放大页面
     · 触控目标不小于 44px。手指不是鼠标
   ============================================================ */

/* ---------- 顶栏菜单键：桌面上不存在 ---------- */
.head__menu {
  display: none;
}

/* 正文顶上那条状态：桌面上左栏已经有了，重复一遍只是噪声 ---------- */
.vitals {
  display: none;
}

/* 抽屉那一排入口：桌面上顶栏已经全有了 ---------- */
.side-nav,
.drawer-mask,
.overlay-x {
  display: none;
}

@media (max-width: 820px) {
  :root {
    --h-head: 46px;
    --h-input: 50px;
  }

  /* ---------- 1. 视口 ---------- */
  .app {
    height: 100vh;
    height: 100dvh;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows:
      calc(var(--h-head) + env(safe-area-inset-top))
      minmax(0, 1fr)
      auto
      calc(var(--h-input) + env(safe-area-inset-bottom));
    grid-template-areas:
      "head"
      "main"
      "act"
      "input";
  }

  /* ---------- 2. 顶栏 ---------- */
  .app__head {
    padding: 0 10px;
    padding-top: env(safe-area-inset-top);
    gap: 8px;
  }

  .head__menu {
    display: grid;
    width: 40px;
    height: 38px;
  }

  /* 品牌名让位给"我在哪"。手机上"问道长生"这四个字没有信息量，
     玩家要的是地名和坐标 */
  .brand {
    display: none;
  }

  .head__mid {
    display: flex;
    flex: 1;
    min-width: 0;
    margin-left: 0;
    gap: 5px;
    font-size: 11px;
  }

  .head__loc {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }

  .head__xy {
    flex: none;
    font-size: 11px;
  }

  /* 时辰、分隔符、"已接后端"在手机上都是可以省的 */
  .head__sep,
  .head__time,
  .head__mode {
    display: none;
  }

  .head__right {
    margin-left: 0;
    gap: 4px;
    flex: none;
  }

  /* 七个入口挤在 390 宽里，每个都只剩一个字。
     只留「交手」——它是唯一"现在就要按"的，
     其余六个搬进抽屉 */
  .app__head .head__right .btn-ghost {
    display: none;
  }

  .app__head .head__right .head__fight {
    display: block;
    padding: 9px 12px;
    min-height: 36px;
    font-size: 12px;
  }

  .head__who:not([hidden]) {
    display: flex;
  }

  /* ---------- 3. 左栏改抽屉 ---------- */
  .app__side {
    display: flex; /* 覆盖 layout.css 的 display:none */
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(84vw, 320px);
    z-index: 140;
    padding: calc(14px + env(safe-area-inset-top)) 14px
      calc(112px + env(safe-area-inset-bottom));
    background: var(--ink-1);
    border-right: 1px solid var(--line-bright);
    box-shadow: 14px 0 40px rgba(0, 0, 0, 0.62);
    transform: translateX(-102%);
    transition: transform 0.26s var(--ease-out);
    overscroll-behavior: contain;
  }

  .app.is-drawer .app__side {
    transform: none;
  }

  /* 抽屉底部那排入口。六个挤一行会横着溢出——「纪年」被切掉半个字，
     看着像坏了。三列两行，一眼看全。 */
  .side-nav {
    position: fixed;
    left: 0;
    bottom: 0;
    width: min(84vw, 320px);
    z-index: 141;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: var(--ink-2);
    border-top: 1px solid var(--line-soft);
    border-right: 1px solid var(--line-bright);
    transform: translateX(-102%);
    transition: transform 0.26s var(--ease-out);
    overscroll-behavior: contain;
  }

  .app.is-drawer .side-nav {
    transform: none;
  }

  .side-nav button {
    padding: 0 6px;
    min-height: 40px;
    font-size: 12.5px;
    letter-spacing: 0.06em;
    color: var(--t-1);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--ink-3);
    white-space: nowrap;
  }

  .side-nav button:active {
    color: var(--qing);
    border-color: var(--qing-dim);
  }

  /* 遮罩要压在抽屉下面、面板上面。放在 .app 里面是因为
     .app 自带 z-index:1 的层叠上下文——放外面会盖住抽屉本身 */
  .drawer-mask {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 139;
    background: rgba(4, 5, 7, 0.55);
  }

  .app.is-drawer .drawer-mask {
    display: block;
    animation: drawer-fade 0.2s var(--ease) both;
  }

  @keyframes drawer-fade {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }

  /* ---------- 4. 正文 ---------- */
  .terminal {
    padding: 12px 14px calc(24px + env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }

  /* ---------- 4.1 状态条 ----------
     一行说三件事：境界、离下一层多远、还能挨几下。
     以前这三样全在抽屉里——打架前想知道自己还剩多少血，得先拉开抽屉、
     再关掉，回来敌人都已经出完手了。 */
  .vitals {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: none;
    padding: 7px 14px 6px;
    border-bottom: 1px solid var(--line-soft);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.018), transparent);
    font-size: 11.5px;
    line-height: 1;
    white-space: nowrap;
  }

  .vitals__realm {
    flex: none;
    color: var(--t-0);
    letter-spacing: 0.04em;
  }

  /* 修为条：只画"离突破还差多少"。数字在旁边，条只是给眼睛的 */
  .vitals__bar {
    flex: 1 1 auto;
    min-width: 34px;
    height: 3px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.07);
    overflow: hidden;
  }

  .vitals__bar i {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 2px;
    background: var(--qing);
    opacity: 0.75;
    transition: width 0.32s var(--ease-out);
  }

  .vitals__exp {
    flex: none;
    font-family: var(--mono);
    font-size: 10.5px;
    color: var(--t-2);
  }

  /* 修为攒满了就把条点亮——"可以渡劫了"这件事该在正文上看得见，
     而不是要玩家自己去道籍里算 */
  .vitals.is-full .vitals__bar i {
    background: var(--jin);
    opacity: 1;
    box-shadow: 0 0 8px rgba(217, 164, 65, 0.5);
  }

  .vitals.is-full .vitals__exp {
    color: var(--jin);
  }

  .vitals__hp {
    flex: none;
    display: flex;
    align-items: baseline;
    gap: 3px;
    font-family: var(--mono);
    font-size: 10.5px;
    color: var(--t-2);
  }

  .vitals__hp em {
    font-style: normal;
    font-family: var(--sans);
    font-size: 10px;
    color: var(--t-3);
  }

  .vitals__hp b {
    font-weight: 500;
    color: var(--t-1);
  }

  /* 三成血以下标红。这不是装饰——再打一场就要掉修为了 */
  .vitals.is-low .vitals__hp b,
  .vitals.is-low .vitals__hp em {
    color: var(--zhu);
  }

  /* ---------- 5. 动作条 ----------
     方向键改成十字，不再是一排四个箭头。
     一排四键的时候，拇指要先看清左右再横着挪——十字不用想。 */
  .actionbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    height: auto;
    min-height: 0;
  }

  .ab-dpad {
    display: grid;
    grid-template-columns: repeat(3, 40px);
    grid-template-rows: repeat(2, 40px);
    gap: 3px;
    flex: none;
  }

  .ab-key {
    width: 40px;
    height: 40px;
    font-size: 15px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .ab-key[data-move="0,-1"] {
    grid-area: 1 / 2;
  }
  .ab-key[data-move="-1,0"] {
    grid-area: 2 / 1;
  }
  .ab-key[data-move="0,1"] {
    grid-area: 2 / 2;
  }
  .ab-key[data-move="1,0"] {
    grid-area: 2 / 3;
  }

  .ab-sep {
    display: none;
  }

  /* 六个日常动作排成两行三列，一眼看全，不用横向滑 */
  .ab-acts {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-auto-rows: 38px;
    gap: 3px;
    overflow: visible;
  }

  .ab-act {
    padding: 0 4px;
    font-size: 12px;
    letter-spacing: 0.02em;
    border-color: var(--line);
    background: var(--ink-2);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .ab-act:active {
    color: var(--qing);
    border-color: var(--qing-dim);
  }

  .ab-right {
    margin-left: 0;
    gap: 0;
  }

  .ab-tianji {
    padding: 5px;
    border-radius: 50%;
  }

  .ab-tianji span {
    display: none;
  }

  /* ---------- 6. 输入行 ---------- */
  .app__input {
    padding: 0 14px;
    padding-bottom: env(safe-area-inset-bottom);
    gap: 8px;
  }

  /* 16px 是 iOS 的底线。15px 都会让整页在聚焦时放大一次 */
  #cmd {
    font-size: 16px;
  }

  .input-hint {
    display: none;
  }

  /* ---------- 7. 面板全屏 ----------
     390 宽的屏上，一个 86vh 的浮层四周还压着 40px 暗边，
     真正能用的地方不到 300 宽——背包九个格子就已经挤了 */
  .overlay {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
  }

  .overlay > * {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    margin: 0;
    border: 0;
    border-radius: 0;
    padding-top: calc(14px + env(safe-area-inset-top));
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  /* 全图：整块撑满，让地图占上半屏、地点清单吃满剩下的地方。
     以前这里是 justify-content: center —— 内容比屏幕短的时候居中，
     顶上就空出两百像素；比屏幕长的时候，滚到顶也看不见第一行 */
  .bigmap {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding-left: 12px;
    padding-right: 12px;
  }

  /* 全屏之后就没有"点外面关闭"这回事了，得给一个明摆着的出口。
     :has() 让它只在真有面板开着的时候出现——不用为它加一个状态位 */
  body:has(.overlay:not([hidden])) .overlay-x {
    display: grid;
    position: fixed;
    right: 12px;
    top: calc(10px + env(safe-area-inset-top));
    z-index: 200;
    width: 40px;
    height: 40px;
    place-items: center;
    font-size: 20px;
    line-height: 1;
    color: var(--t-1);
    background: rgba(12, 14, 17, 0.86);
    border: 1px solid var(--line-bright);
    border-radius: 50%;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
  }

  .overlay-x:active {
    color: var(--qing);
    border-color: var(--qing-dim);
  }

  /* 右上角那个 × 会压住标题行——战斗的"第一回合"、行囊的"9 / 24 格"
     都被盖掉过半。给每个面板的头部让出 46px */
  .battle__head,
  .bag__head,
  .questp__head,
  .panel__head,
  .shop__head,
  .craft__head,
  .trib__head,
  .bigmap__head,
  .auth__head {
    padding-right: 46px;
  }

  /* 手机上写"ESC 关闭"是骗人的——没有 ESC 键。
     右上角那个 × 才是出口，文字还留着会正好被它压住 */
  .questp__esc,
  .bag__esc,
  .bigmap__esc,
  .panel__foot span:last-child {
    display: none;
  }

  /* ---------- 8. 手感 ---------- */
  /* 连点两下不要放大页面。viewport 里已经禁了，
     但部分安卓浏览器只认这一条 */
  button,
  .ab-key,
  .mtile,
  .btile,
  .guide__go {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  /* 长按不要弹"拷贝/查词" */
  .ab-key,
  .ab-act,
  .mtile,
  .btile,
  .guide__go,
  .side-nav button {
    -webkit-touch-callout: none;
    user-select: none;
  }
}

/* 矮屏（横过来的手机、小屏安卓）：把动作条压扁一点，
   不然正文只剩三百来像素 */
@media (max-width: 820px) and (max-height: 640px) {
  .ab-dpad {
    grid-template-columns: repeat(3, 36px);
    grid-template-rows: repeat(2, 36px);
  }
  .ab-key {
    width: 36px;
    height: 36px;
    font-size: 13px;
  }
  .ab-acts {
    grid-auto-rows: 36px;
  }
  .ab-act {
    min-height: 36px;
  }
  .terminal {
    padding-top: 8px;
  }
}

/* ============================================================
   补丁：真机尺寸下量出来的问题
   ------------------------------------------------------------
   下面每一条都是 390×844 上量出来的数，不是"看着差不多"。
   ============================================================ */

@media (max-width: 820px) {
  /* ---------- 1. 开场页 ----------
     原来 .view--intro 是 justify-content:center。内容比屏幕高时，
     居中会把顶部顶到可视区外，而 overflow 只能往下滚——标题和
     「入 道」一起滚不回来，新号第一眼看到的是一屏出身卡，
     最要紧的那个按钮在屏幕外 100px。

     现在：标题固定在顶上，十二张卡自己滚，按钮和账号入口钉在下面。 */
  .view--intro {
    height: 100dvh;
    padding: calc(14px + env(safe-area-inset-top)) 14px
      calc(12px + env(safe-area-inset-bottom));
    justify-content: flex-start;
  }

  .intro__title {
    font-size: 30px;
    letter-spacing: 0.36em;
    text-indent: 0.36em;
    margin-bottom: 10px;
  }

  .intro__sub {
    font-size: 11px;
    letter-spacing: 0.5em;
    text-indent: 0.5em;
  }

  .intro__rule {
    width: 84px;
    margin: 14px 0 16px;
  }

  .intro__prompt {
    font-size: 11px;
    margin-bottom: 10px;
  }

  .origins {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    align-content: start;
    gap: 8px;
    margin-bottom: 12px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .origin {
    padding: 10px 11px;
  }

  .origin__name {
    font-size: 13.5px;
    margin-bottom: 4px;
  }

  .origin__traits {
    font-size: 10.5px;
    margin-bottom: 4px;
  }

  .origin__hint {
    font-size: 10px;
    line-height: 1.45;
  }

  .intro__start {
    width: 100%;
    min-height: 48px;
  }

  .intro__auth {
    margin-top: 10px;
    font-size: 12px;
  }

  .intro__auth button {
    padding: 10px 6px;
    font-size: 12px;
  }

  /* ---------- 2. 动作条：按钮真的要有 44 ----------
     .ab-acts 原来沿用 actionbar.css 的 align-items:center。网格行
     是 38px，按钮却被居中压成内容高度 22px——手指点的是 22px 高
     的一条缝。手机上按十次中六次，那不叫手感差，那叫不能用。 */
  .ab-dpad {
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(2, 44px);
  }

  .ab-key {
    width: 44px;
    height: 44px;
    font-size: 16px;
  }

  .ab-acts {
    align-items: stretch;
    grid-auto-rows: 44px;
  }

  .ab-act {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
  }

  /* ---------- 3. 顶栏账号：别把邮箱截成一串乱码 ----------
     「wjmvrglnn…」既认不出是谁，又占掉顶栏三分之一。
     已经登录的只留一个亮着的点；还没登录的必须写着"登录"——
     那两个字本身才是入口，藏起来就没人点了。 */
  .head__who:not([hidden]) {
    max-width: none;
    padding: 0 9px;
    min-height: 34px;
  }

  .head__who b {
    display: none;
  }

  /* 游客：说清楚这里能干什么 */
  .head__who:not(.is-account) b {
    display: block;
    font-size: 12px;
  }

  .head__who.is-account {
    width: 34px;
    height: 34px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
  }

  /* ---------- 4. 账号面板 ----------
     13px 的输入框，iOS 一聚焦就把整页放大一次；表单顶对齐还会在
     下面留半屏黑，看着像没加载完。 */
  .auth {
    display: flex;
    flex-direction: column;
    /* safe：内容比屏幕高时退回顶对齐。普通 center 会把顶部顶出可视区，
       而 overflow 只能往下滚——那个输入框就永远够不着了 */
    justify-content: safe center;
    padding-left: 22px;
    padding-right: 22px;
  }

  .auth__field input,
  .auth__field select {
    font-size: 16px;
    min-height: 44px;
  }

  .auth__go {
    min-height: 48px;
    font-size: 14px;
  }

  /* 全屏面板右上角已经有 #overlay-x，面板里再来一个就是两个叉 */
  .auth__x {
    display: none;
  }

  /* ---------- 5. 小按钮 ----------
     杂货铺的「买」「×5」是 34×26，任务卡的「接」是 30 高。 */
  .good__btn {
    min-width: 46px;
    min-height: 38px;
  }

  .qcard__btn {
    min-height: 38px;
    padding: 8px 16px;
  }

  .side-nav button {
    min-height: 40px;
  }

  .bag__use {
    min-height: 40px;
  }

  /* ---------- 6. 丹房 / 铸坊的方子行 ----------
     桌面上是「名字 | 说明+材料 | 起炉」三列。390 宽塞不下，
     材料那行被挤成两截（「灵力 40　6 回合　朱砂」/「2/1」），
     读起来像一串没标点的数。改成上二下二：
       凝气丹                    起炉
       补气血。药力薄，但稳。
       灵力 25　5 回合 */
  .recipe {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      'name why'
      'desc desc'
      'meta meta';
    align-items: start;
    gap: 4px 12px;
    padding: 12px 14px;
  }

  .recipe__name {
    font-size: 14px;
  }

  .recipe__desc {
    line-height: 1.55;
  }

  .recipe__meta {
    line-height: 1.7;
  }

  /* 手机上永远没有 hover。把"起炉"做成一个看得见的边，
     而不是一行浅色小字——不然整张卡看着就是一段说明文字 */
  .recipe__go {
    align-self: center;
    padding: 6px 10px;
    color: var(--qing);
    border: 1px solid var(--qing-dim);
    border-radius: var(--r-sm);
  }

  .recipe__why {
    align-self: center;
    max-width: 96px;
    white-space: normal;
    text-align: right;
    line-height: 1.4;
  }

  /* ---------- 7. 渡劫的"起劫"前那一屏 ----------
     .trib__body 是 flex:1，全屏之后它把剩下的高度全吃掉，
     规则和「起 劫」之间空出四百多像素，看着像按钮丢了。 */
  .trib--gate {
    justify-content: safe center;
  }

  .trib--gate .trib__body {
    flex: 0 1 auto;
  }
}
