/* ═══════════════════════════════════════════════════════════
   军训·木头人 · 像素风样式
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg:        #070b05;
  --panel:     #141d0f;
  --panel-2:   #1b2712;
  --line:      #3d5a26;
  --line-2:    #6b8f3e;
  --ink:       #e8f2d8;
  --muted:     #a3b585;
  --olive:     #8fae57;
  --accent:    #ffd95e;
  --danger:    #e8563f;
  --safe:      #7ddc5a;
  --sand:      #d9c48a;
  --shadow:    0 4px 0 #050803, 0 0 0 3px #25361a;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 50% -10%, #1a2711 0%, #0a1006 55%, #050803 100%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.014) 0 1px, transparent 1px 4px);
  color: var(--ink);
  font-family: "Courier New", ui-monospace, Consolas, "Microsoft YaHei", "PingFang SC", monospace;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px 8px 8px;
}

/* ── 顶栏 ─────────────────────────────────────────────────── */

#topbar {
  width: 100%;
  max-width: 1600px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 8px;
  background: var(--panel);
  border: 2px solid var(--line);
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }

.logo {
  width: 18px; height: 18px;
  flex: 0 0 auto;
  background:
    linear-gradient(90deg, transparent 0 3px, var(--accent) 3px 15px, transparent 15px),
    linear-gradient(0deg, transparent 0 3px, #7a5f14 3px 6px, transparent 6px);
  image-rendering: pixelated;
  box-shadow: 0 0 0 2px #0d1408, 3px 3px 0 #2c4019;
}

.brand-text {
  font-weight: 700;
  letter-spacing: 2px;
  font-size: 17px;
  white-space: nowrap;
}
.brand-sub {
  font-style: normal;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--olive);
  border-left: 2px solid var(--line);
  padding-left: 8px;
  white-space: nowrap;
  overflow: hidden;
}

.top-right { display: flex; align-items: center; gap: 8px; }

.badge {
  font-size: 12px;
  padding: 2px 8px;
  border: 2px solid var(--line);
  background: #0d1408;
  white-space: nowrap;
}
.badge.ok   { color: var(--safe);   border-color: #38601f; }
.badge.warn { color: var(--accent); border-color: #6b5a1c; }
.badge.wait { color: var(--muted);  }

.icon-btn {
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--panel-2);
  border: 2px solid var(--line);
  box-shadow: 0 3px 0 #050803;
  padding: 3px 9px;
  cursor: pointer;
  transition: transform .05s;
}
.icon-btn.small { font-size: 11px; padding: 2px 7px; }
.icon-btn:active { transform: translateY(3px); box-shadow: none; }
.icon-btn.off { color: #66705a; }

/* ── 舞台 ─────────────────────────────────────────────────── */

#stage {
  flex: 1 1 auto;
  width: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 0;
  /* 放大超过可视区域时可以滚动。scrollbar-gutter: stable 很关键：
     否则滚动条一出现就会改变 clientWidth/Height，触发 ResizeObserver
     再次重算尺寸 → 滚动条消失 → 再出现……画面会一直抖。 */
  overflow: auto;
  scrollbar-gutter: stable;
}

#canvas-wrap {
  position: relative;
  display: block;
  margin: auto;            /* flex + margin:auto = 既可居中又能滚动 */
  background: #050803;
  border: 4px solid #2c4019;
  box-shadow: 0 0 0 2px #050803, 0 10px 30px rgba(0,0,0,.6);
  line-height: 0;
  touch-action: none;
}

/* 全屏：铺满整屏并把画布居中 */
#canvas-wrap:fullscreen {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  box-shadow: none;
  background: #050803;
  width: 100vw;
  height: 100vh;
}

.zoom-label {
  font-size: 11px;
  color: var(--muted);
  min-width: 38px;
  text-align: right;
  white-space: nowrap;
}

canvas#game {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #233a1a;
}

#scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,.16) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,.35) 100%);
  mix-blend-mode: multiply;
}

/* ── HUD ──────────────────────────────────────────────────── */

#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 7px;
  line-height: 1.2;
  font-size: 12px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(5,8,3,.72), rgba(5,8,3,0));
}
#hud .hud-cell { display: flex; align-items: center; gap: 6px; }
#hud .hud-right { pointer-events: auto; }
#hud .hud-mid { flex: 1 1 auto; justify-content: center; }

.hud-level { color: var(--accent); letter-spacing: 1px; text-shadow: 2px 2px 0 #000; }

.hud-caps {
  padding: 1px 7px;
  border: 2px solid #6b5a1c;
  background: rgba(5,8,3,.7);
  color: var(--accent);
  white-space: nowrap;
}
.hud-caps.done { color: #0d1408; background: var(--safe); border-color: #b8f0a0; }
.hud-caps.pop { animation: capPop .45s steps(4); }
@keyframes capPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.5); }
  100% { transform: scale(1); }
}

.hud-state {
  padding: 1px 8px;
  border: 2px solid;
  background: rgba(5,8,3,.7);
  white-space: nowrap;
}
.hud-state.safe   { color: var(--safe);   border-color: #2f5a1a; }
.hud-state.move   { color: var(--accent); border-color: #6b5a1c; }
.hud-state.danger { color: var(--danger); border-color: #7a2a1c; animation: blink .35s steps(2) infinite; }

@keyframes blink { 50% { opacity: .35; } }

.hud-timer-wrap { color: #fff; }
.hud-timer-wrap b { font-size: 15px; }
.hud-timer-wrap i { font-style: normal; color: var(--muted); }
.hud-best { color: var(--muted); white-space: nowrap; }

/* 倒计时 */
#countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 76px;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 0 #000, 4px 4px 0 #3a2c07, -3px -3px 0 #000, 3px -3px 0 #000, -3px 3px 0 #000;
  pointer-events: none;
  animation: pop .5s steps(4) infinite;
}
@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.16); } 100% { transform: scale(1); } }

/* 提示条 */
#toast {
  position: absolute;
  left: 50%;
  bottom: 12%;
  transform: translateX(-50%);
  padding: 5px 14px;
  font-size: 13px;
  background: rgba(5,8,3,.85);
  border: 2px solid var(--line);
  color: var(--ink);
  white-space: nowrap;
  pointer-events: none;
}

/* ── 触屏方向键 ───────────────────────────────────────────── */

.pad {
  display: none;              /* 默认隐藏；触屏设备由下面的规则打开 */
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 132px;
  height: 132px;
  pointer-events: none;
}
.pad-btn {
  position: absolute;
  width: 44px; height: 44px;
  font-size: 18px;
  color: var(--ink);
  background: rgba(20,29,15,.82);
  border: 2px solid var(--line-2);
  box-shadow: 0 3px 0 rgba(0,0,0,.6);
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}
.pad-btn:active, .pad-btn.pressed { background: rgba(120,150,70,.9); transform: translateY(2px); box-shadow: none; }
.pad-up    { left: 44px; top: 0; }
.pad-left  { left: 0;  top: 44px; }
.pad-right { left: 88px; top: 44px; }
.pad-down  { left: 44px; top: 88px; }

/* ── 遮罩 / 面板 ──────────────────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 14px;
  overflow: auto;
  background: rgba(5,8,3,.86);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.overlay.hidden, .hidden { display: none !important; }

.panel {
  width: 100%;
  max-width: 460px;
  margin: auto;
  padding: 18px 18px 16px;
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: 0 8px 0 #050803, 0 0 0 3px #25361a, 0 20px 50px rgba(0,0,0,.7);
  text-align: center;
}
.menu-panel { max-width: 480px; }

.game-title {
  margin: 0 0 6px;
  font-size: 30px;
  letter-spacing: 6px;
  color: var(--accent);
  text-shadow: 3px 3px 0 #3a2c07, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000;
}
.game-sub, .panel-sub {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.7;
}
.panel-title { margin: 0 0 6px; font-size: 22px; letter-spacing: 4px; color: var(--accent); }

.field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 2px solid var(--line);
  text-align: left;
}
.field span { font-size: 13px; color: var(--muted); white-space: nowrap; }
.field input {
  flex: 1 1 auto;
  min-width: 0;
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
  background: #0b1207;
  border: 2px solid var(--line);
  padding: 5px 8px;
  outline: none;
}
.field input:focus { border-color: var(--line-2); box-shadow: 0 0 0 2px rgba(143,174,87,.25); }

.btns { display: flex; flex-direction: column; gap: 10px; }
.btns.row { flex-direction: row; flex-wrap: wrap; justify-content: center; }
.btns.row .btn { flex: 1 1 auto; min-width: 92px; }

.btn {
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--panel-2);
  border: 3px solid var(--line);
  box-shadow: 0 5px 0 #050803;
  padding: 9px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: transform .05s;
}
.btn b { font-size: 16px; letter-spacing: 2px; }
.btn small { font-size: 11px; color: var(--muted); letter-spacing: 1px; }
.btn:hover { border-color: var(--line-2); }
.btn:active { transform: translateY(5px); box-shadow: none; }
.btn.primary { background: #33501d; border-color: #82a84c; }
.btn.primary small { color: #cfe0b0; }
.btn.ghost { background: #101a0a; color: var(--muted); }

/* ── 记录榜 ───────────────────────────────────────────────── */

.records {
  margin: 16px 0 12px;
  border: 2px solid var(--line);
  background: var(--panel-2);
  text-align: left;
}
.records-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  background: #0f1709;
  border-bottom: 2px solid var(--line);
}
.records-title { font-size: 13px; color: var(--accent); letter-spacing: 2px; }
.tabs { display: flex; gap: 4px; }
.tabs button {
  font-family: inherit;
  font-size: 12px;
  color: var(--muted);
  background: #0b1207;
  border: 2px solid var(--line);
  padding: 2px 8px;
  cursor: pointer;
}
.tabs button.active { color: #0b1207; background: var(--olive); border-color: #b6d183; }

.records-scroll { max-height: 168px; overflow: auto; }

.records-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.records-table th {
  position: sticky; top: 0;
  background: #16200e;
  color: var(--muted);
  font-weight: 400;
  text-align: left;
  padding: 5px 8px;
  border-bottom: 2px solid var(--line);
}
.records-table td { padding: 5px 8px; border-bottom: 1px dashed #2c4019; }
.records-table tr:last-child td { border-bottom: none; }
.records-table tr.me td { color: var(--accent); }
.records-table tr.empty td { color: var(--muted); text-align: center; padding: 14px 8px; }
.records-table .rank { color: var(--olive); }
.records-table .gold   { color: var(--accent); }
.records-table .silver { color: #cfd6c4; }
.records-table .bronze { color: #c69a63; }

/* ── 帮助 ─────────────────────────────────────────────────── */

.help { font-size: 12.5px; color: var(--muted); text-align: left; }
.help summary {
  cursor: pointer;
  color: var(--olive);
  padding: 4px 0;
  list-style: none;
}
.help summary::-webkit-details-marker { display: none; }
.help summary::before { content: "▸ "; }
.help[open] summary::before { content: "▾ "; }
.help ul { margin: 6px 0 0; padding-left: 18px; line-height: 1.75; }
.help b { color: var(--ink); }

/* ── 失败 / 成功 ──────────────────────────────────────────── */

.big-lose {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--danger);
  text-shadow: 3px 3px 0 #3d0f06, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000;
  animation: shake .5s steps(2) 2;
  margin-bottom: 10px;
}
@keyframes shake {
  0% { transform: translate(0,0); }
  25% { transform: translate(-3px,2px); }
  50% { transform: translate(3px,-2px); }
  75% { transform: translate(-2px,-2px); }
  100% { transform: translate(0,0); }
}

.big-win {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: 6px;
  color: var(--safe);
  text-shadow: 3px 3px 0 #143d08, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000;
  margin-bottom: 8px;
  animation: pop .6s steps(3) 2;
}

.stats { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 10px;
  background: var(--panel-2);
  border: 2px solid var(--line);
}
.stat span { font-size: 12.5px; color: var(--muted); }
.stat b { font-size: 18px; color: var(--accent); }

.new-record {
  margin: 10px 0;
  padding: 8px;
  font-size: 17px;
  letter-spacing: 4px;
  color: #241a00;
  background: var(--accent);
  border: 3px solid #fff2b8;
  box-shadow: 0 4px 0 #6b5a1c;
  animation: pulse 1s steps(3) infinite;
}
@keyframes pulse { 50% { transform: scale(1.04); filter: brightness(1.18); } }

.mini-board { margin: 8px 0 14px; font-size: 12.5px; color: var(--muted); text-align: left; }
.mini-board ol { margin: 6px 0 0; padding-left: 22px; }
.mini-board li { padding: 1px 0; }
.mini-board li.me { color: var(--accent); }

/* ── 底栏 ─────────────────────────────────────────────────── */

#foot {
  width: 100%;
  max-width: 1600px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 11px;
  color: #6f7d5c;
  flex-wrap: wrap;
}
#foot .dot { color: #3d5a26; }

/* 屏幕不高时把说明条收起来，把空间全让给游戏画面 */
@media (max-height: 660px) {
  #foot { display: none; }
  #app { padding: 4px 6px 6px; gap: 4px; }
}

/* ── 自适应 ───────────────────────────────────────────────── */

@media (max-width: 560px) {
  body { font-size: 14px; }
  .brand-text { font-size: 15px; letter-spacing: 1px; }
  .brand-sub { display: none; }
  .game-title { font-size: 24px; letter-spacing: 3px; }
  .big-lose { font-size: 29px; letter-spacing: 2px; }
  .big-win { font-size: 27px; letter-spacing: 3px; }
  .panel { padding: 14px 12px 12px; border-width: 2px; }
  .overlay { padding: 10px 8px; align-items: flex-start; }
  #foot { font-size: 10.5px; }
  #hud { font-size: 11px; }
  .hud-best { display: none; }
}

@media (hover: none) and (pointer: coarse) {
  .pad { display: block; }
}

/* JS 侦测到触屏后加 body.touch */
body.touch .pad { display: block; }
