/* Space Shooter — Pixel-HD neon arcade. Original art drawn with Canvas primitives + CSS. */

:root {
  --bg-deep: #0a0a1a;
  --bg-panel: rgba(16, 16, 40, 0.82);
  --bg-panel-solid: #141430;
  --cyan: #00f0ff;
  --magenta: #ff2fd6;
  --orange: #ff9f1c;
  --lime: #8aff00;
  --yellow: #ffe93c;
  --red: #ff3b3b;
  --text: #e8ecff;
  --text-dim: #9aa3c7;
  --border: rgba(0, 240, 255, 0.35);
  --glow-cyan: 0 0 12px rgba(0, 240, 255, 0.55), 0 0 42px rgba(0, 240, 255, 0.22);
  --glow-magenta: 0 0 12px rgba(255, 47, 214, 0.55), 0 0 42px rgba(255, 47, 214, 0.25);
  --font-arcade: "Courier New", ui-monospace, SFMono-Regular, Menlo, monospace;
}

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

html, body {
  height: 100%;
  overflow: hidden; /* app-like full screen; screens scroll internally if needed */
}

body {
  background:
    radial-gradient(ellipse 120% 80% at 50% -10%, #241a4d 0%, rgba(36, 26, 77, 0) 55%),
    radial-gradient(ellipse 90% 60% at 50% 115%, #2b0f3d 0%, rgba(43, 15, 61, 0) 55%),
    linear-gradient(180deg, #0a0a1a 0%, #12082b 55%, #0a0a1a 100%);
  color: var(--text);
  font-family: var(--font-arcade);
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ------- twinkling CSS starfield behind everything ------- */
.bg-stars { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.bg-stars span {
  position: absolute; inset: -50%;
  background-repeat: repeat;
  background-image:
    radial-gradient(1px 1px at 20px 30px, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 130px 90px, #cfe8ff 50%, transparent 51%),
    radial-gradient(2px 2px at 70px 150px, #ffffff 50%, transparent 51%),
    radial-gradient(1px 1px at 190px 40px, #ffd9f6 50%, transparent 51%),
    radial-gradient(1px 1px at 90px 190px, #fff 50%, transparent 51%);
  background-size: 240px 240px;
  opacity: 0.8;
  animation: twinkle 4.5s ease-in-out infinite alternate;
}
.bg-stars span:nth-child(2) { background-size: 340px 340px; animation-duration: 6.5s; opacity: 0.5; transform: translateY(8%); }
.bg-stars span:nth-child(3) { background-size: 460px 460px; animation-duration: 8s; opacity: 0.35; transform: translateY(-6%); }
@keyframes twinkle { from { opacity: 0.25; } to { opacity: 0.9; } }

.vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 5;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(2, 2, 12, 0.55) 100%);
}

/* ------- language toggle ------- */
.lang-toggle {
  position: fixed; top: 10px; right: 10px; z-index: 40;
  background: var(--bg-panel);
  color: var(--cyan);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  font-family: var(--font-arcade); font-weight: bold; font-size: 0.95rem;
  cursor: pointer;
  box-shadow: var(--glow-cyan);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.lang-toggle:hover, .lang-toggle:focus-visible { transform: translateY(-2px) scale(1.03); box-shadow: 0 0 18px rgba(0,240,255,0.6); outline: none; }

/* ======================================================
   Screens
   ====================================================== */
#app { position: relative; z-index: 1; flex: 1; min-height: 0; display: flex; }
.screen { flex: 1; min-height: 0; }
.screen-center {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 12px 16px 8px; overflow-y: auto; text-align: center;
}
.hidden { display: none !important; }

/* ------- title ------- */
.game-title {
  display: flex; flex-direction: column; line-height: 0.95;
  font-weight: 900; letter-spacing: 0.08em;
  animation: title-float 3.2s ease-in-out infinite;
}
.title-line-1 {
  font-size: clamp(2.6rem, 11vw, 4.2rem);
  color: var(--cyan);
  text-shadow: 0 0 6px rgba(0,240,255,0.9), 0 0 26px rgba(0,240,255,0.5), 4px 4px 0 #062a33;
  -webkit-text-stroke: 1px #062a33;
}
.title-line-2 {
  font-size: clamp(3rem, 13vw, 5rem);
  color: var(--magenta);
  text-shadow: 0 0 6px rgba(255,47,214,0.9), 0 0 30px rgba(255,47,214,0.5), 5px 5px 0 #33062a;
  -webkit-text-stroke: 1px #33062a;
}
@keyframes title-float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

.tagline { color: var(--yellow); font-size: clamp(0.7rem, 2.4vw, 0.9rem); letter-spacing: 0.14em; text-transform: uppercase; text-shadow: 0 0 10px rgba(255,233,60,0.5); }

/* ------- menu high score chip ------- */
.menu-highscore {
  display: flex; align-items: baseline; gap: 10px;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 6px 18px; box-shadow: var(--glow-cyan);
}
.menu-hs-label { color: var(--text-dim); font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; }
.menu-hs-value { color: var(--yellow); font-weight: bold; font-size: 1rem; }

/* ======================================================
   Buttons — chunky neon arcade style
   ====================================================== */
.btn {
  font-family: var(--font-arcade); font-weight: 700;
  color: var(--cyan);
  background: linear-gradient(180deg, rgba(0,240,255,0.12), rgba(0,240,255,0.03));
  border: 2px solid var(--cyan);
  border-radius: 12px;
  padding: 12px 26px;
  font-size: 1rem; letter-spacing: 0.1em; text-transform: uppercase;
  cursor: pointer;
  box-shadow: var(--glow-cyan), inset 0 0 18px rgba(0,240,255,0.12);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
  touch-action: manipulation;
}
.btn:hover, .btn:focus-visible { transform: translateY(-2px); background: linear-gradient(180deg, rgba(0,240,255,0.22), rgba(0,240,255,0.08)); box-shadow: 0 0 22px rgba(0,240,255,0.65), inset 0 0 22px rgba(0,240,255,0.2); outline: none; }
.btn:active { transform: translateY(1px) scale(0.98); }

.btn-primary {
  color: #081018; border-color: var(--yellow);
  background: linear-gradient(180deg, #ffe93c 0%, #ffc93c 100%);
  box-shadow: 0 0 18px rgba(255,233,60,0.5), 0 4px 0 #a97800;
  text-shadow: none;
}
.btn-primary:hover, .btn-primary:focus-visible { background: linear-gradient(180deg, #fff06a, #ffd23c); box-shadow: 0 0 28px rgba(255,233,60,0.75), 0 4px 0 #a97800; }
.btn-primary:active { box-shadow: 0 0 12px rgba(255,233,60,0.5), 0 2px 0 #a97800; }

.btn-big { font-size: 1.25rem; padding: 14px 44px; }
.btn-small { font-size: 0.75rem; padding: 8px 14px; }
.btn-ghost { border-color: var(--text-dim); color: var(--text-dim); box-shadow: none; background: transparent; }
.btn-icon { min-width: 120px; }

.menu-buttons { display: flex; flex-direction: column; gap: 10px; width: min(320px, 86vw); }

/* ======================================================
   Leaderboard card
   ====================================================== */
.leaderboard-card {
  background: var(--bg-panel);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 10px 16px 12px;
  width: min(360px, 92vw);
  box-shadow: var(--glow-magenta);
  backdrop-filter: blur(3px);
}
.leaderboard-title { color: var(--magenta); font-size: 0.85rem; letter-spacing: 0.16em; text-transform: uppercase; text-shadow: var(--glow-magenta); margin-bottom: 6px; }
.leaderboard-list { list-style: none; counter-reset: rank; display: flex; flex-direction: column; gap: 2px; }
.leaderboard-list li {
  counter-increment: rank;
  display: grid; grid-template-columns: 2.2em 1fr auto auto; gap: 8px; align-items: baseline;
  padding: 3px 8px; border-radius: 8px; font-size: 0.82rem;
}
.leaderboard-list li:nth-child(odd) { background: rgba(255,255,255,0.04); }
.leaderboard-list li::before { content: counter(rank) "."; color: var(--text-dim); }
.leaderboard-list li.top-1 { background: rgba(255,233,60,0.12); }
.leaderboard-list li.top-1 .lb-initials { color: var(--yellow); }
.lb-initials { color: var(--cyan); font-weight: bold; letter-spacing: 0.1em; }
.lb-score { color: var(--text); font-weight: bold; }
.lb-wave { color: var(--text-dim); font-size: 0.72rem; }
.leaderboard-status { min-height: 1.1em; font-size: 0.66rem; color: var(--text-dim); margin-top: 4px; }
.leaderboard-list .lb-empty { display: block; text-align: center; color: var(--text-dim); font-size: 0.75rem; padding: 8px 0; }
.leaderboard-list .lb-empty::before { content: none; }

/* ======================================================
   Initials gate
   ====================================================== */
.panel-title { color: var(--cyan); font-size: clamp(1.3rem, 5vw, 1.9rem); letter-spacing: 0.08em; text-transform: uppercase; text-shadow: var(--glow-cyan); }
.panel-help { color: var(--text-dim); font-size: 0.8rem; max-width: 420px; }
.initials-form { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.initials-boxes { display: flex; gap: 14px; }
.initial-box {
  width: clamp(64px, 18vw, 88px); height: clamp(80px, 22vw, 104px);
  font-family: var(--font-arcade); font-size: clamp(2.4rem, 9vw, 3.2rem); font-weight: 900;
  text-align: center; text-transform: uppercase;
  color: var(--yellow); background: var(--bg-panel-solid);
  border: 3px solid var(--cyan); border-radius: 12px;
  box-shadow: var(--glow-cyan), inset 0 0 20px rgba(0,240,255,0.15);
  caret-color: var(--magenta); outline: none;
}
.initial-box:focus { border-color: var(--magenta); box-shadow: var(--glow-magenta), inset 0 0 20px rgba(255,47,214,0.2); }
.panel-buttons { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: center; }
.save-status { min-height: 1.2em; font-size: 0.78rem; color: var(--lime); }
.save-status.error { color: var(--orange); }

/* ======================================================
   How to play
   ====================================================== */
.howto-card {
  background: var(--bg-panel); border: 2px solid var(--border); border-radius: 16px;
  padding: 14px 22px; max-width: 560px; width: min(560px, 94vw);
  max-height: 56vh; overflow-y: auto; text-align: left;
  box-shadow: var(--glow-cyan);
}
.howto-content { font-size: 0.82rem; line-height: 1.55; color: var(--text); }
.howto-content h3 { color: var(--yellow); font-size: 0.8rem; letter-spacing: 0.14em; text-transform: uppercase; margin: 10px 0 4px; }
.howto-content ul { padding-left: 1.3em; }
.howto-content li { margin: 2px 0; }
.howto-content b { color: var(--cyan); }
.howto-legend { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 12px; border-top: 1px dashed rgba(255,255,255,0.15); padding-top: 10px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.68rem; color: var(--text-dim); }
.legend-ship { image-rendering: pixelated; width: 36px; height: 36px; }

/* ======================================================
   GAME screen
   ====================================================== */
.screen-game { display: flex; flex-direction: column; align-items: stretch; padding: 6px 8px 2px; gap: 4px; }

.hud {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  width: 100%; max-width: 720px; margin: 0 auto;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 4px 10px;
}
.hud-item { display: flex; align-items: center; gap: 6px; min-width: 0; }
.hud-label { color: var(--text-dim); font-size: 0.58rem; letter-spacing: 0.14em; text-transform: uppercase; }
.hud-value { color: var(--text); font-weight: bold; font-size: clamp(0.8rem, 3vw, 1.05rem); font-variant-numeric: tabular-nums; }
#hud-score { color: var(--yellow); }
#hud-wave { color: var(--cyan); }
.hud-lives { display: flex; gap: 4px; align-items: center; font-size: 0.95rem; letter-spacing: 2px; }
.life-pip { color: var(--cyan); text-shadow: 0 0 6px rgba(0,240,255,0.8); }
.life-pip.lost { color: #3a3a55; text-shadow: none; }
.combo-value { color: var(--magenta); text-shadow: var(--glow-magenta); animation: combo-pop 0.25s ease; }
@keyframes combo-pop { 0% { transform: scale(1.6); } 100% { transform: scale(1); } }

.btn-icon-hud {
  background: transparent; border: 1px solid var(--border); border-radius: 8px;
  color: var(--cyan); font-family: var(--font-arcade); font-weight: 700;
  font-size: 0.6rem; letter-spacing: 0.08em; width: 48px; height: 36px; cursor: pointer;
  touch-action: manipulation;
}
.btn-icon-hud:focus-visible { outline: 2px solid var(--cyan); }

.powerup-bar { display: flex; gap: 8px; justify-content: center; min-height: 20px; font-size: 0.62rem; }
.powerup-chip { background: rgba(138,255,0,0.12); border: 1px solid var(--lime); color: var(--lime); border-radius: 999px; padding: 1px 10px; letter-spacing: 0.08em; }

.canvas-wrap {
  position: relative; flex: 1; min-height: 0; width: 100%;
  display: flex; align-items: center; justify-content: center;
}
#game-canvas {
  background: #05050f;
  border: 2px solid rgba(0, 240, 255, 0.4);
  border-radius: 10px;
  box-shadow: var(--glow-cyan), inset 0 0 60px rgba(0,0,0,0.6);
  image-rendering: pixelated;
  display: block;
}

/* wave banner */
.wave-banner {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  pointer-events: none; z-index: 6;
}
.wave-banner span {
  font-size: clamp(2rem, 9vw, 3.4rem); font-weight: 900; letter-spacing: 0.18em;
  color: var(--yellow);
  text-shadow: 0 0 12px rgba(255,233,60,0.9), 0 0 60px rgba(255,159,28,0.6), 4px 4px 0 #332200;
  animation: banner-zoom 0.5s ease-out;
}
@keyframes banner-zoom { 0% { transform: scale(0.3); opacity: 0; } 60% { transform: scale(1.25); opacity: 1; } 100% { transform: scale(1); } }

.boss-warning {
  position: absolute; top: 12%; left: 0; right: 0; text-align: center; z-index: 6; pointer-events: none;
  font-size: clamp(1.3rem, 6vw, 2rem); font-weight: 900; letter-spacing: 0.2em; color: var(--red);
  text-shadow: 0 0 14px rgba(255,59,59,0.9); animation: boss-flash 0.45s steps(2, jump-none) infinite;
}
@keyframes boss-flash { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }

/* pause overlay */
.overlay {
  position: absolute; inset: 0; z-index: 7;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: rgba(6, 6, 22, 0.78); backdrop-filter: blur(3px); border-radius: 10px;
}
.overlay-title { color: var(--cyan); font-size: 2rem; letter-spacing: 0.2em; text-transform: uppercase; text-shadow: var(--glow-cyan); }
.overlay-buttons { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* ======================================================
   Touch controls — big thumb pad, only on touch/small screens
   ====================================================== */
.touch-controls {
  display: none;
  align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; max-width: 720px; margin: 0 auto;
  padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
}
.touch-btn {
  font-family: var(--font-arcade); font-weight: 900;
  border-radius: 16px; border: 2px solid var(--cyan); color: var(--cyan);
  background: rgba(0, 240, 255, 0.1);
  touch-action: none; user-select: none; cursor: pointer;
  box-shadow: var(--glow-cyan);
}
.touch-move { width: 84px; height: 74px; font-size: 1.6rem; }
.touch-fire {
  flex: 1; height: 74px; font-size: 1.35rem; letter-spacing: 0.2em;
  color: #081018; border-color: var(--magenta);
  background: linear-gradient(180deg, #ff5ce0, #ff2fd6);
  box-shadow: 0 0 22px rgba(255,47,214,0.6), 0 4px 0 #7a1166;
}
.touch-btn:active { transform: scale(0.95); filter: brightness(1.3); }

@media (pointer: coarse), (max-width: 760px) {
  .touch-controls { display: flex; }
}

/* ======================================================
   GAME OVER
   ====================================================== */
.gameover-title {
  color: var(--red); font-size: clamp(1.8rem, 8vw, 2.8rem); letter-spacing: 0.18em; text-transform: uppercase;
  text-shadow: 0 0 16px rgba(255,59,59,0.8), 4px 4px 0 #33060a;
}
.new-high-score {
  color: #081018; background: var(--yellow); border-radius: 10px; padding: 6px 18px;
  font-weight: 900; letter-spacing: 0.16em; font-size: clamp(0.8rem, 3.4vw, 1.05rem);
  box-shadow: 0 0 24px rgba(255,233,60,0.8); animation: combo-pop 0.5s ease;
}
.gameover-stats { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.stat-box {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 8px 18px; min-width: 108px;
}
.stat-label { display: block; color: var(--text-dim); font-size: 0.58rem; letter-spacing: 0.14em; text-transform: uppercase; }
.stat-value { color: var(--yellow); font-size: 1.4rem; font-weight: 900; font-variant-numeric: tabular-nums; }

/* ======================================================
   FOOTER — mandatory credits, always visible
   ====================================================== */
#site-footer {
  position: relative; z-index: 10;
  text-align: center;
  background: rgba(6, 6, 18, 0.9);
  border-top: 1px solid rgba(0, 240, 255, 0.25);
  padding: 5px 10px calc(5px + env(safe-area-inset-bottom));
  font-size: clamp(0.55rem, 2.2vw, 0.72rem);
  color: var(--text-dim);
  line-height: 1.5;
}
#site-footer a { color: var(--cyan); text-decoration: none; }
#site-footer a:hover, #site-footer a:focus-visible { text-decoration: underline; }
.oss-badge { display: flex; align-items: center; justify-content: center; gap: 6px; color: #7dff9a; font-size: 0.62rem; letter-spacing: 0.06em; }
.oss-dot { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border: 1px solid #7dff9a; border-radius: 4px; font-size: 0.55rem; }

/* ======================================================
   Reduced motion: calm everything down
   ====================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .bg-stars span { animation: none; opacity: 0.5; }
}

/* small screens: tighten menu so footer + content fit */
@media (max-height: 640px) {
  .game-title { animation: none; }
  .screen-center { gap: 8px; padding-top: 6px; }
  .leaderboard-card { padding: 6px 12px 8px; }
  .leaderboard-list li { font-size: 0.72rem; padding: 2px 6px; }
}
