:root {
  --bg: #07060f;
  --bg2: #0e0c1c;
  --panel: rgba(18, 14, 40, 0.92);
  --neon: #6cf0ff;
  --neon2: #ff4fd8;
  --neon3: #b8ff4a;
  --warn: #ffb347;
  --danger: #ff5c7a;
  --text: #e8e6ff;
  --muted: #8a86b0;
  --cell: 28px;
  --radius: 14px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; min-height: 100%;
  background: radial-gradient(1200px 800px at 50% -10%, #1a1040 0%, var(--bg) 55%);
  color: var(--text); font-family: var(--font);
  user-select: none; overflow-x: hidden;
}
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; opacity: 0.18;
  background-image: linear-gradient(rgba(108,240,255,0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(108,240,255,0.08) 1px, transparent 1px);
  background-size: 24px 24px;
}
h1 {
  margin: 0; font-size: clamp(1.6rem, 6vw, 2.2rem);
  letter-spacing: 0.12em;
  background: linear-gradient(90deg, var(--neon), var(--neon2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 30px rgba(108,240,255,0.35);
}
.sub { color: var(--muted); font-size: 0.9rem; margin-top: 0.35rem; }
.app { max-width: 480px; margin: 0 auto; padding: 16px 12px 100px; position: relative; z-index: 1; }
.screen { display: none; animation: fadeIn 0.25s ease; }
.screen.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--panel); border: 1px solid rgba(108,240,255,0.22);
  border-radius: var(--radius); padding: 16px; margin-top: 14px;
  box-shadow: 0 0 24px rgba(108,240,255,0.08), inset 0 0 40px rgba(255,79,216,0.04);
}
.btn {
  display: block; width: 100%; margin-top: 10px; padding: 14px 16px;
  border: 1px solid rgba(108,240,255,0.45); border-radius: 12px;
  background: linear-gradient(180deg, rgba(108,240,255,0.18), rgba(108,240,255,0.05));
  color: var(--text); font-size: 1rem; font-weight: 700; letter-spacing: 0.06em;
  cursor: pointer; transition: transform 0.12s, box-shadow 0.12s;
}
.btn:active { transform: scale(0.98); }
.btn.primary {
  background: linear-gradient(135deg, rgba(108,240,255,0.35), rgba(255,79,216,0.28));
  box-shadow: 0 0 18px rgba(108,240,255,0.25);
}
.btn.ghost { background: transparent; border-color: rgba(138,134,176,0.4); color: var(--muted); }
.btn.danger { border-color: rgba(255,92,122,0.5); background: rgba(255,92,122,0.12); }

.theme-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px; margin-top: 12px;
  background: rgba(255,79,216,0.12); border: 1px solid rgba(255,79,216,0.35);
  font-size: 0.85rem; color: #ffc6ef;
}

.hud {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 10px;
}
.hud .stat {
  background: rgba(0,0,0,0.35); border: 1px solid rgba(108,240,255,0.2);
  border-radius: 10px; padding: 8px; text-align: center;
}
.hud .stat .l { font-size: 0.7rem; color: var(--muted); }
.hud .stat .v { font-size: 1.05rem; font-weight: 800; color: var(--neon); font-variant-numeric: tabular-nums; }

.board-wrap {
  display: flex; justify-content: center; gap: 10px; align-items: flex-start;
}
.side-col { width: 72px; display: flex; flex-direction: column; gap: 8px; }
.mini-label { font-size: 0.7rem; color: var(--muted); text-align: center; }
.mini-box {
  width: 72px; height: 72px; background: rgba(0,0,0,0.45);
  border: 1px solid rgba(108,240,255,0.25); border-radius: 10px;
  display: grid; place-items: center; position: relative; overflow: hidden;
}
.mini-box canvas { width: 64px; height: 64px; }
#gameCanvas {
  display: block; background: #05040c;
  border: 2px solid rgba(108,240,255,0.35);
  border-radius: 12px;
  box-shadow: 0 0 28px rgba(108,240,255,0.15), inset 0 0 40px rgba(0,0,0,0.6);
  width: min(280px, 70vw); height: auto; touch-action: none;
}
.chips-bar {
  margin-top: 8px; display: flex; justify-content: space-between; align-items: center;
  font-size: 0.85rem; color: var(--neon3);
}
.wave-banner {
  text-align: center; min-height: 1.2em; font-size: 0.85rem; color: var(--warn);
  margin: 6px 0; letter-spacing: 0.08em;
}

.controls {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, rgba(7,6,15,0.95) 30%);
  display: none;
}
.controls.show { display: block; }
.ctrl-row { display: flex; gap: 8px; justify-content: center; margin-top: 6px; }
.ctrl {
  flex: 1; max-width: 72px; height: 52px; border-radius: 12px;
  border: 1px solid rgba(108,240,255,0.35);
  background: rgba(20,16,48,0.9); color: var(--text);
  font-size: 0.85rem; font-weight: 700; cursor: pointer;
}
.ctrl:active { background: rgba(108,240,255,0.25); }
.ctrl.wide { max-width: 110px; }

.pick-grid { display: grid; gap: 10px; margin-top: 12px; }
.pick-card {
  text-align: left; padding: 14px; border-radius: 12px; cursor: pointer;
  border: 1px solid rgba(108,240,255,0.3);
  background: rgba(0,0,0,0.35); color: var(--text);
}
.pick-card:hover, .pick-card:focus { border-color: var(--neon); box-shadow: 0 0 16px rgba(108,240,255,0.2); }
.pick-card.curse { border-color: rgba(255,92,122,0.5); background: rgba(255,92,122,0.08); }
.pick-card .t { font-weight: 800; color: var(--neon); }
.pick-card.curse .t { color: var(--danger); }
.pick-card .d { font-size: 0.85rem; color: var(--muted); margin-top: 4px; }

.lb-row {
  display: grid; grid-template-columns: 36px 1fr auto; gap: 8px;
  padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 0.92rem;
}
.lb-row .rank { color: var(--neon); font-weight: 800; }
.lb-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .sc { color: var(--neon3); font-variant-numeric: tabular-nums; }

.breakdown { font-size: 0.9rem; color: var(--muted); line-height: 1.6; }
.breakdown b { color: var(--text); }
.input-name {
  width: 100%; padding: 12px; margin-top: 10px; border-radius: 10px;
  border: 1px solid rgba(108,240,255,0.3); background: rgba(0,0,0,0.4);
  color: var(--text); font-size: 1rem;
}
.toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  background: rgba(20,16,48,0.95); border: 1px solid var(--neon);
  padding: 10px 16px; border-radius: 999px; z-index: 50;
  display: none; font-size: 0.9rem; box-shadow: 0 0 20px rgba(108,240,255,0.3);
}
.toast.show { display: block; animation: fadeIn 0.2s ease; }
.ad-slot {
  margin-top: 14px; min-height: 50px; border: 1px dashed rgba(138,134,176,0.35);
  border-radius: 10px; display: grid; place-items: center;
  color: var(--muted); font-size: 0.75rem; background: rgba(0,0,0,0.2);
}
.relic-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag {
  font-size: 0.72rem; padding: 3px 8px; border-radius: 999px;
  background: rgba(108,240,255,0.12); border: 1px solid rgba(108,240,255,0.3); color: var(--neon);
}
.paused-overlay {
  position: absolute; inset: 0; display: none; place-items: center;
  background: rgba(0,0,0,0.55); border-radius: 12px; color: var(--neon); font-weight: 800;
}
.board-rel { position: relative; }
.help-keys { font-size: 0.78rem; color: var(--muted); line-height: 1.5; margin-top: 8px; }
@media (min-width: 520px) {
  :root { --cell: 30px; }
  .controls { display: none !important; }
}

/* ---- 操作说明 overlay ---- */
.help-overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(4, 3, 12, 0.88);
  display: none; place-items: center;
  padding: 16px; overflow-y: auto;
}
.help-overlay.show { display: grid; }
.help-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid rgba(108,240,255,0.4);
  border-radius: var(--radius);
  padding: 18px 16px 16px;
  box-shadow: 0 0 40px rgba(108,240,255,0.2);
  max-height: min(92vh, 720px);
  overflow-y: auto;
}
.help-panel h2 {
  margin: 0 0 10px; font-size: 1.25rem;
  background: linear-gradient(90deg, var(--neon), var(--neon2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.help-section { margin-top: 12px; }
.help-section h3 {
  margin: 0 0 6px; font-size: 0.92rem; color: var(--neon3); letter-spacing: 0.04em;
}
.help-section ul {
  margin: 0; padding-left: 1.15em; color: var(--text);
  font-size: 0.88rem; line-height: 1.65;
}
.help-section li { margin: 2px 0; }
.help-section .kbd {
  display: inline-block; min-width: 1.4em; padding: 1px 6px;
  border-radius: 6px; border: 1px solid rgba(108,240,255,0.35);
  background: rgba(0,0,0,0.4); font-size: 0.8rem; color: var(--neon);
  font-family: ui-monospace, monospace; text-align: center;
}
.ghost-hint {
  text-align: center; font-size: 0.78rem; color: var(--muted);
  margin-top: 6px; min-height: 1.2em; opacity: 0; transition: opacity 0.3s;
  pointer-events: none;
}
.ghost-hint.show { opacity: 1; color: var(--neon); }
.ctrl {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; line-height: 1.15; padding: 4px 2px;
}
.ctrl .ctrl-main { font-size: 0.95rem; font-weight: 800; }
.ctrl .ctrl-sub { font-size: 0.62rem; color: var(--muted); font-weight: 600; letter-spacing: 0.02em; }
.ctrl.wide { max-width: 120px; }
@media (max-width: 519px) {
  .ctrl { max-width: 78px; height: 56px; }
  .ctrl.wide { max-width: 130px; }
}

/* ---- language toggle ---- */
.lang-bar {
  display: flex; justify-content: flex-end; gap: 6px;
  margin-bottom: 4px;
}
.lang-btn {
  min-width: 52px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid rgba(138,134,176,0.45);
  background: rgba(0,0,0,0.35); color: var(--muted);
  font-size: 0.8rem; font-weight: 700; letter-spacing: 0.04em;
  cursor: pointer; transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.lang-btn:hover { border-color: rgba(108,240,255,0.5); color: var(--text); }
.lang-btn.active {
  border-color: var(--neon);
  background: rgba(108,240,255,0.18);
  color: var(--neon);
  box-shadow: 0 0 12px rgba(108,240,255,0.2);
}
