:root {
  color-scheme: dark;
  --bg: #0b1220;
  --panel: rgba(13, 20, 34, 0.84);
  --panel-2: rgba(18, 28, 45, 0.94);
  --ink: #f2f6ff;
  --muted: #aeb9cf;
  --line: rgba(255, 255, 255, 0.1);
  --teal: #39c9b8;
  --coral: #ff7d6e;
  --gold: #f0c15a;
  --violet: #7f77ff;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.32);
  --radius: 8px;
  --dock-h: 188px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  overflow-x: hidden;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

#bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  z-index: 0;
}

.app-shell {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  color: var(--gold);
  font-weight: 800;
  letter-spacing: 0;
}

.brand-copy {
  display: grid;
  min-width: 0;
}

.brand-copy strong {
  font-size: 18px;
  line-height: 1.1;
}

.brand-copy span {
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-btn,
.toggle-btn,
.primary-btn {
  min-height: 42px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.icon-btn {
  width: 42px;
  padding: 0;
  font-size: 20px;
}

.stage {
  min-height: 0;
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 12px;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.stat {
  min-height: 72px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 12px;
  display: grid;
  align-content: space-between;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  font-size: 24px;
  line-height: 1;
}

.arena {
  min-height: 0;
  min-width: 0;
  display: grid;
  gap: 12px;
}

.meter {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 12px 12px;
}

.meter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.meter-bar {
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.meter-bar span {
  display: block;
  width: 0%;
  height: 100%;
  background: var(--teal);
}

.board-shell {
  position: relative;
  width: min(92vw, 72vh, 740px);
  margin: 0 auto;
  aspect-ratio: 1;
  border-radius: calc(var(--radius) + 2px);
  background: var(--panel-2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.board-halo {
  position: absolute;
  inset: 8%;
  border-radius: 30px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  pointer-events: none;
}

.board {
  position: absolute;
  inset: 12px;
  display: grid;
  gap: 8px;
}

.cell {
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: calc(var(--radius) - 2px);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  display: grid;
  place-items: center;
  font-size: var(--cell-font, 26px);
  font-weight: 800;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.22);
  transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease, opacity 120ms ease, border-color 120ms ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cell span {
  position: relative;
  z-index: 1;
}

.cell::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent);
  opacity: 0.55;
}

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

.cell.hit {
  background: rgba(240, 193, 90, 0.18);
  border-color: rgba(240, 193, 90, 0.45);
  color: #fff8d8;
  transform: scale(0.96);
  opacity: 0.92;
}

.cell.pop {
  animation: pop 240ms ease;
}

.fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.result-panel {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(5, 9, 16, 0.28);
  backdrop-filter: blur(4px);
}

.result-card {
  width: min(84%, 300px);
  border-radius: var(--radius);
  background: rgba(13, 20, 34, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  text-align: center;
  display: grid;
  gap: 8px;
}

.result-tag {
  display: inline-grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  margin: 0 auto;
  background: rgba(57, 201, 184, 0.16);
  border: 1px solid rgba(57, 201, 184, 0.28);
  color: var(--teal);
  font-weight: 800;
}

.result-card strong {
  font-size: 28px;
}

.result-card p {
  margin: 0;
  color: var(--muted);
}

.dock {
  min-width: 0;
  display: grid;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
}

.control-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

#mode-group {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mode-note {
  min-height: 34px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  display: flex;
  align-items: center;
  padding: 7px 10px;
  font-size: 12px;
  line-height: 1.35;
}

.control-row button {
  min-height: 40px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
}

.control-row button.active,
.toggle-btn.active {
  background: rgba(57, 201, 184, 0.18);
  border-color: rgba(57, 201, 184, 0.36);
  color: #dffcf8;
}

.toggles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.toggle-btn,
.primary-btn {
  min-height: 42px;
  padding: 0 12px;
  font-weight: 700;
}

.primary-btn {
  background: var(--teal);
  border-color: transparent;
  color: #08231f;
}

.records {
  display: grid;
  grid-template-columns: minmax(88px, 100px) minmax(88px, 100px) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.record {
  min-height: 52px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  padding: 8px 10px;
  display: grid;
  gap: 4px;
}

.record span,
.history {
  color: var(--muted);
  font-size: 12px;
}

.record strong {
  line-height: 1;
  font-size: 14px;
}

.history {
  min-width: 0;
  display: flex;
  gap: 6px;
  overflow: auto;
  padding-bottom: 2px;
}

.history .chip {
  white-space: nowrap;
  min-height: 28px;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 5px 8px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
}

.shake {
  animation: shake 280ms ease;
}

@keyframes pop {
  0% { transform: scale(0.82); }
  70% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@media (max-width: 720px) {
  body {
    overflow-x: hidden;
  }

  .app-shell {
    padding: calc(10px + env(safe-area-inset-top)) 10px calc(10px + env(safe-area-inset-bottom));
  }

  .brand-mark {
    width: 44px;
    height: 44px;
  }

  .brand-copy strong {
    font-size: 16px;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .board-shell {
    width: calc(100vw - 20px);
    max-width: calc(100vw - 20px);
  }

  .dock {
    padding: 10px;
  }

  .control-row,
  .toggles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .records {
    grid-template-columns: minmax(0, 1fr);
  }
}
