:root {
  --bg-dark: #161822;
  --panel-bg: #222638;
  --accent-yellow: #ffd13b;
  --accent-green: #53e37c;
  --accent-red: #ff5468;
  --accent-blue: #4db8ff;
  --text-main: #f8f9ff;
  --text-muted: #9aa3c2;
  --border-comic: #0d0f17;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background: radial-gradient(circle at top, #262b44 0%, #11131c 100%);
  color: var(--text-main);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: env(safe-area-inset-top) 6px env(safe-area-inset-bottom);
  overscroll-behavior: none;
}

#game-shell {
  width: min(1000px, 100%);
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* HUD */
#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel-bg);
  border: 3px solid var(--border-comic);
  border-radius: 16px;
  padding: 8px 14px;
  box-shadow: 0 5px 0 var(--border-comic);
  gap: 12px;
}

.hud-left,
.hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: #181b29;
  border: 2px solid var(--border-comic);
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 800;
  font-size: 14px;
}

.hp-pill { color: #ff7588; }
.level-pill { color: var(--accent-yellow); }
.mine-pill { color: #ff9f43; }
.kill-pill { color: #c7d0f0; }
.board-pill { color: var(--accent-green); }

.hud-center {
  flex: 1;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#timer-box {
  background: #0f111a;
  border: 2px solid var(--border-comic);
  border-radius: 10px;
  padding: 2px 16px;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 1px;
  color: var(--accent-yellow);
  text-shadow: 0 2px 0 #000;
}

#timer-box.urgent {
  color: var(--accent-red);
  animation: pulse 0.6s infinite alternate;
}

@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.08); }
}

#xp-bar-wrap {
  position: relative;
  width: 100%;
  height: 14px;
  background: #11131d;
  border: 2px solid var(--border-comic);
  border-radius: 999px;
  overflow: hidden;
}

#xp-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #38ef7d, #00d2ff);
  transition: width 0.15s ease-out;
}

#xp-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 2px #000;
}

.icon-btn {
  background: #2e344e;
  border: 2px solid var(--border-comic);
  border-radius: 10px;
  width: 34px;
  height: 34px;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--border-comic);
  transition: transform 0.08s;
}

.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--border-comic);
}

/* Arena */
#arena-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  max-height: calc(100dvh - 130px);
  margin: 0 auto;
  background: #1c2030;
  border: 4px solid var(--border-comic);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 8px 0 var(--border-comic);
}

#arena-wrap.portrait {
  aspect-ratio: 10 / 16;
  width: auto;
  height: min(calc(100dvh - 148px), 156vw);
  max-width: 100%;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
  -webkit-touch-callout: none;
}

#weapons-bar {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  pointer-events: none;
}

.weapon-chip {
  background: rgba(15, 18, 28, 0.85);
  border: 2px solid #000;
  border-radius: 10px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 20, 0.78);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}

.overlay.active {
  display: flex;
}

.modal-card {
  background: #24293d;
  border: 4px solid var(--border-comic);
  border-radius: 22px;
  padding: 20px 22px;
  box-shadow: 0 10px 0 var(--border-comic);
  text-align: center;
  max-width: 680px;
  width: 100%;
  max-height: 92%;
  overflow-y: auto;
  animation: popIn 0.2s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.small-card { max-width: 400px; }

@keyframes popIn {
  from { transform: scale(0.86); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.badge-tag {
  display: inline-block;
  background: var(--accent-yellow);
  color: #111;
  font-weight: 900;
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 999px;
  border: 2px solid #000;
  margin-bottom: 8px;
}

.modal-card h1 {
  font-size: 34px;
  font-weight: 900;
  color: var(--accent-yellow);
  text-shadow: 0 3px 0 #000;
  margin-bottom: 4px;
}

.modal-card h2 {
  font-size: 26px;
  font-weight: 900;
  color: var(--accent-yellow);
  text-shadow: 0 2px 0 #000;
  margin-bottom: 6px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 16px;
}

.rules-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
  text-align: left;
}

.rule-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #1a1e2e;
  border: 2px solid #0d0f17;
  border-radius: 12px;
  padding: 10px;
}

.rule-emoji {
  font-size: 24px;
  line-height: 1;
}

.rule-item strong {
  display: block;
  font-size: 14px;
  color: #fff;
  margin-bottom: 2px;
}

.rule-item p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.35;
}

.primary-btn,
.secondary-btn {
  border: 3px solid var(--border-comic);
  border-radius: 14px;
  padding: 12px 28px;
  font-size: 17px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--border-comic);
  transition: transform 0.08s;
}

.primary-btn {
  background: linear-gradient(180deg, #ffe055 0%, #ffbe1a 100%);
  color: #141414;
}

.secondary-btn {
  background: #3a415e;
  color: #fff;
}

.primary-btn:hover { filter: brightness(1.06); }
.primary-btn:active,
.secondary-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--border-comic);
}

.btn-row {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* Upgrade Choices */
.choices-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.choice-card {
  background: #1a1e2e;
  border: 3px solid #0d0f17;
  border-radius: 16px;
  padding: 14px 12px;
  cursor: pointer;
  text-align: center;
  box-shadow: 0 5px 0 #0d0f17;
  transition: transform 0.1s, border-color 0.1s, background 0.1s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.choice-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent-yellow);
  background: #272d44;
}

.choice-icon {
  font-size: 36px;
  line-height: 1;
}

.choice-badge {
  font-size: 11px;
  font-weight: 900;
  padding: 2px 8px;
  border-radius: 999px;
  background: #333b59;
  color: var(--accent-yellow);
}

.choice-title {
  font-size: 15px;
  font-weight: 900;
  color: #fff;
}

.choice-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.35;
}

/* End Screen */
.big-emoji {
  font-size: 54px;
  line-height: 1;
  margin-bottom: 6px;
}

.rank-badge {
  display: inline-block;
  background: #171a28;
  border: 2px solid #0d0f17;
  color: var(--accent-green);
  font-weight: 900;
  padding: 4px 14px;
  border-radius: 999px;
  margin-bottom: 14px;
}

.stats-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.summary-box {
  background: #1a1e2e;
  border: 2px solid #0d0f17;
  border-radius: 10px;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.summary-box span { color: var(--text-muted); }
.summary-box strong { color: #fff; }

/* Footer */
#footer-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  font-size: 12px;
  color: var(--text-muted);
}

.hint-texts {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 14px;
}

#footer-hint b {
  color: var(--accent-yellow);
}

.mode-toggle {
  background: #2e344e;
  color: #fff;
  border: 2px solid var(--border-comic);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--border-comic);
  transition: background 0.12s, transform 0.08s;
}

.mode-toggle.flag-mode {
  background: #ff9f43;
  color: #111;
}

.mode-toggle:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--border-comic);
}

/* Mobile Responsive */
@media (max-width: 680px) {
  #hud {
    flex-wrap: wrap;
    padding: 6px 10px;
    gap: 6px;
    border-radius: 12px;
  }

  .hud-left { order: 1; gap: 5px; }
  .hud-right { order: 2; gap: 5px; }
  .hud-center {
    order: 3;
    flex-basis: 100%;
    max-width: none;
    flex-direction: row;
    gap: 8px;
  }

  #timer-box {
    font-size: 16px;
    padding: 2px 10px;
    flex-shrink: 0;
  }

  .stat-pill {
    padding: 3px 7px;
    font-size: 12px;
  }

  .icon-btn {
    width: 30px;
    height: 30px;
    font-size: 14px;
  }

  .modal-card {
    padding: 16px 14px;
    border-radius: 16px;
  }

  .modal-card h1 { font-size: 24px; }
  .modal-card h2 { font-size: 20px; }

  .rules-grid {
    grid-template-columns: 1fr;
    gap: 7px;
    margin-bottom: 12px;
  }

  .choices-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .choice-card {
    flex-direction: row;
    text-align: left;
    padding: 10px 12px;
    gap: 10px;
  }

  .choice-icon { font-size: 28px; flex-shrink: 0; }

  .hint-texts {
    display: none;
  }

  .weapon-chip {
    font-size: 11px;
    padding: 2px 6px;
  }
}
