/* ============================================================================
 * 菌丝 Mycelium — 界面样式
 * 地图由 Phaser 渲染，右侧面板用 HTML/CSS（排版和列表滚动都更好处理）。
 * ==========================================================================*/
:root {
  --bg:        #0b0e0b;
  --panel:     #131813;
  --panel-2:   #1a211a;
  --line:      #2a332a;
  --line-2:    #3a463a;
  --text:      #d9e2d4;
  --muted:     #7f8d7a;
  --water:     #5ec8e8;
  --nutrient:  #e8b45e;
  --spore:     #d977c0;
  --myco:      #eef4e6;
  --good:      #7ec46b;
  --bad:       #d06060;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
  font-size: 13px;
  /* 桌面：整页不滚，面板自己滚，地图永远钉在视口里。
   * 窄屏会在下面的媒体查询里放开滚动。 */
  overflow: hidden;
}
html { -webkit-text-size-adjust: 100%; }

/* ============================================================================
 * 布局
 * 桌面（宽）：两列 —— 左边地图铺满剩余空间，右边面板独立滚动。
 * 窄屏：单列，地图 sticky 在顶部，整页滚动（见文件末尾的媒体查询）。
 * 高度一律用 dvh 而不是 vh —— 手机上地址栏会吃掉几十像素，100vh 会溢出。
 * ==========================================================================*/
#app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(310px, 29vw, 400px);
  gap: 12px;
  padding: 12px;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
}

/* ---- 地图区 ---------------------------------------------------------- */
/* 尺寸完全交给网格：Phaser 用 Scale.RESIZE 跟着这个容器走，
 * 所以画布永远等于容器大小，不可能溢出屏幕。 */
#stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #060806;
}
#game { width: 100%; height: 100%; }
/* touch-action: none 是手势的前提 —— 否则单指拖会被浏览器当成滚页面、
   双指会被当成浏览器自己的缩放，游戏里的平移/捏合根本收不到。 */
#stage canvas { display: block; touch-action: none; user-select: none; }

/* 手动视野时才出现的「回到自动取景」按钮 */
#viewReset {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 6;
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 7px;
  background: rgba(14, 19, 14, .86);
  border: 1px solid var(--line-2);
  color: var(--text);
  cursor: pointer;
  backdrop-filter: blur(3px);
}
#viewReset:hover { background: #202a20; border-color: #55684f; }

#toast {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  background: rgba(10, 14, 10, .94);
  border: 1px solid var(--line-2);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 12.5px;
  opacity: 0;
  transition: opacity .18s;
  pointer-events: none;
  white-space: nowrap;
}
#toast.on { opacity: 1; }

/* ---- 右侧面板 -------------------------------------------------------- */
#panel {
  min-width: 0;
  min-height: 0;                  /* 不写这条，flex/grid 子项不肯缩，滚动条出不来 */
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;   /* 面板滚到底别把整页带着一起滚 */
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
#panel::-webkit-scrollbar { width: 8px; }
#panel::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
}
.card h2 {
  margin: 0 0 9px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .09em;
  color: var(--muted);
  text-transform: none;
}

.title-row { display: flex; align-items: baseline; justify-content: space-between; }
.title-row .name { font-size: 16px; font-weight: 500; letter-spacing: .04em; }
.title-row .clock { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- 资源 ------------------------------------------------------------ */
.res { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.res + .res { border-top: 1px solid var(--line); }
.res .dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.res .label { flex: 1 1 auto; color: var(--muted); }
.res .val { font-variant-numeric: tabular-nums; font-size: 15px; }
.res .rate { color: var(--muted); font-size: 11.5px; min-width: 74px; text-align: right; font-variant-numeric: tabular-nums; }
/* 维持费告警：水碰到缓冲线（开始降级）时闪红 ——
 * 面板上的信号必须直接指向该做的决策，而不是让玩家自己猜为什么掉级。 */
.res .rate.warn { color: var(--bad); }
/* 壤土递减汇总：水行下面的一小行说明字。
 * 它存在的唯一理由是「机制生效的可视证据」—— 玩家看到远端大片壤土在
 * 偷偷扣水，才会想到去买水脉/收窄网络，而不是以为这功能没做。 */
.topsoil { color: var(--muted); font-size: 11px; padding: 2px 0 5px 19px;
           font-variant-numeric: tabular-nums; }
.topsoil.hide { display: none; }
.topsoil b { font-weight: 400; }
.topsoil b.neg { color: var(--bad); }
.topsoil b.pos { color: var(--good, #6abf69); }
.c-water    { background: var(--water); }
.c-nutrient { background: var(--nutrient); }
.c-spore    { background: var(--spore); }

/* ---- 统计 ------------------------------------------------------------ */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 12px; }
.stats div { display: flex; justify-content: space-between; }
.stats span { color: var(--muted); }
.stats b { font-weight: 400; font-variant-numeric: tabular-nums; }

/* ---- 表单 ------------------------------------------------------------ */
.row { display: flex; align-items: center; gap: 8px; }
.row + .row { margin-top: 8px; }
select, button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 7px;
  padding: 6px 10px;
  cursor: pointer;
}
select { flex: 1 1 auto; }
button:hover:not(:disabled) { border-color: #55684f; background: #202a20; }
button:disabled { opacity: .38; cursor: default; }
button.primary { border-color: #4a6b3e; background: #1b2a16; }
button.primary:hover:not(:disabled) { background: #23361c; }
button.tiny { padding: 3px 9px; font-size: 12px; }
/* 结构模式当前项：冷青高亮，和地图上主干/汇流的配色一致 */
button.tiny.on { border-color: #4d8f88; background: #16292a; color: #9fe8dd; }
.hint { color: var(--muted); font-size: 11.5px; line-height: 1.5; margin: 7px 0 0; }

/* ---- 存档槽 ---------------------------------------------------------- */
/* 每个槽两行：标题行（槽名 + 状态）和副行（摘要 + 操作按钮）。
   用 grid 让按钮固定贴右，摘要过长时省略而不挤压按钮。 */
.slots { display: flex; flex-direction: column; gap: 6px; margin-top: 9px; }
.slots:empty { display: none; }
.slot {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 3px 8px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
}
.slot.empty { opacity: .55; border-style: dashed; }
.slot .slot-title { font-size: 12.5px; }
.slot .slot-title b { color: #9fe8dd; font-weight: 500; }
.slot .slot-sub {
  grid-column: 1;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slot .slot-btns { grid-column: 2; grid-row: 1 / span 2; display: flex; gap: 5px; }
.slot .slot-btns button { padding: 2px 7px; font-size: 11.5px; }

.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { accent-color: #6f9c5c; width: 15px; height: 15px; }

/* ---- 升级 / 基因列表 ------------------------------------------------- */
.list { display: flex; flex-direction: column; gap: 6px; }
.item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
}
.item.ok { border-color: #3f5a36; }
.item .n { font-weight: 400; }
.item .n .lv { color: var(--muted); font-size: 11.5px; margin-left: 5px; }
.item .d { color: var(--muted); font-size: 11.5px; grid-column: 1; }
.item button { grid-row: 1 / span 2; grid-column: 2; min-width: 84px; }
.item.owned { opacity: .55; }
.item.owned .buy { display: none; }

/* ---- 菌株 ------------------------------------------------------------ */
/* 装上 = 高亮边框 + 按钮变「卸下」。用颜色区分而不是换行数，
 * 免得列表高度在点来点去时跳。 */
.item.strain { align-items: start; }
.item.strain.on { border-color: #5a7d4c; background: #1b2419; }
.item.strain .strain-hint { display: block; margin-top: 3px; opacity: .85; }
.item.strain button.on { border-color: #5a7d4c; color: #cfe6bf; }

/* ---- 技能 ------------------------------------------------------------ */
.abilities { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 7px; }
.ab {
  position: relative;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 8px 10px;
  cursor: pointer;
  text-align: left;
  overflow: hidden;
  font: inherit;
  color: var(--text);
}
.ab:hover:not(:disabled) { border-color: #55684f; background: #202a20; }
.ab .nm { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ab .sl { position: absolute; top: 6px; right: 7px; font-size: 10.5px; color: var(--muted); }
.ab .ht { font-size: 11px; color: var(--muted); line-height: 1.45; margin-top: 4px; }
.ab .cdbar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--water); opacity: .6; }
.ab.ready { border-color: #5a7d4c; }
.ab.ready .nm { color: #cfe6bf; }
.ab.locked { opacity: .38; cursor: default; }
.ab:disabled { cursor: default; }

/* ---- 里程碑 ---------------------------------------------------------- */
.ms { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; }
.ms + .ms { border-top: 1px solid var(--line); }
.ms .tick { flex: 0 0 auto; width: 14px; height: 14px; margin-top: 1px; border-radius: 3px;
            border: 1px solid var(--line-2); font-size: 11px; line-height: 13px; text-align: center; color: #0b0e0b; }
.ms.done .tick { background: var(--good); border-color: var(--good); color: #101a0c; }
.ms .txt { flex: 1 1 auto; }
.ms .need { color: var(--muted); font-size: 11.5px; }
.ms.done .need { color: #6d8a63; }
.ms .rw { font-size: 11.5px; color: var(--spore); }
.ms.done { opacity: .72; }

/* ---- 转生 ------------------------------------------------------------ */
#prestigeCard { border-color: #5a3f63; background: #1a121c; }
#prestigeCard h2 { color: #a98bb0; }
.big { font-size: 15px; }
.meter { height: 5px; background: #241a26; border-radius: 3px; overflow: hidden; margin: 8px 0 4px; }
.meter > i { display: block; height: 100%; background: var(--spore); }

/* ---- 记录 ------------------------------------------------------------ */
#log { max-height: 108px; overflow-y: auto; color: var(--muted); font-size: 11.5px; line-height: 1.65; }
#log div:first-child { color: var(--text); }

.hidden { display: none !important; }

/* 自动蔓延未解锁时的灰化 */
.switch.off { opacity: .45; cursor: not-allowed; }
/* 规则行也要能在未解锁时整体变灰（它只作用于自动蔓延） */
.row.off { opacity: .45; }

/* ============================================================================
 * 窄屏 / 手机 / 竖屏平板
 * 单列 + 整页滚动。这里刻意让页面可以滚 —— 桌面那种「面板自己滚」在手机上
 * 没有滚动条提示，内容看起来就像被截断了（这就是「页面都看不全」的成因）。
 * 地图 sticky 在顶部：一边看网络一边改策略，不用来回滚。
 * ==========================================================================*/
@media (max-width: 900px) {
  html { overflow-y: auto; }
  body { height: auto; overflow: visible; }

  #app {
    display: block;              /* 单列。block 而不是 grid，sticky 才有足够的容器高度 */
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 8px;
  }

  #stage {
    position: sticky;
    top: 0;
    z-index: 5;
    height: 46vh;                /* 老浏览器兜底 */
    height: 46svh;               /* svh：地址栏收起/展开时高度不跳 */
    min-height: 200px;
    max-height: 400px;
    border-radius: 8px;
    /* 面板会从下面滚过去。用一圈页面底色的投影把交界盖住，
     * 否则圆角那两像素会透出后面的文字，看着很脏。 */
    box-shadow: 0 10px 16px -6px #050705, 0 0 0 8px var(--bg);
  }

  #panel { overflow: visible; margin-top: 10px; padding-right: 0; }

  /* 手机上收掉次要说明：内容太长反而让人什么都不想读 */
  .ab .ht { display: none; }
  #log { max-height: 130px; }
}

/* ============================================================================
 * 转生抉择（Roguelike 三选一）
 * 这是本作唯一一个**阻塞式**界面：没选完不能继续玩。
 * 所以它必须盖住地图（否则玩家会一边看着卡一边继续点格子），
 * 而且要有明确的「你必须选一个」的视觉压迫感。
 * ==========================================================================*/
#choiceOverlay {
  position: fixed;
  inset: 0;
  z-index: 50;                 /* 高于 #stage 的 sticky(5) 和 toast */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(5, 7, 5, .82);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: choiceIn .22s ease-out;
}
@keyframes choiceIn { from { opacity: 0; } to { opacity: 1; } }

.choice-box {
  width: 100%;
  max-width: 720px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 14px;
  padding: 20px 20px 22px;
  box-shadow: 0 24px 60px -12px #000, 0 0 0 1px #000 inset;
}
.choice-box h2 {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .3px;
}
.choice-box .hint { margin: 0 0 16px; font-size: 12px; }

/* 卡片：桌面三列，窄屏自动塌成一列 */
#choiceCards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.choice-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 13px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-top-width: 3px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font: inherit;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.choice-card:hover,
.choice-card:focus-visible {
  transform: translateY(-2px);
  background: #202820;
  outline: none;
}
/* 三类卡各自一个顶边色，一眼能区分方向 */
.choice-card.strain  { border-top-color: var(--good); }
.choice-card.map     { border-top-color: var(--water); }
.choice-card.genes   { border-top-color: var(--nutrient); }

.choice-card .cc-kind {
  font-size: 10.5px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--muted);
}
.choice-card.strain .cc-kind  { color: var(--good); }
.choice-card.map .cc-kind     { color: var(--water); }
.choice-card.genes .cc-kind   { color: var(--nutrient); }

.choice-card .cc-name { font-size: 14px; font-weight: 600; line-height: 1.35; }
.choice-card .cc-desc { font-size: 11.5px; line-height: 1.55; color: var(--muted); }
/* 「代价」那行要显眼 —— 三选一的核心就是看到底亏什么 */
.choice-card .cc-cost {
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--bad);
  margin-top: auto;            /* 顶到底部，几张卡对齐 */
  padding-top: 6px;
}

/* 窄屏：卡片改单列，且整体上移一点（手机上地图占着上半屏） */
@media (max-width: 900px) {
  #choiceOverlay { align-items: flex-start; padding: 14px 12px; }
  .choice-box { max-width: 100%; padding: 16px 14px 18px; }
  #choiceCards { grid-template-columns: 1fr; gap: 8px; }
  .choice-card { padding: 11px 12px 10px; }
  .choice-card .cc-cost { margin-top: 2px; }
}

/* 更窄：卡片改两列，按钮别再被挤成一条线 */
@media (max-width: 430px) {
  .abilities { grid-template-columns: 1fr 1fr; }
  .item button { min-width: 68px; }
  .stats { gap: 6px 8px; }
}

/* 手机上转横屏：地图必须让出高度，否则面板被挤到看不见 */
@media (max-width: 900px) and (max-height: 560px) {
  #stage { height: 64vh; height: 64svh; min-height: 140px; }
}

