/* ==========================================================================
   猜词 · 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;
}

.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;
}

.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;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  padding: 0;
}
.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);
}
.cal-day { line-height: 1; }
.cal-badge {
  position: absolute;
  bottom: 4px;
  right: 6px;
  font-size: 10px;
  line-height: 1;
  font-family: var(--font-mono);
  color: inherit;
  opacity: 0.9;
}

.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-played  { background: #f0fdf6; border-color: #b7e7d4; }
.legend-dot.is-disabled{ background: var(--bg); border-color: var(--line); opacity: 0.6; }

/* ---------- 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; }
}
