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

html {
  overflow: hidden;
  height: 100%;
}

body {
  background: #0a0a12;
  color: #e8f4ff;
  font-family: "Press Start 2P", monospace;
  overflow: hidden;
  height: 100%;
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#app {
  position: relative;
  width: min(100vw, calc(100vh * 9 / 16));
  height: min(100vh, calc(100vw * 16 / 9));
  max-width: 100vw;
  max-height: 100vh;
  overflow: hidden;
  container-type: size;
  --ui-xs: clamp(9px, 2.4cqw, 13px);
  --ui-sm: clamp(11px, 3cqw, 16px);
  --ui-md: clamp(13px, 3.6cqw, 20px);
  --ui-lg: clamp(16px, 4.8cqw, 28px);
  --ui-xl: clamp(20px, 6cqw, 36px);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.hidden {
  display: none !important;
}

#hud {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  pointer-events: none;
  font-size: var(--ui-sm);
  line-height: 1.9;
  text-shadow: 2px 2px 0 #000;
}

.hud-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.hud-hp-row {
  align-items: center;
  margin-bottom: 4px;
}

.hud-hp-label {
  color: #7ec8ff;
  font-size: var(--ui-xs);
  flex-shrink: 0;
}

.hud-hp {
  display: flex;
  gap: 5px;
  flex: 1;
}

.hud-hp-pip {
  width: 14px;
  height: 14px;
  border: 2px solid #555;
  background: #1a1a2e;
  box-shadow: 2px 2px 0 #000;
}

.hud-hp-pip.filled {
  background: #f44;
  border-color: #faa;
}

.hud-hp-pip.empty {
  background: #222;
  border-color: #444;
}

.hud-hp-text {
  color: #ffb3b3;
  font-size: var(--ui-xs);
  flex-shrink: 0;
}

.hud-hp-pip.invuln {
  background: #fff;
  border-color: #fff;
}

#hud-phase {
  color: #ff6b9d;
  margin-top: 8px;
  font-size: var(--ui-sm);
}

#hud-chest {
  color: #ffd166;
  margin-top: 8px;
  font-size: var(--ui-sm);
}

#weapon-slots {
  margin-top: 10px;
  font-size: var(--ui-xs);
  color: #7ec8ff;
  line-height: 1.8;
  white-space: pre-wrap;
  padding-right: 52px;
}

.hud-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  font-family: inherit;
  font-size: var(--ui-sm);
  padding: 10px 14px;
  background: rgba(26, 74, 138, 0.9);
  color: #fff;
  border: 3px solid #7ec8ff;
  cursor: pointer;
  pointer-events: auto;
  line-height: 1;
}

.hud-btn:hover {
  background: #2a6aba;
}

.hud-btn:active {
  transform: scale(0.96);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(5, 8, 20, 0.88);
  padding: 20px 16px;
  text-align: center;
  gap: 14px;
  overflow: hidden;
}

#overlay-start {
  justify-content: flex-start;
  gap: 12px;
  overflow-y: auto;
  padding-top: 16px;
  padding-bottom: 24px;
}

.overlay h1 {
  font-size: var(--ui-xl);
  line-height: 1.7;
  color: #7ec8ff;
  text-shadow: 3px 3px 0 #1a3a6e;
}

.overlay h2 {
  font-size: var(--ui-lg);
  color: #ffd166;
  line-height: 1.6;
}

.subtitle {
  font-size: var(--ui-sm);
  color: #9ab;
  line-height: 2;
}

.controls-info {
  font-size: var(--ui-xs);
  color: #8ab;
  line-height: 1.9;
  width: 100%;
  max-width: 100%;
}

.controls-info p {
  margin: 0;
}

.unlock-list {
  font-size: var(--ui-xs);
  color: #6a8;
  line-height: 1.9;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.unlock-list div {
  margin: 0;
  word-break: keep-all;
}

.side-panel {
  width: 100%;
  max-width: 100%;
  text-align: left;
  font-size: var(--ui-xs);
  color: #8ab;
  line-height: 1.7;
}

.panel-title {
  color: #7ec8ff;
  margin-bottom: 4px;
}

.panel-subtitle {
  color: #ffd166;
  margin-bottom: 8px;
}

.meta-choices {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.meta-btn {
  font-family: inherit;
  font-size: var(--ui-xs);
  padding: 8px 10px;
  background: #142038;
  color: #cde;
  border: 2px solid #3a5a8a;
  cursor: pointer;
  text-align: left;
  line-height: 1.6;
}

.meta-btn:hover:not(:disabled) {
  background: #1e3058;
  border-color: #7ec8ff;
}

.meta-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.challenge-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 18cqh;
  overflow-y: auto;
}

.challenge-list div {
  color: #7a9;
}

.challenge-list div.done {
  color: #9fd;
}

.hud-graze-streak {
  font-size: var(--ui-xs);
  color: #f9d;
  text-shadow: 2px 2px 0 #000;
  margin-top: 2px;
}

.hud-graze-gauge {
  margin-top: 4px;
  width: 120px;
  height: 6px;
  border: 2px solid #8a3a5a;
  background: #1a0a12;
}

#hud-graze-gauge-fill {
  height: 100%;
  width: 0%;
  background: #ff99dd;
}

.stats .record-new {
  color: #ffd166;
}

.stats .reward-line {
  color: #9fd;
  margin-top: 8px;
}

.pixel-btn {
  font-family: inherit;
  font-size: var(--ui-md);
  padding: 18px 36px;
  background: #1a4a8a;
  color: #fff;
  border: 4px solid #7ec8ff;
  cursor: pointer;
  transition: transform 0.1s, background 0.1s;
}

.pixel-btn:hover {
  background: #2a6aba;
}

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

#overlay-start .pixel-btn:hover {
  transform: scale(1.03);
}

.upgrade-choices {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 92%;
  max-width: 420px;
}

.upgrade-card {
  font-family: inherit;
  font-size: var(--ui-sm);
  padding: 18px 16px;
  background: #12182a;
  border: 3px solid #3a5a8a;
  color: #e8f4ff;
  cursor: pointer;
  text-align: left;
  line-height: 2;
  transition: border-color 0.15s, background 0.15s;
}

.upgrade-card:hover {
  border-color: #7ec8ff;
  background: #1a2848;
}

.upgrade-card .card-title {
  color: #ffd166;
  display: block;
  margin-bottom: 6px;
  font-size: var(--ui-sm);
}

.upgrade-card .card-desc {
  color: #9ab;
  font-size: var(--ui-xs);
}

.upgrade-card.evolution-card {
  border-color: #c9a227;
  background: #1a1408;
}

.upgrade-card.evolution-card:hover {
  border-color: #ffd166;
  background: #2a2010;
}

.upgrade-card.evolution-card .card-title {
  color: #ffd166;
}

.card-top {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}

.card-num {
  font-size: var(--ui-xs);
  color: #667;
  border: 2px solid #3a5a8a;
  background: #0c1220;
  padding: 2px 6px;
  line-height: 1;
}

.card-badge {
  font-size: var(--ui-xs);
  padding: 2px 6px;
  line-height: 1.4;
}

.badge-weapon {
  background: #3a2a10;
  color: #ffd166;
  border: 2px solid #c9a227;
}

.badge-aux {
  background: #0e2a2a;
  color: #7fffd4;
  border: 2px solid #2a8a7a;
}

.badge-new {
  background: #102a14;
  color: #8f8;
  border: 2px solid #3a8a3a;
}

.badge-passive {
  background: #14203a;
  color: #9cf;
  border: 2px solid #3a5a8a;
}

.badge-heal {
  background: #2a1420;
  color: #f9d;
  border: 2px solid #8a3a5a;
}

.badge-evo {
  background: #241a04;
  color: #ffd166;
  border: 2px solid #ffd166;
}

.upgrade-card.rare {
  border-color: #b76eff;
  background: #1c1030;
}

.upgrade-card.rare:hover {
  border-color: #d9a6ff;
  background: #2a1a44;
}

.stats {
  font-size: var(--ui-sm);
  line-height: 2.4;
  color: #bcd;
}

.unlock-toast {
  font-size: var(--ui-sm);
  color: #7fff7f;
  line-height: 2;
  padding: 12px 16px;
  border: 3px solid #3a8a3a;
  background: #0a1a0a;
}
