/**
 * 对局页样式。布局取自设计稿 1c 三栏，并套用 2a 的去框风格
 * （设计稿结尾「下一步」提到的正是这个组合）。
 */

.game {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px 28px 40px;
}

/* —— 头部 —— */
.game-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--hairline);
}
.game-head-left { display: flex; align-items: center; gap: 12px; }
.game-head-right { display: flex; align-items: center; gap: 10px; }
.game-meta { font-size: 12.5px; }

/* —— 断线横幅 —— */
.game-banner {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 9px;
  background: var(--accent-tint);
  color: var(--accent);
  font-size: 12.5px;
}

/* —— 三栏：左信息 / 中棋盘 / 右棋谱 —— */
.game-cols {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 220px;
  gap: 30px;
  align-items: start;
  padding-top: 22px;
}

/* —— 玩家卡 —— */
.game-left { display: flex; flex-direction: column; gap: 14px; }
.pc {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 11px;
  padding: 10px 8px;
  border-radius: 10px;
  transition: background-color .2s;
}
.pc[data-active="true"] { background: var(--accent-tint); }
.pc-body { min-width: 0; }
.pc-top { display: flex; align-items: baseline; gap: 7px; }
.pc-name {
  font-size: 13.5px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pc-color { font-size: 11.5px; }
.pc-bottom { display: flex; align-items: baseline; gap: 8px; min-height: 17px; }
.pc-state { font-size: 12px; color: var(--accent); font-weight: 600; }
.pc-move { font-size: 12px; color: var(--muted); }
.pc-move[data-urgent="true"] { color: var(--danger); font-weight: 700; }
.pc-clock { font-size: 15px; font-variant-numeric: tabular-nums; }

.game-ops { display: flex; flex-direction: column; gap: 8px; }
.game-ops .btn { justify-content: center; }
.game-ops-note { font-size: 11.5px; margin: 4px 0 0; line-height: 1.6; }

/* —— 棋盘栏 —— */
.game-center { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.game-board-host { width: 100%; max-width: 620px; }
.game-hint { font-size: 12.5px; min-height: 19px; margin: 0; text-align: center; }

/* —— 棋谱栏 —— */
.game-right { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.record-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.record-head .muted { font-size: 12px; }
.record-list {
  list-style: none;
  margin: 0; padding: 0;
  max-height: 62vh;
  overflow-y: auto;
  scrollbar-width: thin;
}
.record-row {
  display: grid;
  grid-template-columns: 30px 12px 1fr;
  align-items: center;
  gap: 8px;
  padding: 5px 4px;
  border-bottom: 1px solid var(--hairline);
  font-size: 12.5px;
}
.record-n { color: var(--muted); font-size: 11.5px; }
.record-dot { width: 9px; height: 9px; border-radius: 50%; }
/* 9px 的点用渐变没有意义，纯色反而在各种内核上都稳 */
.record-dot[data-color="black"] { background: var(--stone-black-solid); }
.record-dot[data-color="white"] {
  background: var(--stone-white-solid);
  box-shadow: inset 0 0 0 1px var(--hairline-strong);
}
.record-pos { font-variant-numeric: tabular-nums; }

/* —— 结算 —— */
.result-sub { margin: 0 0 16px; color: var(--text-2); font-size: 13px; }
.result-stats { display: flex; gap: 28px; padding: 4px 0 8px; }
.result-stats > div { display: flex; flex-direction: column; gap: 2px; }
.result-stats strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.result-stats span { font-size: 11.5px; }

/* 重赛窗口的倒计时。房间就活这么久，别让人以为可以慢慢看 */
.result-countdown { margin: 18px 0 4px; }
.result-bar {
  height: 3px;
  border-radius: 2px;
  background: var(--hairline);
  overflow: hidden;
}
.result-bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  /* 从满走到空，由 JS 每 100ms 写一次 scaleX。
     用 transform 而不是 width —— 宽度动画每帧都要重排，
     30 秒里一直占着主线程，正好压在人要点「再战」的时候 */
  transform: scaleX(1);
  transform-origin: left center;
}
/* 带上 .modal 是为了压过 base.css 里的 `.modal p { margin: 0 0 20px }` */
.modal .result-count {
  margin: 8px 0 16px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* 对方已经点了再战，把按钮点亮一下，别让人错过这 30 秒 */
@keyframes btn-pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-tint); }
  50%      { box-shadow: 0 0 0 6px var(--accent-tint); }
}
.btn--pulse { animation: btn-pulse 1.6s ease-in-out infinite; }

/* 进度条本身是信息不是装饰，减弱动效时也留着；闪烁的那个才关掉 */
@media (prefers-reduced-motion: reduce) {
  .btn--pulse { animation: none; }
}

/* —— 平板 1024×768 横屏（设计稿 1f）：棋谱收窄 —— */
@media (max-width: 1180px) {
  .game-cols { grid-template-columns: 220px minmax(0, 1fr) 180px; gap: 20px; }
}

/* —————————————— 聊天（设计稿 1c 右栏） —————————————— */

.chat-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.chat-head .muted { font-size: 12px; }

.chat-list {
  flex: 1;
  min-height: 180px;
  max-height: 46vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 6px 2px;
  scrollbar-width: thin;
}

.chat-msg { display: grid; grid-template-columns: 28px 1fr; gap: 8px; align-items: start; }
.chat-msg[data-role="spectator"] { opacity: .78; }
.chat-body { min-width: 0; }
.chat-who { font-size: 11px; margin-bottom: 2px; }
.chat-text {
  font-size: 13px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  padding: 6px 9px;
  border-radius: 8px;
  background: var(--surface);
}
.chat-msg[data-role="spectator"] .chat-text { background: none; padding: 0; }

.chat-sys {
  font-size: 11.5px;
  text-align: center;
  padding: 3px 0;
}

.chat-phrases { display: flex; flex-wrap: wrap; gap: 5px; }
.chat-phrases .btn { padding: 4px 9px; font-size: 12px; }

.chat-input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 9px;
  background: var(--surface);
  font-size: 13px;
}
.chat-input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }

.chat-note { font-size: 11px; margin: 0; line-height: 1.5; }

/* 请求横幅里的按钮 */
.game-banner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.game-banner .btn { margin-left: auto; }
.game-banner .btn + .btn { margin-left: 0; }

/* 三栏：左信息 / 中棋盘 / 右聊天 */
.game[data-cols="3"] .game-cols { grid-template-columns: 268px minmax(0, 1fr) 268px; }
/* 人机对局无聊天栏：两栏，并收窄整体宽度让版面回到居中 */
.game[data-cols="2"] { max-width: 1000px; }
.game[data-cols="2"] .game-cols { grid-template-columns: 250px minmax(0, 1fr); }
.game[data-cols="2"] .game-board-host { max-width: 620px; margin: 0 auto; }
@media (max-width: 1180px) {
  .game[data-cols="3"] .game-cols { grid-template-columns: 226px minmax(0, 1fr) 226px; gap: 18px; }
  .game[data-cols="2"] .game-cols { grid-template-columns: 210px minmax(0, 1fr); gap: 18px; }
}


/* ————————————————————————————————————————————————————————————
   手机布局（设计稿 1e）
   顺序：对手条 → 棋盘 → 自己条 → 操作条 → 棋谱 → 聊天抽屉

   左栏用 display:contents 摊平，让它的子元素直接参与外层排序 ——
   否则对手条与自己条同在一个容器里，CSS 无法把棋盘插到两者之间。
   ———————————————————————————————————————————————————————————— */
@media (max-width: 860px) {
  .game { padding: 10px 12px 0; }
  .game-head { padding-bottom: 10px; }
  .game-meta { display: none; }          /* 规则文字在窄屏是噪音 */

  .game-cols {
    display: flex;
    flex-direction: column;
    /* 必须覆盖桌面版的 align-items: start —— 否则 flex 项不拉伸，
       棋盘会塌成内容宽度（实测只有 166px） */
    align-items: stretch;
    gap: 10px;
    padding-top: 12px;
    /* 给底部聊天抽屉留位。抽屉收起时高 56px，但带 home 指示条的机型
       还要再让出安全区，写死 68px 在这些机型上会被压住 */
    padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }

  .game-left { display: contents; }
  .game-left > .hr { display: none; }

  .pc[data-slot="top"]    { order: 1; }
  .game-center            { order: 2; }
  .pc[data-slot="bottom"] { order: 3; }
  .game-ops               { order: 4; }
  .game-ops-note          { order: 4; }
  .record                 { order: 5; }
  .game-right             { order: 6; }

  /* 玩家条压成一行，别换行挤成两行 */
  .pc { padding: 6px 8px; gap: 9px; }
  .pc-top { flex-wrap: nowrap; min-width: 0; }
  .pc-color { white-space: nowrap; }
  .pc-clock { font-size: 14px; }
  .pc .avatar--lg { width: 30px; height: 30px; font-size: 13px; }

  .game-center { gap: 8px; }
  .game-board-host { max-width: none; }
  .game-hint { font-size: 12px; min-height: 17px; }

  /* 四个按钮排成一行时，390px 屏上每个只剩约 85px 宽、36px 高：
     「悔棋 · 剩 3」装不下要换行，高度也低于 44px 的触摸目标下限，
     结果就是点不中。改成 2×2，宽度翻倍，高度给足。 */
  .game-ops {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .game-ops .btn {
    min-height: 44px;
    padding: 10px 8px;
    font-size: 13px;
    white-space: nowrap;
    /* 发丝框现在由 base.css 全局给了。这一排是对局里最要紧的操作，
       手机上再叠一层底色，让它比页面上其它按钮更实一点 */
    background: var(--surface);
  }

  /* 棋谱在手机上折成横向滚动条，不吃首屏高度 */
  .record { display: flex; align-items: center; gap: 10px; min-width: 0; }
  .record-head { flex: none; }
  .record-head .act-title { font-size: 12px; }
  .record-list {
    display: flex;
    gap: 6px;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 2px;
  }
  .record-row {
    flex: none;
    border-bottom: 0;
    padding: 3px 7px;
    border-radius: 6px;
    background: var(--surface);
    gap: 5px;
  }

  /* 横幅上的「同意 / 拒绝」按 .btn--sm 只有约 28px 高，
     手指点不准；12 秒就超时的东西更不能让人点两次 */
  .game-banner {
    padding: 12px;
    gap: 8px;
  }
  .game-banner .btn {
    flex: 1;
    margin-left: 0;      /* 桌面版把按钮推到右边，手机上改成平分 */
    min-height: 44px;
    padding: 10px 16px;
    font-size: 14px;
  }
  .game-banner > span {
    flex: 1 0 100%;      /* 文案独占一行，按钮才有地方摊开 */
  }

  /* —— 聊天做成底部抽屉 —— */
  .game-right {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    gap: 0;
    padding: 0 12px env(safe-area-inset-bottom, 8px);
    background: var(--bg);
    border-top: 1px solid var(--hairline-strong);
    box-shadow: 0 -8px 24px -18px rgba(15, 42, 63, .6);
    max-height: 56px;
    overflow: hidden;
    transition: max-height .22s ease-out;
  }
  .game-right.is-open { max-height: 72vh; }

  .chat-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 16px 2px 12px;
    text-align: left;
  }
  .chat-preview {
    flex: 1;
    font-size: 12.5px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .chat-unread {
    flex: none;
    min-width: 18px; height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--accent);
    color: var(--on-accent);
    font: 600 11px/18px var(--font-mono);
    text-align: center;
  }
  .chat-toggle::after {
    content: '';
    flex: none;
    width: 8px; height: 8px;
    margin-right: 4px;
    border-right: 1.5px solid var(--muted);
    border-bottom: 1.5px solid var(--muted);
    transform: rotate(-135deg);
    transition: transform .22s;
  }
  .game-right.is-open .chat-toggle::after { transform: rotate(45deg); }

  .chat-head, .chat-list, .chat-phrases, .chat-input, .chat-note { display: none; }
  .game-right.is-open .chat-head,
  .game-right.is-open .chat-list,
  .game-right.is-open .chat-phrases,
  .game-right.is-open .chat-input { display: flex; }
  .game-right.is-open .chat-head { display: flex; padding-bottom: 6px; }
  .game-right.is-open .chat-list { max-height: 38vh; margin-bottom: 8px; }
  .game-right.is-open .chat-phrases { margin-bottom: 8px; }
  .game-right.is-open .chat-input { display: block; margin-bottom: 10px; }
}

/* 桌面端不需要抽屉开关 */
@media (min-width: 861px) {
  .chat-toggle { display: none; }
}

/* 「标号」开关贴在棋谱标题右侧，开着时用主色点亮 */
.record-numbers { margin-left: auto; flex: none; }
.record-numbers[data-on="true"] { background: var(--accent-tint); color: var(--accent); font-weight: 600; }

/* —— 悔棋：挑一手重下 —— */
.undo-note { margin: 0 0 10px; font-size: 12.5px; }
.undo-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 46vh;
  overflow-y: auto;
  border-top: 1px solid var(--hairline);
}
.undo-row {
  display: grid;
  grid-template-columns: 32px 12px 46px 1fr;
  align-items: center;
  gap: 10px;
  width: 100%;
  /* 44px 是触摸目标下限。棋谱行本来只有 24px 高，直接复用会点不中 */
  min-height: 44px;
  padding: 0 6px;
  border: 0;
  border-bottom: 1px solid var(--hairline);
  background: none;
  color: inherit;
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.undo-row:hover, .undo-row:focus-visible { background: var(--accent-tint); }
.undo-hint { font-size: 11.5px; text-align: right; }

/* ————————————————————————————————————————————————————————————
   小屏：棋盘通栏
   来自用户反馈「希望手机上棋盘能再大一点」。

   棋盘是正方形，宽度就是它的上限 —— 高度再富余也没用，
   所以能加的只有两侧那点留白。页面左右各 12px 的内边距，
   在别的元素上是必要的呼吸感，在棋盘上是纯损失：390px 屏
   格线区只有 343px。这里让棋盘单独顶到屏幕边，格线区 366px。

   自身 3.1% 的内边距不动。最外圈的棋子有一半压在边线之外，
   这圈内边距装的就是那半颗子，收窄会把边上的子切掉。
   ———————————————————————————————————————————————————————————— */
@media (max-width: 560px) {
  /* 选择器必须带上 [data-cols]。人机对局那条 .game[data-cols="2"]
     .game-board-host 里有 margin:0 auto，权重比裸类名高，会把下面的
     负边距整个吃掉 —— 实测棋盘只往右长 12px，撑出一条横向滚动。 */
  .game[data-cols] .game-board-host {
    /* 父级 .game-center 是 align-items:center，外边距抵掉多出的宽度后
       外边距盒仍等于容器宽，边框盒正好各向外探出 12px —— 不产生横向滚动 */
    width: calc(100% + 24px);
    margin-inline: -12px;
  }
  /* 贴着屏幕边的圆角看起来像被裁掉了，通栏就该是平的。
     注意是 .game-board-host.board 不是后代选择器 —— 棋盘组件挂载时
     把 .board 加在宿主元素自己身上，两个类在同一个元素上。 */
  .game-board-host.board { border-radius: 0; }
}

/* 待确认的落子提示。用琥珀，和预览子那圈虚线是同一个颜色语言 ——
   看到虚线圈的人，视线扫到这句话时不用再建立一次联系 */
.game-hint[data-confirm="true"] {
  color: var(--amber);
  font-weight: 600;
}

/* ————————————————————————————————————————————————————————————
   管理员模式
   
   用印，不用闪电也不用齿轮。后两者是通用后台的语言，跟五子棋没关系；
   而印是这个世界里本来就有的东西 —— 棋谱要落款，棋士有名号。一点朱红
   压在暖木色旁边，不用任何图标说明就读得出「权柄」。

   朱红是这套界面里唯一一处高饱和，刻意的：它必须一眼认得出，
   而且普通玩家永远看不到它，不存在打扰谁的问题。
   ———————————————————————————————————————————————————————————— */

.sup { position: relative; }

.sup-seal {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 5px;
  /* 印泥的红。不用 --danger：那是「危险」，这是「权柄」，两种语气 */
  background: #A8352A;
  color: #FBF3E6;
  font: 600 15px/1 var(--font-serif);
  /* 印面的凹凸感：上缘受光，下缘压深 */
  box-shadow: inset 0 1px 0 rgba(255, 235, 210, .38),
              inset 0 -1px 0 rgba(0, 0, 0, .28),
              0 1px 3px rgba(90, 20, 14, .4);
  transition: transform .12s, box-shadow .12s;
}
.sup-seal:hover { transform: translateY(-1px); }
.sup-seal:active { transform: translateY(0); }
.sup-seal[data-open="true"] { box-shadow: inset 0 0 0 2px #FBF3E6, 0 1px 3px rgba(90, 20, 14, .4); }
/* 天眼开着时印章持续呼吸，提醒自己还挂着外挂 */
.sup-seal[data-active="true"]::after {
  content: '';
  position: absolute; inset: -3px;
  border-radius: 7px;
  border: 1px solid #A8352A;
  animation: supPulse 2.2s ease-in-out infinite;
}
@keyframes supPulse { 0%, 100% { opacity: .25; } 50% { opacity: .9; } }

.sup-body {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  width: 236px;
  padding: 10px;
  border-radius: 10px;
  background: var(--bg);
  box-shadow: inset 0 0 0 1px var(--hairline-strong), 0 12px 30px -12px rgba(0, 0, 0, .5);
  display: grid;
  gap: 4px;
}
.sup-hint {
  margin: 0 0 4px;
  padding: 0 6px;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--muted);
}

.sup-act {
  display: grid;
  gap: 1px;
  padding: 8px 10px;
  border-radius: 7px;
  text-align: left;
  transition: background-color .15s;
}
.sup-act:hover:not(:disabled) { background: var(--surface); }
.sup-act:disabled { opacity: .45; }
.sup-act:focus-visible { outline: 2px solid #A8352A; outline-offset: -2px; }
.sup-act-t { font-size: 13.5px; font-weight: 600; }
.sup-act-n { font-size: 11.5px; color: var(--muted); }
/* 开着的那一项用朱红点出来，和印章同色 */
.sup-act[data-on="true"] .sup-act-t { color: #C4502E; }
.sup-act[data-on="true"] .sup-act-t::after {
  content: '·  开';
  margin-left: 6px;
  font-size: 11px;
  font-weight: 500;
}

/* 棋盘上的推荐点。琥珀圈已经被「最后一手」占了，这里用朱红十字准星 —— 
   形状不同，两者同时出现也分得清 */
.board-mark {
  position: absolute;
  width: 9%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 1.5px solid #C4502E;
  z-index: 4;
  pointer-events: none;
  animation: supMark 1.6s ease-in-out infinite;
}
.board-mark::before, .board-mark::after {
  content: '';
  position: absolute;
  background: #C4502E;
}
.board-mark::before { left: 50%; top: -34%; width: 1.5px; height: 168%; margin-left: -.75px; }
.board-mark::after { top: 50%; left: -34%; height: 1.5px; width: 168%; margin-top: -.75px; }
@keyframes supMark { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .sup-seal[data-active="true"]::after { animation: none; opacity: .9; }
  .board-mark { animation: none; opacity: 1; }
}

/* 手机上面板改成贴着右边缘的全宽卡，236px 在 360px 屏上会顶出去 */
@media (max-width: 420px) {
  .sup-body { width: min(236px, calc(100vw - 32px)); }
}

/* ————————————————————————————————————————————————————————————
   复盘播放器
   
   左棋盘右棋谱。棋谱是主角之一 —— 一局下完之后人想知道的不是谁赢了
   （结算已经说了），而是哪一手开始不对，所以棋谱要能扫、能点、
   还要看得见每手花了多久。
   ———————————————————————————————————————————————————————————— */

.rp-sub { margin: 0 0 14px; font-size: 13px; }

.rp-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 216px;
  gap: 20px;
  align-items: start;
}
.rp-board { width: 100%; }
.rp-side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.rp-at {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  min-height: 20px;
}
.rp-note { margin: 0; font-size: 11.5px; line-height: 1.6; }

.rp-ctrl { display: flex; flex-wrap: wrap; gap: 6px; }
.rp-ctrl .btn { flex: 1 1 auto; justify-content: center; }

.rp-list {
  list-style: none;
  margin: 0; padding: 0;
  max-height: 42vh;
  overflow-y: auto;
}
.rp-row {
  display: grid;
  /* 第四列是每手用时。老对局没有这个数据时那个 span 根本不渲染，
     auto 不占宽，行自动回到三列的样子 */
  grid-template-columns: 26px 10px 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 6px;
  border-radius: 6px;
  text-align: left;
  font-size: 12.5px;
  transition: background-color .15s;
}
.rp-row:hover { background: var(--surface); }
.rp-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.rp-row[data-now="true"] { background: var(--accent-tint); color: var(--accent); font-weight: 600; }
.rp-n { color: var(--muted); font-size: 11px; }
.rp-gap { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rp-row[data-now="true"] .rp-gap { color: var(--accent); }
/* 全局最久的一手。一局棋里真正的决策点通常就是它 */
.rp-row[data-slow="true"] .rp-gap { color: var(--amber); font-weight: 600; }

/* 手机上棋盘在上、棋谱在下，棋谱压矮免得整屏都是列表 */
@media (max-width: 700px) {
  .rp-wrap { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .rp-list { max-height: 30vh; }
}
