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

:root {
  --bg: #121213;
  --bg-soft: #1e1e20;
  --border: #3a3a3c;
  --text: #eeeeef;
  --muted: #9a9a9c;
  --green: #538d4e;
  --yellow: #b59f3b;
  --gray: #3a3a3c;
  --accent: #4a90d9;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, sans-serif;
  min-height: 100%;
}

body { padding-bottom: 48px; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.35rem; letter-spacing: 2px; }
.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  width: 36px;
  height: 36px;
  cursor: pointer;
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--bg-soft); }
.topbar-side { display: flex; gap: 8px; }

/* ---------- 联网对战 ---------- */
.battle-panel { max-width: 720px; margin: 14px auto 0; padding: 0 16px; }
.battle-card {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 16px;
  text-align: center;
}
.battle-card h3 { font-size: 1.05rem; margin-bottom: 8px; }
.battle-card .muted-line { color: var(--muted); font-size: 0.85rem; line-height: 1.6; margin: 6px 0; }
.room-code { font-size: 2.2rem; font-weight: bold; letter-spacing: 8px; margin: 10px 0; }
.battle-timer { font-size: 2.2rem; font-weight: bold; font-variant-numeric: tabular-nums; }
.battle-timer.urgent { color: #e5534b; }
.battle-countdown {
  font-size: 3.2rem;
  font-weight: bold;
  margin: 8px 0;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.battle-countdown.pop { animation: cdPop 0.32s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes cdPop {
  0% { transform: scale(1.55); opacity: 0.25; }
  100% { transform: scale(1); opacity: 1; }
}
.battle-sub { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }
.battle-score-big { font-size: 1.6rem; font-weight: bold; margin: 8px 0; }
.battle-hist { font-size: 0.85rem; color: var(--muted); line-height: 1.9; margin: 8px 0; }
.battle-hist .win { color: var(--green); font-weight: bold; }
.battle-row-buttons { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.battle-join-row { display: flex; gap: 8px; justify-content: center; align-items: center; margin-top: 12px; }
#room-input {
  width: 130px;
  padding: 10px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 4px;
  font-size: 1.05rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--text);
}
.opp-progress {
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

/* 对方的打码棋盘 */
.opp-area { max-width: 720px; margin: 24px auto 0; }
.opp-title {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}
.opp-title span { color: var(--text); font-weight: bold; }
.cell.masked { letter-spacing: 1px; font-size: 0.8rem; }
.opp-area .board { opacity: 0.92; }
.battle-warn { color: #e5a93d; font-size: 0.85rem; margin-top: 8px; }
.battle-down {
  border: 1px solid #e5a93d;
  border-radius: 8px;
  background: rgba(229, 169, 61, 0.08);
  padding: 10px 12px;
  margin: 10px 0;
}
.battle-down > strong { color: #e5a93d; }
.battle-down .muted-line { margin: 6px 0 0; }
.battle-down .battle-row-buttons { margin-top: 8px; }
.battle-error { color: #e5534b; font-size: 0.85rem; margin-top: 8px; }

/* ---------- 模式切换 ---------- */
.mode-tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 14px auto 0;
}
.tab {
  background: var(--bg-soft);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 18px;
  font-size: 0.92rem;
  cursor: pointer;
  transition: all 0.15s;
}
.tab.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  font-weight: bold;
}

.status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 10px 0 4px;
  color: var(--muted);
  font-size: 0.9rem;
  min-height: 1.6em;
}
.mode-note {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0 0 4px;
}
.mini-btn {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
}
.mini-btn:hover { background: var(--green); border-color: var(--green); color: #fff; }

/* ---------- 搜索框 ---------- */
.search-wrap {
  position: relative;
  max-width: 460px;
  margin: 8px auto 18px;
  padding: 0 16px;
}
#search {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  background: var(--bg-soft);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 10px;
  outline: none;
}
#search:focus { border-color: var(--accent); }
#search:disabled { opacity: 0.55; cursor: not-allowed; }

.suggestions {
  position: absolute;
  left: 16px;
  right: 16px;
  top: calc(100% + 4px);
  background: #232325;
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 290px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.suggestion {
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}
.suggestion:hover, .suggestion.active { background: #333336; }
.suggestion .cn { font-weight: bold; }
.suggestion .en { color: var(--muted); font-size: 0.82rem; }

/* ---------- 棋盘 ---------- */
.board-outer {
  position: relative;
  max-width: 900px;
  margin: 0 auto;
}
.board-wrap {
  padding: 0 12px;
  overflow-x: auto;
}
.scroll-hint {
  display: none;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 8px;
}
.scroll-fade {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 40px;
  background: linear-gradient(to left, rgba(18, 18, 19, 0.95), rgba(18, 18, 19, 0));
  pointer-events: none;
}
.board { min-width: 680px; }
.row {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr 1.15fr 0.85fr 0.9fr 0.85fr 0.85fr 0.85fr 1fr;
  gap: 5px;
  margin-bottom: 5px;
}
.header-row .cell {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.82rem;
  min-height: auto;
  padding: 2px 4px;
}
.cell {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.88rem;
  padding: 4px 6px;
  word-break: break-all;
  line-height: 1.25;
}
.cell .sub { font-size: 0.72rem; color: rgba(255, 255, 255, 0.75); }
.name-cell { font-weight: bold; }

.cell.g { background: var(--green); border-color: var(--green); color: #fff; }
.cell.y { background: var(--yellow); border-color: var(--yellow); color: #fff; }
.cell.x { background: var(--gray); border-color: var(--gray); color: #ddd; }

/* 翻转揭示动画 */
.cell.reveal {
  animation: flipIn 0.45s ease both;
}
@keyframes flipIn {
  0% { transform: rotateX(90deg); opacity: 0.4; }
  100% { transform: rotateX(0deg); opacity: 1; }
}

/* 前庭敏感用户:关掉翻转和倒计时弹跳,内容照常显示 */
@media (prefers-reduced-motion: reduce) {
  .cell.reveal, .battle-countdown.pop { animation: none; }
}

/* ---------- 图例 ---------- */
.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin: 14px auto 0;
  color: var(--muted);
  font-size: 0.8rem;
}
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 5px;
}
.dot.g { background: var(--green); }
.dot.y { background: var(--yellow); }
.dot.x { background: var(--gray); }

/* ---------- 弹窗 ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal {
  position: relative;
  background: #1f1f22;
  border: 1px solid var(--border);
  border-radius: 14px;
  max-width: 460px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 26px 24px 22px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}
.modal h2 { margin-bottom: 12px; font-size: 1.2rem; }
.modal h3 { margin: 16px 0 8px; font-size: 0.95rem; color: var(--muted); }
.modal p, .modal li { font-size: 0.9rem; line-height: 1.7; margin-bottom: 8px; }
.modal ul { padding-left: 20px; margin-bottom: 8px; }
.modal .muted { color: var(--muted); font-size: 0.82rem; }
.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
}
.modal-close:hover { color: var(--text); }

.chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 5px;
  color: #fff;
  font-size: 0.8rem;
}
.chip.g { background: var(--green); }
.chip.y { background: var(--yellow); }
.chip.x { background: var(--gray); }

/* 统计 */
.stats-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  text-align: center;
}
.stat-box .num { font-size: 1.5rem; font-weight: bold; }
.stat-box .lbl { font-size: 0.72rem; color: var(--muted); }
.stats-dist .dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 0.8rem;
}
.dist-bar {
  background: var(--green);
  border-radius: 4px;
  height: 18px;
  min-width: 24px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6px;
  font-size: 0.75rem;
  color: #fff;
}
.dist-bar.zero { background: var(--gray); }

/* 结算 */
.result-answer {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin: 10px 0 16px;
  font-size: 0.92rem;
  line-height: 1.8;
}
.result-answer .big { font-size: 1.15rem; font-weight: bold; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.action-btn {
  flex: 1;
  padding: 11px 14px;
  font-size: 0.95rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.action-btn.primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: bold; }
.action-btn:hover { filter: brightness(1.12); }
.action-btn[disabled] { opacity: 0.55; cursor: default; filter: none; }
.share-toast {
  margin-top: 10px;
  text-align: center;
  color: var(--green);
  font-size: 0.85rem;
}

/* 更新公告 */
.news-date { color: var(--muted); font-size: 0.8rem; margin-top: -6px; margin-bottom: 12px; }
.news-list { padding-left: 18px; margin: 0; }
.news-list li { font-size: 0.9rem; line-height: 1.8; margin-bottom: 8px; }
.news-link { margin-bottom: 14px; }

/* 昵称弹窗 */
.name-edit-row { display: flex; gap: 8px; margin-top: 12px; }
#name-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  font-size: 1rem;
  background: var(--bg-soft);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 10px;
  outline: none;
}
#name-input:focus { border-color: var(--accent); }
.name-edit-row .action-btn { flex: 0 0 auto; }

/* 天梯排行榜 */
.rank-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.rank-me {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.85rem;
  margin-bottom: 10px;
  line-height: 1.5;
}
.rank-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.rank-row:last-child { border-bottom: none; }
.rank-row .rk { width: 34px; flex: 0 0 auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.rank-row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: bold; }
.rank-row .elo { flex: 0 0 auto; width: 52px; text-align: right; font-weight: bold; font-variant-numeric: tabular-nums; }
.rank-row .sub2 { flex: 0 0 auto; width: 108px; text-align: right; color: var(--muted); font-size: 0.76rem; }
.elo-line { text-align: center; margin: 8px 0; font-size: 0.95rem; }

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  margin: 26px auto 16px;
}
.site-footer a {
  display: inline-block;
  margin-top: 3px;
  color: var(--accent);
  text-decoration: underline;
  word-break: break-all;
}

.hidden { display: none !important; }

/* ---------- 移动端 ---------- */
@media (max-width: 640px) {
  .board { min-width: 780px; }
  .cell { font-size: 0.78rem; min-height: 46px; }
  .topbar h1 { font-size: 1.1rem; }
  .scroll-hint { display: block; }
}
