/* 主页：顶部状态条和图标、画出来的家、家里的东西；S 形地图和商店是盖上来的整块视图。 */

/* 左上角状态坑、右上角图鉴/设置：浮在家的图上面（图铺满整个上半部分垫底），
   不再单独占一行背景。定位相对 .home__scene-box（见下）。 */
.home__hud {
  position: absolute;
  top: var(--sp-3);
  left: var(--sp-3);
  z-index: 2;
  /* 留出右上角图鉴/设置两个圆钮（各 48px + 间距）的宽度，避免窄屏时两边贴在一起 */
  max-width: calc(100% - 136px);
  padding: var(--sp-2) var(--sp-3);
}
.home__hud .hud__label {
  color: var(--ink);
}

.home__icons {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
  z-index: 2;
  display: flex;
  gap: var(--sp-2);
}

/* 主页上下分：上面家的场景占 3 份，下面家里的东西占 2 份，不随内容多少变化 */
.home__main {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.home__scene-box {
  position: relative;
  flex: 3 1 0;
  min-height: 0;
  display: flex;
}

/* ---------- 家的场景 ---------- */
/* 铺满整个上半部分；--k 是设备那一块相对 390 的缩放（最小 0.8），名字牌和按钮跟着缩放 */
.scene {
  --k: 1;
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  border-radius: 18px;
  overflow: hidden;
}

.scene__art {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.scene__hit {
  cursor: pointer;
}

.chip {
  --sk-fill: var(--round);
  --sk-lw: 2px;
  --sk-r: 10px;
  position: absolute;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  width: max-content;
  /* 相邻两台设备在图里相距 80 个单位，名字牌最宽 78 个单位（--u 是图的缩放），永远碰不到；放不下的字由文字适配缩小 */
  max-width: calc(78px * var(--u, 1));
  padding: calc(2px * var(--k)) calc(5px * var(--k));
  color: var(--ink);
  font-size: calc(var(--fs-xs) * var(--k));
  line-height: 1.25;
  text-align: center;
  cursor: pointer;
}
.chip:active {
  --sk-fill: var(--press);
}
.chip.is-alert {
  --sk-line: var(--taint);
  --sk-lw: 3px;
  color: var(--taint);
}

.scene__skin {
  position: absolute;
  width: calc(38px * var(--k));
  height: calc(38px * var(--k));
  padding: calc(7px * var(--k));
  transform: translate(-50%, -50%);
}

/* 位置由脚本给（名字牌下面），这里只负责以那个点为中心 */
.scene__enter {
  position: absolute;
  transform: translate(-50%, -50%);
  --sk-lw: 4px;
  min-width: calc(11rem * var(--k));
  min-height: calc(56px * var(--k));
  font-size: calc(var(--fs-l) * var(--k));
}

/* ---------- 烟 ---------- */
.scene__puff {
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
  animation: puff 3.2s linear infinite;
}
.scene__puff--1 {
  animation-delay: 0.8s;
}
.scene__puff--2 {
  animation-delay: 1.6s;
}
.scene__puff--3 {
  animation-delay: 2.4s;
}
@keyframes puff {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(0.7);
  }
  12% {
    opacity: 0.7;
  }
  100% {
    opacity: 0;
    transform: translate(14px, -58px) scale(2.2);
  }
}

/* ---------- 下半：家里的东西，固定占主页下面 2 份，一排 6 个，多了内部滚动 ---------- */
.stash {
  flex: 2 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.stash__head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.stash__title {
  font-size: var(--fs-m);
  padding: 2px var(--sp-4);
}

.stash__sell {
  min-height: 40px;
  font-size: var(--fs-s);
}

.stash__alert {
  flex: none;
  margin: 0;
  color: #e5836f;
  font-size: var(--fs-s);
}

/* 格子大小固定，一排放几个看宽度；放不下时这一块自己上下滚，不带着整页动 */
.stash__list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.stash__list .item__name {
  color: var(--text);
}
.stash__list .slot {
  --sk-fill: var(--tray);
}
.stash__empty {
  color: var(--text-dim);
}

/* ---------- 盖上来的视图：地图、商店 ---------- */
.sheet {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: var(--z-sheet);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  background: var(--bg);
}
.sheet[hidden] {
  display: none;
}

/* 商店整屏：盖住整页，自己留出安全区 */
.sheet--shop {
  padding: calc(env(safe-area-inset-top) + var(--sp-3)) calc(env(safe-area-inset-right) + var(--sp-3))
    calc(env(safe-area-inset-bottom) + var(--sp-3)) calc(env(safe-area-inset-left) + var(--sp-3));
}

.sheet__head {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.sheet__title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: var(--fs-l);
}

.sheet__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: var(--sp-4);
}
/* 滚动条放进屏幕边距里，卡片左右边缘和头部对齐，整块居中 */
.sheet--shop .sheet__body {
  margin-right: -10px;
  scrollbar-gutter: stable;
}

/* 现有废料单独一整行，左对齐；数字很多时在这一行里换行，不裁、不挤标题 */
.sheet__wallet {
  flex: none;
  display: flex;
}
.sheet__wallet .cost--have {
  color: var(--text);
}

.shop__list[hidden] {
  display: none;
}
/* 每页里所有卡片一样大（取最高的那张），不随内容多少、数字长短变化 */
.shop__list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: 1fr;
  gap: var(--sp-2);
}

.shop-card {
  gap: 6px;
  padding: var(--sp-2) var(--sp-3);
}
.shop-card > .btn {
  margin-top: auto;
  min-height: 40px;
  padding: var(--sp-1) var(--sp-2);
}
.shop-card .costs {
  gap: 4px;
}
.shop-card .cost {
  padding: 1px 7px;
  font-size: var(--fs-xs);
}
.shop-card .cost__icon {
  width: 18px;
  height: 18px;
}
.shop-card__main {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.shop-card__icon {
  --sk-fill: var(--piece-top);
  width: 34px;
  height: 34px;
  padding: 8px;
  cursor: default;
}
.shop-card__name {
  min-width: 0;
  font-size: var(--fs-s);
  font-weight: 700;
  line-height: 1.3;
}
.shop-card__desc {
  margin: 0;
  color: var(--ink-dim);
  font-size: var(--fs-xs);
  font-weight: 400;
  line-height: 1.35;
}

/* ---------- S 形地图：全项目唯一允许滚动的页面 ---------- */
.sheet--route {
  padding: 0;
}
.route-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-top: var(--sp-4);
  display: flex;
  flex-direction: column;
}

.route__back,
.route__shop {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + var(--sp-3));
  --sk-lw: 5px;
  z-index: 1;
}
.route__back {
  left: calc(env(safe-area-inset-left) + var(--sp-3));
}
.route__shop {
  right: calc(env(safe-area-inset-right) + var(--sp-3));
}

/* 路从下往上走：地图比屏幕矮时贴在最底下，上面留空 */
.route {
  position: relative;
  flex: none;
  width: 100%;
  margin-top: auto;
}

/* 地图的高度由这张图按 viewBox 比例撑出来（不用 aspect-ratio，老内核也认） */
.route__art {
  display: block;
  width: 100%;
  height: auto;
}

.road path {
  fill: none;
  stroke-linecap: round;
}
.road__edge {
  stroke: var(--ink);
  stroke-width: 34;
}
.road__bed {
  stroke: var(--ground);
  stroke-width: 26;
}
.road__dash {
  stroke: var(--haze);
  stroke-width: 4;
  stroke-dasharray: 3 16;
}
.road.is-locked .road__bed {
  stroke: var(--ruin);
}
.road.is-locked .road__dash {
  stroke: var(--ink-dim);
}

.route__node {
  position: absolute;
  z-index: 1;
  width: 68px;
  height: 68px;
  padding: 15px;
  --sk-lw: 4px;
  transform: translate(-50%, -50%);
}
.route__icon {
  display: block;
  width: 100%;
  height: 100%;
}
.route__node[data-state='ready'],
.route__node[data-state='digging'] {
  --sk-fill: var(--go);
}
.route__node[data-state='refill'] {
  --sk-fill: var(--round);
}
.route__node[data-state='locked'] {
  --sk-fill: var(--sign);
  color: var(--text-dim);
}
.route__node.is-current::after {
  content: '';
  position: absolute;
  top: -9px;
  right: -9px;
  bottom: -9px;
  left: -9px;
  border: 3px dashed var(--go);
  border-radius: 50%;
  pointer-events: none;
}

.node-label {
  --sk-fill: var(--panel);
  --sk-lw: 3px;
  --sk-r: 12px;
  position: absolute;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-width: calc(71% - 56px);
  padding: var(--sp-2) var(--sp-3);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
/* 点在左边时牌子挂右边，点在右边时牌子挂左边 */
.node-label--right {
  left: calc(28.97% + 48px);
}
.node-label--left {
  right: calc(28.97% + 48px);
  text-align: right;
  align-items: flex-end;
}
.node-label[data-state='locked'] {
  --sk-fill: var(--tray);
}
.node-label__name {
  font-size: var(--fs-m);
  line-height: 1.3;
}
.node-label__line {
  color: var(--ink-dim);
  font-size: var(--fs-s);
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
}
.node-label[data-state='refill'] .node-label__line {
  color: var(--rust);
  font-weight: 700;
}

/* ---------- 垃圾堆详情 ---------- */
.pile {
  display: flex;
  flex-direction: column;
}
.pile__status {
  margin-top: var(--sp-4);
}
.finds {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--sp-2) var(--sp-3);
}
.find {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 0;
  text-align: center;
}
.find__slot {
  width: 100%;
  max-width: 52px;
  cursor: default;
  --icon-bg: var(--panel);
}
/* 没解锁的格子也留名字的位置（英文名常排两行），解锁前后布局不变 */
.find__name {
  min-height: calc(1.2 * var(--fs-xs));
  font-size: var(--fs-xs);
  line-height: 1.2;
}
html[lang='en'] .find__name {
  min-height: calc(2.4 * var(--fs-xs));
}
/* 稀有度角标：挂在格子左下角，和物品数量角标同一个位置 */
.find__slot .badge--rarity {
  top: auto;
  right: auto;
  bottom: -4px;
  left: -5px;
  padding: 0 4px;
  font-size: 10px;
}
.find.is-unknown .find__name {
  color: var(--ink-dim);
}

.pile__status .card__label {
  flex: none;
}
.pile__status .card__value {
  font-weight: 700;
}
.pile__status .card__value.is-short {
  color: var(--taint);
}

.pile-lock {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.pile-lock__state {
  margin: 0;
  color: var(--ink-dim);
}

/* 矮屏（320×568 这类）：垃圾堆详情收紧一档，一次放下不滚动 */
@media (max-height: 600px) {
  .find__slot {
    max-width: 44px;
  }
  .finds {
    row-gap: 4px;
  }
  .pile__status {
    margin-top: var(--sp-2);
  }
  .panel .skins {
    gap: 6px;
  }
  .panel .skins .shop-card > .btn {
    min-height: 30px;
  }
  .panel .skins .swatch {
    height: 20px;
  }
  .panel .skins .shop-card {
    gap: 4px;
    padding: var(--sp-1) var(--sp-2);
  }
}

/* ---------- 设备 ---------- */
.device {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
/* 左右两栏：左边现状 / 充氧，右边升级；按钮都落在栏底，两栏一样高 */
.device__cols {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3);
}
.device__sec {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  min-width: 0;
}
.device__sec .section {
  margin: 0;
}
.device__sec > .card {
  flex: 1 1 auto;
  padding: var(--sp-2) var(--sp-3);
}
.device__sec .card__row {
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
}
.device__sec .card__value {
  text-align: left;
}
.device__confirm {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.device__head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.device__icon {
  flex: none;
  width: 52px;
  height: 52px;
}
.device__desc {
  margin: 0;
}
.device__alert {
  margin: 0;
  color: var(--taint);
  font-weight: 700;
}
@media (max-height: 700px) {
  .device {
    gap: var(--sp-2);
  }
  .device__icon {
    width: 40px;
    height: 40px;
  }
}
@media (max-height: 600px) {
  .device,
  .device__cols {
    gap: 6px;
  }
  .device__icon {
    width: 32px;
    height: 32px;
  }
  .device__desc {
    font-size: var(--fs-s);
    line-height: 1.4;
  }
}
/* ---------- 设置 ---------- */
.settings {
  display: flex;
  flex-direction: column;
}
.settings__sec {
  display: flex;
  flex-direction: column;
}
.credit {
  flex-direction: row;
  align-items: center;
  gap: var(--sp-3);
  --sk-fill: var(--row);
}
.credit__avatar {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
}
.credit__text p {
  margin: 0;
}
.credit a {
  color: var(--rust);
}
.langs,
.cheats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
}
.cheats .btn {
  font-size: var(--fs-s);
}

/* ---------- 横屏手机：左右两栏 ---------- */
@media (orientation: landscape) and (max-height: 540px) {
  /* 主页：左边家的图，右边家里的东西 */
  .home__main {
    flex-direction: row;
  }
  .home__scene-box,
  .stash {
    flex: 1 1 0;
    min-width: 0;
  }

  /* 商店：道具一排四个，皮肤一排三个 */
  .sheet--shop .shop__list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .sheet--shop .shop__list--skins {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  /* 横屏皮肤卡片够宽：色条和名字回到同一行 */
  .shop__list--skins .shop-card__main {
    flex-direction: row;
    align-items: center;
  }
  .shop__list--skins .swatch {
    flex: none;
    width: 44px;
    height: 24px;
  }

  /* 弹窗里的几块内容左右并排 */
  .settings {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--sp-2) var(--sp-5);
    align-items: start;
  }
  .settings__sec:first-child {
    grid-column: 1 / -1;
  }
  .settings__sec .section {
    margin-top: 0;
  }
  .finds {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }
  /* 垃圾堆详情：左边可能挖到的东西，右边氧气 */
  .pile {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 11rem;
    column-gap: var(--sp-4);
    align-items: start;
  }
  .pile > :not(.pile__status) {
    grid-column: 1;
  }
  .pile__status {
    grid-column: 2;
    grid-row: 1 / span 4;
    margin-top: 0;
  }

  .sheet--shop .sheet__head .round {
    width: 40px;
    height: 40px;
    padding: 9px;
  }
  .sheet--shop .sheet__title {
    font-size: var(--fs-m);
  }
}

/* ---------- 换皮肤弹窗：现有废料 + 皮肤卡片 ---------- */
.skins {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
