/* 四个角色共用本地图集，首页、角色卡和战场无需重复下载同一角色。 */
.game-sprite {
  display: block;
  aspect-ratio: 1;
  background: url("/ai/game-characters.webp") 0 0 / 200% 200% no-repeat;
}
.game-sprite[data-character="code"] { background-position: right top; }
.game-sprite[data-character="guard"] { background-position: left bottom; }
.game-sprite[data-character="manager"] { background-position: right bottom; }
.game-sprite[data-character="boss"] { background: url("/ai/game-boss.webp") center / contain no-repeat; }
/* 新关卡的两位首领和两种特殊高管共用一张透明图集。 */
.game-sprite:is([data-character="finance"], [data-character="tech"], [data-character="audit"], [data-character="runner"]) {
  background-image: url("/ai/game-campaign-characters.webp");
}
.game-sprite[data-character="tech"] { background-position: right top; }
.game-sprite[data-character="audit"] { background-position: left bottom; }
.game-sprite[data-character="runner"] { background-position: right bottom; }
.home-game-icon { width: clamp(28px, 3.55vw, 52px); flex: none; }

/* 游戏沿用百搭的墨绿底色与主操作色，咖啡值和危险提示保留独立色彩。 */
#game {
  --game-ink: var(--ink);
  --game-muted: var(--muted);
  --game-line: var(--line);
  --game-panel: var(--surface);
  --game-dark: var(--field);
  --game-raised: #142b22;
  --game-amber: #ffcc79;
  --game-teal: var(--accent-deep);
  --game-rose: var(--danger);
  --game-danger-surface: #3e252a;
  --map-surface: #12271e;
  --map-tile: #1d3228;
  --map-tile-alt: #233d30;
  --map-border: #688e78;
  color: var(--game-ink);
}
body:has(#game:not([hidden])) { background: radial-gradient(ellipse at 56% 12%, var(--accent-soft), var(--paper) 68%); }
body:has(#game:not([hidden])) .wrap { padding-top: 26px; }
.game-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 166px;
  margin-bottom: 14px;
}
.game-hero-copy { position: relative; z-index: 1; }
.game-tag { color: var(--game-teal); font-weight: 700; font-size: 13px; letter-spacing: .12em; }
.game-tag span { margin-inline: 5px; color: var(--game-muted); }
.game-hero h1 { margin-block: 10px; font-size: clamp(30px, 5.4vw, 74px); font-weight: 950; letter-spacing: -.055em; }
.game-hero em { color: var(--accent); font-style: normal; }
.game-hero-copy > p:last-child { color: var(--game-muted); font-size: clamp(14px, 1.6vw, 17px); line-height: 1.6; }
.game-hero-art {
  position: relative;
  isolation: isolate;
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 0 1 346px;
  align-self: stretch;
  min-width: 165px;
  overflow: hidden;
}
.game-hero-art::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 12% 0 5%;
  background: repeating-linear-gradient(130deg, transparent 0 15px, #8de8b82b 16px 17px, transparent 18px 24px);
  mask-image: radial-gradient(ellipse, #000, transparent 70%);
}
.game-hero-art .game-sprite { width: min(50%, 170px); filter: drop-shadow(0 5px 10px var(--paper)); }
.game-hero-art [data-character="manager"] { order: 1; transform: translate(-7%, 2%) rotate(8deg); }
.game-hero-art [data-character="coffee"] { transform: translate(12%, 0) rotate(-6deg); }

.game-levels {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.game-level {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  min-height: 52px;
  padding: 5px 10px;
  border: 1px solid var(--game-line);
  border-radius: 9px;
  background: var(--game-panel);
  color: var(--game-ink);
  text-align: left;
  cursor: pointer;
}
.game-level[data-map="finance"] { background: #24281f; }
.game-level[data-map="tech"] { background: #14282c; }
.game-level[aria-current="step"] { background: var(--accent-soft); border-color: var(--accent); box-shadow: inset 0 -2px var(--accent); }
.game-level:hover:not(:disabled) { border-color: var(--game-teal); }
.game-level:disabled { opacity: 1; cursor: default; }
.game-level[data-locked] .game-sprite { filter: grayscale(.8); opacity: .68; }
.game-level .game-sprite { width: 41px; flex: none; }
.game-level b, .game-level small { display: block; }
.game-level b { font-size: 13px; }
.game-level small { margin-top: 2px; color: var(--game-muted); font-size: 11px; }
.game-level[aria-current="step"] small { color: var(--game-teal); }

/* 指标独立于角色栏和战场排序，移动端操作时仍能一起看到。 */
.game-hud {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 14px;
  border: 1px solid var(--game-line);
  border-radius: 12px;
  background: var(--game-dark);
}
.game-hud > div { display: flex; align-items: center; gap: 12px; padding: 10px clamp(9px, 2vw, 20px); }
.game-hud > div + div { border-left: 1px solid var(--game-line); }
.game-hud > div > div { color: var(--game-muted); font-size: 12px; line-height: 1.35; }
.game-hud strong { display: block; color: var(--game-ink); font: 750 clamp(19px, 2.4vw, 28px)/1.15 ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.game-hud-icon {
  display: grid;
  place-items: center;
  width: clamp(25px, 3.6vw, 40px);
  aspect-ratio: 1;
  flex: none;
  border-radius: 8px;
  font: 800 clamp(15px, 2.1vw, 23px)/1 system-ui, sans-serif;
}
.game-energy { color: var(--game-amber); background: #43342d; }
#game[data-coffee-frozen] .game-hud > div:first-child,
#game[data-map="finance"]:has(.game-boss[data-charging]) .game-hud > div:first-child {
  box-shadow: inset 0 0 0 2px #efad80;
  background: var(--game-danger-surface);
}
#game[data-coffee-frozen] #game-energy::after {
  content: "停产";
  margin-left: 5px;
  color: #ffd0af;
  font: 700 11px system-ui, sans-serif;
}
.game-life { color: var(--game-rose); background: var(--game-danger-surface); }
.game-wave { color: var(--game-teal); background: var(--accent-soft); }

.game-layout {
  display: grid;
  grid-template: "map team" auto "map controls" 1fr / minmax(0, 1fr) 248px;
  gap: 14px;
}
.game-map, .game-team, .game-controls { background: var(--game-panel); border: 1px solid var(--game-line); border-radius: 12px; }
.game-map { grid-area: map; overflow: hidden; }
.game-map-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 11px 16px; }
.game-map-head > div { display: flex; align-items: center; gap: 9px; }
.game-map-head .game-tool { width: auto; margin-top: 0; padding: 5px 8px; font-size: 12px; white-space: nowrap; }
.game-map-head h2, .game-team h2 { font-size: 16px; font-weight: 800; }
#game-phase { border-radius: 5px; padding: 4px 8px; color: var(--game-amber); background: #44342e; font-size: 12px; font-weight: 700; }
.game-sound { min-height: 44px; padding: 5px 8px; color: var(--game-ink); border-color: var(--game-line); background: var(--game-raised); font-size: 12px; }
.game-sound[aria-pressed="true"] { color: var(--game-teal); }
.game-boss { padding: 9px 16px 11px; background: var(--game-danger-surface); border-block: 1px solid #995869; }
.game-boss > div { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.game-boss strong { color: #ffd4a2; font-size: 14px; }
.game-boss span { color: #ffd2d8; font-size: 12px; }
.game-boss progress { display: block; appearance: none; width: 100%; height: 8px; margin-top: 6px; border: 0; border-radius: 5px; background: #271719; accent-color: #f28498; overflow: hidden; }
.game-boss progress::-webkit-progress-bar { background: #271719; }
.game-boss progress::-webkit-progress-value { background: linear-gradient(90deg, #ffaf78, #f28498); }
.game-boss progress::-moz-progress-bar { background: linear-gradient(90deg, #ffaf78, #f28498); }
.game-boss[data-stage="second"] { background: #512534; }
.game-boss[data-charging] { box-shadow: inset 0 0 0 2px #ffae99; }
.game-boss[data-stage="defeated"] { background: var(--accent-soft); border-color: var(--game-line); }
.game-scene { position: relative; isolation: isolate; padding: 65px clamp(12px, 2.9vw, 37px) 13px; background: var(--map-surface); }
/* 窗框和楼宇夜景压低明度，让战场里的角色、血条与格线保持可读。 */
.game-windows {
  position: absolute;
  z-index: -1;
  inset: 0 0 auto;
  height: 67px;
  background:
    repeating-linear-gradient(90deg, #0e241d 0 4px, transparent 4px 19%),
    repeating-linear-gradient(90deg, transparent 0 5px, #99bda144 5px 8px, transparent 8px 16px) 56% bottom / 80% 59% no-repeat,
    repeating-linear-gradient(0deg, #36645444 0 8px, #102d2588 8px 14px) 0 bottom / 100% 53% no-repeat,
    linear-gradient(180deg, #0d201b, #20443a 76%, #456957);
  border-bottom: 3px solid var(--game-dark);
}
/* 审计厅保留暖调，数据中心使用冷青，让关卡地图在统一主题里仍有区分。 */
#game[data-map="finance"] {
  --map-surface: #25271e;
  --map-tile: #3b3b2e;
  --map-tile-alt: #464535;
  --map-border: #a39470;
  --map-wall: url("/ai/game-finance-wall.webp");
}
#game[data-map="tech"] {
  --map-surface: #162b30;
  --map-tile: #223841;
  --map-tile-alt: #29434a;
  --map-border: #749ca3;
  --map-wall: url("/ai/game-tech-wall.webp");
}
#game:is([data-map="finance"], [data-map="tech"]) .game-windows {
  background: linear-gradient(0deg, #081611a0, #08161122), var(--map-wall) center 53% / cover no-repeat;
}
.game-doors {
  display: flex;
  position: absolute;
  inset: 17px clamp(12px, 2.9vw, 37px) auto;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 750;
}
.game-doors span { padding: 5px 9px; border: 1px solid; border-radius: 4px; }
.game-doors span:first-child { color: var(--game-teal); background: var(--accent-soft); }
.game-doors span:last-child { color: var(--game-rose); background: var(--game-danger-surface); }
.game-field { position: relative; isolation: isolate; }
.game-cells { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px 0; }
.game-cell {
  position: relative;
  display: grid;
  place-items: center;
  padding: 0;
  height: clamp(57px, 5.7vw, 78px);
  border: 1px solid var(--map-border);
  border-right: 0;
  border-radius: 0;
  background: var(--map-tile);
  cursor: pointer;
}
.game-cell:nth-child(7n) { border-right: 1px solid var(--map-border); }
.game-cell:nth-child(14n+1), .game-cell:nth-child(14n+3), .game-cell:nth-child(14n+5),
.game-cell:nth-child(14n+7), .game-cell:nth-child(14n+9), .game-cell:nth-child(14n+11),
.game-cell:nth-child(14n+13) { background: var(--map-tile-alt); }
.game-cell[aria-disabled="true"] { cursor: default; }
.game-cell[aria-disabled="false"]:is(:hover, :focus-visible) { background: #345945; }
.game-cell:focus-visible { z-index: 2; outline-offset: -3px; }
.game-cell .game-sprite { width: min(100%, clamp(51px, 5.7vw, 73px)); }
.game-cell.game-upgraded { box-shadow: inset 0 0 0 1px #ffd58e; }
.game-cell.game-upgraded::after { position: absolute; top: 2px; right: 4px; content: "✦"; color: #ffe1a5; font-size: 12px; }
.game-cell.game-threat { background: repeating-linear-gradient(135deg, #714149 0 8px, #5b353d 8px 16px); border-color: #cf8993; }
.game-cell.game-threat[aria-disabled="false"]:is(:hover, :focus-visible) { background: #83515a; }
/* 障碍保留原来的格线，只有同事不能放在格中，高管与预警仍按原路线经过。 */
.game-obstacle::before {
  content: "";
  width: 53%;
  height: 55%;
  border: 2px solid #caa379;
  border-radius: 4px;
  box-shadow: 0 3px 0 #0b1a14aa;
  background: repeating-linear-gradient(90deg, #81614e 0 7px, #715145 7px 9px);
}
#game[data-map="tech"] .game-obstacle::before {
  width: 46%;
  height: 68%;
  border-color: #78b8c5;
  background: repeating-linear-gradient(0deg, #192a39 0 5px, #447587 5px 7px);
}
.game-health {
  position: absolute;
  display: block;
  width: 58%;
  height: 4px;
  bottom: 3px;
  left: 21%;
  border-radius: 4px;
  background: var(--game-dark);
  overflow: hidden;
}
.game-health::before { content: ""; width: var(--health, 100%); height: 100%; display: block; background: var(--game-teal); }
.game-actors { position: absolute; z-index: 1; inset: 0; overflow: hidden; pointer-events: none; }
.game-actor {
  position: absolute;
  display: grid;
  place-items: center;
  width: calc(100% / 7);
  height: calc(100% / 5);
  transform: translateX(-50%);
}
.game-actor .game-sprite { width: min(100%, clamp(51px, 5.7vw, 73px)); filter: drop-shadow(0 2px 1px var(--paper)); }
.game-actor[data-rank="lead"] .game-sprite { filter: hue-rotate(32deg) saturate(1.4) drop-shadow(0 2px 1px var(--paper)); }
.game-actor[data-boss] { z-index: 1; }
.game-actor[data-boss] .game-sprite { transform: scale(1.48); filter: drop-shadow(0 1px 6px #fa8e6388); }
.game-actor .game-sprite { animation: game-walk .7s ease-in-out infinite alternate; }
.game-actor[data-boss] .game-sprite { animation-duration: .95s; }
.game-actor .game-health { background: #482732; }
.game-actor .game-health::before { background: var(--game-rose); }
.game-cell.game-fire .game-sprite { filter: brightness(1.45) drop-shadow(0 0 4px var(--game-teal)); }
.game-actor.game-hit .game-sprite { opacity: .68; }

/* 动效使用独立覆盖层，子弹、补给数字和冲击光效始终不会挡住格子点击。 */
.game-effects { position: absolute; z-index: 2; inset: 0; overflow: hidden; pointer-events: none; }
.game-fx {
  position: absolute;
  transform: translate(-50%, -50%);
  color: #ffe1a5;
  font-size: 14px;
  font-weight: 850;
  white-space: nowrap;
  text-shadow: 0 2px 4px var(--paper);
  animation: game-fx-fade .36s ease-out both;
}
.game-fx[data-fx="shot"] {
  width: clamp(13px, 2vw, 29px);
  height: 4px;
  border-radius: 5px;
  background: #baffec;
  box-shadow: 0 0 9px #70efda;
  animation: game-shot .19s linear both;
}
.game-fx[data-fx="earn"] { animation: game-rise .75s ease-out both; }
.game-fx:is([data-fx="impact"], [data-fx="deploy"]) {
  width: clamp(24px, 4vw, 44px);
  aspect-ratio: 1;
  border: 3px solid #ffca8e;
  border-radius: 50%;
  animation: game-ring .32s ease-out both;
}
.game-fx[data-fx="deploy"] { border-color: #a0f5e0; }
.game-fx:is([data-fx="sweep"], [data-fx="skill"]) {
  width: 100%;
  height: min(8vw, 46px);
  background: linear-gradient(90deg, transparent 1%, #ff8d9c9c 33%, #ffd6b3b0 85%, transparent);
  animation: game-fx-fade .47s ease-out both;
}
.game-fx[data-fx="skill"] { background: linear-gradient(90deg, transparent, #9af0dd91, #d1fff1aa, transparent); }
.game-fx[data-fx="entry"] {
  transform: translate(-100%, -110%);
  padding: 5px 9px;
  background: var(--game-danger-surface);
  border: 1px solid #ffae99;
  border-radius: 5px;
  animation: game-fx-fade 1.6s ease-out both;
}
#game[data-phase="paused"] :is(.game-fx, .game-actor .game-sprite) { animation-play-state: paused; }
@keyframes game-walk { to { translate: 0 -4px; } }
@keyframes game-shot { to { left: var(--end); opacity: .35; } }
@keyframes game-rise { from { transform: translate(-50%, -35%); } to { transform: translate(-50%, -155%); opacity: 0; } }
@keyframes game-ring { from { transform: translate(-50%, -50%) scale(.55); } to { transform: translate(-50%, -50%) scale(1.45); opacity: 0; } }
@keyframes game-fx-fade { 65% { opacity: 1; } to { opacity: 0; } }

.game-status { padding: 11px 16px; color: var(--game-muted); font-size: 13px; line-height: 1.55; }
.game-outcome {
  display: grid;
  position: absolute;
  z-index: 3;
  inset: 0;
  place-content: center;
  padding: 18px;
  text-align: center;
  background: #06120fe8;
  color: var(--game-ink);
  pointer-events: none;
}
.game-outcome strong { color: var(--game-amber); font-size: clamp(24px, 4vw, 42px); }
.game-outcome span { margin-top: 8px; font-size: 14px; }

.game-team { grid-area: team; padding: 13px; }
.game-team h2 { margin: 0 0 10px 3px; }
.game-roster { display: grid; gap: 8px; }
.game-card {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding: 4px 8px 4px 3px;
  border: 1px solid var(--game-line);
  border-radius: 8px;
  text-align: left;
  color: var(--game-ink);
  background: var(--game-raised);
  cursor: pointer;
}
.game-card .game-sprite { width: 100%; }
.game-card[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.game-card b, .game-card small { display: block; font-size: 13px; }
.game-card small { margin-top: 3px; color: var(--game-muted); font-size: 12px; }
.game-cost { display: inline-block; color: var(--game-amber); font-size: 12px; margin-top: 3px; }
.game-card[data-unaffordable] .game-cost { color: var(--game-rose); }
.game-controls { grid-area: controls; padding: 13px; align-self: start; }
.game-controls .button { width: 100%; min-height: 44px; }
.game-start { background: var(--accent); color: #041b12; }
.game-start:hover:not(:disabled) { background: #69eaaa; }
.game-tool { width: 100%; min-height: 44px; margin-top: 8px; color: var(--game-teal); background: var(--game-raised); border-color: #4c7863; }
.game-tool span { color: var(--game-amber); font-size: 12px; }
.game-tool:is(:hover, [aria-pressed="true"]):not(:disabled) { background: var(--accent-soft); border-color: var(--game-teal); }
.game-tool:disabled { cursor: default; }
.game-restart { margin-top: 8px; color: var(--game-ink); background: var(--game-raised); border-color: var(--game-line); }
.game-restart:hover { background: var(--accent-soft); }
.game-controls p { margin-top: 9px; color: var(--game-muted); font-size: 12px; line-height: 1.55; }

@media (min-width: 841px) and (max-height: 820px) {
  /* 矮屏桌面收紧标题和棋盘，让值班时少滚动一段距离。 */
  .game-hero { min-height: 128px; }
  .game-hero-art .game-sprite { width: min(50%, 128px); }
  .game-cell { height: clamp(48px, 8vh, 65px); }
  .game-cell .game-sprite, .game-actor .game-sprite { width: min(100%, clamp(45px, 7.8vh, 63px)); }
}
@media (max-width: 840px) {
  /* 手机先选角色再看战场，把开始按钮留在战场下方以免误开波次。 */
  .game-hero { min-height: 135px; }
  .game-layout { grid-template: "team" auto "map" auto "controls" auto / minmax(0, 1fr); }
  .game-roster { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  /* 滚动到较低路线时保留实时资源和波次，棋盘焦点预留对应高度。 */
  .game-hero { position: relative; min-height: 114px; }
  .game-hero-art { position: absolute; inset: 0 -5px auto auto; min-width: 0; width: 118px; height: 58px; }
  .game-hero-copy { padding-top: 32px; }
  .game-levels { gap: 5px; }
  .game-level { flex-direction: column; justify-content: center; gap: 3px; padding: 5px 2px; text-align: center; }
  .game-level .game-sprite { width: 28px; }
  .game-level b { font-size: 12px; }
  .game-level small { font-size: 10px; }
  .game-roster { gap: 5px; }
  .game-card { grid-template-columns: 1fr; justify-items: center; gap: 0; padding: 4px 2px 6px; text-align: center; }
  .game-card .game-sprite { width: 42px; }
  .game-hud { position: sticky; top: 0; z-index: 4; }
  .game-hud > div { gap: 5px; padding-inline: 5px; }
  .game-scene { padding: 55px 0 10px; }
  .game-windows { height: 57px; }
  .game-cell { height: 50px; scroll-margin-top: 68px; }
  .game-team { padding: 9px; }
  .game-map-head { flex-wrap: wrap; padding: 9px 11px; }
  .game-map-head > div { gap: 5px; }
}
@media (prefers-reduced-motion: reduce) {
  /* 保留敌人位置和危险路线信息，装饰动效只在原位短暂淡出。 */
  .game-cell.game-fire .game-sprite { filter: none; }
  .game-actor.game-hit .game-sprite { opacity: 1; }
  .game-actor .game-sprite { animation: none; }
  .game-fx[data-fx] { animation-name: game-fx-fade; }
  .game-fx[data-fx="shot"] { left: var(--end) !important; }
}
