/* 成语猜词。整个游戏由大号汉字构成,所以字体栈 CJK 优先——其他游戏 Courier
   优先是因为它们的中文只是小号 UI 标签。像素感靠 CSS 几何(2px 硬边框、
   4px 硬投影、steps() 过渡)而不是字体文件,与仓库"零素材"一致。 */
:root {
  --tile-hit: #6f9e4c;      /* 位置对 */
  --tile-near: var(--px-cyan);
  --tile-miss: #4a4640;
  /* 格子同时受宽度与高度约束:6 行棋盘 + 4 行候选 + 标题 + 操作行要一屏放下,
     只看 vw 会在矮窗口里把按钮挤出视口。 */
  --tile-size: min(clamp(44px, 13.5vw, 62px), 7.1dvh);
  --pool-size: min(clamp(38px, 11.5vw, 52px), 6dvh);
}

body {
  min-height: 100dvh;
  margin: 0;
  background: var(--px-bg);
  color: var(--px-ink);
  font-family: "Microsoft YaHei", "Microsoft YaHei UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
}

.idiom-game {
  display: grid;
  width: min(560px, 100%);
  min-height: 100dvh;
  align-content: start;
  gap: 14px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px max(20px, calc(env(safe-area-inset-bottom) + 14px));
}

.game-heading { display: flex; align-items: start; justify-content: space-between; gap: 12px; padding-left: 56px; }
.game-heading h1 { margin: 3px 0 0; font-size: clamp(22px, 6vw, 30px); }
.heading-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: 6px; }
.mode-chip { align-self: center; border: 2px solid var(--px-line); padding: 5px 9px; background: var(--px-panel-2); color: var(--px-accent); font-size: 11px; font-weight: 900; white-space: nowrap; }

/* ── 棋盘:六行,每行四格 ── */
.board { display: grid; gap: 7px; padding: 12px; }
.guess-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.tile {
  display: grid;
  height: var(--tile-size);
  place-items: center;
  border: 2px solid var(--px-line);
  background: var(--px-panel-2);
  color: var(--px-ink);
  /* CJK 是方块字,所以格子做正方、字居中、line-height 压到 1 */
  font-size: calc(var(--tile-size) * 0.52);
  font-weight: 700;
  line-height: 1;
}
.tile.is-empty { color: transparent; }
.tile.is-active { border-color: var(--px-accent); }
.tile.is-filled { border-color: var(--px-muted); }
.tile.mark-hit { border-color: var(--tile-hit); background: var(--tile-hit); color: #f4fbee; }
.tile.mark-near { border-color: var(--tile-near); background: var(--tile-near); color: #10201d; }
.tile.mark-miss { border-color: var(--tile-miss); background: var(--tile-miss); color: #b3ada2; }
/* 提交后逐格翻开,错峰由 --index 控制 */
.guess-row.is-revealing .tile { animation: tile-flip var(--reveal-duration, 260ms) steps(3, end) both; animation-delay: calc(var(--index, 0) * var(--reveal-stagger, 130ms)); }
@keyframes tile-flip { 0% { transform: scaleY(1); } 50% { transform: scaleY(.05); } 100% { transform: scaleY(1); } }
/* 输入行填字时的轻微弹一下 */
.tile.just-filled { animation: tile-pop 140ms steps(2, end); }
@keyframes tile-pop { 50% { transform: scale(1.12); } }
/* 非法提交时整行摇一下 */
.guess-row.is-invalid { animation: row-shake 260ms steps(4, end); }
@keyframes row-shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.hint-line { min-height: 20px; margin: 0; color: var(--px-danger); font-size: 12px; font-weight: 800; text-align: center; }

/* ── 候选字网格 ── */
.pool-zone { display: grid; gap: 7px; }
.char-pool { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.char-key {
  display: grid;
  height: var(--pool-size);
  place-items: center;
  border: 2px solid var(--px-line);
  padding: 0;
  background: var(--px-panel);
  color: var(--px-ink);
  box-shadow: 3px 3px 0 #0e0e0d;
  font: 700 calc(var(--pool-size) * 0.46) / 1 inherit;
  cursor: pointer;
  transition: background-color var(--px-fast) steps(2, end), border-color var(--px-fast) steps(2, end);
}
.char-key:hover:not(:disabled), .char-key:focus-visible { border-color: var(--px-accent); background: var(--px-panel-2); outline: none; }
.char-key:focus-visible { outline: 3px solid var(--px-accent); outline-offset: 2px; }
.char-key:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #0e0e0d; }
/* 已知状态:命中/存在的字高亮，确认不存在的压暗但仍可点(玩家可能想再确认) */
.char-key.mark-hit { border-color: var(--tile-hit); background: var(--tile-hit); color: #f4fbee; }
.char-key.mark-near { border-color: var(--tile-near); background: var(--tile-near); color: #10201d; }
.char-key.mark-miss { border-color: var(--tile-miss); color: #6f6a61; filter: brightness(.72); }
.char-key:disabled { cursor: default; opacity: .5; }

.action-row { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; }

/* ── 浮层 ── */
.overlay-layer { position: fixed; z-index: 140; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(12, 12, 11, .78); backdrop-filter: blur(3px); }
.overlay-layer[hidden] { display: none; }
.overlay-card { width: min(420px, 100%); max-height: 88dvh; overflow: auto; padding: 20px; }
.overlay-card header { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.overlay-card h2 { margin: 4px 0 0; font-size: 24px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 2px solid var(--px-line); padding: 10px 12px; background: var(--px-panel-2); cursor: pointer; }
.toggle-row strong { display: block; font-size: 13px; }
.toggle-row small { display: block; margin-top: 4px; color: var(--px-muted); font-size: 10px; line-height: 1.5; }
.toggle-row input { width: 20px; height: 20px; flex: 0 0 auto; }
.settings-hint { margin: 8px 0 0; color: var(--px-muted); font-size: 11px; font-weight: 700; line-height: 1.5; }
.menu-actions { display: grid; gap: 8px; margin-top: 16px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 18px; }
.stat-cell { border: 2px solid var(--px-line); padding: 9px 6px; background: var(--px-panel-2); text-align: center; }
.stat-cell b { display: block; color: var(--px-accent); font-size: 20px; }
.stat-cell span { display: block; margin-top: 4px; color: var(--px-muted); font-size: 9px; }
.dist-list { display: grid; gap: 4px; margin: 8px 0 0; padding: 0; list-style: none; }
.dist-list li { display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 8px; font-size: 11px; font-weight: 800; }
.dist-bar { height: 14px; min-width: 3px; background: var(--px-line); }
.dist-list li.is-best .dist-bar { background: var(--px-accent); }

.result-card { text-align: center; }
.result-answer { margin: 10px 0 6px; color: var(--px-accent); font-size: 28px; font-weight: 700; letter-spacing: 4px; }
.result-copy { margin: 0; color: var(--px-muted); font-size: 12px; line-height: 1.6; }
.share-box { margin: 14px 0 0; padding: 10px; border: 2px dashed var(--px-line); background: var(--px-panel-2); color: var(--px-ink); font: 700 13px/1.5 "Courier New", monospace; white-space: pre; overflow-x: auto; }

.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* 共享引导 toast 的默认 bottom 是 148px,那是给别的游戏的底部按钮排调的。
   这里下方是"候选字网格 + 操作行",硬编码一个数值在不同视口都会压住内容,
   所以按实际元素高度算:4 行候选 + 间距 + 操作行 + 余量。 */
.arcade-coach {
  bottom: calc(env(safe-area-inset-bottom) + var(--pool-size) * 4 + 150px);
}

@media (max-width: 460px) {
  .idiom-game { gap: 10px; padding-inline: 10px; }
  /* 窄屏把标题与按钮排成上下两块,否则四个按钮会被挤到第二行、和标题错位 */
  .game-heading { flex-direction: column; align-items: stretch; gap: 8px; padding-left: 50px; }
  .game-heading h1 { font-size: 20px; }
  .heading-actions { justify-content: start; }
  .mode-chip { margin-right: auto; font-size: 10px; padding: 4px 7px; }
  .board { padding: 9px; gap: 6px; }
  .char-pool { gap: 5px; }
}

/* 矮屏(横屏手机)再压一档,并收紧纵向间距 */
@media (max-height: 560px) {
  :root { --tile-size: min(40px, 7dvh); --pool-size: min(36px, 6dvh); }
  .idiom-game { gap: 8px; }
  .board { padding: 8px; gap: 5px; }
  .game-heading h1 { font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .guess-row.is-revealing .tile, .tile.just-filled, .guess-row.is-invalid { animation: none; }
  .char-key { transition: none; }
}
