/* =========================================================
   发条巡轨 · game.css
   调色板集中在 CSS 变量里：深海军蓝石墨 / 薄荷青货格 / 珊瑚残骸
   ========================================================= */

:root {
  /* 底色 */
  --ink: #0b1220;
  --ink-deep: #060a14;
  --panel: #111a2c;
  --panel-2: #182339;
  --line: #26374f;
  --line-soft: #1b2842;

  /* 主色 */
  --mint: #4ef0c0;
  --cyan: #35d8f5;
  --coral: #ff6f61;
  --coral-deep: #d8443a;
  --warn: #ffb454;

  /* 文字 */
  --text: #dfe9f7;
  --text-dim: #8494ac;

  --font-ui: "Segoe UI", "Microsoft YaHei", "PingFang SC", "Noto Sans SC",
    system-ui, sans-serif;
}

* { box-sizing: border-box; }

/* 允许用 hidden 属性关闭覆盖层与提示列表（class 会覆盖 UA 的 [hidden] 规则） */
[hidden] { display: none !important; }

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

body {
  background:
    radial-gradient(1200px 600px at 50% -10%, #12203a 0%, transparent 60%),
    linear-gradient(180deg, var(--ink-deep) 0%, var(--ink) 55%, #05080f 100%);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* ---------- 舞台 ---------- */
.stage {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  width: 100%;
  min-height: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: clamp(8px, 1.6vw, 18px);
}

/* ---------- HUD ---------- */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, var(--panel-2) 0%, var(--panel) 100%);
  box-shadow: 0 1px 0 rgba(78, 240, 192, 0.08) inset, 0 8px 22px rgba(0, 0, 0, 0.35);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--mint);
  text-shadow: 0 0 14px rgba(78, 240, 192, 0.45);
  white-space: nowrap;
}

.brand-gear {
  font-size: 20px;
  color: var(--cyan);
  animation: spin 9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hud-stats {
  display: flex;
  align-items: stretch;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 96px;
  padding: 6px 10px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: rgba(6, 10, 20, 0.55);
}

.hud-label {
  font-size: 12px;
  letter-spacing: 1.5px;
  color: var(--text-dim);
}

.hud-value {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.hud-cells { color: var(--cyan); }

.hud-state { color: var(--warn); letter-spacing: 1px; }
.hud-state[data-tone="play"] { color: var(--mint); }
.hud-state[data-tone="win"]  { color: var(--mint); }
.hud-state[data-tone="loss"] { color: var(--coral); }

.hud-lives { display: inline-flex; gap: 3px; font-size: 15px; line-height: 1; }
.heart { color: rgba(132, 148, 172, 0.28); }
.heart.on {
  color: var(--coral);
  text-shadow: 0 0 8px rgba(255, 111, 97, 0.65);
}

/* ---------- 画板 ---------- */
.board {
  position: relative;
  width: 100%;
  /* 保持 720:440 画面比例，并避免在小高度视口里纵向溢出 */
  max-width: min(920px, calc((100vh - 205px) * 1.6363));
  aspect-ratio: 720 / 440;
  margin-inline: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--ink-deep);
  box-shadow:
    0 0 0 1px rgba(78, 240, 192, 0.06),
    0 18px 46px rgba(0, 0, 0, 0.5);
  touch-action: none;
}

.board canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- 覆盖层 ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  background:
    radial-gradient(420px 260px at 50% 34%, rgba(53, 216, 245, 0.10), transparent 70%),
    rgba(6, 10, 20, 0.78);
  backdrop-filter: blur(3px);
  transition: opacity 0.22s ease;
}

.overlay[hidden] { display: none; }

.overlay[data-state="loss"] .overlay-title { color: var(--coral); }
.overlay[data-state="win"]  .overlay-title { color: var(--mint); }

.overlay-title {
  margin: 0;
  font-size: clamp(26px, 5.2vw, 42px);
  font-weight: 800;
  letter-spacing: 6px;
  color: var(--text);
  text-shadow: 0 0 22px rgba(78, 240, 192, 0.35);
}

.overlay-text {
  margin: 0;
  max-width: 480px;
  font-size: 14px;
  line-height: 1.75;
  color: var(--text-dim);
}

.overlay-tips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--text-dim);
}

.overlay-tips b { color: var(--cyan); font-weight: 600; }

/* ---------- 按钮 ---------- */
.btn {
  margin-top: 4px;
  min-width: 168px;
  padding: 11px 26px;
  border: 1px solid rgba(78, 240, 192, 0.55);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(78, 240, 192, 0.20), rgba(53, 216, 245, 0.12));
  color: var(--mint);
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 3px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.btn:hover {
  background: linear-gradient(180deg, rgba(78, 240, 192, 0.30), rgba(53, 216, 245, 0.18));
  box-shadow: 0 0 24px rgba(78, 240, 192, 0.28);
}

.btn:active { transform: scale(0.96); }

.btn:focus-visible,
.pad:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

/* ---------- 触屏方向键 ---------- */
.touchpad {
  position: relative;
  width: 172px;
  height: 118px;
  margin: 2px auto 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.pad {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 39px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  color: var(--cyan);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
  transition: background 0.1s ease, color 0.1s ease, box-shadow 0.1s ease;
}

.pad-left  { left: 0;   top: 39px; }
.pad-up    { left: 58px; top: 0; }
.pad-right { left: 116px; top: 39px; }
.pad-down  { left: 58px; top: 78px; }

.pad.active,
.pad:active {
  background: linear-gradient(180deg, rgba(78, 240, 192, 0.30), rgba(53, 216, 245, 0.20));
  border-color: rgba(78, 240, 192, 0.6);
  color: var(--mint);
  box-shadow: 0 0 18px rgba(78, 240, 192, 0.30);
}

.hint {
  margin: 0;
  text-align: center;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--text-dim);
}

/* ---------- 无障碍 ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  overflow-wrap: normal;
}

@media (prefers-reduced-motion: reduce) {
  .brand-gear { animation: none; }
  .overlay, .btn, .pad { transition: none; }
}