:root {
  --bg: #05070f;
  --panel: rgba(16, 22, 44, 0.74);
  --line: rgba(120, 190, 255, 0.18);
  --text: #e9f1ff;
  --muted: #8ea4c8;
  --cyan: #6ff0ff;
  --gold: #ffd479;
  --danger: #ff6b8b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

.app {
  display: grid;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "head" "stage" "pad" "foot";
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
}

.app[data-orient="landscape"] {
  grid-template-columns: minmax(0, 1fr) clamp(220px, 30vw, 340px);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "stage head" "stage side" "stage pad" "stage foot";
}

/* ---------- 顶部信息 ---------- */
.topbar {
  grid-area: head;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas: "brand chips" "stats stats";
  align-items: center;
  gap: 8px 10px;
  padding: 8px 12px;
  background: linear-gradient(180deg, rgba(24, 34, 66, 0.85), rgba(10, 14, 30, 0.85));
  border: 1px solid var(--line);
  border-radius: 16px;
}

.brand { grid-area: brand; display: flex; align-items: center; gap: 9px; min-width: 0; }
.logo { width: 30px; height: 30px; flex: none; }
.logo svg { width: 100%; height: 100%; display: block; }
.brand-text h1 { margin: 0; font-size: 16px; letter-spacing: 0.08em; font-weight: 600; }
.brand-text p { margin: 1px 0 0; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }

.stats {
  grid-area: stats;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}
.stat {
  min-width: 52px;
  text-align: center;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.stat span { display: block; font-size: 10px; color: var(--muted); }
.stat b { font-size: 15px; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }

.chips { grid-area: chips; display: flex; align-items: center; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.chip {
  display: none;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  white-space: nowrap;
}
.chip.is-on { display: inline-flex; }
.chip b { font-size: 13px; font-variant-numeric: tabular-nums; }
.combo-chip.is-on { color: var(--gold); border-color: rgba(255, 212, 121, 0.45); background: rgba(255, 212, 121, 0.12); }
.combo-chip.is-hot { color: #ff9d5c; border-color: rgba(255, 157, 92, 0.5); background: rgba(255, 157, 92, 0.14); }
.shield-chip.is-on { color: #bff6ff; border-color: rgba(120, 240, 255, 0.45); background: rgba(120, 240, 255, 0.14); }
.hint-chip.is-on { color: #ffe0a0; border-color: rgba(255, 205, 120, 0.45); background: rgba(255, 205, 120, 0.14); }
.heart-chip { display: inline-flex; }
.heart { width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 255, 255, 0.14); display: block; }
.heart.on { background: linear-gradient(135deg, #ff9ab4, #ff4d78); box-shadow: 0 0 8px rgba(255, 90, 130, 0.6); }

/* ---------- 棋盘 ---------- */
.stage { grid-area: stage; position: relative; min-width: 0; min-height: 0; }
.board-wrap { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.board-box {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--line), 0 18px 60px rgba(0, 0, 0, 0.55), 0 0 70px rgba(80, 150, 255, 0.10);
}
canvas { display: block; touch-action: none; }

/* ---------- 弹窗 ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 14px;
  background: rgba(4, 7, 16, 0.84);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.overlay.show { display: flex; }
.panel { display: none; width: 100%; max-width: 400px; margin: auto; }
.panel.active { display: block; animation: pop 0.24s ease-out; }
.panel-inner {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}
.kicker { margin: 0; font-size: 10.5px; letter-spacing: 0.24em; color: var(--cyan); text-transform: uppercase; }
.panel h2 { margin: 4px 0 8px; font-size: 24px; letter-spacing: 0.04em; }
.lead { margin: 0 0 4px; font-size: 13px; line-height: 1.75; color: #c3d3ef; }
.meta { margin: 10px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
.meta b { color: var(--gold); }

.rules { list-style: none; margin: 12px 0 4px; padding: 0; display: grid; gap: 6px; }
.rules li { font-size: 12.5px; line-height: 1.6; color: #b6c7e6; padding-left: 15px; position: relative; }
.rules li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 6px;
  height: 6px;
  border-radius: 2px;
  background: var(--cyan);
  transform: rotate(45deg);
}
.rules b { color: #fff; font-weight: 600; }
.rules.compact li { font-size: 11.5px; }
.app[data-orient="portrait"] .rules.compact { display: block; columns: 2; column-gap: 14px; margin: 0; }
.app[data-orient="portrait"] .rules.compact li { font-size: 11.5px; line-height: 1.5; margin-bottom: 3px; break-inside: avoid; }
.app[data-orient="portrait"] .side .card:first-child { padding: 9px 12px; }
.app[data-orient="portrait"] .side .card:first-child h3 { margin-bottom: 5px; font-size: 11.5px; }

.rows { display: grid; gap: 6px; margin: 12px 0 4px; }
.rows.two { grid-template-columns: 1fr 1fr; }
.rows.two div { flex-direction: column; align-items: flex-start; gap: 2px; padding: 8px 10px; }
.rows.two b { font-size: 15px; }
.rows div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 8px 11px;
  background: rgba(255, 255, 255, 0.045);
  border-radius: 10px;
}
.rows span { color: var(--muted); }
.rows b { font-variant-numeric: tabular-nums; }

/* ---------- 玩法引导 ---------- */
.guide-list { list-style: none; margin: 12px 0 6px; padding: 0; display: grid; gap: 8px; }
.guide-item { display: none; }
.guide-item.is-active {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid rgba(120, 240, 255, 0.35);
  background: rgba(120, 240, 255, 0.07);
  min-height: 92px;
}
.guide-item b { display: block; font-size: 15px; margin-bottom: 3px; }
.guide-item p { margin: 0; font-size: 12.5px; line-height: 1.7; color: #b9cbe8; }
.guide-step { margin: 2px 0 0; font-size: 11px; color: var(--muted); letter-spacing: 0.1em; }
.guide-ic {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  position: relative;
}
.guide-ic::before,
.guide-ic::after { content: ''; position: absolute; background: var(--cyan); border-radius: 2px; }
.guide-ic[data-ic="move"]::before { left: 8px; top: 15px; width: 18px; height: 3px; }
.guide-ic[data-ic="move"]::after { right: 7px; top: 10px; width: 10px; height: 10px; border-top: 3px solid var(--cyan); border-right: 3px solid var(--cyan); background: none; transform: rotate(45deg); border-radius: 0; }
.guide-ic[data-ic="combo"]::before { left: 7px; top: 15px; width: 7px; height: 7px; transform: rotate(45deg); background: var(--gold); }
.guide-ic[data-ic="combo"]::after { left: 15px; top: 11px; width: 12px; height: 12px; transform: rotate(45deg); background: var(--gold); opacity: 0.6; }
.guide-ic[data-ic="dash"]::before { left: 7px; top: 15px; width: 20px; height: 3px; background: linear-gradient(90deg, var(--cyan), rgba(111, 240, 255, 0)); }
.guide-ic[data-ic="dash"]::after { display: none; }
.guide-ic[data-ic="shield"]::before { left: 9px; top: 9px; width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--cyan); background: none; }
.guide-ic[data-ic="shield"]::after { display: none; }
.guide-dots { display: flex; justify-content: center; gap: 6px; margin: 6px 0 10px; }
.guide-dots i { width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 255, 255, 0.18); }
.guide-dots i.is-on { background: var(--cyan); box-shadow: 0 0 8px rgba(111, 240, 255, 0.6); }

/* ---------- 按钮 ---------- */
.btn {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  padding: 9px 14px;
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.08s ease, background 0.2s ease;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn.primary {
  background: linear-gradient(135deg, rgba(111, 240, 255, 0.24), rgba(91, 140, 255, 0.24));
  border-color: rgba(111, 240, 255, 0.45);
  color: #e2fbff;
}
.btn.ghost { background: transparent; color: var(--muted); }
.btn.lg { width: 100%; padding: 13px; font-size: 15px; margin-top: 10px; }
.btn.wide { width: 100%; margin-top: 8px; }
.btn-row { display: flex; gap: 8px; margin-top: 8px; }
.btn-row .btn { flex: 1; }
.btn.ad-btn { background: linear-gradient(135deg, rgba(255, 200, 90, 0.26), rgba(255, 140, 90, 0.22)); border-color: rgba(255, 200, 120, 0.5); color: #ffe7b8; }
.btn[hidden] { display: none !important; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: rgba(255, 212, 121, 0.18); color: var(--gold); }
.badge.is-empty { background: rgba(255, 255, 255, 0.08); color: #8ea4c8; }
.btn.is-off { color: var(--muted); text-decoration: line-through; }

/* ---------- 虚拟方向键 ---------- */
.dpad {
  grid-area: pad;
  display: none;
  justify-self: center;
  align-self: center;
  width: var(--pad, 132px);
  max-width: 68vw;
  aspect-ratio: 1 / 1;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 5px;
  border-radius: 20px;
  background: rgba(14, 22, 44, 0.6);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.dpad.is-on { display: grid; }
.dpad-btn {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid rgba(120, 190, 255, 0.22);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  color: #cfeeff;
  padding: 0;
  cursor: pointer;
  position: relative;
  touch-action: none;
  transition: background 0.12s ease, transform 0.08s ease;
}
.dpad-btn:active,
.dpad-btn.is-press {
  background: linear-gradient(135deg, rgba(111, 240, 255, 0.34), rgba(91, 140, 255, 0.3));
  transform: scale(0.94);
}
.dpad-btn.up { grid-area: 1 / 2; }
.dpad-btn.left { grid-area: 2 / 1; }
.dpad-btn.mid { grid-area: 2 / 2; }
.dpad-btn.right { grid-area: 2 / 3; }
.dpad-btn.down { grid-area: 3 / 2; }
.dpad-btn.up::before,
.dpad-btn.down::before,
.dpad-btn.left::before,
.dpad-btn.right::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  border: 7px solid transparent;
}
.dpad-btn.up::before { border-width: 0 6px 9px; border-bottom-color: currentColor; transform: translate(-50%, -60%); }
.dpad-btn.down::before { border-width: 9px 6px 0; border-top-color: currentColor; transform: translate(-50%, -40%); }
.dpad-btn.left::before { border-width: 6px 9px 6px 0; border-right-color: currentColor; transform: translate(-60%, -50%); }
.dpad-btn.right::before { border-width: 6px 0 6px 9px; border-left-color: currentColor; transform: translate(-40%, -50%); }
.dpad-btn.mid {
  font-size: 12px;
  letter-spacing: 0.06em;
  color: #e2fbff;
  background: linear-gradient(135deg, rgba(111, 240, 255, 0.18), rgba(91, 140, 255, 0.18));
  border-color: rgba(111, 240, 255, 0.34);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.dpad-btn.mid .badge { font-size: 10px; padding: 0 6px; }
.app[data-orient="landscape"] .dpad { width: min(132px, 34vh); max-width: none; }

/* ---------- 底部操作 ---------- */
.bottombar {
  grid-area: foot;
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  padding: 6px 2px;
}
.app[data-orient="portrait"] .bottombar { gap: 7px; padding: 0; }
.app[data-orient="portrait"] .bottombar .btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 46px;
  padding: 11px 4px;
  font-size: 13.5px;
  border-radius: 13px;
}

/* ---------- 侧栏 ---------- */
.side {
  grid-area: side;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  min-height: 0;
}
.app[data-orient="portrait"] .side { display: none; }
.app[data-orient="landscape"] .side .card { display: none; }
.app[data-orient="landscape"] .side .credit { display: block; }
.app[data-orient="landscape"] .card { padding: 9px 11px; }
.app[data-orient="landscape"] .card h3 { margin-bottom: 6px; font-size: 12px; }
.app[data-orient="landscape"] .rules.compact { gap: 3px; margin: 0; }
.app[data-orient="landscape"] .rules.compact li { font-size: 11px; line-height: 1.5; }
.app[data-orient="landscape"] .side .card:last-of-type .rows { display: flex; gap: 14px; margin: 0; }
.app[data-orient="landscape"] .side .card:last-of-type .rows div { padding: 0; background: none; font-size: 12px; gap: 6px; }
.app[data-orient="landscape"] .side .card:last-of-type .btn { margin-top: 8px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 11px 13px;
}
.card h3 { margin: 0 0 8px; font-size: 12.5px; letter-spacing: 0.14em; color: #dceaff; }
.card .btn { width: 100%; margin-top: 8px; }
.app[data-orient="portrait"] .side .card:last-of-type {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
}
.app[data-orient="portrait"] .side .card:last-of-type h3 { display: none; }
.app[data-orient="portrait"] .side .card:last-of-type .rows { display: flex; gap: 16px; margin: 0; }
.app[data-orient="portrait"] .side .card:last-of-type .rows div { padding: 0; background: none; font-size: 12px; gap: 6px; }
.app[data-orient="portrait"] .side .card:last-of-type .btn { width: auto; margin: 0; padding: 7px 14px; font-size: 12px; white-space: nowrap; }
.credit { margin: 0; font-size: 10.5px; line-height: 1.65; color: #6d7f9d; }
.credit b { color: #93a7c9; }

.toast {
  position: fixed;
  left: var(--toast-left, 50%);
  top: var(--toast-top, 158px);
  transform: translate(-50%, -14px);
  background: rgba(9, 14, 30, 0.95);
  border: 1px solid var(--line);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 12.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 60;
  width: max-content;
  max-width: min(86vw, var(--toast-max, 340px));
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* ---------- 小屏微调 ---------- */
@media (max-height: 700px) {
  .dpad-btn.mid { font-size: 10px; }
  .dpad-btn.mid .badge { font-size: 9px; padding: 0 4px; }
}
@media (max-height: 460px) {
  .topbar { padding: 5px 10px; gap: 8px; }
  .brand-text h1 { font-size: 14px; }
  .stat { min-width: 46px; padding: 3px 6px; }
  .stat b { font-size: 13px; }
  .btn { padding: 7px 11px; font-size: 12px; }
  .panel h2 { font-size: 20px; }
  .rules { gap: 4px; }
  .guide-item { padding: 8px 10px; }
  .guide-item p { font-size: 11.5px; }
}

@media (max-width: 430px) {
  .bottombar { gap: 6px; }
  .bottombar .btn { padding: 7px 9px; font-size: 11.5px; border-radius: 10px; }
  .bottombar .btn .badge { padding: 0 5px; }
  .app[data-orient="portrait"] .bottombar .btn { padding: 10px 4px; font-size: 12.5px; border-radius: 12px; }
}

@media (max-width: 380px) {
  .brand-text { display: none; }
  .stat { min-width: 44px; }
  .bottombar .btn { padding: 6px 8px; font-size: 11px; }
  .app[data-orient="portrait"] .bottombar .btn { padding: 9px 3px; font-size: 12px; }
}
