/*
 * [INPUT]: fp-shell.css 外壳变量、game/index.html 的游戏工作台结构与 board-view.js 的格尺寸/视图变量。
 * [OUTPUT]: MagicPath 外壳适配下的 Crossmath 游戏层样式：难度进度页签、快切选关与 3×5 矩阵面板、HUD、棋盘微反馈动画、聚焦算式栏、聚合托盘、操作栏、柠檬绿通关卡与双栏响应式。
 * [POS]: game 的视觉层，配合 /fp-shell.css 运行，零外部字体或图片。
 * [PROTOCOL]: 变更时更新此头部，然后检查 CLAUDE.md
 */
:root {
  --ink: #182B2C; --muted: #657470; --green: #225E55; --olive: #577500; --lime: #E8F2B5;
  --paper: #F8F8F3; --card: #FFFFFF; --line: #D9E1DB; --red: #B43018;
  --serif: Georgia, Charter, 'Times New Roman', ui-serif, serif;
}
html { scroll-behavior: smooth; }
a { color: var(--green); text-underline-offset: 3px; touch-action: manipulation; }
button, select { font: inherit; color: inherit; touch-action: manipulation; }
button { cursor: pointer; min-height: 44px; padding: 8px 12px; border: 1px solid #CDD8CF; border-radius: 8px; background: var(--card); font-weight: 670; }
button:hover:not(:disabled) { border-color: var(--green); }
button:disabled { opacity: 0.48; cursor: default; }
button:focus-visible, a:focus-visible, select:focus-visible, summary:focus-visible, .board-scroll:focus-visible { outline: 3px solid #D8784B; outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: -9999px; top: 0; background: var(--ink); color: #FFFDF7; padding: 10px 16px; z-index: 30; }
.skip-link:focus { left: 0; }

#analytics-status { font-size: 12px; }

.diff-bar { display: flex; gap: 6px; flex-wrap: wrap; margin: 16px 0 12px; }
.diff-btn { flex: 1; min-width: 68px; min-height: 42px; padding: 6px 8px; font-size: 12.5px; border-radius: 10px; background: #EAEFE9; border-color: #D6DFD7; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.2; font-variant-numeric: tabular-nums; }
.diff-btn small { font-size: 10px; font-weight: 600; color: var(--muted); }
.diff-btn[aria-pressed="true"] { background: var(--ink); color: #FFFDF7; box-shadow: 0 3px 10px rgba(24, 43, 44, 0.14); border-color: var(--ink); }
.diff-btn[aria-pressed="true"] small { color: var(--lime); }
.diff-btn .solved-mark { color: var(--lime); font-weight: 800; }
.diff-btn[aria-pressed="false"] .solved-mark { color: var(--green); }

.game-workbench { background: var(--card); border: 1px solid #D8DED6; border-radius: 15px; padding: 14px; box-shadow: 0 3px 0 #E6E9E2; }
.hud-bar { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex-wrap: wrap; padding-bottom: 6px; border-bottom: 1px solid #e5e9df; margin-bottom: 6px; }
.level-picker { display: flex; align-items: center; gap: 4px; flex: 1 1 240px; min-width: 0; font-size: 13px; font-weight: 700; }
.nav-step-btn { min-height: 40px; min-width: 38px; padding: 4px 8px; font-size: 16px; line-height: 1; flex-shrink: 0; }
.level-picker select { flex: 1; min-width: 0; min-height: 40px; max-width: 100%; padding: 4px 6px; border-radius: 4px; border: 1px solid #c3cec0; background: white; font-weight: 700; font-size: 12.5px; text-overflow: ellipsis; }
.grid-toggle-btn { min-height: 40px; padding: 4px 9px; font-size: 11.5px; font-weight: 750; background: #eef2e8; border-color: #c3cec0; white-space: nowrap; flex-shrink: 0; }
.grid-toggle-btn[aria-expanded="true"] { background: var(--ink); color: #fffef8; border-color: var(--ink); }
.hud-badges { display: flex; align-items: center; gap: 5px; font-size: 11.5px; font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.badge { background: #edf1e7; border: 1px solid #d6dfd0; padding: 3px 7px; border-radius: 3px; font-weight: 650; }
.badge.rule-badge { background: #eef4dc; border-color: #c5d982; color: #2c4c00; }

.level-grid-panel { background: #f2f5ec; border: 1px solid #ced8c7; border-radius: 4px; padding: 10px; margin-bottom: 8px; }
.level-grid-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11.5px; font-weight: 700; color: var(--muted); margin-bottom: 8px; flex-wrap: wrap; }
.link-btn { min-height: 32px; padding: 4px 9px; font-size: 11px; font-weight: 650; color: var(--red); background: transparent; border-color: #d8c2bc; border-radius: 4px; }
.level-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
.level-cell { min-height: 42px; padding: 4px 2px; border-radius: 3px; background: var(--card); border: 1px solid #cbd4c7; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.level-cell .cell-num { font-size: 12.5px; font-weight: 800; }
.level-cell .cell-meta { font-size: 9.5px; font-weight: 700; color: var(--muted); }
.level-cell.peak { border-color: #b7cf72; background: #f9fde8; }
.level-cell.peak .cell-meta { color: #3d6300; }
.level-cell.solved { background: #e6f2c2; border-color: #7ea340; color: #1f4400; }
.level-cell.solved .cell-meta { color: #244d00; font-weight: 800; }
.level-cell.current { border: 2px solid var(--ink); box-shadow: inset 0 0 0 2px var(--lime); }

.status-banner { padding: 7px 10px; border-radius: 4px; font-size: 12.5px; margin-bottom: 6px; background: #eef2e8; border-left: 4px solid var(--green); }
.status-banner.valid { background: #e9f3c5; border-left-color: #4f8116; color: #244705; }
.status-banner.conflict { background: #fff0e8; border-left-color: #b64533; color: #7d2519; }
.status-banner.info { background: #edf2e9; border-left-color: var(--ink); }

.confirm-box { padding: 12px; border-radius: 4px; background: #fff4df; border: 1px solid #d8ae68; color: #6e4212; margin-bottom: 10px; font-size: 12.5px; }
.confirm-box strong { display: block; margin-bottom: 4px; font-size: 13.5px; }
.confirm-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.confirm-actions .danger { color: #823426; border-color: #b99b6e; }

.victory-card { padding: 16px 18px; border-radius: 15px; background: var(--lime); border: 1px solid #C5D67D; color: var(--ink); margin-bottom: 12px; }
.victory-card .v-tag { display: inline-block; background: var(--ink); color: var(--lime); font-size: 10px; font-weight: 800; letter-spacing: 1px; padding: 3px 8px; border-radius: 999px; margin-bottom: 6px; }
.victory-card h2 { margin: 0 0 6px; font-size: 20px; font-weight: 850; color: var(--ink); }
.victory-stats { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: #334942; margin: 6px 0 10px; font-variant-numeric: tabular-nums; }
.victory-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.victory-actions .btn-lime { background: var(--green); border-color: var(--green); color: #FFFDF7; font-weight: 800; }
.victory-actions .btn-ghost { background: var(--card); border-color: #B4C3B6; color: var(--ink); }

@keyframes cellPop {
  0% { transform: scale(0.92); }
  60% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

.board-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
.board-help { font-size: 11.5px; color: var(--muted); margin-block: 4px; }
.board-controls { display: flex; gap: 6px; }
.board-controls button { font-size: 12px; min-height: 36px; padding: 4px 9px; }
.board-scroll { width: 100%; max-height: var(--board-height); overflow: auto; padding: 4px; border-radius: 4px; background: #eff2ea; border: 1px solid #dce2d5; overflow-anchor: none; }
.board-scroll[data-view="zoom"] { height: var(--board-height); }
#board { --edit-font: 18px; width: max-content; min-width: 100%; display: flex; flex-direction: column; gap: 3px; }
#board [role="row"] { display: grid; grid-template-columns: repeat(var(--columns), var(--cell-size, 44px)); gap: 3px; justify-content: center; }
#board button { padding: 0; min-width: 0; min-height: 0; height: var(--cell-size, 44px); border-radius: 2px; font-size: var(--cell-font, 18px); font-weight: 750; font-variant-numeric: tabular-nums; position: relative; overflow: hidden; display: grid; place-items: center; user-select: none; }
#board button.just-popped { animation: cellPop 160ms ease-out; }
#board button[data-kind="void"] { background: transparent; border-color: transparent; pointer-events: none; }
#board button[data-kind="void"]::before { content: '·'; color: #81917a; font-size: 11px; }
#board button[data-kind="given"] { background: #e5ebe0; border: 1px solid #cad4c3; color: var(--ink); cursor: default; }
#board button[data-kind="given"].in-active-eq { background: #dce6d2; }
#board button[data-kind="operator"], #board button[data-kind="equals"] { background: #e8ede2; border-color: transparent; color: #465e55; font-weight: 600; cursor: default; }
#board button[data-kind="equals"].eq-balanced { background: #e4f2b8; border-color: #7ea340; color: #244d00; font-weight: 800; }
#board button[data-kind="equals"].eq-balanced::after { content: '✓'; position: absolute; bottom: 0; right: 2px; font-size: min(9px, calc(var(--cell-font, 18px) * 0.5)); }
#board button[data-kind="equals"].eq-conflict { background: #ffe6dc; border-color: #c44735; color: #8f2116; font-weight: 800; }
#board button[data-kind="slot"] { background: #ffffff; border: 1.5px dashed #93a694; box-shadow: inset 0 2px 3px rgba(20, 61, 50, 0.05); color: #7c9084; }
#board button[data-kind="slot"].in-active-eq { border-color: #5b7867; background: #fbfdf7; }
#board button[data-kind="slot"].filled { background: #fffef6; border: 1.5px solid var(--green); box-shadow: 0 2px 0 #b7c8b6; color: #0d4a37; }
#board button[data-kind="slot"].hinted { background: #edf8c7; border: 1.5px solid #6b9430; box-shadow: none; color: #264d00; }
#board button[data-kind="slot"].hinted::after { content: '★'; position: absolute; top: 1px; right: 2px; font-size: min(9px, calc(var(--cell-font, 18px) * 0.5)); color: #4e7314; }
#board button[data-kind="slot"].eq-line-balanced { border-color: #5b8c22; background: #f6fce2; }
#board button[data-kind="slot"].eq-line-conflict { border: 2px solid #c44735; background: #fff5f2; color: var(--red); }
#board button[data-kind="slot"].flagged { border: 2px solid #c44735; background: #fff0ed; color: var(--red); }
#board button[data-kind="slot"].flagged::before { content: '!'; position: absolute; top: 0; left: 3px; font-size: 10px; font-weight: 900; color: #b6291c; }
#board button[data-kind="slot"][aria-selected="true"] { border: 2px solid var(--ink); box-shadow: inset 0 0 0 2.5px var(--lime); background: #f9fde8; z-index: 2; }
#board button[data-kind="slot"].armed-target:not(.hinted) { border-color: var(--green); background: #f5fbe0; }

.control-dock { margin-top: 8px; background: transparent; border: none; border-top: 1px solid var(--line); border-radius: 0; padding: 12px 0 0; }
.active-eq-hud { background: var(--card); border: 1px solid var(--line); border-radius: 4px; padding: 7px 9px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 5px; }
.eq-hud-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); font-weight: 700; letter-spacing: 0.4px; flex-wrap: wrap; }
.eq-hud-row { display: flex; flex-direction: column; gap: 4px; background: var(--card); border: 1px solid #d8e0d2; border-radius: 4px; padding: 5px 8px; font-variant-numeric: tabular-nums; }
.eq-hud-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.eq-dir { font-size: 11px; font-weight: 800; color: var(--green); min-width: 54px; }
.eq-tokens { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; flex: 1; font-size: 14px; font-weight: 700; }
.eq-slot-pill { min-height: 28px; min-width: 32px; padding: 2px 7px; border-radius: 3px; border: 1.5px dashed #8ca18e; background: #ffffff; font-size: 13.5px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; }
.eq-slot-pill.filled { border-style: solid; border-color: var(--green); background: #f5faeb; }
.eq-slot-pill.active { border: 2px solid var(--ink); background: var(--lime); box-shadow: 0 1px 4px rgba(20, 61, 50, 0.15); }
.eq-state-tag { font-size: 11px; font-weight: 750; padding: 2px 6px; border-radius: 3px; background: #edf1e8; color: var(--muted); }
.eq-state-tag.balanced { background: #e4f2b8; color: #244d00; }
.eq-state-tag.conflict { background: #ffe6dc; color: #8f2116; }

.tray-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; margin-bottom: 6px; }
.tray-header strong { font-size: 12.5px; }
.tray-header span { color: var(--muted); font-size: 11.5px; }
.tile-tray { display: grid; grid-template-columns: repeat(auto-fill, minmax(50px, 1fr)); gap: 6px; margin-bottom: 10px; }
.tray-tile { min-height: 46px; padding: 4px; border-radius: 3px; background: #ffffff; border: 1.5px solid #b5c4b4; box-shadow: 0 3px 0 #cbd6c8; font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; display: grid; place-items: center; position: relative; }
.tray-tile:hover:not(:disabled) { border-color: var(--green); background: #fbfef2; }
.tray-tile[aria-pressed="true"] { background: var(--lime); border: 2px solid var(--ink); box-shadow: 0 4px 0 var(--ink); transform: translateY(-3px); }
.tray-tile .count-badge { position: absolute; top: 2px; right: 3px; font-size: 9.5px; font-weight: 800; background: #e5ece0; color: var(--green); padding: 0 4px; border-radius: 3px; line-height: 1.3; }
.tray-tile[aria-pressed="true"] .count-badge { background: var(--ink); color: var(--lime); }
.tray-tile.used { background: #ebeee6; border: 1px dashed #c4cdc0; box-shadow: none; color: #8c9c92; font-weight: 600; }
.tray-tile.used .count-badge { background: transparent; color: #8c9c92; }

.action-bar { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.action-bar button { min-height: 44px; padding: 6px 4px; font-size: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border-radius: 4px; }
.action-bar button .ico { font-size: 14px; line-height: 1; }
.action-bar .btn-hint { background: #eef6d4; border-color: #b7cf72; color: #274a00; }
.action-bar .btn-reset { color: var(--red); }

.solver-callout { margin-top: 16px; padding: 14px 16px; border-radius: 12px; background: #EDF1E9; border: 1px solid #D5DED5; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; font-size: 13px; }
.solver-callout a { font-weight: 760; display: inline-flex; align-items: center; min-height: 44px; }
.small { font-size: 13px; }
.muted { color: var(--muted); }

.guide { margin-top: 24px; max-width: 100%; display: grid; gap: 14px; }
.guide-nav { display: flex; gap: 16px; flex-wrap: wrap; padding: 6px 0; font-size: 13px; font-weight: 670; }
.guide section { background: var(--card); border: 1px solid #D8DED6; border-radius: 15px; padding: 20px 24px; }
.guide h2 { font-size: 20px; font-weight: 820; letter-spacing: -0.5px; margin: 0 0 10px; }
.guide p, .guide li { font-size: 13.5px; color: var(--muted); }
.guide code { font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; background: #e9eee3; padding: 1px 5px; border-radius: 4px; color: #0f382d; }
.guide details { border-top: 1px solid #e1e6dc; padding-block: 4px; }
.guide summary { min-height: 44px; display: flex; align-items: center; font-weight: 650; cursor: pointer; font-size: 14px; color: var(--ink); }
.rule-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-block: 8px; }
.rule-table caption { text-align: left; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.rule-table th, .rule-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.rule-table thead th { background: #edf1e8; }

@media (min-width: 760px) {
  .game-workbench { padding: 20px; }
  .work-split { display: grid; grid-template-columns: minmax(340px, 1.3fr) minmax(300px, 1fr); gap: 24px; align-items: start; }
  .control-dock { margin-top: 0; position: sticky; top: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
