/* Base Style Variables */
:root {
  --color-bg: #0b0b1e;
  --color-panel: #161632;
  --color-border: #3c3c78;
  --color-text-white: #ffffff;
  --color-text-gray: #a0a0c0;
  
  /* Cyber Neon Colors */
  --color-cyan: #00f0ff;
  --color-magenta: #ff007f;
  --color-yellow: #ffea00;
  --color-green: #39ff14;
  --color-red: #ff3333;
  
  --font-pixel: 'Press Start 2P', cursive, monospace;
  --font-korean: 'Noto Sans KR', sans-serif;
  
  --pixel-border: 4px solid var(--color-border);
  --pixel-border-cyan: 4px solid var(--color-cyan);
  --pixel-border-magenta: 4px solid var(--color-magenta);
}

/* Reset & Basic Setup */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  image-rendering: pixelated; /* Crisp retro scaling for canvas & images */
  user-select: none;
  -webkit-user-select: none;
}

body {
  background-color: #050510;
  color: var(--color-text-white);
  font-family: var(--font-korean);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
}

/* --- CRT Screen & Scanline Effect --- */
.crt-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, rgba(16, 16, 48, 0) 60%, rgba(0, 0, 0, 0.75) 100%);
  pointer-events: none;
  z-index: 999;
}

.crt-scanlines {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    rgba(18, 16, 16, 0) 50%, 
    rgba(0, 0, 0, 0.25) 50%
  ), linear-gradient(
    90deg,
    rgba(255, 0, 0, 0.04),
    rgba(0, 255, 0, 0.01),
    rgba(0, 0, 255, 0.04)
  );
  background-size: 100% 4px, 6px 100%;
  pointer-events: none;
  z-index: 998;
}

/* Ambient Starry Background */
.space-ambient {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(to bottom, #020208 0%, #0d0d2b 100%);
  overflow: hidden;
  z-index: 1;
}

.star-layer {
  position: absolute;
  width: 200%;
  height: 200%;
  top: -50%;
  left: -50%;
  background-image: 
    radial-gradient(1px 1px at 20px 30px, #eee, rgba(0,0,0,0)),
    radial-gradient(1px 1px at 40px 70px, #fff, rgba(0,0,0,0)),
    radial-gradient(2px 2px at 90px 10px, #ddd, rgba(0,0,0,0)),
    radial-gradient(1px 1px at 150px 80px, #fff, rgba(0,0,0,0)),
    radial-gradient(2px 2px at 220px 120px, #00f0ff, rgba(0,0,0,0)),
    radial-gradient(1px 1px at 280px 40px, #ff007f, rgba(0,0,0,0));
  background-repeat: repeat;
  background-size: 300px 300px;
}

.star-slow {
  opacity: 0.3;
  animation: starScroll 180s linear infinite;
}

.star-fast {
  opacity: 0.6;
  background-size: 200px 200px;
  animation: starScroll 90s linear infinite;
}

@keyframes starScroll {
  from { transform: translateY(0); }
  to { transform: translateY(300px); }
}

/* --- Game Container & Arcade Housing --- */
.game-container {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100%;
  max-height: 800px;
  background-color: var(--color-bg);
  border: 8px solid #222244;
  box-shadow: 
    0 0 0 4px #000,
    0 10px 30px rgba(0,0,0,0.8),
    inset 0 0 20px rgba(0, 240, 255, 0.2);
  z-index: 10;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header & Footer Info */
.game-footer {
  margin-top: 10px;
  font-size: 10px;
  color: var(--color-text-gray);
  font-family: var(--font-pixel);
  text-align: center;
  letter-spacing: 0.5px;
  z-index: 5;
}

/* --- Screens Handling --- */
.screen {
  display: none;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding: 20px;
  overflow-y: auto;
  position: relative;
}

.screen.active {
  display: flex;
}

/* Custom Scrollbar for Retro Panels */
.screen::-webkit-scrollbar {
  width: 6px;
}
.screen::-webkit-scrollbar-track {
  background: var(--color-bg);
}
.screen::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border: 1px solid var(--color-bg);
}

/* --- Common Pixel Art Elements --- */
.pixel-btn {
  font-family: var(--font-pixel);
  font-size: 12px;
  padding: 12px 16px;
  border: var(--pixel-border);
  background-color: #202040;
  color: var(--color-text-white);
  cursor: pointer;
  outline: none;
  position: relative;
  box-shadow: inset -4px -4px 0px 0px #101026;
  text-align: center;
  transition: transform 0.05s, box-shadow 0.05s;
}

.pixel-btn:active {
  transform: translate(2px, 2px);
  box-shadow: inset -2px -2px 0px 0px #101026;
}

.btn-primary {
  border-color: var(--color-cyan);
  background-color: #002b3d;
  color: var(--color-cyan);
  text-shadow: 0 0 5px var(--color-cyan);
  box-shadow: inset -4px -4px 0px 0px #001a24, 0 0 10px rgba(0, 240, 255, 0.4);
}
.btn-primary:active {
  box-shadow: inset -2px -2px 0px 0px #001a24;
}

.btn-secondary {
  border-color: var(--color-border);
  background-color: #1a1a36;
  color: var(--color-text-gray);
}

.btn-success {
  border-color: var(--color-green);
  background-color: #0f3d0f;
  color: var(--color-green);
  text-shadow: 0 0 5px var(--color-green);
  box-shadow: inset -4px -4px 0px 0px #082008, 0 0 10px rgba(57, 255, 20, 0.3);
}

.btn-danger-small {
  font-size: 8px;
  padding: 8px;
  border-color: var(--color-red);
  background-color: #3b0000;
  color: var(--color-red);
  align-self: center;
}

.pixel-divider {
  border: 0;
  border-top: 4px dashed var(--color-border);
  margin: 12px 0;
}

/* --- 1. START / MAIN MENU SCREEN --- */
.logo-area {
  text-align: center;
  margin-top: 30px;
  margin-bottom: 25px;
}

.game-title {
  font-family: var(--font-pixel);
  font-size: 26px;
  line-height: 1.4;
  letter-spacing: -1px;
  text-shadow: 4px 4px 0px #000;
  color: var(--color-text-white);
  animation: floatTitle 4s ease-in-out infinite;
}

.game-title .highlight {
  color: var(--color-magenta);
  text-shadow: 4px 4px 0px #000, 0 0 15px var(--color-magenta);
}

@keyframes floatTitle {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-8px) scale(1.02); }
}

.tagline {
  font-size: 11px;
  color: var(--color-text-gray);
  margin-top: 15px;
  text-shadow: 1px 1px 0px #000;
}

.best-score-badge {
  background-color: var(--color-panel);
  border: var(--pixel-border);
  padding: 12px;
  text-align: center;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.badge-label {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--color-yellow);
}

.badge-value {
  font-family: var(--font-pixel);
  font-size: 16px;
  color: var(--color-cyan);
  text-shadow: 0 0 8px rgba(0, 240, 255, 0.6);
}

.instruction-box {
  background-color: rgba(22, 22, 50, 0.6);
  border: 4px solid var(--color-border);
  padding: 15px;
  margin-bottom: 25px;
  font-size: 12px;
}

.instruction-box h2 {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--color-yellow);
  margin-bottom: 12px;
}

.guide-list {
  list-style: none;
  line-height: 1.6;
}

.guide-list li {
  margin-bottom: 8px;
}

.guide-list li strong {
  color: var(--color-cyan);
}

.guide-list code {
  background-color: #0b0b1e;
  border: 2px solid var(--color-border);
  padding: 1px 5px;
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--color-magenta);
}

.start-actions {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-top: auto;
  margin-bottom: 20px;
}

.audio-setting-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.audio-setting-row button {
  flex: 1;
}

/* --- 2. HANGAR / UPGRADE SCREEN --- */
.screen-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.screen-header h2 {
  font-family: var(--font-pixel);
  font-size: 12px;
  color: var(--color-text-white);
}

.coin-display {
  background-color: #000;
  border: 4px solid var(--color-yellow);
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-pixel);
  font-size: 12px;
  color: var(--color-yellow);
}

.hangar-preview {
  display: flex;
  gap: 15px;
  background-color: #0b0b23;
  border: var(--pixel-border);
  padding: 12px;
  margin-bottom: 15px;
}

.spaceship-platform {
  flex: 0 0 120px;
  height: 120px;
  background-color: #060614;
  border: 4px dashed var(--color-border);
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.spaceship-platform::before {
  content: "GRID SCAN";
  position: absolute;
  top: 4px;
  left: 4px;
  font-family: var(--font-pixel);
  font-size: 6px;
  color: rgba(0, 240, 255, 0.4);
}

.hangar-stats {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-pixel);
  font-size: 8px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 2px solid rgba(60, 60, 120, 0.4);
  padding-bottom: 4px;
}

.stat-name {
  color: var(--color-text-gray);
}

.stat-val {
  color: var(--color-cyan);
}

.upgrade-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 5px;
}

.upgrade-item {
  background-color: var(--color-panel);
  border: var(--pixel-border);
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: border-color 0.2s;
}

.upgrade-item:hover {
  border-color: var(--color-cyan);
}

.upgrade-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 65%;
}

.upgrade-title {
  font-weight: bold;
  font-size: 13px;
  color: var(--color-text-white);
}

.upgrade-desc {
  font-size: 10px;
  color: var(--color-text-gray);
}

.btn-upgrade {
  padding: 8px 12px;
  min-width: 90px;
  border-color: var(--color-yellow);
  background-color: #3b3500;
  color: var(--color-yellow);
  box-shadow: inset -4px -4px 0px 0px #242000;
}
.btn-upgrade:active {
  box-shadow: inset -2px -2px 0px 0px #242000;
}

.btn-upgrade.maxed {
  border-color: var(--color-text-gray);
  background-color: #222;
  color: var(--color-text-gray);
  cursor: not-allowed;
  box-shadow: none;
  pointer-events: none;
}
.btn-upgrade.maxed::before {
  content: "MAX";
  font-family: var(--font-pixel);
  font-size: 8px;
}
.btn-upgrade.maxed .upgrade-cost {
  display: none;
}

.hangar-actions {
  display: flex;
  gap: 15px;
  margin-top: auto;
  margin-bottom: 10px;
}

.hangar-actions button {
  flex: 1;
}

/* --- 3. LAUNCH TIMING SCREEN (Gauge Phase) --- */
.phase-header {
  text-align: center;
  margin-bottom: 30px;
}
.phase-header h2 {
  font-family: var(--font-pixel);
  font-size: 16px;
  color: var(--color-magenta);
  text-shadow: 0 0 5px rgba(255, 0, 127, 0.4);
}
.phase-header p {
  font-size: 11px;
  color: var(--color-text-gray);
  margin-top: 10px;
}

.gauge-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex: 1;
}

.gauge-container {
  width: 60px;
  height: 280px;
  background-color: #050510;
  border: 4px solid var(--color-border);
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 15px rgba(0,0,0,0.5);
}

#gauge-bar {
  width: 100%;
  height: 0%;
  background: linear-gradient(to top, var(--color-green), var(--color-yellow), var(--color-magenta));
  position: absolute;
  bottom: 0;
  left: 0;
}

/* Sweet spots */
.gauge-marker {
  position: absolute;
  left: 0;
  width: 100%;
  text-align: center;
  font-family: var(--font-pixel);
  font-size: 6px;
  font-weight: bold;
  pointer-events: none;
  height: 15px;
  line-height: 15px;
}

.perfect-marker {
  bottom: 80%; /* 80% to 90% is perfect */
  background-color: rgba(255, 0, 127, 0.3);
  border-top: 2px solid var(--color-magenta);
  border-bottom: 2px solid var(--color-magenta);
  color: var(--color-text-white);
  height: 25px;
  line-height: 25px;
}

.good-marker {
  bottom: 60%; /* 60% to 80% is good */
  background-color: rgba(0, 240, 255, 0.2);
  border-top: 2px dashed var(--color-cyan);
  border-bottom: 2px dashed var(--color-cyan);
  color: var(--color-cyan);
  height: 55px;
  line-height: 55px;
}

.gauge-feedback-text {
  font-family: var(--font-pixel);
  font-size: 16px;
  color: var(--color-yellow);
  height: 25px;
  text-align: center;
}

.btn-launch {
  border-color: var(--color-magenta);
  background-color: #3b001d;
  color: var(--color-magenta);
  font-size: 16px;
  padding: 16px;
  width: 100%;
  text-shadow: 0 0 5px var(--color-magenta);
  box-shadow: inset -6px -6px 0px 0px #240012, 0 0 15px rgba(255, 0, 127, 0.5);
  margin-bottom: 20px;
}
.btn-launch:active {
  box-shadow: inset -3px -3px 0px 0px #240012;
}

/* --- 4. FLIGHT GAMEPLAY SCREEN --- */
#game-screen {
  padding: 10px;
  justify-content: space-between;
  overflow: hidden;
}

.game-hud {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background-color: rgba(22, 22, 50, 0.85);
  border: var(--pixel-border);
  padding: 8px;
  width: 100%;
}

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

.hud-left, .hud-center, .hud-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

.hud-label {
  font-family: var(--font-pixel);
  font-size: 6px;
  color: var(--color-text-gray);
  margin-bottom: 4px;
}

.hud-value {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--color-cyan);
}

#hud-coins {
  color: var(--color-yellow);
}

.hud-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hud-bar-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bar-label {
  font-family: var(--font-pixel);
  font-size: 7px;
  color: var(--color-text-white);
  width: 40px;
}

.bar-container {
  flex: 1;
  height: 12px;
  background-color: #000;
  border: 2px solid var(--color-border);
  position: relative;
}

.bar-fill {
  height: 100%;
  width: 100%;
  background-color: var(--color-green);
  transition: width 0.05s linear;
}

.fuel-bar-container .bar-fill {
  background: linear-gradient(to right, var(--color-red), var(--color-yellow) 40%, var(--color-green) 70%);
}

.charges-dots {
  display: flex;
  gap: 6px;
  align-items: center;
}

.charge-dot {
  width: 10px;
  height: 10px;
  background-color: var(--color-cyan);
  border: 2px solid #000;
  box-shadow: 0 0 5px var(--color-cyan);
}

.charge-dot.empty {
  background-color: #222;
  box-shadow: none;
}

/* Canvas area */
.canvas-wrapper {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  background-color: #02020a;
  border: 4px solid var(--color-border);
  margin: 8px 0;
  overflow: hidden;
}

#game-canvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.overlay-tip {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(0,0,0,0.8);
  border: 2px solid var(--color-cyan);
  padding: 6px 12px;
  font-size: 10px;
  color: var(--color-cyan);
  pointer-events: none;
  animation: fadeOutTip 3s forwards 2s;
  text-align: center;
  white-space: nowrap;
}

@keyframes fadeOutTip {
  to { opacity: 0; visibility: hidden; }
}

.warning-alert {
  position: absolute;
  top: 20px;
  font-family: var(--font-pixel);
  font-size: 12px;
  color: var(--color-red);
  background-color: rgba(0,0,0,0.85);
  border: 4px solid var(--color-red);
  padding: 6px 12px;
  animation: blinkAlert 0.5s infinite alternate;
  pointer-events: none;
}

@keyframes blinkAlert {
  from { opacity: 0.3; }
  to { opacity: 1; }
}

/* Mobile Controls HUD */
.mobile-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 80px;
  gap: 10px;
  z-index: 20;
}

.touch-side {
  flex: 1;
  height: 100%;
  background-color: rgba(22, 22, 50, 0.7);
  border: 4px solid var(--color-border);
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: var(--font-pixel);
  font-size: 18px;
  color: var(--color-text-gray);
  cursor: pointer;
  touch-action: none;
}

.touch-side:active {
  background-color: rgba(0, 240, 255, 0.2);
  color: var(--color-cyan);
  border-color: var(--color-cyan);
}

.touch-center {
  flex: 0 0 120px;
  height: 100%;
}

.btn-mobile-boost {
  width: 100%;
  height: 100%;
  font-size: 11px;
  padding: 0;
  border-color: var(--color-cyan);
  background-color: #002b3d;
  color: var(--color-cyan);
  box-shadow: inset -4px -4px 0px 0px #001a24;
}

.btn-mobile-boost:active {
  box-shadow: inset -2px -2px 0px 0px #001a24;
  background-color: #003a52;
}

/* Hide mobile controls on desktop if screen width is large & no touch */
@media (min-width: 768px) {
  /* PC environment styling can be adjusted, but we keep controls visible for simplicity, or styled nicely */
}

/* --- 5. GAME OVER / RESULT SCREEN --- */
.result-header {
  text-align: center;
  margin-top: 20px;
  margin-bottom: 20px;
}

.gameover-title {
  font-family: var(--font-pixel);
  font-size: 18px;
  color: var(--color-red);
  text-shadow: 0 0 10px rgba(255, 51, 51, 0.4);
  margin-bottom: 10px;
}

.result-summary {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.result-card {
  background-color: var(--color-panel);
  border: var(--pixel-border);
  padding: 12px 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.result-label {
  font-size: 12px;
  color: var(--color-text-gray);
  font-weight: bold;
}

.result-val {
  font-family: var(--font-pixel);
  font-size: 12px;
  color: var(--color-cyan);
}

.coin-reward-card {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.reward-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
}

.height-reward, .collect-reward {
  display: flex;
  justify-content: space-between;
  color: var(--color-text-white);
}

.total-reward {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--color-yellow);
}

.record-banner {
  background-color: rgba(255, 239, 0, 0.15);
  border: 4px solid var(--color-yellow);
  padding: 10px;
  text-align: center;
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--color-yellow);
  margin-bottom: 20px;
  animation: flashRecord 0.8s infinite alternate;
}

@keyframes flashRecord {
  from { opacity: 0.5; box-shadow: 0 0 5px rgba(255, 239, 0, 0.2); }
  to { opacity: 1; box-shadow: 0 0 15px rgba(255, 239, 0, 0.6); }
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
  margin-bottom: 15px;
}

.hidden {
  display: none !important;
}
