:root {
  --bg-deep: #090b14;
  --panel-bg: rgba(14, 18, 32, 0.86);
  --panel-border: rgba(255, 255, 255, 0.14);
  --solar: #ffb84d;
  --solar-glow: rgba(255, 184, 77, 0.45);
  --lunar: #62e3ff;
  --lunar-glow: rgba(98, 227, 255, 0.45);
  --accent: #ff5e7e;
  --text-main: #f4f7ff;
  --text-muted: #9aa7c7;
  --font-ui: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Fira Code", Menlo, Consolas, monospace;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 25%, #19213c 0%, #090b14 75%);
  color: var(--text-main);
  font-family: var(--font-ui);
}

#app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  gap: 10px;
}

#game-shell {
  position: relative;
  width: min(96vw, calc((100vh - 64px) * 16 / 9));
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  overflow: hidden;
  background: #05070e;
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.72),
    0 0 0 1px rgba(255, 255, 255, 0.12),
    0 0 42px rgba(98, 227, 255, 0.12);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  outline: none;
}

.hidden {
  display: none !important;
}

/* HUD */
.hud {
  position: absolute;
  top: 8px;
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  pointer-events: none;
  z-index: 10;
}

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

.hud-center {
  flex-direction: column;
  gap: 1px;
  background: rgba(9, 12, 24, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  padding: 3px 10px;
  border-radius: 10px;
  white-space: nowrap;
}

.hud-stage {
  font-size: clamp(10px, 1.15vw, 12px);
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
}

.hud-stars {
  display: flex;
  gap: 5px;
  font-size: 12px;
  line-height: 1;
}

.star-slot {
  color: rgba(255, 255, 255, 0.24);
  transition: transform 0.25s ease, color 0.25s ease, text-shadow 0.25s ease;
}

.star-slot.collected {
  color: #ffd84d;
  text-shadow: 0 0 10px rgba(255, 216, 77, 0.9);
  transform: scale(1.18);
}

.hud-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(9, 12, 24, 0.74);
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(8px);
  font-size: clamp(10px, 1.1vw, 12px);
  font-weight: 700;
  white-space: nowrap;
}

.hearts-pill {
  gap: 4px;
  font-size: 14px;
}

.heart {
  color: #ff4d6d;
  text-shadow: 0 0 8px rgba(255, 77, 109, 0.7);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.heart.empty {
  color: rgba(255, 255, 255, 0.2);
  text-shadow: none;
}

.power-pill .power-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff5e7e;
  box-shadow: 0 0 8px #ff5e7e;
}

.power-pill.ember .power-dot { background: #ff8c32; box-shadow: 0 0 10px #ff8c32; }
.power-pill.magnet .power-dot { background: #5ce1ff; box-shadow: 0 0 10px #5ce1ff; }
.power-pill.star .power-dot { background: #ffe44d; box-shadow: 0 0 12px #ffe44d; }

.phase-pill {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  transition: all 0.22s ease;
}

.phase-pill.solar {
  border-color: rgba(255, 184, 77, 0.55);
  color: #ffd382;
  box-shadow: 0 0 14px rgba(255, 184, 77, 0.28);
}

.phase-pill.lunar {
  border-color: rgba(98, 227, 255, 0.55);
  color: #93eeff;
  box-shadow: 0 0 16px rgba(98, 227, 255, 0.34);
}

.hud-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  background: rgba(9, 12, 24, 0.74);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  padding: 2px 7px;
  border-radius: 8px;
  min-width: 48px;
  white-space: nowrap;
}

.stat-label {
  font-size: 8px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.08em;
}

.stat-val {
  font-family: var(--font-mono);
  font-size: clamp(10px, 1.15vw, 13px);
  font-weight: 800;
  color: #fff;
}

.hud-btn {
  pointer-events: auto;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(14, 18, 34, 0.8);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.12s ease;
}

.hud-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  transform: translateY(-1px);
}

/* Boss HUD */
.boss-hud {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: min(62%, 520px);
  background: rgba(10, 11, 22, 0.82);
  border: 1px solid rgba(255, 94, 126, 0.45);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  padding: 8px 12px;
  z-index: 12;
  pointer-events: none;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55), 0 0 22px rgba(255, 94, 126, 0.22);
}

.boss-title {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #ffd3df;
  margin-bottom: 6px;
}

.boss-bar-track {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.boss-bar-ghost {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  background: rgba(255, 220, 120, 0.55);
  transition: width 0.5s ease;
}

.boss-bar-fill {
  position: relative;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff3e6c, #ff8c42, #ffd859);
  box-shadow: 0 0 12px rgba(255, 94, 126, 0.75);
  transition: width 0.16s ease;
}

/* Combo Banner */
.combo-banner {
  position: absolute;
  top: 64px;
  right: 18px;
  text-align: right;
  pointer-events: none;
  z-index: 11;
  animation: comboPop 0.2s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.combo-count {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 900;
  line-height: 1;
  background: linear-gradient(135deg, #ffe36e, #ff7096, #70e8ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.8));
}

.combo-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85);
}

@keyframes comboPop {
  0% { transform: scale(1.35) rotate(-4deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* Tech Inspector */
.inspector {
  position: absolute;
  top: 56px;
  left: 14px;
  width: 240px;
  background: rgba(11, 14, 26, 0.9);
  border: 1px solid rgba(98, 227, 255, 0.35);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  padding: 10px 12px;
  z-index: 25;
  font-size: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.55);
}

.inspector-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 800;
  color: var(--lunar);
  margin-bottom: 6px;
}

.mini-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
}

.inspector-metrics {
  font-family: var(--font-mono);
  font-size: 10px;
  color: #d6e4ff;
  background: rgba(255, 255, 255, 0.06);
  padding: 4px 6px;
  border-radius: 6px;
  margin-bottom: 8px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  color: #e6eeff;
}

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

.mini-btn {
  flex: 1;
  padding: 5px 4px;
  font-size: 10px;
  font-weight: 700;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
}

.mini-btn:hover {
  background: rgba(98, 227, 255, 0.22);
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 40%, rgba(12, 16, 32, 0.52), rgba(6, 8, 18, 0.82));
  backdrop-filter: blur(4px);
  z-index: 30;
  padding: 20px;
}

.title-card, .modal-card {
  width: min(92%, 640px);
  background: rgba(12, 16, 30, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 18px;
  padding: 26px 28px;
  text-align: center;
  box-shadow:
    0 24px 64px rgba(0, 0, 0, 0.65),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.modal-card {
  width: min(90%, 440px);
}

.modal-card.wide {
  width: min(94%, 720px);
}

.badge-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
}

.badge {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #dce6ff;
}

.badge.solar {
  color: #ffd27d;
  border-color: rgba(255, 184, 77, 0.45);
  background: rgba(255, 184, 77, 0.12);
}

.badge.lunar {
  color: #8eeeff;
  border-color: rgba(98, 227, 255, 0.45);
  background: rgba(98, 227, 255, 0.12);
}

.game-title {
  font-size: clamp(32px, 5vw, 52px);
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1.05;
  background: linear-gradient(100deg, #ffe285 0%, #ff8577 45%, #75e8ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 18px rgba(255, 150, 90, 0.25));
}

.game-subtitle {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #e8f0ff;
  margin-top: 6px;
}

.game-tagline {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 8px;
  margin-bottom: 18px;
}

.menu-buttons {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.menu-buttons.vertical {
  flex-direction: column;
}

.btn-primary, .btn-secondary {
  border: none;
  border-radius: 11px;
  padding: 11px 20px;
  font-size: 13.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.btn-primary {
  background: linear-gradient(135deg, #ffb84d 0%, #ff5e7e 55%, #63d8ff 100%);
  color: #0b0d17;
  box-shadow: 0 8px 24px rgba(255, 110, 120, 0.35);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 30px rgba(255, 110, 120, 0.5);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #f4f7ff;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.16);
  transform: translateY(-1px);
}

.controls-grid {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  text-align: left;
}

.ctrl-item {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
}

/* Stage select */
.modal-title {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 16px;
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stage-card {
  text-align: left;
  padding: 13px 14px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.18s ease, background 0.18s ease;
  color: #fff;
}

.stage-card:hover {
  transform: translateY(-2px);
  border-color: rgba(98, 227, 255, 0.65);
  background: rgba(98, 227, 255, 0.12);
}

.stage-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.stage-code {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 800;
  color: var(--solar);
}

.stage-stars {
  font-size: 13px;
  letter-spacing: 2px;
  color: #ffd84d;
}

.stage-name {
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 4px;
}

.stage-desc {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Stage Clear */
.clear-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.14em;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 216, 77, 0.18);
  border: 1px solid rgba(255, 216, 77, 0.5);
  color: #ffe27a;
  margin-bottom: 8px;
}

.clear-stars {
  font-size: 32px;
  letter-spacing: 8px;
  margin-bottom: 12px;
  text-shadow: 0 0 18px rgba(255, 216, 77, 0.65);
}

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

.clear-stat-box {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 8px 6px;
}

.clear-stat-box .lbl {
  font-size: 10px;
  color: var(--text-muted);
}

.clear-stat-box .val {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 800;
  margin-top: 2px;
}

/* Optional subtle CRT scanline overlay */
.crt-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.16) 3px
  );
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.45);
}

/* Bottom Footer */
#footer-bar {
  width: min(96vw, calc((100vh - 64px) * 16 / 9));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 11.5px;
  color: var(--text-muted);
  padding: 0 4px;
}

#footer-tip {
  color: #ffd382;
  font-weight: 600;
}

@media (max-width: 780px) {
  .controls-grid { grid-template-columns: repeat(2, 1fr); }
  #footer-tip { display: none; }
}
