/* 楚河漢界 · 中国象棋 — HUD
   设计语：碑帖。近单色的墨与纸灰，细发丝线，朱砂只作最小限度的记号。
   无渐变紫、无重辉光、无大圆角——克制、锋利、像一件案头器物。 */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #14110d;
  --ink: #e8e0d0;
  --muted: #978c7a;
  --panel: rgba(16, 13, 10, 0.58);
  --line: rgba(232, 222, 205, 0.16);
  --line-strong: rgba(232, 222, 205, 0.34);
  --cinnabar: #b5432f;
  --han: #c05a42;          /* 红方记号（朱） */
  --chu: #7f95a8;          /* 黑方记号（黛） */
  --serif: "Songti SC", "STSong", "SimSun", serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app, #app canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(14px + env(safe-area-inset-top, 0px)) calc(18px + env(safe-area-inset-right, 0px)) 14px calc(18px + env(safe-area-inset-left, 0px));
  pointer-events: none;
  z-index: 10;
}
#brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-shadow: 0 1px 10px rgba(0,0,0,0.65);
}
#brand .b1 {
  font-family: var(--calli, var(--serif));
  font-size: 19px;
  font-weight: 900;
  letter-spacing: 6px;
  margin-right: -6px;      /* 吃掉末字后的悬挂字距，右侧副标才贴得住 */
}
#brand .b2 {
  font-size: 11px;
  letter-spacing: 4px;
  color: var(--muted);
}
#btn-menu { display: none; }
#btns {
  display: flex;
  gap: 0;
  pointer-events: auto;
  background: linear-gradient(rgba(20,16,11,.55), rgba(14,11,8,.62));
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 3px 4px;
  backdrop-filter: blur(10px);
  box-shadow: 0 6px 24px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.05);
}
/* 组间竖界栏（像简牍的编绳） */
#btns button + button::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  width: 1px; height: 13px;
  margin-top: -6.5px;
  background: var(--line);
}
#btn-undo::before, #btn-sound::before { background: var(--line-strong) !important; height: 17px !important; margin-top: -8.5px !important; }
#btns button, #endpanel button {
  appearance: none;
  border: none;
  background: none;
  color: rgba(232,224,208,.82);
  font-family: var(--calli, var(--serif));
  font-size: 13px;
  letter-spacing: 3px;
  text-indent: 3px;
  padding: 7px 13px 6px;
  border-radius: 0;
  text-shadow: 0 1px 8px rgba(0,0,0,0.7);
  transition: color .18s, background .18s, opacity .18s;
  white-space: nowrap;
}
#btns button { position: relative; }
#btns button::after {
  content: '';
  position: absolute;
  left: 10px; right: 10px; bottom: 2px;
  height: 1px;
  background: var(--cinnabar);
  transform: scaleX(0);
  transition: transform .22s cubic-bezier(.2,.9,.3,1);
}
@media (hover: hover) {
  #btns button:hover { background: rgba(255,255,255,.05); color: #fff; }
  #btns button:hover::after { transform: scaleX(1); }
}
#btns button:active { transform: translateY(1px); }
#btns button.off { opacity: 0.45; }

/* ---------- 行棋方 ---------- */
#turn {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 13px;
  letter-spacing: 4px;
  padding-right: 14px;     /* 末字悬挂字距，右内边距相应收窄 */
  z-index: 9;
  backdrop-filter: blur(8px);
  pointer-events: none;
  transition: opacity .3s;
}
#turn-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--han);
  transition: background .3s;
}
#turn.black #turn-dot { background: var(--chu); }
#turn.over { opacity: 0.5; }

/* ---------- 横幅 ---------- */
#banner {
  position: fixed;
  top: 21%;
  left: 50%;
  transform: translate(-50%, -8px);
  font-family: var(--calli, var(--serif));
  font-size: clamp(30px, 6.5vw, 46px);
  font-weight: 900;
  letter-spacing: 0.4em;
  text-indent: 0.2em;
  color: var(--ink);
  text-shadow: 0 2px 26px rgba(0,0,0,0.85);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 11;
}
#banner.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 阵亡托盘 ---------- */
#dock {
  position: fixed;
  left: 14px;
  bottom: calc(14px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 5px;
  z-index: 9;
  pointer-events: none;
  max-width: min(46vw, 330px);
}
.tray-side {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 5px 12px 5px 9px;
  backdrop-filter: blur(8px);
  min-height: 30px;
}
.tray-side .tl {
  font-family: var(--calli, var(--serif));
  font-size: 12px;
  width: 14px;
  text-align: center;
  flex: none;
  color: var(--muted);
}
.tray-side.r .tl { color: var(--han); }
.tray-side.b .tl { color: var(--chu); }
.tray { display: flex; flex-wrap: wrap; gap: 3px; }
.cap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 19px; height: 19px;
  border-radius: 50%;
  font-family: var(--calli, var(--serif));
  font-size: 11.5px;
  line-height: 1;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  animation: capin .3s cubic-bezier(.2,.9,.3,1.35);
}
.cap.r { color: var(--han); border-color: rgba(192,90,66,0.5); }
.cap.b { color: var(--chu); border-color: rgba(127,149,168,0.5); }
@keyframes capin { from { transform: scale(0) rotate(-40deg); opacity: 0; } }

/* ---------- 着法帖 ---------- */
/* 一页竖排手抄棋谱：右起、行间有界栏、回合数用汉字小字 */
#history {
  position: fixed;
  right: 14px;
  bottom: calc(14px + var(--safe-b));
  width: min(40vw, 360px);
  height: 32vh;
  min-height: 200px;
  transition: width .26s cubic-bezier(.2,.9,.3,1), height .26s cubic-bezier(.2,.9,.3,1), min-height .26s;
  overflow-x: auto;
  overflow-y: hidden;
  direction: rtl;                       /* 右起 */
  background:
    linear-gradient(rgba(22, 18, 12, 0.72), rgba(16, 13, 9, 0.78)),
    repeating-linear-gradient(90deg, rgba(232,222,205,.07) 0 1px, transparent 1px 74px);
  border: 1px solid var(--line);
  border-top: 1px solid var(--line-strong);
  padding: 30px 12px 12px;
  z-index: 9;
  backdrop-filter: blur(8px);
  scrollbar-width: none;
}
#history::-webkit-scrollbar { display: none; }
/* 默认折叠成一枚小签，点标题展开 */
#history.folded {
  width: 96px;
  height: 34px;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}
#history.folded #history-list { display: none; }
#history.folded #history-title {
  top: 0; right: 0; left: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.4em;
  text-indent: 0.4em;
}
#history-title { cursor: pointer; user-select: none; transition: color .18s; }
@media (hover: hover) {
  #history-title:hover { color: var(--ink); }
}
#history-title .grip {
  display: inline-block;
  width: 16px; height: 1px;
  background: var(--line-strong);
  margin-left: 8px;
  vertical-align: middle;
}
#history-title {
  position: absolute;
  top: 8px; right: 12px; left: 12px;
  direction: ltr;
  font-family: var(--calli, var(--serif));
  font-size: 11px;
  letter-spacing: 0.55em;
  text-indent: 0.55em;
  color: var(--muted);
  text-align: center;
}
#history-list {
  list-style: none;
  display: flex;
  flex-direction: row;                  /* 每一回合一列 */
  align-items: flex-start;
  gap: 0;
  height: 100%;
  direction: rtl;
}
#history-list li {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 74px;
  flex: none;
  padding-top: 2px;
  direction: ltr;
}
#history-list span {
  font-family: var(--calli, var(--serif));
  writing-mode: vertical-rl;            /* 竖排 */
  text-orientation: upright;
  letter-spacing: 0.16em;
  line-height: 1.1;
}
#history-list .hn { font-size: 11px; color: rgba(151,140,122,.7); }
#history-list .hr { font-size: 15px; color: var(--han); }
#history-list .hb { font-size: 15px; color: var(--chu); }
#history-list li:first-child .hr,
#history-list li:first-child .hb { text-shadow: 0 0 12px currentColor; }

/* ---------- 终局 ---------- */
#endpanel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  background: rgba(14, 11, 8, 0.88);
  border: 1px solid var(--line-strong);
  padding: 34px 52px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 12;
  backdrop-filter: blur(10px);
}
#endpanel.show { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
#end-text {
  font-family: var(--calli, var(--serif));
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 7px;
  text-indent: 3.5px;
  margin-bottom: 22px;
}
.end-btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
#endpanel button {
  font-size: 14px;
  padding: 9px 20px;
  border: 1px solid var(--line);
}
@media (hover: hover) {
  #endpanel button:hover { border-color: var(--line-strong); color: #fff; }
}

/* ---------- 提示 ---------- */
#hint {
  position: fixed;
  bottom: calc(12px + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--muted);
  opacity: 0.6;
  pointer-events: none;
  z-index: 8;
  white-space: nowrap;
}
body.booted #hint { animation: hintfade 1s 8s forwards; }
@keyframes hintfade { to { opacity: 0; } }

#skiphint {
  position: fixed;
  bottom: calc(24px + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  letter-spacing: 5px;
  color: var(--ink);
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
  z-index: 13;
}
body.cinematic #skiphint { opacity: 0.7; }
body.cinematic #history, body.cinematic #dock, body.cinematic #turn { opacity: 0.12; }

/* ---------- 碑框面板 / 拓片标题 / 印 ---------- */
.overlay .panel.framed {
  position: relative;
  background:
    linear-gradient(rgba(18, 14, 10, 0.94), rgba(12, 9, 6, 0.96)),
    repeating-linear-gradient(0deg, rgba(255,255,255,.014) 0 1px, transparent 1px 3px);
  border: 1px solid rgba(232, 222, 205, 0.28);
  box-shadow: 0 0 0 1px rgba(0,0,0,.6), 0 30px 80px rgba(0,0,0,.55);
  padding: 46px 52px 38px;
}
/* 内框 + 四角断口，仿碑面刻框 */
.panel.framed::before {
  content: '';
  position: absolute;
  inset: 9px;
  border: 1px solid rgba(232, 222, 205, 0.14);
  pointer-events: none;
}
.panel.framed::after {
  content: '';
  position: absolute;
  inset: 9px;
  pointer-events: none;
  background:
    linear-gradient(var(--bg), var(--bg)) top left / 16px 16px no-repeat,
    linear-gradient(var(--bg), var(--bg)) top right / 16px 16px no-repeat,
    linear-gradient(var(--bg), var(--bg)) bottom left / 16px 16px no-repeat,
    linear-gradient(var(--bg), var(--bg)) bottom right / 16px 16px no-repeat;
  opacity: .9;
}
.panel.framed > * { position: relative; z-index: 1; }

.entry-panel { min-width: 380px; }
.rubbing {
  display: block;
  width: min(340px, 66vw);
  height: auto;
  margin: 2px auto 14px;
  image-rendering: auto;
}
.entry-panel .sub {
  font-family: var(--serif);
  font-size: 12px;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  color: var(--muted);
  margin-bottom: 26px;
}
.entry-panel .foot {
  margin-top: 22px;
  font-size: 10px;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  color: rgba(151, 140, 122, 0.6);
}
.panel.framed > .seal,
.seal {
  /* 特指度要压过 .panel.framed > *，否则会被它改成 relative 而塌成 0×0 */
  position: absolute;
  display: block;
  top: -16px; right: -16px;
  width: 62px; height: 62px;
  background-size: contain;
  background-repeat: no-repeat;
  transform: rotate(6deg);
  filter: drop-shadow(0 3px 8px rgba(0,0,0,.55));
  z-index: 2;
  pointer-events: none;
}

/* 模式按钮：两行字 + 左侧刻痕，hover 时刻痕点亮并渗出一线 */
.modes { flex-direction: column; gap: 8px; }
.overlay button.mode {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  width: 100%;
  padding: 13px 18px 13px 26px;
  border: 1px solid rgba(232, 222, 205, 0.14);
  background: rgba(255,255,255,.02);
  overflow: hidden;
  transition: border-color .2s, background .2s;
}
.overlay button.mode b {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.28em;
  text-indent: 0.28em;
}
.overlay button.mode i {
  font-style: normal;
  font-size: 10.5px;
  letter-spacing: 0.22em;
  color: var(--muted);
  transition: color .2s;
}
.overlay button.mode::before {          /* 左侧刻痕 */
  content: '';
  position: absolute;
  left: 10px; top: 50%;
  width: 2px; height: 14px;
  margin-top: -7px;
  background: rgba(232, 222, 205, 0.28);
  transition: height .22s cubic-bezier(.2,.9,.3,1), background .22s, margin-top .22s;
}
.overlay button.mode::after {           /* hover 渗出的底线 */
  content: '';
  position: absolute;
  left: 0; bottom: 0; height: 1px;
  width: 0;
  background: linear-gradient(90deg, var(--cinnabar), transparent);
  transition: width .32s ease;
}
@media (hover: hover) {
  .overlay button.mode:hover { border-color: rgba(232,222,205,.34); background: rgba(255,255,255,.05); }
  .overlay button.mode:hover::before { height: 30px; margin-top: -15px; background: var(--cinnabar); }
  .overlay button.mode:hover::after { width: 100%; }
  .overlay button.mode:hover i { color: rgba(232,222,205,.75); }
}
.overlay button.mode:active { transform: translateY(1px); }

/* 全屏暗角：把注意力收到盘面上 */
#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 7;
  background: radial-gradient(ellipse 76% 68% at 50% 46%, transparent 42%, rgba(8,6,4,.42) 100%);
}

/* ---------- 分镜层 ---------- */
#letterbox {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 14;
  --lb: 0vh;
}
#letterbox::before, #letterbox::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: var(--lb);
  background: #000;
  transition: height .3s ease;
}
#letterbox::before { top: 0; }
#letterbox::after { bottom: 0; }

#flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 15;
}

#cintitle {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(1.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
  z-index: 16;
  transition: opacity .18s ease, transform .35s cubic-bezier(.16,.9,.3,1);
}
#cintitle.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#cintitle b {
  font-family: var(--serif);
  font-size: clamp(64px, 14vw, 120px);
  font-weight: 900;
  line-height: 0.9;
  color: #f6efdd;
  text-shadow: 0 0 40px rgba(0,0,0,.9), 0 6px 0 rgba(0,0,0,.35);
}
#cintitle i {
  font-family: var(--serif);
  font-style: normal;
  font-size: clamp(13px, 2.4vw, 17px);
  letter-spacing: 0.6em;
  text-indent: 0.6em;
  color: var(--han);
  text-shadow: 0 2px 14px rgba(0,0,0,.9);
}

#fallback {
  position: fixed;
  inset: auto 0 40% 0;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
}

/* ---------- 浮层 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  overflow-y: auto;          /* 内容超高（键盘弹起/横屏/小屏）时必须能滚，而不是被裁掉 */
  background: rgba(8, 6, 4, 0.55);
  backdrop-filter: blur(7px);
  z-index: 45;               /* 模态浮层必须压住弹幕(38)/观战章(40)/互动条(41) */
}
.overlay.hidden { display: none; }
.overlay .panel {
  margin: auto;              /* margin:auto 双轴居中，超高时顶部不会被裁 */
  background: rgba(16, 13, 10, 0.92);
  border: 1px solid var(--line-strong);
  padding: 42px 48px;
  text-align: center;
  min-width: 340px;
  max-width: 92vw;
}
.overlay h1 {
  font-family: var(--serif);
  font-size: clamp(26px, 6vw, 34px);
  font-weight: 900;
  letter-spacing: 0.42em;
  margin-bottom: 10px;
  /* 字距会在末字后多出一格空白，居中时字形整体左偏半格——补回半格才是光学居中 */
  text-indent: 0.21em;
}
.overlay h2 {
  font-family: var(--serif);
  font-size: 19px;
  letter-spacing: 6px;
  text-indent: 3px;
  margin-bottom: 22px;
  font-weight: 700;
}
.overlay .sub { color: var(--muted); font-size: 11px; letter-spacing: 4px; margin-bottom: 32px; }
.overlay .row { display: flex; gap: 10px; justify-content: center; }
.overlay button {
  appearance: none;
  border: 1px solid var(--line);
  background: none;
  color: var(--ink);
  border-radius: 0;
  transition: border-color .15s, color .15s, background .15s;
}
@media (hover: hover) {
  .overlay button:hover { border-color: var(--line-strong); color: #fff; background: rgba(255,255,255,0.04); }
}
.overlay button.big { font-size: 14.5px; padding: 14px 26px; letter-spacing: 4px; }
.overlay button.ghost { background: none; border: none; color: var(--muted); font-size: 12px; margin-top: 16px; letter-spacing: 3px; }
.overlay input {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  padding: 11px 12px;
  margin-bottom: 12px;
  width: 100%;
  text-align: center;
  letter-spacing: 2px;
  outline: none;
  border-radius: 0;
}
.overlay input:focus { border-color: var(--line-strong); }
.overlay .or { color: var(--muted); font-size: 11px; margin: 8px 0 12px; letter-spacing: 5px; }
.overlay .joinrow { display: flex; gap: 8px; }
.overlay .joinrow input { flex: 1; text-transform: uppercase; }
.overlay .joinrow button { padding: 0 18px; font-size: 14px; }
#conn-status, #lc-status { min-height: 18px; font-size: 12px; color: var(--muted); margin-top: 10px; letter-spacing: 1px; }
#lc-code.code { font-family: var(--serif); letter-spacing: 7px; font-size: 24px; color: var(--han); }
.share { display: flex; gap: 8px; margin-bottom: 14px; }
.share input { font-size: 12px; letter-spacing: 0; margin-bottom: 0; }
.share button { padding: 0 14px; font-size: 13px; white-space: nowrap; }
#lc-waiting { color: var(--muted); font-size: 13px; letter-spacing: 4px; margin-bottom: 14px; }
#lc-waiting.breath { animation: breath 2s ease-in-out infinite; }
@keyframes breath { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }
.sides { display: flex; gap: 8px; align-items: center; justify-content: center; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.sides button { padding: 7px 16px; font-size: 13px; letter-spacing: 2px; }
.sides button.sel { border-color: var(--ink); color: #fff; }
#lc-players .lp { font-size: 14px; padding: 5px 0; letter-spacing: 2px; }
#lc-players .lp.off { color: var(--muted); }

/* 人机设置 */
.pickrow { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.pickrow .pl { font-size: 12px; letter-spacing: 4px; color: var(--muted); flex: none; width: 32px; text-align: left; }
.picks { display: flex; gap: 6px; flex: 1; }
.picks button { flex: 1; padding: 10px 6px; font-size: 13px; letter-spacing: 1px; white-space: nowrap; }
.picks button.sel { border-color: var(--ink); color: #fff; background: rgba(255,255,255,0.05); }
#vsai .note { font-size: 11px; color: var(--muted); letter-spacing: 1px; line-height: 1.7; margin: 6px 0 18px; }
#vsai button.big { width: 100%; }

/* 倒数 */
#countdown {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: clamp(64px, 15vw, 100px);
  font-weight: 900;
  color: var(--ink);
  text-shadow: 0 4px 34px rgba(0, 0, 0, 0.8);
  z-index: 40;
  pointer-events: none;
  letter-spacing: 10px;
  text-indent: 5px;
}
#countdown.show { display: flex; }
#countdown.pop { animation: cdpop .6s ease-out; }
@keyframes cdpop { 0% { transform: scale(1.5); opacity: 0; } 30% { opacity: 1; } 100% { transform: scale(1); } }

/* toast */
#toasts {
  position: fixed;
  top: 100px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 35;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: rgba(16, 13, 10, 0.92);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 13px;
  letter-spacing: 2px;
  padding: 9px 18px;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity .25s, transform .25s;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  backdrop-filter: blur(8px);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast button {
  border: 1px solid var(--line);
  background: none;
  color: var(--ink);
  padding: 4px 12px;
  font-size: 12px;
}
.toast button:hover { border-color: var(--line-strong); }

#peeroff {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(70, 26, 16, 0.92);
  border: 1px solid rgba(220, 120, 90, 0.4);
  color: #f0d0c0;
  font-size: 13px;
  letter-spacing: 2px;
  padding: 8px 20px;
  z-index: 34;
  display: none;
}
#peeroff.show { display: block; }

/* ---------- 手机 ---------- */
@media (max-width: 900px) {
  #topbar { padding: 10px 12px; }
  #brand .b1 { font-size: 15px; letter-spacing: 3px; }
  #brand .b2 { display: none; }
  #btn-menu {
    display: block;
    pointer-events: auto;
    appearance: none;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--ink);
    font-size: 14px;
    line-height: 1;
    padding: 8px 11px;
    backdrop-filter: blur(8px);
  }
  #btns {
    position: fixed;
    top: 46px;
    right: 12px;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: rgba(16, 13, 10, 0.94);
    border: 1px solid var(--line-strong);
    padding: 6px 4px;
    backdrop-filter: blur(10px);
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
    transition: opacity .2s, transform .2s;
  }
  body.menu-open #btns { opacity: 1; transform: none; pointer-events: auto; }
  #btns button { font-size: 13px; padding: 10px 18px; text-align: right; border-bottom: none; }

  /* 底部三层：着法抽屉 → 托盘 → 行棋方，互不遮挡 */
  #turn { top: auto; bottom: calc(74px + var(--safe-b)); font-size: 12px; padding: 6px 14px; letter-spacing: 3px; }
  #banner { top: 25%; }

  #dock {
    left: 8px; right: 8px;
    bottom: calc(50px + var(--safe-b));
    max-width: none;
    flex-direction: row;
    gap: 6px;
  }
  .tray-side { flex: 1; min-width: 0; padding: 4px 8px; }
  .tray { flex: 1; min-width: 0; overflow-y: auto; max-height: 60px; scrollbar-width: none; }
  .tray::-webkit-scrollbar { display: none; }
  .cap { width: 17px; height: 17px; font-size: 10.5px; }

  /* 手机/iPad 竖屏：着法帖改成底部抽屉——收起是一枚 44px 小签，点开向上展开 */
  #history {
    left: 8px; right: 8px; bottom: calc(104px + var(--safe-b));
    width: auto; height: min(34vh, 260px); min-height: 0;
    padding: 34px 12px 12px;
    overflow-x: auto; overflow-y: hidden;
    transition: height .26s cubic-bezier(.2,.9,.3,1), padding .26s;
  }
  #history.folded { height: 44px; padding: 0 12px; overflow: hidden; }
  #history.folded #history-title {
    top: 0; right: 0; left: 0; bottom: 0;
  }

  #hint { display: none; }
  #endpanel { padding: 26px 30px; width: min(80vw, 340px); }
  #end-text { font-size: 21px; }
  .overlay .panel { padding: 30px 24px; min-width: 0; width: 88vw; }
  .pickrow { flex-direction: column; align-items: stretch; gap: 6px; }
  .pickrow .pl { width: auto; }
  .picks button { padding: 11px 4px; font-size: 12.5px; }
}

/* ---------- 触屏：所有可点区域至少 44px（手机与 iPad 通用） ---------- */
@media (pointer: coarse) {
  #btns button,
  .overlay button,
  .picks button,
  .sides button,
  #endpanel button,
  .toast button,
  #btn-menu,
  #cheer-toggle,
  .cheer-btn { min-height: 44px; }
  .cheer-btn { align-items: center; }
  .overlay button.big { padding: 16px 26px; font-size: 15px; }
  .overlay input { padding: 14px 12px; font-size: 16px; }   /* 16px 以下 iOS 会自动放大页面 */
  .share button, .joinrow button { min-width: 64px; }
  #history-title { min-height: 44px; }
  .cap { width: 21px; height: 21px; font-size: 12px; }
}

/* ---------- iPad 横屏：顶栏留在原位，但按钮放大到可点 ---------- */
@media (min-width: 901px) and (pointer: coarse) {
  #topbar { padding: 16px 20px; }
  #btns { gap: 4px; }
  #btns button { font-size: 14px; padding: 12px 14px; letter-spacing: 1px; }
  #turn { font-size: 14px; padding: 9px 20px; }
  #history { width: 210px; font-size: 13px; }
  .tray-side { padding: 7px 14px 7px 10px; }
}

/* ---------- 窄屏：入口三个按钮竖排，别挤成一行 ---------- */
@media (max-width: 560px) {
  .overlay .row { flex-direction: column; }
  .overlay .row button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.06s !important; }
}

/* ---------- 观战 / 互动 ---------- */
/* 语汇跟全站一致：近单色、碑帖边框、朱砂只做记号。别做成直播间。 */

#spectate-badge {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 40; display: flex; align-items: center; gap: 7px;
  padding: 6px 14px; font-size: 13px; letter-spacing: .12em;
  color: #e6dcc4; background: rgba(20, 16, 10, .72);
  border: 1px solid rgba(226, 214, 188, .22);
  backdrop-filter: blur(6px);
}
#spectate-badge .dot {
  width: 7px; height: 7px; border-radius: 50%; background: #c0523a;
  animation: sp-pulse 1.8s ease-in-out infinite;
}
@keyframes sp-pulse { 0%, 100% { opacity: 1 } 50% { opacity: .25 } }

/* 弹幕层：不吃事件，纯飘 */
#danmu { position: fixed; inset: 0; pointer-events: none; z-index: 38; overflow: hidden; }
#danmu .dm {
  position: absolute; right: -40%; white-space: nowrap;
  display: inline-flex; align-items: baseline; gap: 8px;
  padding: 5px 13px; font-size: 15px;
  color: #efe6d2; background: rgba(18, 14, 9, .58);
  border: 1px solid rgba(226, 214, 188, .16);
  text-shadow: 0 1px 3px rgba(0, 0, 0, .8);
}
#danmu .dm.run { animation: dm-fly 7s linear forwards; }
#danmu .dm b { font-size: 12px; opacity: .62; font-weight: 400; }
#danmu .dm em { font-style: normal; color: #d9a441; font-weight: 700; }
#danmu .dm.r { border-left: 3px solid #8f2f1f; }
#danmu .dm.b { border-left: 3px solid #6a89a8; }
#danmu .dm.pump { animation: dm-fly 7s linear forwards, dm-pump .26s ease-out; }
@keyframes dm-fly { from { right: -40% } to { right: 104% } }
@keyframes dm-pump { 50% { transform: scale(1.14) } }

/* 互动条 */
#cheerbar {
  position: fixed; left: 50%; bottom: calc(16px + var(--safe-b)); transform: translateX(-50%);
  z-index: 41; display: flex; align-items: flex-end; gap: 10px;
  max-width: min(96vw, 760px);
}
#cheerbar.hidden { display: none; }
#cheer-toggle {
  flex: none; width: 42px; height: 42px; font-size: 19px; cursor: pointer;
  color: #e6dcc4; background: rgba(20, 16, 10, .78);
  border: 1px solid rgba(226, 214, 188, .24);
}
@media (hover: hover) {
  #cheer-toggle:hover { background: rgba(40, 32, 20, .9); }
}
#cheer-groups {
  display: none; flex-direction: column; gap: 5px;
  padding: 9px 11px; background: rgba(18, 14, 9, .8);
  border: 1px solid rgba(226, 214, 188, .18);
  backdrop-filter: blur(7px);
}
#cheerbar.open #cheer-groups { display: flex; }
#cheerbar.cool #cheer-groups { opacity: .45; pointer-events: none; }
.cheer-row { display: flex; align-items: center; gap: 5px; }
.cheer-lab {
  flex: none; width: 2.6em; font-size: 11px; letter-spacing: .1em;
  color: rgba(230, 220, 196, .62);
}
.cheer-btn {
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  padding: 5px 10px; font-size: 13px; white-space: nowrap;
  color: #e6dcc4; background: rgba(48, 40, 28, .5);
  border: 1px solid rgba(226, 214, 188, .16);
  transition: background .12s, transform .12s;
}
.cheer-btn i { font-style: normal; font-size: 15px; }
@media (hover: hover) {
  .cheer-btn:hover { background: rgba(78, 64, 42, .75); }
}
.cheer-btn.throw { border-color: rgba(192, 82, 58, .38); }
.cheer-btn.hit { transform: scale(1.16); background: rgba(140, 74, 42, .85); }

/* 观战时下方按不到棋子，互动条可以铺开一点 */
body.spectating #hint { opacity: 0; }

.share-note {
  margin: 8px 0 0; font-size: 12px; line-height: 1.7;
  color: rgba(230, 220, 196, .5);
}
.share-note b { color: rgba(230, 220, 196, .82); font-weight: 600; }

@media (max-width: 680px) {
  #cheerbar { bottom: calc(10px + var(--safe-b)); gap: 7px; }
  #cheer-groups { padding: 7px 8px; gap: 4px; }
  .cheer-btn { padding: 5px 7px; font-size: 12px; gap: 3px; }
  .cheer-lab { width: 2.2em; font-size: 10px; }
  #danmu .dm { font-size: 13px; padding: 4px 10px; }
}


/* ---------- 房间屏（联机唯一一屏） ---------- */
.room-panel { width: min(94vw, 520px); }
.rm-lead { margin: 0 0 8px; font-size: 13px; color: rgba(230, 220, 196, .62); }
.rm-lead2 {
  margin: 18px 0 9px; font-size: 12px; letter-spacing: .14em;
  color: rgba(230, 220, 196, .45);
}
#rm-share .share { display: flex; gap: 8px; }
#rm-link {
  flex: 1 1 auto; min-width: 0; font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
#btn-share { flex: none; min-width: 78px; }

.rm-name { display: block; margin-top: 16px; }
.rm-name > span {
  display: block; margin-bottom: 6px; font-size: 12px;
  letter-spacing: .14em; color: rgba(230, 220, 196, .45);
}
.rm-name input { width: 100%; }

#rm-seats { display: flex; flex-direction: column; gap: 8px; }
.seat {
  display: flex; align-items: baseline; gap: 12px; width: 100%;
  padding: 13px 16px; text-align: left; cursor: pointer;
  color: #e6dcc4; background: rgba(48, 40, 28, .34);
  border: 1px solid rgba(226, 214, 188, .18);
  transition: background .14s, border-color .14s;
}
.seat b { font-size: 16px; font-weight: 600; letter-spacing: .08em; }
.seat i { font-style: normal; font-size: 12.5px; color: rgba(230, 220, 196, .55); }
@media (hover: hover) {
  .seat:hover:not(:disabled) { background: rgba(78, 64, 42, .5); }
}
.seat.sel { border-color: #a8532f; background: rgba(120, 56, 32, .34); }
.seat.sel b::after { content: ' ✓'; color: #d9a441; }
.seat.taken:disabled { opacity: .42; }
.seat:disabled { cursor: default; }
.seat.watch { border-style: dashed; }

#rm-viewers {
  margin-top: 12px; font-size: 12px; line-height: 1.7;
  color: rgba(230, 220, 196, .5);
}
#rm-status {
  margin-top: 10px; min-height: 1.5em; font-size: 13px;
  color: rgba(217, 164, 65, .9);
}

/* 平板：两个座位并排，观战独占一行——iPad 上一屏能装下，不该逼人滚动 */
@media (min-width: 700px) {
  #rm-seats { display: grid; grid-template-columns: 1fr 1fr; }
  .seat.watch { grid-column: 1 / -1; }
  .seat { flex-direction: column; gap: 3px; align-items: flex-start; }
}

.seat.primary {
  border-color: #a8532f;
  background: rgba(120, 56, 32, .26);
}

/* 手机：竖排、加大触点、去掉不必要的留白。
   触点一律 ≥44px —— iOS HIG 的最小可点尺寸，低于这个数在手机上很难按准。 */
@media (max-width: 699px) {
  .room-panel { width: 94vw; padding: 20px 18px 18px; }
  .seat { padding: 15px 15px; min-height: 56px; }
  .seat b { font-size: 17px; }
  #rm-link { font-size: 12px; min-height: 44px; }
  #btn-share { min-height: 44px; padding: 0 16px; }
  .rm-name input { min-height: 44px; }
  #btn-room-back { min-height: 44px; }
  .rm-lead2 { margin: 14px 0 8px; }
}
