/* ==================================================================
   style.css —— 军训保卫战 界面样式
   风格：军绿 + 卡其 + 警示橙，硬朗大字，轻微做旧纸张质感
   ================================================================== */

/* ---------- 设计变量 ---------- */
:root {
  --army-dark: #16281a;
  --army: #24462a;
  --army-mid: #2f5a34;
  --army-light: #4b8049;
  --khaki: #d9c9a3;
  --khaki-dim: #b8a67e;
  --sand: #f2e7c9;
  --paper: #fbf6e6;
  --water: #46c2f0;
  --water-deep: #0d5e86;
  --warn: #ff8b3d;
  --danger: #e6453c;
  --gold: #ffd766;
  --ok: #6cd46a;
  --shadow-hard: 0 6px 0 rgba(0, 0, 0, 0.35);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Noto Sans SC", system-ui, sans-serif;
  color: var(--sand);
  background:
    radial-gradient(1200px 700px at 15% -10%, #3b6b3f 0%, transparent 60%),
    radial-gradient(900px 600px at 110% 10%, #2b5233 0%, transparent 55%),
    linear-gradient(160deg, #14251a 0%, #0d1a12 55%, #101c14 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* 背景细网格：训练场沙盘的感觉 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 46px 46px, 46px 46px;
  z-index: 0;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1240px;
  margin: 0 auto;
  padding: 14px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ================= 顶部标题条 ================= */
.top-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(46, 84, 50, 0.95), rgba(24, 44, 28, 0.95));
  border: 2px solid rgba(217, 201, 163, 0.28);
  box-shadow: var(--shadow-hard), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.banner-left { display: flex; align-items: center; gap: 12px; min-width: 0; }

.banner-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px; height: 46px;
  border-radius: 10px;
  background: linear-gradient(180deg, #7a3f22, #52260f);
  color: var(--gold);
  font-weight: 800;
  letter-spacing: 2px;
  font-size: 15px;
  border: 2px solid rgba(255, 215, 102, 0.5);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.4);
}

.banner-title {
  margin: 0;
  font-size: clamp(18px, 2.4vw, 26px);
  letter-spacing: 2px;
  color: var(--paper);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
}
.banner-title small {
  display: block;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 1px;
  color: var(--khaki-dim);
  margin-top: 3px;
}
.banner-right { display: flex; gap: 8px; flex-shrink: 0; }

/* ================= 通用按钮 ================= */
.ghost-btn {
  padding: 9px 14px;
  border-radius: 10px;
  border: 2px solid rgba(217, 201, 163, 0.45);
  background: rgba(0, 0, 0, 0.18);
  color: var(--sand);
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}
.ghost-btn:hover { background: rgba(217, 201, 163, 0.16); border-color: var(--khaki); }
.ghost-btn:active { transform: translateY(2px); }
.ghost-btn.big { padding: 12px 20px; font-size: 15px; }

.primary-btn {
  padding: 12px 26px;
  border-radius: 12px;
  border: 2px solid #8a5c00;
  background: linear-gradient(180deg, #ffd766, #f0a72c);
  color: #4a2c00;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 4px 0 #8a5c00;
  transition: transform 0.1s ease, filter 0.15s ease;
}
.primary-btn:hover { filter: brightness(1.06); }
.primary-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #8a5c00; }
.primary-btn.slim { padding: 8px 14px; font-size: 13px; box-shadow: 0 3px 0 #8a5c00; }
.primary-btn[disabled] { filter: grayscale(0.7) brightness(0.85); cursor: not-allowed; }

.pill-btn {
  padding: 8px 16px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.28);
  background: rgba(0, 0, 0, 0.22);
  color: var(--paper);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease;
}
.pill-btn:hover { background: rgba(255, 255, 255, 0.14); }
.pill-btn:active { transform: translateY(2px); }

/* ================= HUD ================= */
.hud {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(20, 38, 24, 0.92), rgba(12, 24, 16, 0.92));
  border: 2px solid rgba(217, 201, 163, 0.22);
  box-shadow: var(--shadow-hard);
  flex-wrap: wrap;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
  border: 2px solid rgba(255, 255, 255, 0.08);
  min-width: 150px;
}
.hud-water { border-color: rgba(70, 194, 240, 0.45); background: rgba(10, 60, 84, 0.35); }
.hud-score { border-color: rgba(255, 215, 102, 0.42); background: rgba(84, 62, 10, 0.32); }

.hud-icon { display: inline-flex; }
.hud-text { display: flex; flex-direction: column; line-height: 1.15; }
.hud-text em { font-style: normal; font-size: 11px; letter-spacing: 2px; color: var(--khaki-dim); }
.hud-text strong { font-size: 24px; font-weight: 800; letter-spacing: 1px; font-variant-numeric: tabular-nums; }
.hud-water strong { color: #9fe4ff; }
.hud-score strong { color: var(--gold); }

/* 数字跳动动画 */
@keyframes hud-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.28); }
  100% { transform: scale(1); }
}
.hud-text strong.pop { animation: hud-pop 0.28s ease; }

.hud-meta { display: flex; gap: 8px; background: transparent; border: none; padding: 0; min-width: 0; }
.meta-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(217, 201, 163, 0.18);
  min-width: 74px;
}
.meta-chip em { font-style: normal; font-size: 10px; letter-spacing: 2px; color: var(--khaki-dim); }
.meta-chip strong { font-size: 16px; color: var(--paper); font-variant-numeric: tabular-nums; }

.hud-actions { margin-left: auto; }

/* ================= 画布舞台 ================= */
.stage-wrap {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  border: 3px solid rgba(217, 201, 163, 0.35);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5), inset 0 0 0 2px rgba(0, 0, 0, 0.35);
  background: #2f5a34;
  aspect-ratio: 1180 / 700;
  width: 100%;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  cursor: crosshair;
}

/* 画布进入游戏前的轻微呼吸光 */
.stage-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 90px rgba(0, 0, 0, 0.45);
}

/* ================= 覆盖层与面板 ================= */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: radial-gradient(circle at 50% 40%, rgba(10, 22, 14, 0.72), rgba(6, 14, 9, 0.92));
  backdrop-filter: blur(3px);
  overflow: auto;
}
.overlay.hidden { display: none; }

.screen { display: none; width: 100%; max-width: 900px; }
.screen.active { display: block; animation: screen-in 0.28s ease; }

@keyframes screen-in {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.panel {
  position: relative;
  border-radius: 18px;
  padding: 22px 24px;
  background:
    linear-gradient(180deg, rgba(250, 245, 229, 0.97), rgba(226, 214, 184, 0.97));
  color: #22301f;
  border: 3px solid #8a7a4e;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5), inset 0 0 0 3px rgba(255, 255, 255, 0.5);
}
/* 做旧斜纹 */
.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 15px;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    135deg,
    rgba(120, 100, 60, 0.05) 0px,
    rgba(120, 100, 60, 0.05) 6px,
    transparent 6px,
    transparent 14px
  );
  opacity: 0.75;
}
.panel-small { max-width: 460px; margin: 0 auto; text-align: center; }
.panel-over { max-width: 760px; margin: 0 auto; }
.panel-howto { max-width: 820px; margin: 0 auto; }

.panel-title {
  margin: 0 0 6px;
  font-size: clamp(20px, 2.6vw, 28px);
  letter-spacing: 2px;
  color: #29401f;
  text-shadow: 0 1px 0 #fff;
}
.panel-title.danger { color: #a3231b; }
.panel-sub { margin: 0 0 16px; font-size: 13.5px; line-height: 1.7; color: #4c5a43; }
.panel-foot { margin-top: 14px; font-size: 12px; color: #6a7157; text-align: center; }

/* ---------- 难度卡片 ---------- */
.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}

.diff-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 16px 14px;
  text-align: left;
  cursor: pointer;
  border-radius: 14px;
  border: 3px solid #8a7a4e;
  background: linear-gradient(180deg, #fffdf4, #efe6cd);
  color: #26301f;
  box-shadow: 0 5px 0 rgba(90, 76, 40, 0.55);
  transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease;
  overflow: hidden;
}
.diff-card::after {
  content: "";
  position: absolute;
  right: -30px; top: -30px;
  width: 90px; height: 90px;
  border-radius: 50%;
  opacity: 0.16;
  background: currentColor;
}
.diff-card:hover { transform: translateY(-4px); box-shadow: 0 9px 0 rgba(90, 76, 40, 0.55); }
.diff-card:active { transform: translateY(1px); box-shadow: 0 3px 0 rgba(90, 76, 40, 0.55); }

.diff-flag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: 9px;
  font-weight: 800;
  color: #fff;
  border: 2px solid rgba(0, 0, 0, 0.25);
}
.diff-name { font-size: 21px; font-weight: 800; letter-spacing: 3px; }
.diff-desc { font-size: 12.5px; color: #56603f; line-height: 1.6; }
.diff-tag {
  align-self: flex-start;
  margin-top: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  background: rgba(0, 0, 0, 0.08);
  color: #4c5a43;
}
.diff-easy { color: #2b7a3a; }
.diff-easy .diff-flag { background: #3fa04d; }
.diff-easy:hover { border-color: #3fa04d; }
.diff-normal { color: #2f6fa8; }
.diff-normal .diff-flag { background: #3d84c6; }
.diff-normal:hover { border-color: #3d84c6; }
.diff-hard { color: #b23a2c; }
.diff-hard .diff-flag { background: #d1483a; }
.diff-hard:hover { border-color: #d1483a; }

/* ---------- 结算数据 ---------- */
.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 6px 0 16px;
}
.result-item {
  padding: 12px;
  border-radius: 12px;
  background: rgba(36, 70, 42, 0.1);
  border: 2px dashed rgba(90, 76, 40, 0.35);
  text-align: center;
}
.result-item em { display: block; font-style: normal; font-size: 11px; letter-spacing: 2px; color: #6a7157; }
.result-item strong { display: block; font-size: 26px; font-weight: 800; color: #29401f; font-variant-numeric: tabular-nums; }

/* ---------- 排行榜 ---------- */
.rank-block {
  border-radius: 14px;
  border: 2px solid rgba(90, 76, 40, 0.35);
  background: rgba(255, 255, 255, 0.55);
  padding: 12px 14px;
  margin-bottom: 16px;
}
.rank-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.rank-head h3 { margin: 0; font-size: 15px; letter-spacing: 2px; color: #29401f; }
.rank-tools { display: flex; gap: 8px; align-items: center; }
.name-input {
  width: 150px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 2px solid rgba(90, 76, 40, 0.45);
  background: #fffdf4;
  font-size: 13px;
  color: #26301f;
  font-family: inherit;
}
.name-input:focus { outline: 2px solid #3d84c6; outline-offset: 1px; }
.rank-status { min-height: 18px; font-size: 12px; color: #6a7157; margin: 8px 0 4px; }
.rank-status.ok { color: #2b7a3a; font-weight: 700; }
.rank-status.err { color: #a3231b; font-weight: 700; }

.rank-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 190px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.rank-list li {
  display: grid;
  grid-template-columns: 34px 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 9px;
  background: rgba(36, 70, 42, 0.08);
  font-size: 13px;
}
.rank-list li .rk { font-weight: 800; color: #6a7157; text-align: center; }
.rank-list li .nm { font-weight: 700; color: #26301f; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-list li .df { font-size: 11px; color: #6a7157; }
.rank-list li .sc { font-weight: 800; color: #a3231b; font-variant-numeric: tabular-nums; }
.rank-list li:nth-child(1) { background: linear-gradient(90deg, rgba(255, 215, 102, 0.55), rgba(255, 215, 102, 0.12)); }
.rank-list li:nth-child(2) { background: linear-gradient(90deg, rgba(200, 210, 220, 0.55), rgba(200, 210, 220, 0.12)); }
.rank-list li:nth-child(3) { background: linear-gradient(90deg, rgba(226, 178, 118, 0.5), rgba(226, 178, 118, 0.1)); }
.rank-list .empty { justify-content: center; color: #6a7157; font-style: italic; }

/* ---------- 玩法说明 ---------- */
.howto-body { max-height: 46vh; overflow: auto; padding-right: 6px; }
.howto-body p { margin: 0 0 10px; font-size: 13.5px; line-height: 1.8; color: #3d4a35; }
.howto-units { margin: 0 0 10px; padding-left: 20px; font-size: 13.5px; line-height: 1.9; color: #3d4a35; }
.howto-units li b { color: #29401f; }
kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid rgba(90, 76, 40, 0.5);
  border-bottom-width: 2px;
  background: #fffdf4;
  font-family: inherit;
  font-size: 12px;
}

/* ---------- 按钮行 ---------- */
.btn-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 6px; }

/* ================= 底部士兵栏 ================= */
.dock {
  display: flex;
  align-items: stretch;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(28, 52, 32, 0.96), rgba(14, 28, 18, 0.96));
  border: 2px solid rgba(217, 201, 163, 0.28);
  box-shadow: var(--shadow-hard);
}

.dock-title {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  padding-right: 12px;
  border-right: 2px dashed rgba(217, 201, 163, 0.25);
  flex-shrink: 0;
}
.dock-title span { font-size: 15px; font-weight: 800; letter-spacing: 3px; color: var(--khaki); }
.dock-title small { font-size: 11px; color: rgba(217, 201, 163, 0.6); max-width: 120px; line-height: 1.5; }

.dock-cards {
  display: flex;
  gap: 10px;
  flex: 1;
  overflow-x: auto;
  padding-bottom: 4px;
}

/* 士兵卡片（JS 生成 <button class="unit-card">） */
.unit-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 118px;
  padding: 8px 10px 10px;
  border-radius: 12px;
  border: 2px solid rgba(217, 201, 163, 0.35);
  background: linear-gradient(180deg, rgba(70, 108, 70, 0.5), rgba(24, 44, 28, 0.75));
  color: var(--sand);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  overflow: hidden;
  font-family: inherit;
}
.unit-card:hover { transform: translateY(-3px); border-color: var(--khaki); }
.unit-card:active { transform: translateY(0); }
.unit-card.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(255, 215, 102, 0.35), 0 0 22px rgba(255, 215, 102, 0.35);
  background: linear-gradient(180deg, rgba(120, 96, 30, 0.6), rgba(44, 40, 16, 0.8));
}
.unit-card.locked { filter: grayscale(0.55) brightness(0.7); cursor: not-allowed; }

.uc-thumb { width: 64px; height: 64px; image-rendering: pixelated; }
.uc-name { font-size: 12.5px; font-weight: 800; letter-spacing: 1px; }
.uc-cost {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 800;
  color: #9fe4ff;
}
.uc-cost .dot {
  width: 9px; height: 12px;
  border-radius: 3px 3px 5px 5px;
  background: linear-gradient(180deg, #8fe0ff, #2aa8dc);
  border: 1px solid #0d5e86;
}
.uc-desc { font-size: 10.5px; color: rgba(217, 201, 163, 0.75); line-height: 1.45; text-align: center; min-height: 26px; }
.uc-key {
  position: absolute;
  top: 5px; left: 6px;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.4);
  color: var(--khaki);
}

/* 冷却遮罩：从上往下退去 */
.uc-cd {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 0%;
  background: rgba(6, 14, 9, 0.62);
  pointer-events: none;
  transition: height 0.08s linear;
}
/* 资源不足：红色描边 */
.unit-card.no-water { border-color: rgba(230, 69, 60, 0.55); }

/* 资源不足提示 */
@keyframes shake-x {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
.hud-water.deny { animation: shake-x 0.3s ease; border-color: var(--danger) !important; }

/* ================= 页脚说明 ================= */
.footnote {
  margin: 0;
  text-align: center;
  font-size: 11.5px;
  color: rgba(217, 201, 163, 0.45);
}

/* ================= 小屏适配 ================= */
@media (max-width: 860px) {
  .hud { gap: 8px; }
  .hud-item { min-width: 0; flex: 1 1 130px; padding: 6px 10px; }
  .hud-text strong { font-size: 19px; }
  .hud-meta { flex: 1 1 100%; }
  .dock { flex-direction: column; }
  .dock-title { flex-direction: row; align-items: center; gap: 10px; border-right: none; border-bottom: 2px dashed rgba(217, 201, 163, 0.25); padding: 0 0 8px; }
  .dock-title small { max-width: none; }
  .unit-card { min-width: 102px; }
  .uc-thumb { width: 52px; height: 52px; }
  .banner-badge { display: none; }
}
