/* ================================================
   像素星途 (Pixel Starway) - Stylesheet
   Space pixel aesthetic with glassmorphism HUD
   ================================================ */

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Orbitron:wght@400;700;900&display=swap');

/* ---- Reset & Base ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --c-bg:        #04070f;
  --c-surface:   rgba(8, 15, 35, 0.85);
  --c-border:    rgba(100, 180, 255, 0.25);
  --c-accent:    #38bdf8;
  --c-accent2:   #a78bfa;
  --c-gold:      #fbbf24;
  --c-danger:    #f87171;
  --c-green:     #4ade80;
  --c-text:      #e2e8f0;
  --c-muted:     #64748b;
  --font-pixel:  'Press Start 2P', monospace;
  --font-ui:     'Orbitron', sans-serif;
  --glow-blue:   0 0 16px rgba(56, 189, 248, 0.7);
  --glow-gold:   0 0 14px rgba(251, 191, 36, 0.8);
  --glow-red:    0 0 14px rgba(248, 113, 113, 0.7);
  --glow-purple: 0 0 16px rgba(167, 139, 250, 0.7);
}

html, body {
  width: 100%;
  height: 100%;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-ui);
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---- Starfield Background ---- */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(56, 40, 120, 0.4) 0%, transparent 70%),
    radial-gradient(ellipse 40% 30% at 80% 30%, rgba(30, 80, 160, 0.3) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

/* ---- Layout ---- */
#app {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

/* ---- HUD Bar (top) ---- */
#hud {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(480px, 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 8px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 10;
  gap: 8px;
}

/* Score block */
.hud-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 70px;
}

.hud-label {
  font-family: var(--font-pixel);
  font-size: 6px;
  color: var(--c-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.hud-value {
  font-family: var(--font-pixel);
  font-size: 10px;
  line-height: 1;
}

#score-value    { color: var(--c-accent);  text-shadow: var(--glow-blue);   }
#best-value     { color: var(--c-gold);    text-shadow: var(--glow-gold);   }
#level-value    { color: var(--c-accent2); text-shadow: var(--glow-purple); }

/* HP hearts */
#hp-bar {
  display: flex;
  gap: 5px;
  align-items: center;
}

.heart {
  display: inline-block;
  width: 14px;
  height: 14px;
  position: relative;
  transition: transform 0.2s, opacity 0.3s;
}

.heart::before,
.heart::after {
  content: '';
  position: absolute;
  background: var(--c-danger);
  border-radius: 50% 50% 0 0;
  box-shadow: var(--glow-red);
}

.heart::before {
  width: 8px; height: 8px;
  top: 0; left: 1px;
}

.heart::after {
  width: 8px; height: 8px;
  top: 0; right: 1px;
}

.heart-body {
  position: absolute;
  bottom: 0; left: 0;
  width: 14px; height: 10px;
  background: var(--c-danger);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  box-shadow: var(--glow-red);
}

.heart.lost {
  opacity: 0.2;
  transform: scale(0.7);
}

.heart.pulse {
  animation: heart-pulse 0.4s ease-out;
}

@keyframes heart-pulse {
  0%   { transform: scale(1.6); }
  100% { transform: scale(1);   }
}

/* ---- Canvas Wrapper ---- */
#canvas-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  width: 100%;
  max-width: 480px;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  border-left:  1px solid var(--c-border);
  border-right: 1px solid var(--c-border);
}

/* ---- Overlay Screens ---- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(4, 7, 15, 0.88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 20;
  gap: 0;
  animation: overlay-in 0.4s ease;
}

@keyframes overlay-in {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1);    }
}

.overlay.hidden {
  display: none;
}

/* Title logo */
.game-logo {
  font-family: var(--font-pixel);
  font-size: clamp(13px, 3.5vw, 18px);
  color: var(--c-accent);
  text-shadow: var(--glow-blue);
  letter-spacing: 3px;
  text-align: center;
  line-height: 2;
  margin-bottom: 6px;
}

.game-logo span {
  display: block;
  font-size: 0.55em;
  color: var(--c-accent2);
  text-shadow: var(--glow-purple);
  letter-spacing: 5px;
}

/* Pixel spaceship deco */
.logo-ship {
  font-size: clamp(36px, 10vw, 56px);
  margin-bottom: 18px;
  animation: float 3s ease-in-out infinite;
  filter: drop-shadow(0 0 12px rgba(56,189,248,0.8));
}

@keyframes float {
  0%, 100% { transform: translateY(0px);  }
  50%       { transform: translateY(-10px); }
}

/* Score summary (game over) */
.score-summary {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 12px;
  padding: 18px 30px;
  margin: 18px 0;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 220px;
  backdrop-filter: blur(10px);
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  font-family: var(--font-pixel);
  font-size: 8px;
}

.summary-row .label { color: var(--c-muted); }
.summary-row .val   { color: var(--c-accent); }
.summary-row .val.gold  { color: var(--c-gold);  text-shadow: var(--glow-gold); }
.summary-row .val.green { color: var(--c-green); }

/* CTA Buttons */
.btn {
  font-family: var(--font-pixel);
  font-size: 10px;
  padding: 13px 26px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 2px;
  transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
  outline: none;
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.1);
  opacity: 0;
  transition: opacity 0.2s;
}

.btn:hover::after { opacity: 1; }

.btn:active {
  transform: scale(0.95) !important;
}

.btn-primary {
  background: linear-gradient(135deg, #1d6fce, #5b21b6);
  color: #fff;
  box-shadow: 0 4px 24px rgba(56,189,248,0.4), 0 0 0 1px rgba(56,189,248,0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(56,189,248,0.6), var(--glow-blue);
}

.btn-secondary {
  background: transparent;
  color: var(--c-muted);
  border: 1px solid var(--c-border);
  font-size: 7px;
  padding: 8px 16px;
  margin-top: 6px;
}

.btn-secondary:hover {
  color: var(--c-text);
  border-color: var(--c-accent);
}

/* Instruction tips */
.tips {
  font-family: var(--font-pixel);
  font-size: 6px;
  color: var(--c-muted);
  line-height: 2.4;
  text-align: center;
  margin-top: 10px;
}

.tips b {
  color: var(--c-accent);
}

/* ---- Mobile Controls ---- */
#mobile-controls {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(480px, 100%);
  display: none; /* shown via JS on touch device */
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px 14px;
  background: rgba(4, 7, 15, 0.75);
  border-top: 1px solid var(--c-border);
  backdrop-filter: blur(8px);
  z-index: 10;
  gap: 12px;
}

.ctrl-group {
  display: flex;
  gap: 10px;
}

.ctrl-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1.5px solid var(--c-border);
  background: rgba(56, 189, 248, 0.1);
  color: var(--c-accent);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  box-shadow: 0 0 8px rgba(56,189,248,0.2);
}

.ctrl-btn:active,
.ctrl-btn.pressed {
  background: rgba(56, 189, 248, 0.3);
  box-shadow: var(--glow-blue);
}

.ctrl-btn-jump {
  width: 60px;
  height: 60px;
  background: rgba(167, 139, 250, 0.15);
  border-color: rgba(167, 139, 250, 0.4);
  color: var(--c-accent2);
  font-size: 22px;
  box-shadow: 0 0 8px rgba(167,139,250,0.2);
}

.ctrl-btn-jump:active,
.ctrl-btn-jump.pressed {
  background: rgba(167, 139, 250, 0.35);
  box-shadow: var(--glow-purple);
}

/* ---- Toast Notifications ---- */
#toast-container {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 30;
  pointer-events: none;
}

.toast {
  font-family: var(--font-pixel);
  font-size: 9px;
  padding: 6px 14px;
  border-radius: 20px;
  letter-spacing: 1px;
  animation: toast-life 1.6s ease forwards;
  white-space: nowrap;
}

.toast.coin  { background: rgba(251,191,36,0.2);  color: var(--c-gold);    border: 1px solid rgba(251,191,36,0.4);    box-shadow: var(--glow-gold);   }
.toast.dmg   { background: rgba(248,113,113,0.2); color: var(--c-danger);  border: 1px solid rgba(248,113,113,0.4);  box-shadow: var(--glow-red);    }
.toast.level { background: rgba(167,139,250,0.2); color: var(--c-accent2); border: 1px solid rgba(167,139,250,0.4);  box-shadow: var(--glow-purple); }
.toast.shield { background: rgba(56,189,248,0.2); color: var(--c-accent);  border: 1px solid rgba(56,189,248,0.4);   box-shadow: var(--glow-blue);   }

@keyframes toast-life {
  0%   { opacity: 0; transform: translateY(8px) scale(0.9); }
  15%  { opacity: 1; transform: translateY(0)   scale(1);   }
  70%  { opacity: 1; transform: translateY(-4px);            }
  100% { opacity: 0; transform: translateY(-14px);           }
}

/* ---- Responsive ---- */
@media (max-width: 520px) {
  .game-logo { font-size: 12px; }
  .score-summary { padding: 14px 18px; min-width: 180px; }
  .btn { font-size: 8px; padding: 11px 20px; }
}

/* ---- Pixel scanline effect overlay ---- */
#scanlines {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.04) 2px,
    rgba(0,0,0,0.04) 4px
  );
  pointer-events: none;
  z-index: 5;
}

/* ---- Pause indicator ---- */
#pause-badge {
  position: absolute;
  top: 56px;
  right: 14px;
  font-family: var(--font-pixel);
  font-size: 7px;
  color: var(--c-accent2);
  letter-spacing: 2px;
  padding: 4px 10px;
  border: 1px solid rgba(167,139,250,0.4);
  border-radius: 4px;
  background: rgba(8,15,35,0.8);
  display: none;
  z-index: 15;
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ---- Combo badge ---- */
#combo-badge {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--c-gold);
  text-shadow: var(--glow-gold);
  letter-spacing: 1px;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 12;
  pointer-events: none;
  white-space: nowrap;
}
