/* 墨迹寻踪 · 一笔画 —— 洒金宣纸 / 浓墨 / 朱砂印
 *
 * 色值不是随手挑的，是按 WCAG 对比度定的（tests/theme.test.js 会复算，改色先跑它）：
 *   浓墨 #1C1B19 对纸 15.7:1（正文级）
 *   小字墨 #736E64 对卡片 4.99:1 / 对纸底 4.61:1（小字要 4.5:1 —— 中墨 #8A8579
 *     只有 3.4:1，只配给描边之类的非文字图形用）
 *   朱砂 #B7332F 5.4:1
 *   金墨 #8A6C1C 对卡片 ≈4.8:1（「提示」按钮的文字色，金色里唯一够小字对比度的深度）
 *   淡墨 #87827A 对画布中心 3.66:1、**对最外圈纸色 3.18:1**（图形级下限 3:1）。
 *     只按中心纸色挑会漏：节点撒在椭圆 0.88~1.0 处，边上一圈才是最容易不达标的地方。
 * 未走的线是谜题的核心信息，不能淡到看不见 —— 它靠「浅灰 + 细」与走过的
 * 「浓墨 + 粗 + 墨晕」拉开辨识度（两者相差 6.4:1），而不是靠淡到快消失。
 *
 * 页面分区（自上而下，窄屏单列；宽屏 ≥900px 两栏，信息整体挪到右栏）：
 *   hud（品牌 + 状态纸签）→ 画布 → 提示 → 主操作按钮 → meta（低频设置条）→ 页脚
 * 所有信息控件统一成一种「纸签」样式（.chip），低频操作统一成小字条，
 * 层级：画布 > 主按钮 > 纸签 > 设置条 > 页脚。
 */

:root {
  --paper: #f7f4ec;
  --paper-card: #fffdf8;
  --ink: #1c1b19;
  --ink-text: #736e64; /* 小字专用：对卡片 4.99:1、对纸底 4.61:1 —— 小字要 4.5:1，中墨不够 */
  --ink-mid: #8a8579; /* 只给非文字用（描边、次要图形） */
  --cinnabar: #b7332f;
  --cinnabar-soft: #d9a9a6;
  --gold-deep: #b8912f;
  --gold-ink: #8a6c1c; /* 金色文字专用（对卡片 ≈4.8:1）；金描边仍用 --gold-deep */
  --serif: 'Songti SC', 'STSong', 'KaiTi', '楷体', 'Noto Serif CJK SC', 'Source Han Serif SC', serif;
  --sans: system-ui, -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --hairline: rgba(138, 133, 121, 0.3);
  --lift: 0 14px 26px -18px rgba(60, 52, 38, 0.55);
  /* ── 设计 token ──────────────────────────────────────────────
     刻意排在全部颜色变量之后：theme.test.js 取 indexOf('--paper:') 等
     「第一次出现」再读其后第一个 hex，同名变量或插在它前面都会读错值。
     以下 token 一律不含 --chrome 字样，也不含 min-width 媒体查询。 */

  /* 间距：只收敛现有值，不新增档位（新增就意味着有元素要长高） */
  --sp-1: 0.25rem;   /* meta-actions gap */
  --sp-2: 0.45rem;   /* hint / footer-note margin-top */
  --sp-3: 0.6rem;    /* controls margin-top / button 纵向 padding */

  /* 字号：把散落各处的 clamp() 全部搬进来，数值一个都没改 */
  --fs-brand:   clamp(0.98rem, 2.5vw, 1.12rem);
  --fs-sub:     clamp(0.66rem, 1.8vw, 0.76rem);
  --fs-chip:    clamp(0.74rem, 1.9vw, 0.86rem);
  --fs-btn:     clamp(0.86rem, 2.2vw, 1rem);
  --fs-meta:    clamp(0.7rem, 1.8vw, 0.78rem);
  --fs-link:    clamp(0.68rem, 1.8vw, 0.76rem);
  --fs-overlay: clamp(0.95rem, 2.5vw, 1.12rem);
  --fs-hint:    clamp(0.85rem, 2.2vw, 1.02rem);

  /* 字距：收敛散落的 letter-spacing */
  --ls-brand: 0.18em;  /* 标题 */
  --ls-body:  0.05em;  /* 正文 */
  --ls-chip:  0.04em;  /* 纸签 */

  /* 圆角 */
  --rad-sm: 4px;      /* brand-mark / rotate-hint */
  --rad-md: 6px;      /* button / nameInput */
  --rad-lg: 10px;     /* dialog */
  --rad-pill: 999px;  /* chip */

  /* 阴影：落实文件头声明的层级「画布 > 主按钮 > 纸签 > 设置条 > 页脚」 */
  --shadow-chip:   0 1px 0 rgba(255, 255, 255, 0.8) inset;
  --shadow-btn:    0 1px 0 rgba(255, 255, 255, 0.9) inset, 0 14px 26px -18px rgba(60, 52, 38, 0.55);
  --shadow-canvas: 0 0 0 1px rgba(138, 133, 121, 0.28), 0 16px 30px -20px rgba(60, 52, 38, 0.6);
  --shadow-card:   0 1px 0 rgba(255, 255, 255, 0.95) inset, 0 22px 44px -26px rgba(60, 52, 38, 0.5);
  --shadow-seal:   0 3px 8px -3px rgba(183, 51, 47, 0.6);

  /* 动效：统一曲线与三档时长（原来是 0.16s/0.2s/0.3s 三种写法各写一遍） */
  --ease:   cubic-bezier(0.2, 0.6, 0.3, 1);
  --dur-1:  0.16s;  /* 悬停反馈 */
  --dur-2:  0.25s;  /* 状态切换 */
  --dur-3:  0.3s;   /* 画布 */

  /* 焦点环与禁用态。焦点用浓墨（对纸底 15.7:1，远超图形级 3:1）；
     禁用色刻意比小字墨 #736e64 更淡 —— 后者是 AA 可读色，用在禁用态会读成「正常但有点灰」 */
  --focus: #1c1b19;
  --focus-halo: 0 0 0 3px rgba(247, 244, 236, 0.92);
  --ink-disabled: #a8a296;
  /* 画布以外占掉的纵向高度（窄屏：HUD、提示、按钮行、设置条、页脚都在上下方。
     逐项：body padding ~19 + 容器 padding ~22 + HUD 两行 ~75 + 提示 31 + 按钮行 54
     + 设置条 43 + 页脚 48 + 边框 2 ≈ 294，留余量取 312） */
  --chrome: 312px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* 只在「会误触拖拽」的区域禁选；规则、法务、提示行仍然可以选中复制 */
.game-container {
  user-select: none;
  -webkit-user-select: none;
}

.footer-note,
.legal-note,
.hint {
  user-select: text;
  -webkit-user-select: text;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding: clamp(0.6rem, 2.4vw, 1.5rem);
  display: flex;
  flex-direction: column; /* 卡片与法务页脚纵向堆叠；只有一个子元素时照常居中 */
  justify-content: center;
  align-items: center;
  font-family: var(--sans);
  color: var(--ink);
  /* 纸底 + 洒金：几层极淡的金点，纯 CSS，不引外部图片 */
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 12% 34%, rgba(200, 162, 74, 0.32) 0 0.9px, transparent 1.7px),
    radial-gradient(circle at 73% 16%, rgba(200, 162, 74, 0.24) 0 1.1px, transparent 1.9px),
    radial-gradient(circle at 41% 78%, rgba(200, 162, 74, 0.28) 0 0.8px, transparent 1.6px),
    radial-gradient(ellipse at 20% 18%, rgba(255, 255, 255, 0.85), transparent 45%),
    radial-gradient(ellipse at 88% 92%, rgba(138, 133, 121, 0.12), transparent 50%);
  background-size: 210px 190px, 320px 260px, 170px 150px, 100% 100%, 100% 100%;
}

/* 裱好的纸卡：衬纸色外圈 + 纸面 + 一道描金细边
 *
 * 布局：窄屏单列 flex（HUD → 画布列 → 设置条 → 页脚），
 * 宽屏 ≥900px 换成两列 grid（画布列在左，HUD 与低频操作整块挪到右栏）——
 * 目的是把操作区的高度让出来，画布能吃到几乎整个视口高度。
 * 关键结构约束：左列（画布+提示+按钮）和右栏（设置+页脚）各自包成一个容器，
 * 这样画布的高度永远不会把另一栏的行撑出空洞（grid 跨行项会拉伸所跨的行）。
 * 窄屏用 order 重排，DOM 顺序不动。 */
.game-container {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1000px;
  padding: clamp(0.7rem, 2.2vw, 1.15rem) clamp(0.8rem, 2.6vw, 1.6rem) clamp(0.6rem, 2vw, 1rem);
  /* 宣纸质感 = 底层竖向渐变 + 两层交叉纤维。
     纤维用 repeating-linear-gradient 近似，透明度压到 .028/.020 —— 再高就变成屏幕上的脏点。
     纯 background-image，不参与布局，不影响 --chrome 预算。 */
  background-color: var(--paper-card);
  background-image:
    repeating-linear-gradient(94deg, rgba(120, 104, 74, 0.028) 0 1px, transparent 1px 5px),
    repeating-linear-gradient(4deg, rgba(120, 104, 74, 0.02) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, var(--paper-card), var(--paper));
  border: 1px solid var(--hairline);
  border-radius: clamp(0.7rem, 2vw, 1.1rem);
  outline: 1px solid rgba(200, 162, 74, 0.4);
  outline-offset: -5px;
  /* 第二层极淡暖色内阴影：让卡片像被压在一张纸上，而不是浮在纸面上 */
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.95) inset,
    0 1px 0 rgba(120, 104, 74, 0.05) inset,
    var(--shadow-card);
}

.hud {
  order: 1;
}

.play-col {
  order: 2;
  min-width: 0;
}

/* 窄屏时右栏容器就地解散：HUD / 设置条 / 页脚按 order 参与整列排序 */
.rail-col {
  display: contents;
}

.meta-bar {
  order: 3;
}

.footer-note {
  order: 4;
}

.boot-error {
  order: 5;
}

/* ---------- 达成者昵称弹窗 ---------- */
/* 与卡片同一套纸感。原生 <dialog> 渲染在 top layer，不参与 grid 排布，
   所以这里只需要管它自己的尺寸与质感 */

#nameDialog {
  width: min(92vw, 340px);
  padding: 1.1rem 1.2rem 0.9rem;
  background: var(--paper-card);
  border: 1px solid var(--hairline);
  border-radius: var(--rad-lg);
  box-shadow: var(--lift);
  color: var(--ink);
}

#nameDialog::backdrop {
  background: rgba(60, 52, 38, 0.35);
  backdrop-filter: blur(2px);
}

.dialog-title {
  margin: 0 0 0.35rem;
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
}

.dialog-note {
  margin: 0 0 0.7rem;
  font-size: 0.76rem;
  line-height: 1.5;
  color: var(--ink-text);
}

#nameInput {
  width: 100%;
  min-height: 38px;
  padding: 0.4rem 0.7rem;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: var(--rad-md);
  /* 全局 * 把 user-select 关掉了，输入框得单独开回来，否则选不中、粘不进 */
  user-select: text;
  -webkit-user-select: text;
}

#nameInput:focus {
  /* 原先用的 --gold-deep 对纸底只有 2.68:1，低于 WCAG 图形级 3:1 ——
     是个不合格的焦点指示。金墨留作「提示」按钮的文字色，焦点环统一用浓墨 */
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
  margin-top: 0.8rem;
}

/* 宽屏媒体查询把所有 button.btn-secondary 都拉成 width:100%（给 meta-bar 竖排用的），
   弹窗里这三个按钮要的是紧凑并排，得拉回来。
   选择器带 .dialog-actions（特异性 0,2,0），压得住媒体查询里的 button.btn-secondary（0,1,1） */
.dialog-actions .btn-secondary {
  width: auto;
  flex: 0 0 auto;
  min-height: 30px;
}

/* 账号列表：一行一个已有账号，点一下就切过去。
   上限约 4 行，再多就列表内部滚动 —— 弹窗自己不长高 */
.account-list {
  list-style: none;
  margin: 0.55rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 148px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(138, 133, 121, 0.45) transparent;
}

.account-list[hidden] {
  display: none; /* 全局 * 不影响 <ul>，但 .account-list 自己写了 display:flex，得显式收回 */
}

.account-item {
  display: flex;
}

/* 用 .account-list 后代选择器（0,2,0）：才压得过全局 button（0,0,1）
   与 button:hover:not(:disabled)（0,2,1） */
.account-list .account-pick {
  display: block;
  width: 100%;
  min-height: 32px;
  padding: 0.2rem 0.6rem;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink-text); /* 4.61:1 对纸底，小字达标 */
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: var(--rad-md);
  box-shadow: none;
  cursor: pointer;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease),
    border-color var(--dur-1) var(--ease);
}

.account-list .account-pick:hover {
  color: var(--ink);
  background: rgba(138, 133, 121, 0.12);
  border-color: rgba(138, 133, 121, 0.55);
  transform: none;
  box-shadow: none;
}

/* 当前账号：朱砂标出「你现在在这儿」 */
.account-list .account-pick.current {
  color: var(--cinnabar);
  background: rgba(183, 51, 47, 0.06);
  border-color: var(--cinnabar-soft);
}

/* 「切换 / 改名」是提交类动作，靠右；「匿名」是退出动作，独占左端。
   匿名用 order 提到最前（DOM 顺序不变，Tab 仍是 切换→改名→匿名）；
   自动外边距挂在切换按钮左侧，把两个提交类按钮推到右端 */
#nameSkipBtn {
  order: -1;
}

#nameOkBtn {
  margin-left: auto;
}

/* ---------- HUD：品牌 + 状态纸签，一条带子说完所有状态 ---------- */

.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.5rem;
}

/* display:contents 让纸签成为 .hud 的直接子项，换行时和品牌排在同一条流里 */
.hud-stats {
  display: contents;
}

/* 页眉品牌：一枚小朱印当标识 */
.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  margin-right: auto; /* 有空间时把纸签推到行尾，品牌独占左侧 */
}

.brand-mark {
  width: 1.55rem;
  height: 1.55rem;
  display: grid;
  place-items: center;
  border-radius: var(--rad-sm);
  background: var(--cinnabar);
  color: #fffcf6;
  font-family: var(--serif);
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: var(--shadow-seal);
  flex: 0 0 auto;
}

.brand-name {
  font-family: var(--serif);
  font-size: var(--fs-brand);
  letter-spacing: var(--ls-brand);
  /* 字距会在末字之后也留一份，宽屏下 .brand 居中时整块因此偏左约 0.09em。
     用等量负边距抵消尾隙，中文标题排版的常规做法，不影响任何纵向尺寸 */
  margin-right: calc(var(--ls-brand) * -1);
  color: var(--ink);
  white-space: nowrap;
}

.brand-sub {
  font-size: var(--fs-sub);
  letter-spacing: 0.06em;
  color: var(--ink-text);
  white-space: nowrap;
}

/* 纸签：所有状态信息共用的一种胶囊样式（关卡 / 难度 / 进度 / 本局分） */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  min-height: 30px;
  padding: 0.28rem 0.8rem;
  background: var(--paper-card);
  border: 1px solid var(--hairline);
  border-radius: var(--rad-pill);
  color: var(--ink-text);
  font-size: var(--fs-chip);
  font-weight: 500;
  letter-spacing: var(--ls-chip);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  box-shadow: var(--shadow-chip);
  line-height: 1; /* 纵向节奏由 min-height 托底，写死行高免得跟着继承值漂 */
  transition: color var(--dur-2), border-color var(--dur-2), background var(--dur-2);
  transition-timing-function: var(--ease);
}

.chip b {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.12em;
  color: var(--ink);
}

/* 本局分是最常盯的数字：加重一档 */
/* 颜色、字重、描边色都不参与布局 —— 30px 由 min-height 托底，所以这里是零纵向增量。
   刻意不动字号：字号变大会把纸签撑宽，窄屏 HUD 可能从两行掉到三行（+38px），那才是真的吃了高度预算 */
.chip-score {
  color: var(--ink);
  font-weight: 700; /* 600 → 700 */
  border-color: rgba(28, 27, 25, 0.32); /* hairline → 更实的墨边，从一行信息里跳出来 */
  margin-left: auto; /* 行内空间够时靠右，和左侧品牌/纸签拉开 */
}

.chip.complete {
  color: var(--cinnabar);
  border-color: var(--cinnabar-soft);
  background: #fdf6f4;
}

/* 手机横屏：纵向只有 300~400px，画布必然很小，给一句提示（不强制旋转） */
.rotate-hint {
  display: none;
  flex-basis: 100%;
  margin: 0;
  padding: 0.35rem 0.6rem;
  border-radius: var(--rad-sm);
  background: rgba(183, 51, 47, 0.08);
  color: var(--cinnabar);
  font-size: 0.75rem;
}

/* 横屏且很矮：藏掉品牌、设置条与页脚（它们最不参与操作），把纵向让给画布，并提示转竖屏 */
@media (max-height: 500px) and (orientation: landscape) {
  :root {
    --chrome: 210px;
  }

  .brand,
  .brand-sub,
  .meta-bar,
  .footer-note,
  .legal-note {
    display: none;
  }

  .rotate-hint {
    display: block;
  }
}

/* ---------- 主操作按钮：撤销 / 重来 / 提示 / 下一关 ---------- */

.controls {
  display: flex;
  justify-content: space-between;
  margin-top: var(--sp-3);
  gap: 0.55rem;
}

button {
  background: var(--paper-card);
  border: 1px solid var(--hairline);
  padding: var(--sp-3) 1.1rem;
  min-height: 44px; /* 触屏最小点击高度 */
  border-radius: var(--rad-md);
  font-weight: 600;
  font-size: var(--fs-btn);
  letter-spacing: 0.06em;
  line-height: 1; /* 纵向由 min-height 托底，行高写死免得继承漂移 */
  color: var(--ink);
  font-family: inherit;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset, var(--lift);
  cursor: pointer;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease),
    transform var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  white-space: nowrap;
}

button:hover:not(:disabled) {
  background: rgba(28, 27, 25, 0.06);
  transform: translateY(-1px);
  /* 比常态大一号：悬停时按钮「抬起」，与 --lift 的静态值刻意不同 */
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset, 0 16px 26px -18px rgba(60, 52, 38, 0.6);
}

button:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: inset 0 3px 8px rgba(60, 52, 38, 0.18);
}

button:disabled {
  /* 不用 opacity / grayscale —— 那会把文字和描边一起压成糊状，
     和「加载中」在视觉上分不开。改成「换色 + 去阴影」：结构还在，只是墨退到纸里。
     颜色刻意比小字墨更淡（对卡片 2.50:1），读作「不可用」而不是「正常但有点灰」。 */
  opacity: 1;
  filter: none;
  color: var(--ink-disabled);
  background: transparent;
  border-color: rgba(138, 133, 121, 0.22);
  box-shadow: none;
  pointer-events: none;
}

/* 提示是付费能力：描金 + 金墨字，和免费操作区分开 */
#hintBtn {
  border-color: rgba(200, 162, 74, 0.6);
  color: var(--gold-ink);
}

#hintBtn:hover:not(:disabled) {
  background: rgba(200, 162, 74, 0.08);
}

/* 主操作（下一关）：墨底纸字，一眼看出这是往前走 */
#nextBtn {
  background: var(--ink);
  color: var(--paper-card);
  border-color: rgba(200, 162, 74, 0.55);
}

#nextBtn:hover:not(:disabled) {
  background: #2c2a26;
}

#nextBtn:disabled {
  /* 墨底按钮禁用后不能还留一块墨 —— 那是「可点」的暗示 */
  background: transparent;
  color: var(--ink-disabled);
}

/* ---------- 焦点环：键盘可见、鼠标不打扰 ---------- */
/* outline 不参与布局 —— 宽屏只剩 23.9px 余量时，这是唯一安全的做法。
   浓墨 #1c1b19 对纸底 15.7:1，远超 WCAG 图形级 3:1。 */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* 墨底按钮上浓墨环几乎看不见（1.20:1），夹一层纸色光晕把两者断开。
   纸晕要排在最前面，否则会被按钮自己的 box-shadow 盖掉。 */
button:focus-visible {
  box-shadow: var(--focus-halo), 0 1px 0 rgba(255, 255, 255, 0.9) inset, var(--lift);
}

/* ---------- 设置条：低频设置与小操作，一条安静的附属条 ---------- */

.meta-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.8rem;
  margin-top: 0.55rem;
  padding-top: 0.55rem;
  border-top: 1px dashed var(--hairline); /* 虚线隔开：这里是「附属」，不是主操作 */
  font-size: var(--fs-meta);
  color: var(--ink-text);
}

#recordDisplay {
  font-variant-numeric: tabular-nums;
  margin-left: auto;
  /* 记录也是玩家会盯的信息：从小字灰提到浓墨，并加重一档。
     这一行的高度本来就由 .auto-next 的 min-height:30px 托底，改颜色与字重不加高 */
  color: var(--ink);
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* 低频操作是一条「按钮排」而不是混在文案里：
   分组感全由按钮自己的底色+描边给出，容器只加横向间距 —— 纵向一分不加 */
.meta-actions {
  display: flex;
  gap: 0.3rem;
}

/* 小号勾选框：自动下一关的开关（触屏最小点击尺寸） */
.auto-next {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 30px;
  padding: 0 0.15rem;
  cursor: pointer;
  white-space: nowrap;
}

.auto-next input {
  accent-color: var(--cinnabar);
  cursor: pointer;
  margin: 0;
}

/* 次级按钮：比主按钮轻（更小、不抬起、不带投影），比纯链接重（有底、有边、有圆角）——
   一眼「能点」，又不会跟主操作抢视线，也就不会和下方的规则文案糊成一片。
   min-height 30px 是这一行本来就有的高度（同一行的 .auto-next 就是 30px），
   所以给它加底色与描边不占任何额外的纵向预算。 */
button.btn-secondary {
  flex: 0 0 auto; /* 覆盖全局 button 的 flex:1：次级按钮按内容宽，不跟着拉伸 */
  min-height: 30px;
  padding: 0 0.7rem;
  border-radius: var(--rad-md);
  font-size: var(--fs-link);
  font-weight: 600;
  letter-spacing: var(--ls-chip);
  color: var(--ink);
  background: var(--paper-card);
  border: 1px solid var(--hairline);
  box-shadow: none;
}

/* 必须带 :not(:disabled)：全局 button:hover:not(:disabled) 的特异性同为 (0,2,1)，
   不带的话按源码顺序它会反压回来，悬停态就丢了 */
button.btn-secondary:hover:not(:disabled) {
  color: var(--ink);
  background: rgba(138, 133, 121, 0.12);
  border-color: rgba(138, 133, 121, 0.55);
  box-shadow: none;
  transform: none; /* 次级按钮不抬起：那是主按钮才有的待遇 */
}

button.btn-secondary:active:not(:disabled) {
  transform: none;
  box-shadow: inset 0 2px 5px rgba(60, 52, 38, 0.14);
}

/* 必须显式写：上面把 color 提到了 --ink，会压过全局 button:disabled 的退色 */
button.btn-secondary:disabled {
  color: var(--ink-disabled);
  background: transparent;
  border-color: rgba(138, 133, 121, 0.22);
  box-shadow: none;
}

/* 二次确认态：点「重新开局」之后按钮文字会变，但那一眼看不出是破坏性操作。
   转朱砂 + 淡朱底，让「再点一次就真重来」这件事在按下之前就摆在眼前。 */
button.btn-secondary.armed {
  color: var(--cinnabar);
  background: rgba(183, 51, 47, 0.08);
  border-color: rgba(183, 51, 47, 0.35);
}

button.btn-secondary.armed:hover:not(:disabled) {
  color: var(--cinnabar);
  background: rgba(183, 51, 47, 0.14);
  border-color: rgba(183, 51, 47, 0.5);
}

/* ---------- 画布区 ---------- */

/* 画布外框：宽度、居中都归它管，画布自己只负责铺满它 —— 覆盖按钮靠它定位。
   高度够的屏幕就铺到 1100px；矮屏（笔记本）按视口高度自动收，避免逼出滚动条。 */
.canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 1100px;
  min-width: 0; /* grid 列里的元素默认不肯收缩，会被画布撑破列宽 */
  margin: 0 auto;
}

/* 画布的纵向预算：--chrome 是「画布以外占掉的纵向高度」，宽屏两栏时大幅变小 */
@supports (height: 100dvh) {
  .canvas-wrap {
    width: min(100%, 1100px, max(260px, calc((100dvh - var(--chrome)) * 1.2121)));
  }
}

/* 画布裱边：装裱纸的「一层白边 + 一道压痕」。
   必须挂在 .canvas-wrap 的伪元素上，不能给 canvas 加 inset ——
   canvas 是 replaced element，CSS 阴影画在它自己的位图之上，内阴影会盖住边缘节点
   （而淡墨对纸面最外圈只保 3.18:1，很脆）。
   绝对定位 + pointer-events:none，不参与布局也不吃拖拽事件。 */
.canvas-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: clamp(0.5rem, 1.4vw, 0.85rem);
  box-shadow:
    inset 0 0 0 1px rgba(138, 133, 121, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    inset 0 -12px 20px -14px rgba(90, 72, 44, 0.22);
}

/* 画布：比例锁在世界坐标系上（720×594），纸面本身由 JS 画 */
canvas {
  display: block;
  width: 100%;
  aspect-ratio: 720 / 594;
  height: auto;
  border-radius: clamp(0.5rem, 1.4vw, 0.85rem);
  background: #fcfaf4;
  box-shadow: var(--shadow-canvas);
  cursor: crosshair;
  touch-action: none;
  transition: box-shadow var(--dur-3) var(--ease);
}

canvas.dragging {
  /* 拖拽时把外投影收掉、换一道内投影：画布像被按进纸里，而不是浮起来 */
  box-shadow: 0 0 0 1px rgba(28, 27, 25, 0.55),
    inset 0 2px 10px rgba(60, 52, 38, 0.1),
    0 10px 20px -20px rgba(60, 52, 38, 0.5);
}

canvas.shake {
  animation: shake 0.4s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

/* 通关后浮在画布正中央的「下一关」：让鼠标不用离开画布 */
button.next-overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  flex: 0 0 auto;
  min-height: 48px;
  padding: 0.7rem 1.7rem;
  border-radius: var(--rad-md);
  font-family: var(--serif);
  font-size: var(--fs-overlay);
  letter-spacing: 0.1em;
  color: var(--paper-card);
  background: var(--ink);
  border: 1px solid rgba(200, 162, 74, 0.75);
  box-shadow: 0 16px 30px -14px rgba(28, 27, 25, 0.75);
  animation: pop 0.25s ease-out;
}

/* 倒计时秒数：留出固定宽度，免得数字每跳一下按钮宽度就变一次 */
.next-countdown {
  display: inline-block;
  min-width: 1.4ch;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

button.next-overlay:hover:not(:disabled) {
  background: #2c2a26;
  transform: translate(-50%, -50%) scale(1.03);
}

button.next-overlay:active:not(:disabled) {
  transform: translate(-50%, -50%) scale(0.98);
}

/* 必须显式写：全局 button{display:flex} 会盖掉浏览器默认的 [hidden]{display:none} */
button.next-overlay[hidden] {
  display: none;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.85);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* ---------- 提示行与页脚 ---------- */

.hint {
  text-align: center;
  font-weight: 500;
  margin-top: var(--sp-2);
  font-size: var(--fs-hint);
  letter-spacing: var(--ls-body);
  min-height: 1.5rem;
  color: var(--ink-text);
  /* 提示里的数字频繁变化（「第 12 关」「−10」「连击 ×4」），等宽数字让整行宽度稳定，
     否则数字跳动会带着整行左右抖。只影响数字字形宽度，不改变行高 */
  font-variant-numeric: tabular-nums;
  /* 写死行高是为了确定性（normal 会随字体栈解析出的比例浮动），
     但取值必须贴着 normal 实际解析出的比例：本机 sans 栈下 normal ≈ 1.29。
     试过 1.45，两行提示在 1024×600 下会多吃 5.3px，而那种尺寸余量本来就只剩 5.9px。 */
  line-height: 1.3;
  transition: color var(--dur-2) var(--ease);
}

.hint.warn {
  color: var(--cinnabar);
}

.hint.win {
  color: var(--cinnabar);
  font-family: var(--serif);
  letter-spacing: 0.08em;
}

.footer-note {
  color: var(--ink-text);
  text-align: center;
  margin-top: 0.5rem;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  line-height: 1.85;
}

/* 规则里的数值挑出来：一眼能扫到「罚多少」 */
.footer-note b {
  font-weight: 600;
  color: var(--ink);
}

/* 法务页脚：独立在卡片之外，字号更小、更淡 —— 和上面的玩法规则彻底分开 */
.legal-note {
  margin-top: 0.7rem;
  text-align: center;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: var(--ink-text);
}

.footer-note a,
.legal-note a {
  color: var(--ink-text);
  text-decoration: none;
  border-bottom: 1px solid rgba(138, 133, 121, 0.45);
}

.footer-note a:hover,
.legal-note a:hover {
  color: var(--ink);
  border-bottom-color: var(--gold-deep);
}

.boot-error {
  color: var(--cinnabar);
  text-align: center;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

/* ---------- 宽屏：两栏。画布在左，信息与低频操作整块挪到右栏 ---------- */

@media (min-width: 900px) {
  :root {
    /* 画布上方只剩提示行、下方只剩按钮行 —— 纵向几乎全给操作区。
       172 是逐项加出来的（body padding 48 + 容器 padding 34 + 边框 2 + 提示行 31 + 按钮行 51
       ≈ 166，再留 6px 余量）：这个值估小了就会顶出滚动条，而滚动条比画布小几像素更糟 */
    --chrome: 172px;
  }

  .game-container {
    --rail: 272px;
    --gap: 18px;
    /* 容器宽度跟着画布走，画布、提示、按钮行才会落在同一条竖直线上 */
    --canvas-w: min(calc((100dvh - var(--chrome)) * 1.2121), 1100px);
    width: min(100%, calc(var(--canvas-w) + var(--rail) + var(--gap)));
    /* 必须放开窄屏那个 1000px 的宽度上限：不放的话大屏上容器被卡在 1000px，
       画布反而比窄屏还小（这个坑是算尺寸时逐屏核对才发现的） */
    max-width: none;
    display: grid;
    column-gap: var(--gap);
    grid-template-columns: minmax(0, 1fr) var(--rail);
    /* 左列整体（画布+提示+按钮）占 play，右栏整体（HUD+设置+页脚）占 rail——
       每栏只有一个跨行容器、只有一行，画布的高度才不会把右栏撑出空洞 */
    grid-template-areas: 'play rail';
    align-items: start;
  }

  .play-col {
    grid-area: play;
  }

  /* 右栏是一个整体容器：画布再高也不会把它撑散 */
  .rail-col {
    grid-area: rail;
    display: flex;
    flex-direction: column;
  }

  .hud {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
  }

  /* 报错信息整行铺开，别被自动排布塞进某一栏里 */
  .boot-error {
    grid-column: 1 / -1;
  }

  /* 右栏：信息与设置纵向堆叠，每枚纸签整栏宽居中，像一叠签筒 */
  .hud-stats {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
  }

  .brand {
    margin-right: 0;
    justify-content: center;
  }

  .brand-sub {
    display: none; /* 272px 宽的栏里塞不下一行小字 */
  }

  .chip {
    justify-content: center;
  }

  .chip-score {
    margin-left: 0;
  }

  .meta-bar {
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.9rem;
  }

  #recordDisplay {
    margin-left: 0;
  }

  .meta-actions {
    width: 100%;
    gap: 0.3rem;
  }

  .meta-actions .btn-secondary {
    flex: 1;
  }

  button.btn-secondary {
    width: 100%;
    min-height: 32px;
  }

  .footer-note {
    text-align: center;
    margin-top: 1.1rem;
  }

  .hint {
    margin-top: 0.45rem;
  }

  .controls {
    margin-top: 0.45rem;
  }
}

@media (max-width: 420px) {
  .controls {
    gap: 0.35rem;
  }

  button {
    padding: 0.55rem 0.5rem;
    font-size: 0.84rem;
  }

  .brand-sub {
    display: none; /* 窄屏先让位给标题 */
  }

  .chip {
    padding: 0.24rem 0.65rem;
    letter-spacing: 0.02em;
  }
}

@media (prefers-reduced-motion: reduce) {
  canvas.shake {
    animation: none;
  }

  button {
    transition: none;
  }

  button.next-overlay {
    animation: none;
  }
}

/* ---------- 零成本增强 ---------- */

/* 选中态：朱砂淡染，和印章同源 */
::selection {
  background: rgba(183, 51, 47, 0.16);
  color: var(--ink);
}

/* 滚动条只改颜色不改宽度 —— ::-webkit-scrollbar 的 width 会改变可用宽度、
   挤窄画布，而现状六个分辨率都不出滚动条，纯属负收益。
   标准属性在 Chrome/Edge/Firefox 都受支持。 */
html {
  scrollbar-width: thin;
  scrollbar-color: rgba(138, 133, 121, 0.45) transparent;
}


/* ---------- 预览版新增（默认不生效；由 ?v=2 在 <html> 上挂 data-next 分组） ---------- */

/* 品牌名从 span 改成 h1 后要清掉浏览器默认外边距，字号与字距仍沿用 .brand-name */
h1.brand-name {
  margin-block: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* 结算卡：叠在画布下缘，不参与布局 —— 布局断言的预算一位不变 */
.settle-card {
  position: absolute;
  left: 50%;
  bottom: 4%;
  transform: translateX(-50%);
  width: min(80%, 360px);
  padding: 0.65rem 0.9rem 0.75rem;
  background: var(--paper-card);
  border: 1px solid rgba(138, 133, 121, 0.38);
  border-radius: var(--rad-lg);
  box-shadow: 0 18px 34px -18px rgba(60, 52, 38, 0.55);
  text-align: center;
  z-index: 2;
  animation: pop 0.25s ease-out;
}

.settle-head {
  font-family: var(--serif);
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  color: var(--ink);
}

.settle-head b {
  font-size: 1.55rem;
  color: var(--gold-ink);
  font-variant-numeric: tabular-nums;
}

.settle-rows {
  display: flex;
  justify-content: center;
  gap: 0.9rem;
  margin: 0.3rem 0 0.15rem;
  font-size: 0.76rem;
  color: var(--ink-text);
}

.settle-rows b {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.settle-rank {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--ink-text);
  margin-bottom: 0.45rem;
}

button.settle-next {
  flex: 0 0 auto;
  width: 100%;
  min-height: 44px;
  border-radius: var(--rad-md);
  font-family: var(--serif);
  font-size: 0.95rem;
  letter-spacing: 0.1em;
  color: var(--paper-card);
  background: var(--ink);
  border: 1px solid rgba(200, 162, 74, 0.75);
}

button.settle-next:hover:not(:disabled) {
  background: #2c2a26;
}

/* 通关与死路分开：通关走金墨，死路保留朱砂。色、形、文案三通道 */
html[data-next~="read"] .hint.win {
  color: var(--gold-ink);
}

.hint.advisory {
  color: var(--gold-ink);
  font-family: var(--serif);
}

/* 触控目标提到 44px 与刘海屏安全区 */
html[data-next~="touch"] button.btn-secondary,
html[data-next~="touch"] .auto-next,
html[data-next~="touch"] .account-pick,
html[data-next~="touch"] .account-item {
  min-height: 44px;
}

html[data-next~="touch"] #nameInput {
  min-height: 44px;
}

html[data-next~="touch"] body {
  padding:
    max(clamp(0.6rem, 2.4vw, 1.5rem), env(safe-area-inset-top))
    max(clamp(0.6rem, 2.4vw, 1.5rem), env(safe-area-inset-right))
    max(clamp(0.6rem, 2.4vw, 1.5rem), env(safe-area-inset-bottom))
    max(clamp(0.6rem, 2.4vw, 1.5rem), env(safe-area-inset-left));
}

@media (prefers-reduced-motion: reduce) {
  .settle-card { animation: none; }
}


/* 44px 触控目标会推高设置条，画布预算必须同步加高，否则窄屏会多出一条滚动 */
html[data-next~="touch"] {
  --chrome: 360px;
}

/* 421~899px：设置条只多一行（音效），不需要按手机的 360px 留 */
@media (min-width: 421px) and (max-width: 899px) {
  html[data-next~="touch"] {
    --chrome: 330px;
  }
}

@media (min-width: 900px) {
  html[data-next~="touch"] {
    --chrome: 196px;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  html[data-next~="touch"] {
    --chrome: 234px;
  }
}


/* ---------- 信息层级（read 组）：规则折叠 + 只留一个「下一关」 ---------- */

.rules-toggle {
  display: none;
}

html[data-next~="read"] .rules-toggle {
  display: inline-flex;
  align-items: center;
}

html[data-next~="read"] .footer-note {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  margin-top: 0;
  transition: max-height var(--dur-2) var(--ease), opacity var(--dur-2) var(--ease), margin-top var(--dur-2) var(--ease);
}

html[data-next~="read"] body.rules-open .footer-note {
  max-height: 14rem;
  opacity: 1;
  margin-top: 0.5rem;
}

/* 通关后底栏的「下一关」降级：同一主操作只留结算卡一个 */
html[data-next~="read"] .controls button#nextBtn:not(:disabled) {
  background: var(--paper-card);
  color: var(--ink);
  border: 1px solid rgba(138, 133, 121, 0.38);
  box-shadow: none;
}

html[data-next~="read"] .controls button#nextBtn:not(:disabled):hover {
  background: #f3eee2;
}



/* ---------- 结算明细 / 战报 / 引导 / 续局 / 音效开关 ---------- */

.settle-meta {
  font-size: 0.7rem;
  letter-spacing: 0.03em;
  color: var(--ink-text);
  margin-bottom: 0.5rem;
}

.settle-meta:empty {
  display: none;
}

.settle-actions {
  display: flex;
  gap: 0.45rem;
}

button.settle-share {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 0.8rem;
  border-radius: var(--rad-md);
  border: 1px solid rgba(138, 133, 121, 0.38);
  background: var(--paper-card);
  color: var(--ink);
  font-size: 0.82rem;
  box-shadow: none;
}

button.settle-share:hover {
  background: #f3eee2;
}

button.settle-next {
  flex: 1;
  width: auto;
}

.onboard {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(247, 244, 236, 0.84);
  border-radius: clamp(0.5rem, 1.4vw, 0.85rem);
  z-index: 5;
}

.onboard[hidden] {
  display: none;
}

.onboard-card {
  width: min(86%, 380px);
  padding: 0.95rem 1rem 1rem;
  background: var(--paper-card);
  border: 1px solid rgba(138, 133, 121, 0.38);
  border-radius: var(--rad-lg);
  box-shadow: 0 18px 34px -18px rgba(60, 52, 38, 0.55);
  text-align: center;
}

.onboard-step {
  font-family: var(--serif);
  font-size: 0.98rem;
  letter-spacing: 0.06em;
  line-height: 1.75;
  min-height: 3.4em;
}

.onboard-dots {
  display: flex;
  justify-content: center;
  gap: 0.35rem;
  margin: 0.55rem 0 0.75rem;
}

.onboard-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(138, 133, 121, 0.35);
}

.onboard-dots i.on {
  background: var(--cinnabar);
}

.onboard-actions {
  display: flex;
  gap: 0.5rem;
}

.onboard-actions button {
  flex: 1;
  min-height: 44px;
}

button.btn-primary {
  background: var(--ink);
  color: var(--paper-card);
  border: 1px solid var(--ink);
}

.resume-bar {
  position: fixed;
  top: max(0.75rem, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.4rem 0.6rem;
  width: min(92vw, 560px);
  padding: 0.35rem 0.6rem;
  border: 1px solid rgba(200, 162, 74, 0.45);
  border-left: 3px solid var(--gold-ink);
  border-radius: var(--rad-sm);
  background: #fbf6e8;
  box-shadow: 0 16px 30px -18px rgba(60, 52, 38, 0.45);
  font-size: 0.76rem;
  color: var(--ink-text);
}

.resume-bar[hidden] {
  display: none;
}

.resume-bar span {
  flex: 1;
  min-width: 10rem;
}

.resume-bar button {
  flex: 0 0 auto;
  width: auto;
  min-height: 32px;
}

@media (max-width: 620px) {
  .resume-bar {
    flex-wrap: wrap;
  }
  .resume-bar span {
    flex-basis: 100%;
  }
}

.sound-toggle {
  display: none;
}

html[data-next~="sound"] .sound-toggle {
  display: inline-flex;
}



/* ---------- 暗色：只暗外壳，纸仍是浅色（墨吸在纸里，纸不该跟着变黑） ---------- */

@media (prefers-color-scheme: dark) {
  html[data-next~="dark"] {
    --paper: #171612;
    --paper-card: #24211b;
    --ink: #ece7d9;
    --ink-text: #b8b1a2;
    --ink-mid: #8f897b;
    --cinnabar: #d65a52;
    --cinnabar-soft: #7a3a36;
    --gold-deep: #d3ab52;
    --gold-ink: #d8b45a;
    --hairline: rgba(214, 205, 185, 0.22);
    --focus: #ece7d9;
    color-scheme: dark;
  }

  html[data-next~="dark"] body {
    background-image:
      radial-gradient(circle at 12% 34%, rgba(200, 162, 74, 0.2) 0 0.9px, transparent 1.7px),
      radial-gradient(circle at 73% 16%, rgba(200, 162, 74, 0.14) 0 1.1px, transparent 1.9px),
      radial-gradient(circle at 41% 78%, rgba(200, 162, 74, 0.17) 0 0.8px, transparent 1.6px),
      radial-gradient(ellipse at 20% 18%, rgba(255, 255, 255, 0.035), transparent 45%),
      radial-gradient(ellipse at 88% 92%, rgba(0, 0, 0, 0.4), transparent 50%);
  }

  html[data-next~="dark"] .game-container {
    background-image:
      repeating-linear-gradient(94deg, rgba(236, 231, 217, 0.028) 0 1px, transparent 1px 5px),
      repeating-linear-gradient(2deg, rgba(236, 231, 217, 0.02) 0 1px, transparent 1px 6px);
  }

  html[data-next~="dark"] button:hover:not(:disabled) {
    background: rgba(236, 231, 217, 0.08);
  }

  html[data-next~="dark"] .onboard {
    background: rgba(23, 22, 18, 0.86);
  }

  html[data-next~="dark"] .resume-bar {
    background: #2a261d;
  }

  html[data-next~="dark"] .settle-card {
    border-color: rgba(214, 205, 185, 0.2);
  }
}
