* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #161a24;
  --bg2: #1e2431;
  --tile: #2b3446;
  --tile-hi: #3a465e;
  --line: #3d4a63;
  --txt: #e8edf7;
  --dim: #8794ab;
  --accent: #4ade80;
  --warn: #fbbf24;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body { touch-action: manipulation; }

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- 顶部状态栏 ---------- */
.hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
}
.hud-stats { flex: 1; display: flex; gap: 14px; justify-content: center; }
.stat { display: flex; align-items: baseline; gap: 2px; }
.stat b { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat i { font-size: 11px; font-style: normal; color: var(--dim); }

.hud-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--txt);
  border-radius: 10px;
  font-size: 15px;
  line-height: 1;
  padding: 9px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background .12s, opacity .12s;
}
.hud-btn:active { background: var(--tile-hi); }
#btn-back { padding: 9px 14px; font-size: 20px; }

/* ---------- 底部工具条 ---------- */
.tools {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  padding: 4px 12px calc(10px + env(safe-area-inset-bottom));
}
.tool-btn {
  flex: 1;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--txt);
  border-radius: 14px;
  padding: 11px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 14px;
  transition: background .12s, opacity .12s;
}
.tool-btn:active { background: var(--tile-hi); }
.tool-btn:disabled { opacity: .32; }
.tool-icon { font-size: 15px; line-height: 1; }
.tool-label { font-size: 13.5px; }
.tool-btn em {
  font-style: normal;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  background: rgba(74, 222, 128, .12);
  border-radius: 6px;
  padding: 1px 6px;
  min-width: 22px;
}
.tool-btn:disabled em { color: var(--dim); background: rgba(135, 148, 171, .12); }

/* ---------- 棋盘 ---------- */
.stage {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 0 6px 8px;
}
#board { display: block; touch-action: none; }

/* ---------- 遮罩面板 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 15, 22, .86);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
  animation: fade .18s ease;
}
.overlay.hidden { display: none; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.panel {
  width: 100%;
  max-width: 380px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px 18px;
  text-align: center;
}
.panel h1 { font-size: 24px; font-weight: 700; letter-spacing: 2px; }
.panel h2 { font-size: 21px; font-weight: 700; margin-bottom: 6px; }
.panel .sub { color: var(--dim); font-size: 12.5px; margin-top: 8px; line-height: 1.55; }
.panel .foot { color: var(--dim); font-size: 11px; margin-top: 14px; opacity: .7; }

.level-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin-top: 18px;
}
.level-item {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--txt);
  border-radius: 12px;
  padding: 13px 4px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: border-color .12s, background .12s;
}
.level-item:active { background: var(--tile); }
.level-item .num { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.level-item .meta { font-size: 10px; color: var(--dim); }
.level-item.done { border-color: var(--accent); }
.level-item.done .num::after { content: " ✓"; color: var(--accent); font-size: 13px; }
.level-item.locked { opacity: .38; }
.level-item.locked .meta::after { content: " 🔒"; }

.act { display: flex; gap: 9px; margin-top: 18px; }
.btn {
  flex: 1;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--txt);
  border-radius: 12px;
  padding: 13px;
  font-size: 14.5px;
  font-weight: 500;
  cursor: pointer;
}
.btn:active { background: var(--tile); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #10281a; font-weight: 600; }
.btn.primary:active { opacity: .82; }
.btn:disabled { opacity: .35; }

.link-btn {
  appearance: none;
  border: 0;
  background: none;
  color: var(--dim);
  font-size: 13px;
  margin-top: 14px;
  padding: 6px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* 横屏矮屏：收紧顶部 */
@media (max-height: 460px) {
  .hud { padding: 4px 8px; }
  .panel { padding: 16px 14px; }
  .panel h1 { font-size: 19px; }
}
