:root {
  --green-900: #0f1f13;
  --green-800: #16291a;
  --green-700: #1e3a22;
  --green-600: #2c5330;
  --line: #35603a;
  --sand: #e8dfc4;
  --gold: #ffd93b;
  --red: #e0574a;
  --text: #eef6e8;
  --muted: #a9c19f;
  --radius: 14px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(1200px 600px at 50% -10%, #24462a 0%, var(--green-900) 70%);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { overflow: hidden; }

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 1600px;
  margin: 0 auto;
  padding: 10px 12px 12px;
  gap: 10px;
}

/* ---------- 顶栏 ---------- */
.hud {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  background: linear-gradient(180deg, var(--green-700), var(--green-800));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 14px;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; letter-spacing: 0.5px; }
.brand span { font-size: 20px; }
.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-left: auto; }
.stat {
  display: flex; flex-direction: column; align-items: center;
  min-width: 88px; padding: 4px 10px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
}
.stat span { font-size: 11px; color: var(--muted); }
.stat b { font-size: 18px; font-variant-numeric: tabular-nums; }
.stat.warn b { color: var(--gold); }
.stat.warn.danger b { color: var(--red); animation: blink 0.7s steps(2, end) infinite; }
@keyframes blink { 50% { opacity: 0.35; } }
.tools { display: flex; gap: 8px; }

/* ---------- 按钮 ---------- */
.btn {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: linear-gradient(180deg, #2f5c33, #234626);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 14px;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(180deg, #f0b429, #d18b12); color: #2b1d00; border-color: #f7d072; font-weight: 700; }
.btn.ghost { background: rgba(255, 255, 255, 0.06); }
.btn.on { background: linear-gradient(180deg, #3f9e4d, #2b7a37); border-color: #7ee08c; }
.btn.ghost.off { opacity: 0.55; }
.btn:disabled { opacity: 0.6; cursor: progress; }

/* ---------- 舞台 ---------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: #8fd0f2;
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* 口令牌 */
.cmd {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  min-width: min(420px, 78vw);
  text-align: center;
  padding: 8px 22px 10px;
  background: rgba(12, 26, 15, 0.82);
  border: 2px solid rgba(255, 217, 59, 0.5);
  border-radius: 16px;
  backdrop-filter: blur(4px);
  pointer-events: none;
}
.cmd-label { font-size: 11px; letter-spacing: 4px; color: var(--gold); opacity: 0.85; }
.cmd-text { font-size: clamp(28px, 5vw, 46px); font-weight: 800; letter-spacing: 6px; line-height: 1.15; }
.cmd-bar { height: 8px; margin: 6px auto 2px; width: 100%; background: rgba(255, 255, 255, 0.16); border-radius: 6px; overflow: hidden; }
.cmd-bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #7ee08c, #ffd93b); transition: width 0.06s linear; }
.cmd.rest .cmd-text { color: var(--muted); }
.cmd.rest .cmd-bar i { background: linear-gradient(90deg, #4a7d52, #6fa87a); }
.cmd-hint { font-size: 12px; color: var(--muted); }

/* 提示条 */
.toast {
  position: absolute;
  left: 50%; bottom: 16px;
  transform: translate(-50%, 20px);
  z-index: 7;
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(10, 20, 12, 0.86);
  border: 1px solid var(--line);
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.good { border-color: #7ee08c; color: #c9f7cf; }
.toast.warn { border-color: var(--gold); color: #ffe9a8; }

/* ---------- 遮罩层 ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: auto;
  background: rgba(6, 14, 8, 0.62);
  backdrop-filter: blur(3px);
}
.overlay[hidden] { display: none; }
.card {
  width: min(900px, 100%);
  background: linear-gradient(180deg, #17301c, #102315);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px 22px 18px;
  box-shadow: var(--shadow);
}
.card.narrow { width: min(560px, 100%); }
.card h1 { margin: 0 0 6px; font-size: clamp(20px, 3vw, 26px); }
.card .sub { margin: 0 0 14px; color: var(--muted); font-size: 14px; line-height: 1.7; }
.grid { display: grid; grid-template-columns: 1.05fr 0.95fr; gap: 16px; }
.card h3 { margin: 0 0 8px; font-size: 15px; color: var(--gold); }
.rules { margin: 0; padding-left: 18px; font-size: 13.5px; line-height: 1.85; color: #dbe9d4; }
.tip { margin: 10px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.7; }
kbd {
  display: inline-block;
  padding: 1px 7px;
  margin: 0 1px;
  border-radius: 6px;
  background: #0d1a10;
  border: 1px solid #3d6a42;
  border-bottom-width: 2px;
  font-family: inherit;
  font-size: 12.5px;
  color: #eaf7e4;
}
table.keys { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.keys tr { border-bottom: 1px dashed rgba(255, 255, 255, 0.1); }
table.keys td { padding: 6px 4px; }
table.keys td:last-child { text-align: right; white-space: nowrap; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
input {
  font: inherit;
  flex: 1 1 180px;
  min-width: 140px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  outline: none;
}
input:focus { border-color: var(--gold); }
.msg { min-height: 18px; margin: 10px 0 0; font-size: 13.5px; color: var(--gold); }

.score { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0 4px; }
.score > div {
  flex: 1 1 120px;
  text-align: center;
  padding: 10px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
}
.score span { display: block; font-size: 12px; color: var(--muted); }
.score b { font-size: 24px; font-variant-numeric: tabular-nums; }

.board { margin-top: 14px; }
.board ol { list-style: none; margin: 0; padding: 0; }
.board li {
  display: grid;
  grid-template-columns: 34px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 14px;
  background: rgba(255, 255, 255, 0.04);
  margin-bottom: 5px;
}
.board li.me { background: rgba(255, 217, 59, 0.16); border: 1px solid rgba(255, 217, 59, 0.5); }
.board li.empty { display: block; text-align: center; color: var(--muted); background: none; }
.board .rank { text-align: center; font-weight: 700; }
.board .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .score { color: var(--gold); font-variant-numeric: tabular-nums; font-weight: 700; }
.board .sub { color: var(--muted); font-size: 12px; }
.board .meta, .meta { margin: 8px 0 0; font-size: 12px; color: var(--muted); }

/* ---------- 操作键盘 ---------- */
.pad {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 8px;
}
.key {
  font: inherit;
  color: var(--text);
  background: linear-gradient(180deg, #24492a, #17301c);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  touch-action: manipulation;
  user-select: none;
  transition: transform 0.06s ease, background 0.12s ease;
}
.key b { font-size: 13px; font-weight: 600; }
.key i { font-size: 11px; font-style: normal; color: var(--muted); }
.key.report { background: linear-gradient(180deg, #6b4a12, #4a3208); border-color: #a97b1c; }
.key:hover { filter: brightness(1.12); }
.key.flash { transform: translateY(2px) scale(0.97); filter: brightness(1.5); }

/* ---------- 响应式 ---------- */
@media (max-width: 1024px) {
  .pad { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .app { padding: 8px; gap: 8px; }
  .hud { padding: 6px 10px; gap: 8px; }
  .brand b { font-size: 14px; }
  .stat { min-width: 68px; padding: 3px 8px; }
  .stat b { font-size: 15px; }
  .tools { margin-left: auto; }
  .btn { padding: 6px 10px; font-size: 13px; }
  .pad { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cmd { min-width: 88vw; padding: 6px 12px 8px; }
  .score b { font-size: 20px; }
  .board li { grid-template-columns: 28px 1fr auto; }
  .board .sub { display: none; }
}
@media (max-height: 620px) and (orientation: landscape) {
  .pad { grid-template-columns: repeat(9, minmax(0, 1fr)); }
  .key b { font-size: 11.5px; }
}
