/* 基础样式。所有框、按钮、圆都用同一种手绘画法：
   元素本身不画底色，由 ::before 画一块「底色 + 粗描边」，再套 #sk 滤镜让边缘轻微抖动，
   像马克笔画在纸上。都是平的，不画影子和厚度。各组件只改 --sk-fill / --sk-line / --sk-lw / --sk-r 这几个变量。 */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-m);
  font-weight: 700;
  /* 字体文件只有 400 一档，粗体全靠浏览器自己模拟；有些内核（老 WebView、部分国产浏览器）不模拟，
     字就会看起来是细的。补一层描边保证不管有没有模拟都够粗。 */
  -webkit-text-stroke: 0.3px currentColor;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px dashed var(--line);
  outline-offset: 4px;
}

/* 滚动条：细圆条，颜色跟着所在的底色走（深色页面上是纸板色，浅色弹窗里是深棕），轨道是一道淡淡的槽 */
:root {
  --sb-thumb: var(--piece-mid);
  --sb-thumb-active: var(--piece-top);
  --sb-track: rgba(233, 223, 201, 0.08);
}
.panel,
.shelf,
.card {
  --sb-thumb: var(--ink-dim);
  --sb-thumb-active: var(--ink);
  --sb-track: rgba(29, 24, 20, 0.1);
}
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  margin: 6px;
  border-radius: var(--radius-pill);
  background: var(--sb-track);
}
::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: var(--radius-pill);
  background: var(--sb-thumb) padding-box;
}
::-webkit-scrollbar-thumb:active {
  background-color: var(--sb-thumb-active);
}
::-webkit-scrollbar-corner {
  background: transparent;
}
/* 不认 ::-webkit-scrollbar 的浏览器（火狐）用标准写法；认的浏览器不写这两条，否则会盖掉上面的圆条样式 */
@supports not selector(::-webkit-scrollbar) {
  * {
    scrollbar-width: thin;
    scrollbar-color: var(--sb-thumb) var(--sb-track);
  }
}

.sk-defs {
  position: absolute;
  width: 0;
  height: 0;
}

#app {
  position: relative;
  width: 100%;
  max-width: var(--stage-max);
  height: 100%;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
}

.page {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  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));
}

.icon {
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- 手绘框 ---------- */

.btn,
.round,
.badge,
.sign,
.panel,
.toast,
.slot,
.shelf,
.pill,
.detail__icon,
.lang,
.board-box,
.tray,
.hud__bar,
.card,
.chip,
.node-label,
.cost,
.field {
  position: relative;
  isolation: isolate;
  background: none;
  border: 0;
}
.btn::before,
.round::before,
.badge::before,
.sign::before,
.panel::before,
.toast::before,
.slot::before,
.shelf::before,
.pill::before,
.detail__icon::before,
.lang::before,
.board-box::before,
.tray::before,
.hud__bar::before,
.card::before,
.chip::before,
.node-label::before,
.cost::before,
.field::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: -1;
  background: var(--sk-fill, transparent);
  border: var(--sk-lw, var(--border)) solid var(--sk-line, var(--ink));
  border-radius: var(--sk-r, var(--radius));
  filter: url(#sk);
}

/* ---------- 按钮：平的，粗描边 + 底色，没有厚度 ---------- */

.btn {
  --sk-fill: var(--round);
  --sk-lw: 3px;
  --sk-r: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--touch);
  padding: var(--sp-2) var(--sp-4);
  color: var(--ink);
  font-size: var(--fs-m);
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  cursor: pointer;
}
.btn:active {
  --sk-fill: var(--press);
}
.btn--dark {
  --sk-fill: var(--sign);
  color: var(--text);
}
.btn--dark:active {
  --sk-fill: var(--ink-dim);
}
/* 主操作：强调色 */
.btn--go {
  --sk-fill: var(--go);
}
.btn--go:active {
  --sk-fill: #c8931f;
}
/* 深色底上的次要按钮：只有描边 */
.btn--ghost {
  --sk-fill: transparent;
  --sk-line: var(--line);
  color: var(--text);
}
.btn--ghost:active {
  --sk-fill: var(--ink-dim);
}
/* 条件不够时仍然占位，只是变浅；点了会说原因 */
.btn.is-off {
  opacity: 0.45;
}

.round {
  --sk-fill: var(--round);
  --sk-lw: 3px;
  --sk-r: 50%;
  flex: none;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 11px;
  color: var(--ink);
  cursor: pointer;
}
.round:active {
  --sk-fill: var(--press);
}
.round--dark {
  --sk-fill: var(--sign);
  --sk-line: var(--line);
  color: var(--text);
}
.round--dark:active {
  --sk-fill: var(--ink-dim);
}
.round.is-empty {
  --sk-fill: var(--piece-mid);
}

.badge {
  --sk-fill: var(--count);
  --sk-lw: 2px;
  --sk-r: var(--radius-pill);
  position: absolute;
  top: -9px;
  right: -11px;
  min-width: 28px;
  height: 26px;
  padding: 0 6px;
  color: var(--ink);
  font-size: var(--fs-xs);
  line-height: 26px;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
}
.badge--taint {
  --sk-fill: var(--taint);
  color: #fff;
}

/* ---------- 弹窗：全项目只有这一种 ---------- */

.panel-veil {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: var(--z-panel);
  display: grid;
  place-items: center;
  padding: calc(env(safe-area-inset-top) + var(--sp-4)) var(--sp-4) calc(env(safe-area-inset-bottom) + var(--sp-4));
  background: rgba(10, 8, 6, 0.72);
}

.panel {
  --sk-fill: var(--panel);
  --sk-lw: 4px;
  --sk-r: 20px;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: calc(var(--stage-max) - 32px);
  max-height: 86vh;
  max-height: min(86dvh, 720px);
  color: var(--ink);
}

/* 大弹窗：宽度撑满画面，高度固定占满大半屏；里面哪一块滚动由内容自己决定 */
.panel--large {
  height: 86vh;
  height: min(86dvh, 720px);
  max-width: var(--stage-max);
}
.panel--large .panel__body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel__head {
  flex: none;
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-4) var(--sp-2) var(--sp-5);
}

.panel__title {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding-top: 6px;
  font-size: var(--fs-l);
  line-height: 1.3;
}

.panel__close {
  --sk-fill: transparent;
  --sk-line: transparent;
  width: 40px;
  height: 40px;
  padding: 10px;
}

.panel__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-2) var(--sp-5) var(--sp-4);
}
.panel__body p {
  margin: 0 0 var(--sp-3);
}
.panel__body p:last-child {
  margin-bottom: 0;
}

.panel__actions {
  flex: none;
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5) var(--sp-5);
  border-top: 2px dashed var(--ink-dim);
}
.panel__actions[hidden] {
  display: none;
}
.panel__actions .btn {
  flex: 1 1 0;
  min-width: 0;
}

/* 矮屏：弹窗收紧留白、按钮矮一点，内容仍然一次放下 */
@media (max-height: 700px) {
  .panel-veil {
    padding-top: calc(env(safe-area-inset-top) + var(--sp-2));
    padding-bottom: calc(env(safe-area-inset-bottom) + var(--sp-2));
  }
  .panel {
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
  }
  .panel__head {
    padding: var(--sp-2) var(--sp-3) 0 var(--sp-4);
  }
  .panel__body {
    padding: var(--sp-1) var(--sp-4) var(--sp-3);
  }
  .panel__actions {
    padding: var(--sp-2) var(--sp-4) var(--sp-3);
  }
  .panel .btn {
    min-height: 40px;
    padding-top: var(--sp-1);
    padding-bottom: var(--sp-1);
  }
  .panel .section {
    margin: var(--sp-2) 0 var(--sp-1);
  }
  .panel .card {
    gap: var(--sp-1);
    padding: var(--sp-2) var(--sp-3);
  }
}

/* 更矮的屏（320×568 这类）：再收一档 */
@media (max-height: 600px) {
  .panel .btn {
    min-height: 36px;
  }
  .panel .section {
    margin: var(--sp-1) 0 2px;
  }
  .panel .card {
    padding: 6px var(--sp-3);
  }
}

/* 横屏手机：画面用满整个宽度，弹窗变宽，里面的内容左右排开 */
@media (orientation: landscape) and (max-height: 540px) {
  #app {
    max-width: 960px;
  }
  .panel {
    max-width: 720px;
    max-width: min(720px, 100%);
  }
}

/* ---------- 提示条 ---------- */

/* 提示在画面最下面（关卡页是收工按钮的位置），不挡棋盘、背包和能量条；提示不接收点击 */
.toast-layer {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + var(--sp-3));
  z-index: var(--z-toast);
  width: calc(100% - 32px);
  max-width: calc(var(--stage-max) - 32px);
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.toast {
  --sk-fill: var(--round);
  --sk-lw: 3px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 100%;
  padding: var(--sp-2) var(--sp-4);
  color: var(--ink);
  text-align: center;
}
.toast__sub {
  font-size: var(--fs-s);
  font-weight: 400;
  color: var(--ink-dim);
}
.toast.is-leaving {
  opacity: 0;
  transition: opacity 160ms;
}

@media (orientation: landscape) and (max-height: 540px) {
  /* 横屏：提示放进右半边、收工按钮上面的空白，不压左边的棋盘和家 */
  .toast-layer {
    left: 75%;
    width: calc(50% - 32px);
    bottom: calc(env(safe-area-inset-bottom) + 80px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
