*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #090d14;
  --bg-panel: rgba(12, 18, 31, 0.96);
  --border: rgba(125, 211, 252, 0.26);
  --text: #eaf2ff;
  --text-muted: #9eb1c9;
  --accent: #2563eb;
  --accent-hover: #38bdf8;
  --danger: #ef4444;
  --success: #22c55e;
  --gold: #facc15;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

html,
body {
  height: 100%;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

body {
  background:
    radial-gradient(ellipse at 18% 10%, rgba(34, 197, 94, 0.12) 0%, transparent 44%),
    radial-gradient(ellipse at 86% 80%, rgba(14, 165, 233, 0.15) 0%, transparent 46%),
    linear-gradient(180deg, #0b1020 0%, #06080d 100%);
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 12px;
  position: relative;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 520px;
  padding: 8px 4px 14px;
}

.header h1 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0;
}

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

.game-area {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow), 0 0 0 1px var(--border);
}

#game-canvas {
  display: block;
  background: #050810;
  max-width: min(100vw - 24px, 480px);
  height: auto;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 8, 16, 0.72);
  backdrop-filter: blur(4px);
  z-index: 10;
  padding: 18px;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 30px 26px;
  text-align: center;
  width: min(360px, 100%);
  box-shadow: var(--shadow);
}

.panel h2 {
  font-size: 1.55rem;
  margin-bottom: 8px;
  letter-spacing: 0;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.86rem;
  line-height: 1.55;
  margin-bottom: 20px;
}

.stats-preview {
  margin-bottom: 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.stats-preview strong {
  color: var(--accent-hover);
  font-size: 1.1rem;
}

.score-line {
  color: var(--text-muted);
  margin-bottom: 8px;
}

.score-line strong {
  color: var(--text);
  font-size: 1.3rem;
}

.menu-panel .btn,
.panel > .btn {
  width: 100%;
  margin-top: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  font-size: 0.94rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s, color 0.15s;
  font-family: inherit;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.14);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 12px;
  font-size: 0.86rem;
}

.btn-ghost:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.hidden {
  display: none !important;
}

.hud {
  position: absolute;
  top: 58px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 5;
  pointer-events: none;
  width: min(480px, calc(100vw - 24px));
  padding: 0 10px;
}

.hud-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.hud-top {
  justify-content: space-between;
}

.hud-bars {
  align-items: stretch;
}

.hud-item,
.hud-meter,
.boss-hud {
  background: rgba(0, 0, 0, 0.58);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.25);
}

.hud-item {
  flex: 1;
  min-width: 0;
  padding: 6px 9px;
  font-size: 0.78rem;
  text-align: center;
  white-space: nowrap;
}

.hud-item span {
  color: var(--text);
  font-weight: 800;
  margin-left: 4px;
}

.hud-meter {
  flex: 1;
  min-width: 0;
  padding: 7px 8px;
}

.meter-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 0.72rem;
}

.meter-label strong {
  color: var(--text);
  font-size: 0.72rem;
}

.meter-track {
  height: 7px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
}

.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  transition: width 0.16s ease;
}

.energy-fill {
  background: linear-gradient(90deg, #22c55e, #38bdf8, #facc15);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.65);
}

.progress-fill {
  background: linear-gradient(90deg, #38bdf8, #2563eb);
}

.boss-hud {
  padding: 8px 10px;
}

.boss-track {
  height: 9px;
}

.boss-fill {
  background: linear-gradient(90deg, #ef4444, #f97316, #facc15);
  box-shadow: 0 0 12px rgba(248, 113, 113, 0.75);
}

.upgrade-panel {
  width: min(430px, 100%);
}

.upgrade-options {
  display: grid;
  gap: 10px;
}

.upgrade-card {
  display: grid;
  grid-template-columns: 42px 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 3px;
  width: 100%;
  min-height: 80px;
  padding: 12px;
  border: 1px solid rgba(125, 211, 252, 0.32);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

.upgrade-card:hover {
  transform: translateY(-1px);
  background: rgba(37, 99, 235, 0.24);
  border-color: rgba(56, 189, 248, 0.7);
}

.upgrade-icon {
  grid-row: 1 / span 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  margin-top: 4px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.22), rgba(56, 189, 248, 0.28));
  color: #e0f2fe;
  font-size: 1.05rem;
  font-weight: 900;
}

.upgrade-card strong {
  align-self: end;
  font-size: 0.98rem;
}

.upgrade-card span:last-child {
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(360px, 100vw);
  height: 100vh;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  z-index: 100;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.4);
  animation: slideIn 0.25s ease;
}

@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.settings-header h2 {
  font-size: 1.1rem;
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.setting-group {
  margin-bottom: 24px;
}

.setting-group h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.setting-group label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  margin-bottom: 12px;
  color: var(--text-muted);
}

.setting-group select {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
}

.setting-group select:focus {
  outline: none;
  border-color: var(--accent);
}

.range-label {
  flex-direction: row !important;
  align-items: center;
  flex-wrap: wrap;
}

.range-label input[type="range"] {
  flex: 1;
  min-width: 120px;
  accent-color: var(--accent);
}

.range-label span {
  min-width: 40px;
  text-align: right;
  color: var(--text);
  font-size: 0.8rem;
}

.preview-group canvas {
  width: 100%;
  border-radius: 8px;
  background: #050810;
  border: 1px solid var(--border);
  margin-bottom: 10px;
}

.settings-footer {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.settings-footer .btn {
  flex: 1;
}

@media (max-width: 520px) {
  #app {
    padding: 8px;
  }

  .header {
    padding-bottom: 10px;
  }

  .header h1 {
    font-size: 1.08rem;
  }

  .btn {
    min-height: 36px;
    padding: 8px 12px;
    font-size: 0.86rem;
  }

  .panel {
    padding: 22px 18px;
  }

  .hud {
    top: 50px;
    width: calc(100vw - 16px);
    padding: 0 7px;
    gap: 6px;
  }

  .hud-row {
    gap: 5px;
  }

  .hud-item {
    padding: 5px 5px;
    font-size: 0.7rem;
  }

  .hud-meter {
    padding: 6px;
  }

  .meter-label {
    font-size: 0.68rem;
  }

  .upgrade-card {
    grid-template-columns: 38px 1fr;
    min-height: 76px;
    padding: 10px;
  }

  .upgrade-icon {
    width: 38px;
    height: 38px;
  }
}

.mobile-controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px 16px 40px;
  z-index: 20;
  pointer-events: none;
}

.mobile-controls > * {
  pointer-events: auto;
}

.joystick-container {
  width: 120px;
  height: 120px;
  position: relative;
}

.joystick-base {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(125, 211, 252, 0.3);
  position: relative;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3), inset 0 2px 10px rgba(255, 255, 255, 0.05);
}

.joystick-thumb {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.8), rgba(37, 99, 235, 0.9));
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 4px 15px rgba(56, 189, 248, 0.5), inset 0 2px 8px rgba(255, 255, 255, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.4);
  transition: transform 0.05s ease-out;
}

@media (min-width: 768px) {
  .mobile-controls {
    display: none !important;
  }
}

@media (max-width: 767px) {
  .mobile-controls.hidden {
    display: none !important;
  }
  
  .mobile-controls:not(.hidden) {
    display: flex;
  }
}
