/* ==========================================================================
   猜词 · Chinese Semantle
   设计原则：
   - 克制的色彩：纸张白 + 墨黑 + 一处暖橙作为强调
   - 字体：系统中文 + 等宽数字
   - 不使用花哨阴影；仅用 1px hairline 与 subtle 灰阶分层
   ========================================================================== */

:root {
  /* 基础色 */
  --bg:           #fafaf7;        /* 米白纸张 */
  --surface:     #ffffff;
  --ink:         #1a1a1a;         /* 主要文字 */
  --ink-2:       #4a4a4a;         /* 次要文字 */
  --ink-3:       #8a8a85;         /* 弱化文字 */
  --line:        #e8e6e0;         /* hairline */
  --line-strong: #d6d2c8;

  /* 单一暖色强调（Semantle 风格的"温度感"）*/
  --accent:      #c2410c;         /* 暖橙 */
  --accent-soft: #fef3eb;
  --accent-line: #f5d4be;

  /* 接近度分档色：克制的渐变 */
  --hot-bg:      #fef3eb;
  --hot-fg:      #c2410c;
  --hot-bar:     #ea580c;

  --warm-bg:     #f7f4ed;
  --warm-fg:     #846a3c;
  --warm-bar:    #c4a268;

  --cold-bg:     #f5f4f0;
  --cold-fg:     #8a8a85;
  --cold-bar:    #c8c5bc;

  /* 字体 */
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: "SF Mono", ui-monospace, "Menlo", "Consolas", monospace;

  /* 尺寸 */
  --max-w: 720px;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* 防止 iOS 横向滚动 + 子元素负 margin 等情况撑出视口 */
  overflow-x: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: transparent;
  color: inherit;
}

input {
  font-family: inherit;
}

.app {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 32px 20px 80px;
  /* 处理 iOS Safari 的 safe-area（notch/灵动岛 / 横屏底栏），
   * 优先尊重 safe-area，至少保证 20px 左右内边距。
   */
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
}

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

/* ---------- gameinfo bar（topbar 下方独立一行：当前游戏的元信息） ---------- */

.gameinfo-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}
/* hidden 属性需要显式 override 自定义 display，否则 display: flex 会覆盖默认 display: none */
.gameinfo-bar[hidden] { display: none; }

.gameinfo-mode {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
  white-space: nowrap;
}

.gameinfo-mode::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-3);
}

.gameinfo-mode.is-random::before { background: var(--accent); }
.gameinfo-mode.is-daily::before  { background: #10b981; }
.gameinfo-mode.is-shared::before { background: #6366f1; }

/* puzzle-badge 推到 gameinfo-bar 最右侧 */
.gameinfo-bar .puzzle-badge {
  margin-left: auto;
}

/* ---------- 加载占位（首屏冷启动期间显示） ---------- */

.loading-placeholder {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}
/* 同 .gameinfo-bar：display: flex 会覆盖 hidden，需显式声明 */
.loading-placeholder[hidden] { display: none; }

.loading-mode {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 12px;
  color: var(--ink-2);
  white-space: nowrap;
}

.loading-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: loading-pulse 1.2s ease-in-out infinite;
}

@keyframes loading-pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50%      { opacity: 1;    transform: scale(1.15); }
}

.loading-tip {
  margin: 0;
  font-size: 13px;
  color: var(--ink-3);
  flex: 1 1 auto;
  min-width: 0;
}

.loading-tip.is-warming {
  /* 超时后变更文案的视觉强调（轻微） */
  color: var(--ink-2);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand h1 {
  font-size: 22px;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-sub {
  color: var(--ink-3);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.topbar-actions input {
  width: 130px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 14px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
}

.topbar-actions input:focus {
  border-color: var(--ink-2);
}

/* ---------- buttons ---------- */

.btn {
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-primary {
  background: var(--ink);
  color: #fff;
}

.btn-primary:hover {
  background: #000;
}

.btn-primary:disabled {
  background: var(--line-strong);
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--line);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface);
  border-color: var(--ink-2);
  color: var(--ink);
}

.btn-ghost:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---------- guess form ---------- */

.guess-section {
  margin-top: 24px;
}

/* ---------- rules card ---------- */

.rules-card {
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-2);
}

.rules-summary {
  list-style: none;          /* 隐藏默认三角 */
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  outline: none;
}

.rules-summary::-webkit-details-marker {
  display: none;             /* Safari 默认三角 */
}

.rules-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.02em;
}

.rules-title::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 12px;
  background: var(--accent);
  border-radius: 2px;
  margin-right: 8px;
  vertical-align: -1px;
}

/* 用纯 CSS 画一个会旋转的小三角 */
.rules-toggle {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--ink-3);
  transition: transform 0.18s ease;
  transform: rotate(-90deg);  /* 折叠时朝右 */
}

.rules-card[open] .rules-toggle {
  transform: rotate(0deg);    /* 展开时朝下 */
}

.rules-list {
  list-style: none;
  margin: 12px 0 2px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rules-list li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.rules-num {
  flex: 0 0 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 16px;
  text-align: center;
  font-weight: 600;
  margin-top: 2px;
}

.rules-text {
  flex: 1;
}

.rules-text strong {
  color: var(--accent);
  font-weight: 600;
}

.guess-form {
  display: flex;
  gap: 8px;
}

.guess-form input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 16px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
}

.guess-form input:focus {
  border-color: var(--ink);
}

.guess-form .btn {
  padding: 12px 24px;
  font-size: 15px;
}

.guess-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  justify-content: center;
}

.guess-actions .btn {
  font-size: 13px;
  padding: 6px 14px;
}

.hint-quota {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  margin-left: 2px;
}

.status-msg {
  margin: 10px 4px 0;
  font-size: 13px;
  color: var(--ink-3);
  min-height: 1.4em;
  text-align: center;
}

.status-msg.error { color: var(--accent); }

/* ---------- history ---------- */

.history-section {
  margin-top: 32px;
}

.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.history-count {
  font-size: 13px;
  color: var(--ink-3);
}

.history-count strong {
  color: var(--ink);
  font-weight: 600;
  font-family: var(--font-mono);
}

.sort-tabs {
  display: flex;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.sort-tab {
  padding: 6px 14px;
  font-size: 13px;
  color: var(--ink-3);
  background: var(--surface);
  border-right: 1px solid var(--line);
  transition: background 0.15s, color 0.15s;
}

.sort-tab:last-child {
  border-right: none;
}

.sort-tab.is-active {
  background: var(--ink);
  color: #fff;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.history-row {
  display: grid;
  grid-template-columns: 32px 1fr 80px 140px 56px;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.history-row.is-pinned {
  background: var(--accent-soft);
  border-bottom-color: var(--accent-line);
  border-radius: var(--radius);
  margin-bottom: 4px;
  padding: 12px 10px;
  border: 1px solid var(--accent-line);
}

.history-row.is-target {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.history-row.is-target .col-rank,
.history-row.is-target .col-pct {
  color: #fff;
}

.col-order {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-3);
  text-align: right;
}

.col-word {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.col-word .player {
  font-size: 11px;
  color: var(--ink-3);
  font-weight: 400;
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 3px;
}

.col-word .hint-badge {
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--ink-3);
  font-weight: 400;
  background: transparent;
  border: 1px solid var(--line);
  padding: 0 5px;
  border-radius: 3px;
  line-height: 1.4;
}

.history-row.is-target .col-word .player {
  color: rgba(255,255,255,0.8);
  background: rgba(255,255,255,0.15);
}

.col-pct {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-2);
  text-align: right;
}

.col-bar {
  height: 6px;
  background: var(--cold-bg);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.col-bar > span {
  display: block;
  height: 100%;
  background: var(--cold-bar);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.col-bar.warm > span { background: var(--warm-bar); }
.col-bar.hot  > span { background: var(--hot-bar); }

.col-rank {
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: right;
  color: var(--ink-3);
}

.col-rank.warm { color: var(--warm-fg); }
.col-rank.hot  { color: var(--hot-fg); font-weight: 600; }

/* ---------- finish ---------- */

.finish-banner {
  margin-top: 32px;
  padding: 24px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius);
  text-align: center;
}

.finish-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--accent);
}

/* 放弃路径：降调为中性灰，避免暖橙喜庆色与"遗憾"语义冲突 */
.finish-banner.is-give-up {
  background: var(--bg);
  border-color: var(--line);
}
.finish-title.is-give-up {
  color: var(--ink-2);
}

.finish-detail {
  font-size: 14px;
  color: var(--ink-2);
  margin: 0 0 16px;
}

/* ---------- footer ---------- */

.footer {
  margin-top: 48px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-3);
  text-align: center;
}
.footer a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--line);
  transition: color 0.15s, border-color 0.15s;
}
.footer a:hover {
  color: var(--ink-1);
  border-bottom-color: var(--ink-3);
}
.footer-sep {
  margin: 0 8px;
  color: var(--line-strong);
}

/* ---------- puzzle code badge ---------- */

.puzzle-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s, background 0.15s;
}
.puzzle-badge:hover {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}
.puzzle-badge-label {
  font-size: 11px;
  color: var(--ink-3);
}
.puzzle-badge-code {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.04em;
}

/* ---------- leaderboard ---------- */

.leaderboard-card {
  margin-top: 14px;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* 折叠：与 .rules-card 同一交互模式 */
.leaderboard-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  outline: none;
}
.leaderboard-summary::-webkit-details-marker { display: none; }

.leaderboard-head-left {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
}

.leaderboard-details[open] .leaderboard-body {
  margin-top: 10px;
}
.leaderboard-details .rules-toggle { transform: rotate(-90deg); }
.leaderboard-details[open] .rules-toggle { transform: rotate(0deg); }

.leaderboard-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.02em;
}
.leaderboard-title::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 12px;
  background: var(--accent);
  border-radius: 2px;
  margin-right: 8px;
  vertical-align: -1px;
}
.leaderboard-meta {
  font-size: 12px;
  color: var(--ink-3);
}
.leaderboard-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.leaderboard-row {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 13px;
  border-top: 1px dashed var(--line);
}
.leaderboard-row:first-child { border-top: 0; }
.lb-rank {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-3);
  text-align: center;
}
.lb-rank-1 { color: var(--accent); }
.lb-rank-2, .lb-rank-3 { color: var(--ink-2); }
.lb-name {
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-2);
}
.leaderboard-empty {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--ink-3);
}

/* ---------- submit score box ---------- */

.submit-score-box {
  margin: 14px 0 6px;
  padding: 12px 14px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius);
}
.submit-score-tip {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--ink-2);
}
.submit-score-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-wrap: wrap;
}
.submit-score-row input {
  flex: 1 1 160px;
  min-width: 0;
  padding: 8px 10px;
  font-size: 14px;
  font-family: var(--font-sans);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}
.submit-score-row input:focus {
  outline: none;
  border-color: var(--accent);
}
.submit-score-msg {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--ink-2);
  min-height: 1em;
}
.submit-score-msg.error {
  color: var(--accent);
}

/* ---------- finish actions ---------- */

.finish-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* ---------- topbar nav (icon buttons) ---------- */

.topbar-left {
  display: flex;
  align-items: center;
}

.topbar-nav {
  display: flex;
  gap: 6px;
  align-items: center;
  flex: 1 1 auto;
  justify-content: center;
}

.btn-nav {
  position: relative;
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0;          /* 按钮内的文本仅作语义/无障碍备用，视觉用 ::before 图标 */
  border-radius: 8px;
}

.btn-nav::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 18px;
  background: currentColor;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: contain;
  mask-size: contain;
}

/* 「每日挑战」图标：日历 + 中心圆点（暗示「今日」） */
#daily-btn::before {
  -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect x='3' y='5' width='18' height='16' rx='2'/><path d='M3 9h18'/><path d='M8 3v4M16 3v4'/><circle cx='12' cy='14' r='2' fill='black' stroke='none'/></svg>");
  mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect x='3' y='5' width='18' height='16' rx='2'/><path d='M3 9h18'/><path d='M8 3v4M16 3v4'/><circle cx='12' cy='14' r='2' fill='black' stroke='none'/></svg>");
}

/* 「回溯」图标：逆时针时钟箭头 */
#calendar-btn::before {
  -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M3 12a9 9 0 1 0 3-6.7'/><polyline points='3 4 3 10 9 10'/><polyline points='12 7 12 12 15 14'/></svg>");
  mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M3 12a9 9 0 1 0 3-6.7'/><polyline points='3 4 3 10 9 10'/><polyline points='12 7 12 12 15 14'/></svg>");
}

/* 日历 nav 中的「‹ ›」用文字而非 mask */
#cal-prev, #cal-next {
  font-size: 18px;
  line-height: 1;
}
#cal-prev::before, #cal-next::before { display: none; }

.btn-nav:hover:not(:disabled) {
  color: var(--ink);
  background: var(--surface);
}

/* 红点：新一题已上线 */
.nav-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--bg);
}

/* ---------- scoring badge + tooltip ---------- */

.scoring-badge {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 12px;
  cursor: help;
  user-select: none;
  outline: none;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s;
}
.scoring-badge:focus-visible {
  border-color: var(--ink-2);
}
.scoring-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-3);
  border: 1.5px solid var(--ink-3);
  box-sizing: border-box;
  flex: 0 0 8px;
}
.scoring-badge.is-scoring .scoring-dot {
  background: #10b981;
  border-color: #10b981;
}
.scoring-badge.is-not-scoring .scoring-dot {
  background: transparent;
  border-color: var(--ink-3);
}
.scoring-badge.is-scoring {
  color: #047857;
  border-color: #b7e7d4;
  background: #f0fdf6;
}
.scoring-badge.is-not-scoring {
  color: var(--ink-2);
}

.scoring-badge-label {
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* tooltip：纯 CSS hover 浮层 */
.scoring-tooltip {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 280px;
  max-width: calc(100vw - 32px);
  padding: 10px 12px;
  background: var(--ink);
  color: #fff;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.55;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.15s, transform 0.15s;
  z-index: 50;
  /* 确保长文本在容器内强制换行，不溢出 */
  white-space: normal;
  overflow-wrap: break-word;
  word-break: break-word;
}
.scoring-tooltip::before {
  content: "";
  position: absolute;
  top: -5px;
  right: 16px;
  width: 10px;
  height: 10px;
  background: var(--ink);
  transform: rotate(45deg);
}
.scoring-badge:hover .scoring-tooltip,
.scoring-badge:focus-visible .scoring-tooltip,
.scoring-badge:focus-within .scoring-tooltip {
  opacity: 1;
  transform: translateY(0);
}
.scoring-tooltip-reason {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}
.scoring-tooltip-rule {
  display: block;
  color: rgba(255,255,255,0.78);
  font-weight: 400;
}

/* ---------- leaderboard mode tip ---------- */

.leaderboard-mode-tip {
  margin: 0 0 10px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink-2);
  background: var(--bg);
  border-radius: 6px;
  border: 1px dashed var(--line);
}
.leaderboard-mode-tip.is-scoring {
  color: #047857;
  background: #f0fdf6;
  border-color: #b7e7d4;
  border-style: solid;
}
.leaderboard-mode-tip:empty { display: none; }
.lb-tip-primary { display: block; font-weight: 500; }
.lb-tip-rule {
  display: block;
  margin-top: 6px;
  color: var(--ink-3);
  font-size: 11.5px;
}

/* ---------- modal (calendar) ---------- */

body.modal-open { overflow: hidden; }

/* hidden 属性优先：覆盖 .modal 的 display: flex */
.modal[hidden] { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 18, 22, 0.45);
  backdrop-filter: blur(2px);
}
.modal-panel {
  position: relative;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0,0,0,0.18);
  width: 100%;
  max-width: 380px;
  padding: 18px 18px 16px;
  z-index: 1;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.modal-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}
.modal-close {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 18px;
  color: var(--ink-3);
  line-height: 1;
}
.modal-close:hover {
  background: var(--bg);
  color: var(--ink);
}

/* ---------- calendar ---------- */

.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.calendar-month-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.02em;
}
.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--ink-3);
  text-align: center;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-loading {
  grid-column: 1 / -1;
  text-align: center;
  padding: 24px 0;
  font-size: 13px;
  color: var(--ink-3);
}
.cal-loading.is-error { color: var(--accent); }

.cal-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px;
  color: var(--ink-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  padding: 4px 2px;
  /* badge 文本可能较长（谜底词），cell 是固定 aspect 1:1，
     不允许 badge 撑破 cell；超出截断 */
  overflow: hidden;
}
.cal-cell:hover:not(:disabled):not(.is-empty) {
  background: var(--bg);
  border-color: var(--ink-2);
  color: var(--ink);
}
.cal-cell.is-empty {
  background: transparent;
  border-color: transparent;
  cursor: default;
  pointer-events: none;
}
.cal-cell.is-disabled {
  color: var(--line-strong);
  background: transparent;
  border-color: var(--line);
  cursor: not-allowed;
  opacity: 0.6;
}
.cal-cell.is-today {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.cal-cell.is-current {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--accent);
}
.cal-cell.is-played {
  background: #f0fdf6;
  border-color: #b7e7d4;
  color: #047857;
}
.cal-cell.is-played.is-current {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
/* 「挑战中」：玩家猜过词但未结束（保存进度），视觉上比 is-played 浅一档 */
.cal-cell.is-inprogress {
  background: #fff7ed;
  border-color: #fed7aa;
  color: #c2410c;
}
.cal-cell.is-inprogress.is-current {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.cal-day { line-height: 1; font-weight: 500; }
.cal-badge {
  /* 居中展示在 .cal-cell 中 .cal-day 下方（cell 是 column flex） */
  font-size: 8px;
  line-height: 1.1;
  letter-spacing: 0.02em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* 不同状态的 badge 配色：与 cell 当前色调融合 */
.cal-badge-unplayed   { color: var(--ink-3); }
.cal-badge-inprogress { color: var(--accent); font-weight: 500; }
.cal-badge-revealed   { color: inherit; opacity: 0.85; }

.calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin: 12px 2px 2px;
  font-size: 11px;
  color: var(--ink-3);
}
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.legend-dot.is-today   { border-color: var(--accent); }
.legend-dot.is-current { background: var(--accent-soft); border-color: var(--accent); }
.legend-dot.is-inprogress { background: #fff7ed; border-color: #fed7aa; }
.legend-dot.is-played  { background: #f0fdf6; border-color: #b7e7d4; }
.legend-dot.is-disabled{ background: var(--bg); border-color: var(--line); opacity: 0.6; }

/* ---------- 自定义出题浮层 ---------- */

.custom-puzzle-panel {
  width: 100%;
  max-width: 420px;
  padding: 22px 22px 18px;
}

.custom-puzzle-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: 4px;
}

.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
}
.custom-puzzle-form input[type="text"] {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 14px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
}
.custom-puzzle-form input[type="text"]:focus {
  border-color: var(--ink-2);
}
.form-hint {
  margin: 0;
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.5;
}
.form-row-checks {
  gap: 10px;
}
.form-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
}
.form-check input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}
.custom-puzzle-msg {
  margin: 0;
  font-size: 13px;
  min-height: 18px;
  color: var(--ink-3);
}
.custom-puzzle-msg.error { color: var(--accent); }
.custom-puzzle-msg.success { color: #047857; }

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
}

/* ---------- copy-toast：复制成功的浮窗反馈 ---------- */

.copy-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  padding: 10px 16px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
}
.copy-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- mode tabs + room panel ---------- */

.mode-tabs {
  display: inline-flex;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.mode-tab {
  padding: 7px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-3);
  background: transparent;
  border-right: 1px solid var(--line);
  transition: background 0.15s, color 0.15s;
}
.mode-tab:last-child { border-right: none; }
.mode-tab.is-active {
  background: var(--ink);
  color: #fff;
}
.mode-tab:hover:not(.is-active) {
  color: var(--ink);
  background: var(--bg);
}

.room-reconnect-bar {
  margin-top: 12px;
  padding: 8px 12px;
  font-size: 13px;
  color: #92400e;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  text-align: center;
}
.room-reconnect-bar[hidden] { display: none; }

.room-panel {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.room-panel[hidden] { display: none; }

.room-field { margin-bottom: 12px; }
.room-label {
  display: block;
  font-size: 12px;
  color: var(--ink-3);
  margin-bottom: 4px;
}
.room-field input,
.room-code-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 14px;
  color: var(--ink);
  outline: none;
}
.room-field input:focus,
.room-code-input:focus { border-color: var(--ink-2); }

.room-lobby-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.room-code-input {
  width: 110px;
  flex: 0 0 auto;
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.room-or {
  font-size: 12px;
  color: var(--ink-3);
}

.room-session-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.room-code-display {
  font-size: 13px;
  color: var(--ink-2);
}
.room-code-display strong {
  font-family: var(--font-mono);
  font-size: 15px;
  letter-spacing: 0.08em;
  color: var(--ink);
}
.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.room-players {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.room-player {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--ink-2);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.room-player.is-host::after {
  content: "房主";
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
  margin-left: 2px;
}
.room-player.is-offline {
  opacity: 0.4;
}
.room-player.is-self {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--ink);
}

/* 联机聊天：右下角浮层，不占主栏文档流高度 */
.room-chat {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 80; /* 低于 .modal(100) / .copy-toast(200) */
  width: min(360px, calc(100vw - 24px));
  max-height: 40vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
  overflow: hidden;
}
.room-session[hidden] .room-chat,
body.is-view-stage .room-chat {
  display: none !important;
}
.room-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  flex: 0 0 auto;
  cursor: pointer;
  user-select: none;
}
.room-chat-title {
  font-size: 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.room-chat-badge {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.room-chat-badge[hidden] { display: none !important; }
.room-chat-toggle {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 16px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.room-chat-toggle:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}
.room-chat-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
}
.room-chat.is-collapsed {
  max-height: none;
  width: auto;
  min-width: 96px;
}
.room-chat.is-collapsed .room-chat-body {
  display: none;
}
.room-chat.is-collapsed .room-chat-head {
  border-bottom: none;
}
.room-chat-log {
  flex: 1 1 auto;
  min-height: 80px;
  max-height: calc(40vh - 96px);
  overflow-y: auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  line-height: 1.45;
  background: var(--bg);
}
.room-chat-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 8px;
  color: var(--ink-2);
}
.room-chat-item.is-me {
  color: var(--ink);
}
.room-chat-item.is-me .room-chat-name {
  color: var(--accent);
}
.room-chat-name {
  font-weight: 700;
  color: var(--ink);
  flex: 0 0 auto;
}
.room-chat-text {
  flex: 1 1 auto;
  min-width: 0;
  word-break: break-word;
}
.room-chat-time {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.room-chat-form {
  display: flex;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  flex: 0 0 auto;
}
.room-chat-form input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 14px;
  color: var(--ink);
  outline: none;
}
.room-chat-form input:focus {
  border-color: var(--ink-2);
}

.gameinfo-mode.is-room::before { background: #6366f1; }

/* ---------- live status (audience) ---------- */

.live-status-bar {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--accent);
}
.live-status-bar[hidden] { display: none; }
.live-lock-badge {
  font-weight: 600;
  padding: 2px 8px;
  background: #fff;
  border-radius: 999px;
  border: 1px solid var(--accent-line);
}
.live-lock-badge[hidden] { display: none; }
.live-countdown {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.live-heat-badge {
  margin-left: auto;
  font-size: 12px;
  color: var(--ink-2);
}
.live-heat-badge[hidden] { display: none; }

.room-ws-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink-3);
  background: var(--bg);
}
.room-ws-status[data-state="on"] {
  color: #166534;
  border-color: #bbf7d0;
  background: #f0fdf4;
}
.room-ws-status[data-state="reconnecting"] {
  color: #92400e;
  border-color: #fde68a;
  background: #fffbeb;
}

/* 观众输入 ≥16px 防 iOS 自动缩放 */
#guess-input {
  font-size: 16px;
}

/* ---------- host 中控 ---------- */

.host-panel {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--line-strong);
}
.host-panel[hidden] { display: none; }
.host-panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  cursor: pointer;
  user-select: none;
  padding: 6px 8px;
  margin-left: -8px;
  margin-right: -8px;
  border-radius: var(--radius);
}
.host-panel-head:hover {
  background: var(--bg);
}
.host-panel-chevron {
  margin-left: auto;
  color: var(--ink-3);
  font-size: 12px;
  transition: transform 0.15s ease;
  line-height: 1;
}
.host-panel.is-collapsed .host-panel-head {
  margin-bottom: 0;
}
.host-panel.is-collapsed .host-panel-chevron {
  transform: rotate(-90deg);
}
.host-panel.is-collapsed .host-panel-body {
  display: none;
}
.host-live-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink-3);
  letter-spacing: 0.04em;
}
.host-live-pill[data-on="1"] {
  background: #fef2f2;
  border-color: #fecaca;
  color: #b91c1c;
}
.host-share-row,
.host-actions,
.host-toggles,
.host-timer-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.host-qr-row {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 12px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.host-qr {
  width: 108px;
  height: 108px;
  flex: 0 0 auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.host-qr img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.host-qr-fallback {
  font-size: 11px;
  color: var(--ink-3);
  text-align: center;
  padding: 8px;
}
.host-code-xl {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--ink);
  line-height: 1.2;
}
.host-audience-url {
  font-size: 12px;
  color: var(--ink-2);
  word-break: break-all;
  margin: 4px 0;
}
.host-hint {
  font-size: 11px;
  color: var(--ink-3);
}
.host-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-2);
  padding: 4px 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
}
.host-toggle input { accent-color: var(--accent); }
.host-timer-label {
  font-size: 12px;
  color: var(--ink-3);
}
.host-timer-input {
  width: 72px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 14px;
  background: #fff;
}
.host-countdown {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  min-width: 64px;
}
.host-heat {
  font-size: 12px;
  color: var(--ink-2);
  margin-left: auto;
}
.host-pending,
.host-events {
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.host-pending-head,
.host-events-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
}
.host-pending-tip {
  font-size: 11px;
  color: var(--ink-3);
}
.host-pending-list,
.host-event-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 180px;
  overflow: auto;
}
.host-pending-empty {
  margin: 0;
  font-size: 12px;
  color: var(--ink-3);
}
.host-pending-item,
.host-event-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.host-pending-item:last-child,
.host-event-item:last-child { border-bottom: none; }
.host-pending-meta { flex: 1 1 auto; min-width: 0; color: var(--ink-2); }
.host-pending-actions { display: flex; gap: 6px; }
.gift-tier {
  display: inline-block;
  min-width: 22px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  color: #fff;
}
.tier-s { background: #94a3b8; }
.tier-m { background: #0ea5e9; }
.tier-l { background: #f59e0b; }
.tier-xl { background: #ef4444; }
.host-gift-map {
  margin-top: 10px;
  font-size: 12px;
  color: var(--ink-2);
}
.host-gift-map summary {
  cursor: pointer;
  color: var(--ink-3);
  user-select: none;
}
.host-gift-map-list {
  margin: 8px 0 0;
  padding-left: 0;
  list-style: none;
}
.host-gift-map-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

/* body 模式标记：隐藏单人无关控件 */
body.is-view-stage .app,
body.is-view-stage #copy-toast,
body.is-view-stage .modal { display: none !important; }
body.is-view-stage #stage-root { display: flex; }
body.is-role-host .mode-tabs { /* 中控仍可用联机面板 */ }

/* ---------- stage 大屏 1080p ---------- */

.stage-root {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  flex-direction: column;
  color: #f8fafc;
  font-family: var(--font-sans);
  background: #0b1020;
  overflow: hidden;
}
.stage-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(194, 65, 12, 0.18), transparent 55%),
    radial-gradient(ellipse 70% 50% at 80% 90%, rgba(14, 165, 233, 0.12), transparent 50%),
    linear-gradient(180deg, #0b1020 0%, #111827 100%);
  pointer-events: none;
}
.stage-header,
.stage-main,
.stage-footer {
  position: relative;
  z-index: 1;
}
.stage-header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 28px 40px 12px;
}
.stage-brand-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.stage-brand-sub {
  margin-left: 10px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.16em;
  padding: 3px 8px;
  border-radius: 4px;
  background: #ef4444;
  color: #fff;
  vertical-align: middle;
}
.stage-room-badge {
  margin-left: auto;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 16px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
}
.stage-room-label {
  font-size: 14px;
  color: rgba(248,250,252,0.55);
}
.stage-room-code {
  font-family: var(--font-mono);
  font-size: 36px;
  letter-spacing: 0.14em;
}
.stage-ws-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #64748b;
  box-shadow: 0 0 0 4px rgba(100,116,139,0.2);
}
.stage-ws-dot[data-state="on"] {
  background: #22c55e;
  box-shadow: 0 0 0 4px rgba(34,197,94,0.25);
}
.stage-ws-dot[data-state="reconnecting"] {
  background: #f59e0b;
  box-shadow: 0 0 0 4px rgba(245,158,11,0.25);
}
.stage-main {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr 340px;
  gap: 28px;
  padding: 12px 40px 20px;
  min-height: 0;
}
.stage-left,
.stage-center,
.stage-right {
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.stage-timer-block {
  padding: 24px 16px;
  border-radius: 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  text-align: center;
}
.stage-timer {
  font-family: var(--font-mono);
  font-size: 88px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.04em;
  color: #fdba74;
  text-shadow: 0 0 40px rgba(251, 146, 60, 0.35);
}
.stage-timer.is-urgent {
  color: #fca5a5;
  animation: stage-pulse 1s ease-in-out infinite;
}
.stage-timer-label {
  margin-top: 8px;
  font-size: 18px;
  color: rgba(248,250,252,0.6);
}
.stage-heat-block {
  margin-top: 20px;
  padding: 16px;
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
}
.stage-heat-label {
  font-size: 14px;
  color: rgba(248,250,252,0.5);
  margin-bottom: 8px;
}
.stage-heat-bar {
  height: 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}
.stage-heat-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #fb923c, #ef4444);
  border-radius: inherit;
  transition: width 0.35s ease;
}
.stage-heat-val {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
}
.stage-lock-pill {
  margin-top: 16px;
  text-align: center;
  padding: 10px;
  border-radius: 999px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fecaca;
  font-size: 16px;
  font-weight: 600;
}
.stage-lock-pill[hidden] { display: none; }
.stage-thermo-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 12px;
  color: rgba(248,250,252,0.85);
}
.stage-guess-count {
  font-size: 16px;
  font-weight: 500;
  color: rgba(248,250,252,0.5);
  font-family: var(--font-mono);
}
.stage-top-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stage-top-item {
  display: grid;
  grid-template-columns: 48px 1fr 100px 90px;
  gap: 12px;
  align-items: center;
  padding: 14px 18px;
  border-radius: 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.06);
  font-size: 22px;
}
.stage-top-item.is-hot {
  background: rgba(194, 65, 12, 0.18);
  border-color: rgba(251, 146, 60, 0.35);
}
.stage-top-rank {
  font-family: var(--font-mono);
  font-weight: 700;
  color: #fdba74;
}
.stage-top-word {
  font-weight: 700;
  letter-spacing: 0.04em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stage-top-player {
  font-size: 14px;
  color: rgba(248,250,252,0.45);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stage-top-pct {
  font-family: var(--font-mono);
  text-align: right;
  color: rgba(248,250,252,0.75);
}
.stage-win {
  position: absolute;
  inset: 18% 22%;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 24px;
  background: rgba(15, 23, 42, 0.88);
  border: 2px solid rgba(251, 146, 60, 0.55);
  box-shadow: 0 0 80px rgba(251, 146, 60, 0.25);
  animation: stage-win-in 0.5s ease;
}
.stage-win[hidden] { display: none; }
.stage-center { position: relative; }
.stage-win-title {
  font-size: 36px;
  color: #fdba74;
  letter-spacing: 0.2em;
}
.stage-win-word {
  margin-top: 12px;
  font-size: 96px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #fff;
  text-shadow: 0 0 40px rgba(251,146,60,0.5);
}
.stage-feed-head {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 10px;
  color: rgba(248,250,252,0.7);
}
.stage-feed-head-sm {
  margin-top: 18px;
  font-size: 15px;
}
.stage-recent-list,
.stage-event-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stage-recent-list { flex: 1; max-height: 52%; }
.stage-event-list { flex: 0 1 38%; max-height: 38%; }
.stage-recent-item,
.stage-event-item {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.05);
  font-size: 18px;
  animation: stage-row-in 0.35s ease;
}
.stage-recent-item .w { font-weight: 700; margin-right: 8px; }
.stage-recent-item .p { color: rgba(248,250,252,0.45); font-size: 14px; }
.stage-recent-item .s {
  float: right;
  font-family: var(--font-mono);
  color: #fdba74;
}
.stage-event-item { font-size: 15px; color: rgba(248,250,252,0.75); }
.stage-footer {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 40px 28px;
}
.stage-qr {
  width: 96px;
  height: 96px;
  border-radius: 10px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex: 0 0 auto;
}
.stage-qr img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.stage-qr-fallback {
  font-size: 11px;
  color: #64748b;
  text-align: center;
  padding: 6px;
}
.stage-audience-url {
  font-size: 16px;
  color: rgba(248,250,252,0.55);
  word-break: break-all;
}

/* 特效层 */
.stage-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  overflow: hidden;
}
.fx-heart {
  position: absolute;
  bottom: 10%;
  font-size: 28px;
  color: #fb7185;
  animation: fx-float-up 2.4s ease-out forwards;
  text-shadow: 0 0 12px rgba(251,113,133,0.6);
}
.fx-flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(253,186,116,0.35), transparent 60%);
  animation: fx-flash 0.8s ease-out forwards;
}
.fx-banner {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%) translateY(-10px);
  padding: 14px 28px;
  border-radius: 999px;
  background: rgba(15,23,42,0.85);
  border: 1px solid rgba(253,186,116,0.5);
  color: #fdba74;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.08em;
  animation: fx-banner 2.8s ease forwards;
  white-space: nowrap;
}
.fx-pending {
  position: absolute;
  right: 40px;
  top: 120px;
  padding: 16px 22px;
  border-radius: 14px;
  background: rgba(127, 29, 29, 0.85);
  border: 1px solid rgba(248, 113, 113, 0.6);
  color: #fecaca;
  font-size: 22px;
  font-weight: 700;
  animation: stage-pulse 1.2s ease-in-out infinite;
}

@keyframes stage-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.75; transform: scale(1.03); }
}
@keyframes stage-win-in {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes stage-row-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fx-float-up {
  0% { opacity: 0; transform: translateY(20px) scale(0.8); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-280px) scale(1.2); }
}
@keyframes fx-flash {
  0% { opacity: 0; }
  20% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes fx-banner {
  0% { opacity: 0; transform: translateX(-50%) translateY(12px); }
  15% { opacity: 1; transform: translateX(-50%) translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-16px); }
}

/* 1080p 后排可读：大屏最小字号兜底 */
@media (min-width: 1600px) {
  .stage-timer { font-size: 110px; }
  .stage-top-item { font-size: 26px; padding: 16px 20px; }
  .stage-recent-item { font-size: 20px; }
}

/* ---------- responsive ---------- */

@media (max-width: 540px) {
  .app {
    /* 窄屏：进一步压缩左右内边距，让卡片接近贴边，更利用屏幕空间 */
    padding: 20px 12px 60px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .history-row {
    grid-template-columns: 28px 1fr 60px 80px 48px;
    gap: 8px;
    font-size: 13px;
  }

  /* 窄屏隐藏品牌副标题（英文 Chinese Semantle），
   * 让 topbar 横向空间够 brand + 4 个按钮单行排布。 */
  .brand-sub { display: none; }

  /* ---- 窄屏 topbar 重排 ----
   * 设计意图：尽量保持 topbar 单行，brand-sub 隐藏后留出的空间够装 4 个按钮。
   * 如果 4 个按钮加起来仍超过可用宽度，flex-wrap 会让它们自然换行；
   * 但**不**主动强制 .topbar-actions 独占一行（避免空间够时也被推到下一行）。
   * 当前游戏的 mode / scoring / puzzle_code 徽章在独立的 .gameinfo-bar 中。
   */
  .topbar {
    gap: 12px 8px;
    align-items: center;
  }
  .topbar-left {
    flex: 0 1 auto;
    min-width: 0;
  }
  .topbar-actions {
    flex: 0 1 auto;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
  }
  /* 次要元素全部不可被压扁，单行显示 */
  .topbar-nav .btn-nav,
  #custom-puzzle-btn,
  #new-game-btn {
    flex-shrink: 0;
    white-space: nowrap;
  }
  .topbar-nav { gap: 4px; }

  /* gameinfo-bar 在窄屏上同样保持单行可换行；编号徽章去 label 节省横向空间 */
  .puzzle-badge { padding: 3px 8px; }
  .puzzle-badge-label { display: none; }

  /* 窄屏：tooltip 改为相对视口居中下浮，避免 scoring-badge 位置变化
   * 导致 absolute 定位的 tooltip 出屏。
   * 用 fixed 而非 absolute，彻底脱离父级 overflow / 位置影响。 */
  .scoring-tooltip {
    position: fixed;
    top: auto;
    bottom: 20px;
    left: 12px;
    right: 12px;
    width: auto;
    max-width: none;
    transform: translateY(8px);
  }
  .scoring-badge:hover .scoring-tooltip,
  .scoring-badge:focus-visible .scoring-tooltip,
  .scoring-badge:focus-within .scoring-tooltip {
    transform: translateY(0);
  }
  /* 窄屏 tooltip 不再有指向 badge 的箭头（因为位置已远离 badge） */
  .scoring-tooltip::before { display: none; }
}
