/* ============================================================
   弹弹棋 · 与小游戏柜主页同一套设计语言
   纸灰底 / 藏青墨 / 暖木奶咖点缀 / 2px 硬边 + 大圆角 + 轻硬阴影
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --paper:      #eaf0f1;   /* 主页纸灰底 */
  --paper-deep: #dde7e9;
  --white:      #fbfcf9;   /* 卡片纸白 */
  --panel:      #fbfcf9;   /* 面板纸白 */
  --ink:        #173246;   /* 主页藏青墨 */
  --muted:      #5d7481;   /* 次要文字 */
  --line:       rgba(23,50,70,.16);
  --red:        #e15d44;   /* 主页品牌橘红：红方 */
  --red-puck:   #cf5a45;
  --red-deep:   #c24a33;
  --blue:       #4078ab;   /* 棋子蓝：蓝方 */
  --blue-soft:  #5787af;
  --blue-deep:  #2f5d85;
  --yellow:     #e3b44e;   /* 主页四格品牌色 */
  --green:      #6b9679;
  --ice:        #3e95c4;   /* 冰川蓝：棋盘主色 */
  --ice-deep:   #1d6a96;

  --font-sans: "Noto Sans SC", -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;

  --shadow:      5px 5px 0 rgba(23,50,70,.13);
  --shadow-lg:   9px 9px 0 rgba(23,50,70,.12);
}

html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  color: var(--ink);
  background-color: var(--paper);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 20px 14px 24px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.app {
  width: 100%;
  max-width: min(620px, max(280px, calc((100dvh - 200px) * 760 / 940)));
}

/* 入场：错峰浮现 */
.topbar    { animation: rise .5s .02s ease-out both; }
.hud       { animation: rise .5s .10s ease-out both; }
.board-wrap{ animation: rise .55s .18s ease-out both; }
.hint      { animation: rise .5s .30s ease-out both; }
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- 主页同款细点纸纹 ---------- */
.grain {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  opacity: .24;
  background-image: radial-gradient(#9ab1b6 .7px, transparent .7px);
  background-size: 13px 13px;
}

/* ---------- 顶栏（品牌标识与主页一致） ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 2px 2px 0;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  line-height: 1;
  text-decoration: none;
  color: var(--ink);
}
.logo-mark {
  width: 30px; height: 30px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 3px;
  transform: rotate(-11deg);
  transition: transform .2s ease;
  flex: none;
}
.logo:hover .logo-mark { transform: rotate(-11deg) scale(1.08); }
.logo-mark i { display: block; border-radius: 3px; background: var(--red); }
.logo-mark i:nth-child(2) { background: var(--yellow); }
.logo-mark i:nth-child(3) { background: var(--blue-soft); }
.logo-mark i:nth-child(4) { background: var(--green); }
.logo-zh {
  font-weight: 900;
  font-size: 23px;
  letter-spacing: -.01em;
  color: var(--ink);
}
.logo-en {
  display: block;
  margin-top: 3px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 2.6px;
  color: var(--muted);
}

.top-actions { display: flex; gap: 9px; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 12px;
  border: 2px solid var(--ink);
  background: var(--white);
  color: var(--ink);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 3px 3px 0 rgba(23,50,70,.16);
  transition: transform .08s, box-shadow .08s, background .12s, color .12s;
}
.icon-btn:hover { background: var(--ink); color: var(--white); }
.icon-btn:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 rgba(23,50,70,.16); }
.icon-btn.muted .sound-wave { opacity: .25; }

/* ---------- 计分牌 ---------- */
.hud {
  display: flex;
  align-items: stretch;
  margin-bottom: 14px;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background: var(--white);
  box-shadow: var(--shadow);
  overflow: visible;
}

.player-card {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
}
.player-card.ai  { border-right: 2px solid var(--ink); }
.player-card.you { flex-direction: row-reverse; text-align: right; }

.player-name {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--muted);
  line-height: 1.25;
  white-space: nowrap;
  flex: none;
}
.player-card.ai .player-name::before  { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--red-puck); margin-right: 6px; vertical-align: 1px; }
.player-card.you .player-name::after { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--blue); margin-left: 6px; vertical-align: 1px; }

.player-count {
  font-weight: 900;
  font-size: 34px;
  line-height: .95;
  min-width: 32px;
  text-align: center;
  color: var(--ink);
}
.player-card.ai .player-count  { color: var(--red-puck); }
.player-card.you .player-count { color: var(--blue); }

.pips { display: flex; flex-wrap: wrap; gap: 5px; }
.player-card.you .pips { justify-content: flex-end; }

.pip {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: transparent;
  border: 2px solid var(--ink);
  transition: background .18s, transform .18s, border-color .18s;
}
.pip.on-red  { background: var(--red-puck);  border-color: var(--red-deep); }
.pip.on-blue { background: var(--blue); border-color: var(--blue-deep); }
.pip.pop { transform: scale(1.4) rotate(90deg); }

.vs {
  align-self: center;
  width: 38px; height: 38px;
  margin: 0 -21px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  border: 2px solid var(--ink);
  font-weight: 900;
  font-size: 12px;
  letter-spacing: .04em;
  display: flex; align-items: center; justify-content: center;
  z-index: 2;
  flex: none;
}

/* ---------- 棋盘（白纸卡托 + 冰川蓝球场） ---------- */
.board-wrap {
  position: relative;
  width: 100%;
  margin: 0 auto;
  padding: 15px;
  border-radius: 22px;
  border: 2px solid var(--ink);
  background: var(--white);
  box-shadow: var(--shadow-lg);
}
.board-inner {
  position: relative;
  border-radius: 15px;
  border: 2px solid rgba(29, 106, 150, .5);
  overflow: hidden;
  background: var(--ice);
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 760 / 940;
  touch-action: none;
  cursor: pointer;
}
#fx {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
}

/* ---------- 遮罩与面板 ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  background: rgba(234,240,241,.84);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  transition: opacity .28s;
  z-index: 4;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.overlay { scrollbar-width: none; }
.overlay::-webkit-scrollbar { display: none; }

.panel {
  width: min(540px, 100%);
  margin: auto;
  background: var(--panel);
  border: 2px solid var(--ink);
  border-radius: 20px;
  padding: 26px 28px 24px;
  box-shadow: var(--shadow-lg);
  animation: panelIn .38s cubic-bezier(.2,.9,.25,1) both;
}
.panel.hidden { display: none; }
@keyframes panelIn {
  from { opacity: 0; transform: translateY(20px) scale(.975); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.panel-kicker {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .14em;
  color: var(--ice-deep);
  margin-bottom: 10px;
}
.panel-title {
  font-weight: 900;
  font-size: clamp(34px, 9vw, 42px);
  letter-spacing: -.03em;
  line-height: 1.12;
  color: var(--ink);
}
.panel-title::after {
  content: "";
  display: block;
  width: 48px; height: 7px;
  border-radius: 4px;
  background: var(--red);
  margin-top: 12px;
}
#overPanel[data-winner="p2"] .panel-title::after { background: var(--red); }
#overPanel[data-winner="p1"] .panel-title::after { background: var(--blue); }

.panel-sub {
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.65;
}

/* 分段选择器 */
.mode-label, .diff-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 16px 0 8px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .08em;
  color: var(--ink);
}
.mode-label em, .diff-label em {
  font-style: normal;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--muted);
}

.mode-group, .diff-group {
  display: flex;
  border: 2px solid var(--ink);
  border-radius: 12px;
  overflow: hidden;
  background: var(--white);
}
.mode-btn, .diff-btn {
  flex: 1;
  padding: 11px 0;
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .1em;
  cursor: pointer;
  transition: background .13s, color .13s;
}
.mode-btn + .mode-btn, .diff-btn + .diff-btn { box-shadow: inset 2px 0 0 var(--ink); }
.mode-btn:hover, .diff-btn:hover { background: rgba(23,50,70,.06); }
.mode-btn.selected, .diff-btn.selected { background: var(--ink); color: var(--white); }
.mode-btn.selected:hover, .diff-btn.selected:hover { background: var(--ink); }
#modeGroup .mode-btn { font-size: 13px; letter-spacing: .04em; white-space: nowrap; }
#diffWrap.hidden { display: none; }

.online-link { display: flex; gap: 8px; margin: 22px 0 14px; }
.online-link.hidden, .online-bar.hidden, .online-actions .hidden { display: none; }
.online-link input { min-width: 0; flex: 1; border: 2px solid var(--ink); border-radius: 10px; padding: 10px 12px; font: 700 12px var(--font-sans); color: var(--ink); background: var(--white); }
.online-link button, .online-bar button { border: 2px solid var(--ink); border-radius: 10px; padding: 9px 12px; background: var(--white); color: var(--ink); font: 800 12px var(--font-sans); cursor: pointer; white-space: nowrap; }
.online-actions { display: flex; gap: 12px; margin-top: 18px; }
.online-actions .btn-primary, .online-actions .btn-ghost { flex: 1; width: auto; font-size: 13px; letter-spacing: .06em; }
.room-notice { margin: 18px 0; padding: 10px 12px; border: 2px solid var(--blue); border-radius: 10px; background: rgba(64,120,171,.09); color: var(--blue-deep); font: 700 12px/1.6 var(--font-sans); }
.room-notice.hidden, .room-exit.hidden { display: none; }
.room-exit { width: 100%; margin-top: 12px; font-size: 13px; }
.online-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; margin: 10px 0 0; padding: 8px 12px; border: 2px solid var(--ink); border-radius: 12px; background: var(--white); color: var(--ink); font: 800 12px var(--font-sans); }

/* 简则 */
.rules-mini {
  list-style: none;
  margin: 15px 0 0;
  border-top: 2px dashed var(--line);
  padding-top: 11px;
}
.rules-mini li {
  position: relative;
  padding: 5px 0 5px 20px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted);
}
.rules-mini li::before {
  content: "";
  position: absolute;
  left: 1px; top: 12px;
  width: 8px; height: 8px;
  border-radius: 2px;
  background: var(--ink);
  transform: rotate(45deg);
}
.rules-mini li:nth-child(even)::before { background: var(--red); }
.rules-mini b { color: var(--ink); font-weight: 800; }

/* 按钮 */
.btn-primary {
  width: 100%;
  border: 2px solid var(--ink);
  border-radius: 12px;
  cursor: pointer;
  padding: 13px 24px;
  background: var(--ink);
  color: var(--white);
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .14em;
  text-align: center;
  box-shadow: 4px 4px 0 rgba(23,50,70,.2);
  transition: transform .09s, box-shadow .09s, background .13s, border-color .13s;
}
#btnStart { margin-top: 18px; }
.btn-primary:hover { background: var(--red); border-color: var(--red-deep); }
.btn-primary:active { transform: translate(3px,3px); box-shadow: 1px 1px 0 rgba(23,50,70,.2); }
.btn-primary:disabled {
  background: var(--paper-deep);
  border-color: var(--muted);
  color: var(--muted);
  box-shadow: none;
  cursor: default;
}

.btn-ghost {
  cursor: pointer;
  padding: 13px 20px;
  flex: 1;
  border-radius: 12px;
  border: 2px solid var(--ink);
  background: var(--white);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .16em;
  transition: background .13s, color .13s, transform .09s;
}
.btn-ghost:hover { background: var(--ink); color: var(--white); }
.btn-ghost:active { transform: translate(2px,2px); }

.over-actions { display: flex; gap: 12px; margin-top: 24px; }
.over-actions .btn-primary { flex: 1; }

/* ---------- 回合横幅（胶囊条） ---------- */
.turn-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  padding: 8px 20px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .08em;
  color: var(--ink);
  background: var(--white);
  box-shadow: 3px 3px 0 rgba(23,50,70,.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  white-space: nowrap;
  z-index: 5;
}
.turn-banner::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 9px;
  vertical-align: 1px;
  background: var(--ink);
}
.turn-banner.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.turn-banner.you  { background: var(--blue); border-color: var(--blue-deep); color: #fff; }
.turn-banner.you::before  { background: #fff; }
.turn-banner.ai   { background: var(--red); border-color: var(--red-deep); color: #fff; }
.turn-banner.ai::before   { background: #fff; }
.turn-banner.wait { background: var(--ink); color: var(--white); }
.turn-banner.wait::before { background: var(--yellow); }

/* ---------- 倒计时 ---------- */
.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 150px;
  letter-spacing: -.04em;
  text-align: center;
  color: var(--ink);
  text-shadow: 6px 6px 0 rgba(225,93,68,.4);
  pointer-events: none;
  z-index: 6;
}
.countdown.hidden { display: none; }
.countdown.pop { animation: countPop .4s cubic-bezier(.2,.9,.3,1.2); }
@keyframes countPop {
  0%   { transform: scale(.4) rotate(-4deg); opacity: 0; }
  55%  { transform: scale(1.12) rotate(1deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.hint {
  margin-top: 13px;
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: .04em;
}
.hint::before {
  content: "TIP · ";
  font-weight: 800;
  letter-spacing: .08em;
  color: var(--red);
}
.hint-touch { display: none; }
@media (pointer: coarse) {
  .hint-desktop { display: none; }
  .hint-touch { display: inline; }
}

/* ---------- 规则弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(23,50,70,.34);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 80;
  animation: fadeIn .2s ease-out both;
}
.modal-mask.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: min(520px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--panel);
  border: 2px solid var(--ink);
  border-radius: 20px;
  padding: 28px 30px 26px;
  box-shadow: 12px 12px 0 rgba(23,50,70,.18);
  animation: panelIn .32s cubic-bezier(.2,.9,.25,1) both;
}
.modal-kicker {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .14em;
  color: var(--ice-deep);
  margin-bottom: 8px;
}
.modal h3 {
  font-weight: 900;
  color: var(--ink);
  font-size: 27px;
  letter-spacing: -.02em;
  margin-bottom: 18px;
}
.modal h3::after {
  content: "";
  display: block;
  width: 44px; height: 6px;
  border-radius: 3px;
  background: var(--red);
  margin-top: 10px;
}
.rules-full {
  list-style: none;
  counter-reset: rule;
}
.rules-full li {
  counter-increment: rule;
  position: relative;
  padding: 0 0 13px 40px;
  font-size: 13.5px;
  line-height: 1.72;
  color: var(--muted);
}
.rules-full li::before {
  content: counter(rule, decimal-leading-zero);
  position: absolute;
  left: 0; top: 1px;
  font-weight: 900;
  font-size: 17px;
  color: var(--red);
  letter-spacing: -.02em;
}
.rules-full li:nth-child(even)::before { color: var(--blue); }
.rules-full b { color: var(--ink); font-weight: 800; }
.modal .btn-primary { display: block; margin: 10px auto 0; width: auto; padding: 13px 44px; }
.modal .btn-primary::after { content: none; }

/* ---------- 焦点可见性（与主页一致） ---------- */
.logo:focus-visible,
.icon-btn:focus-visible,
.mode-btn:focus-visible,
.diff-btn:focus-visible,
.btn-primary:focus-visible,
.btn-ghost:focus-visible,
.online-link button:focus-visible,
.online-bar button:focus-visible {
  outline: 3px solid var(--red);
  outline-offset: 3px;
}

/* ---------- 移动端 ---------- */
@media (max-width: 560px) {
  body { padding: 12px 8px 16px; }
  .logo-zh { font-size: 20px; }
  .logo-mark { width: 26px; height: 26px; }
  .logo-en { font-size: 8.5px; letter-spacing: 2px; }
  .icon-btn { width: 36px; height: 36px; border-radius: 10px; }
  .player-card { gap: 8px; padding: 9px 11px; }
  .player-name { font-size: 11px; }
  .player-count { font-size: 27px; min-width: 26px; }
  .pip { width: 9.5px; height: 9.5px; }
  .vs { width: 32px; height: 32px; margin: 0 -18px; font-size: 10px; }
  .board-wrap { padding: 9px; border-radius: 18px; }
  .board-inner { border-radius: 11px; }
  .panel { padding: 22px 20px 20px; border-radius: 18px; }
  .countdown { font-size: 100px; }
}

@media (max-height: 820px) {
  /* 短视口优先保证开始按钮可见；完整规则由右上角入口查看。 */
  .rules-mini { display: none; }
  .panel { padding-top: 20px; padding-bottom: 20px; }
}

@media (min-width: 700px) {
  .rules-mini li { white-space: nowrap; }
}

@media (max-height: 560px) and (orientation: landscape) {
  /* 横屏矮视口允许页面滚动，避免棋盘被压缩到难以操作。 */
  .app { max-width: 420px; }
}

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