/* style.css */

@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;700;800&family=Inter:wght@400;600;700&family=JetBrains+Mono:wght@600;700&display=swap');

:root {
  --sky-top: #4fa8e8;
  --sky-bottom: #bfe3ff;
  --sun: #ffd34d;
  --ink: #16324a;
  --cloud-white: #ffffff;
  --accent-orange: #ff8c42;
  --accent-red: #ff5d5d;
  --panel-bg: rgba(255, 255, 255, 0.92);
  --panel-border: #16324a;
  --radius-lg: 22px;
  --radius-md: 14px;
  --font-display: 'Baloo 2', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  background: linear-gradient(to bottom, var(--sky-top), var(--sky-bottom));
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: relative;
}
.screen.active { display: block; }

.mute-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: rgba(255,255,255,0.9);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  pointer-events: auto;
}
.mute-toggle:active { transform: scale(0.92); }
.mute-toggle-game {
  position: static;
  width: 34px;
  height: 34px;
  font-size: 14px;
  margin-top: 4px;
  align-self: flex-end;
}

/* ============ SETUP SCREEN ============ */

.setup-wrap {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 16px 48px;
  position: relative;
}

.title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 38px;
  line-height: 1.05;
  text-align: center;
  color: #fff;
  text-shadow: 0 3px 0 var(--ink), 0 3px 8px rgba(0,0,0,0.25);
  margin: 6px 0 22px;
  letter-spacing: 1px;
}
.title-accent { color: var(--sun); text-shadow: 0 3px 0 var(--ink), 0 3px 8px rgba(0,0,0,0.25); }

.title-small {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 28px;
  text-align: center;
  color: var(--ink);
  margin: 8px 0 18px;
}

.setup-card {
  background: var(--panel-bg);
  border: 3px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 8px 0 rgba(22, 50, 74, 0.18);
}

.field-label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  margin: 18px 0 8px;
}
.field-label:first-child { margin-top: 0; }

.text-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 17px;
  font-family: var(--font-body);
  font-weight: 600;
  border: 2px solid var(--ink);
  border-radius: var(--radius-md);
  outline: none;
  background: #fff;
}
.text-input:focus { border-color: var(--accent-orange); box-shadow: 0 0 0 3px rgba(255,140,66,0.25); }

.jet-select, .color-select, .class-select {
  display: grid;
  gap: 10px;
}
.jet-select { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.color-select { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.class-select { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.option-btn {
  background: #f4f8fc;
  border: 2px solid #c7d6e3;
  border-radius: var(--radius-md);
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 11px;
  color: var(--ink);
  transition: transform 0.08s ease, border-color 0.12s ease, background 0.12s ease;
  min-width: 0;
  width: 100%;
  overflow: hidden;
}
.jet-option canvas {
  width: 100%;
  max-width: 64px;
  height: auto;
  aspect-ratio: 3 / 2;
}
.jet-option span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.option-btn:active { transform: scale(0.96); }
.option-btn.selected {
  border-color: var(--accent-orange);
  background: #fff3e8;
  box-shadow: 0 0 0 2px rgba(255,140,66,0.3);
}

.class-option { font-size: 14px; padding: 12px 6px; }

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  display: block;
}

.btn-primary, .btn-secondary {
  width: 100%;
  margin-top: 18px;
  padding: 14px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  border-radius: var(--radius-md);
  border: 2px solid var(--ink);
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.12s ease;
}
.btn-primary {
  background: var(--accent-orange);
  color: #fff;
  box-shadow: 0 4px 0 var(--ink);
}
.btn-primary:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

.btn-secondary {
  background: #fff;
  color: var(--ink);
  margin-top: 10px;
}
.btn-secondary:active { transform: translateY(2px); }

/* ============ GAME SCREEN ============ */

#screen-game { background: #4fa8e8; }

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  padding: 14px 16px;
  pointer-events: none;
}
.hud-left, .hud-right {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hud-score {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 20px;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0,0,0,0.35);
}
.hud-lives { display: flex; gap: 4px; font-size: 22px; }
.life-icon { filter: drop-shadow(0 1px 1px rgba(0,0,0,0.3)); }
.life-icon.life-lost { opacity: 0.25; filter: grayscale(1); }
.hud-class {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  background: rgba(22,50,74,0.55);
  padding: 4px 10px;
  border-radius: 10px;
}

.problem-banner {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255,255,255,0.95);
  border: 3px solid var(--ink);
  border-radius: var(--radius-md);
  padding: 10px 22px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 26px;
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(22,50,74,0.3);
  pointer-events: none;
  white-space: nowrap;
}

.input-bar-wrap {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  width: min(90%, 360px);
}
.answer-input {
  width: 100%;
  padding: 14px 18px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 22px;
  text-align: center;
  border: 3px solid var(--ink);
  border-radius: var(--radius-lg);
  outline: none;
  background: #fff;
  box-shadow: 0 4px 0 rgba(22,50,74,0.3);
}
.answer-input:focus { border-color: var(--accent-orange); }

.pause-overlay {
  position: absolute;
  inset: 0;
  background: rgba(22,50,74,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}
.pause-overlay.hidden { display: none; }
.pause-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 260px;
  text-align: center;
}
.pause-card h2 { font-family: var(--font-display); margin: 0 0 12px; }

/* ============ GAME OVER / SCORES ============ */

.gameover-wrap, .scores-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gameover-stats {
  background: var(--panel-bg);
  border: 3px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 18px 24px;
  margin-bottom: 14px;
  width: 100%;
  max-width: 360px;
}
.stat-line { font-size: 16px; margin: 6px 0; font-weight: 600; }

.gameover-newhigh {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 20px;
  color: var(--accent-orange);
  margin-bottom: 10px;
  animation: pulse 1s infinite ease-in-out;
}
.gameover-newhigh.hidden { display: none; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.gameover-wrap .btn-primary, .gameover-wrap .btn-secondary,
.scores-wrap .btn-primary {
  max-width: 320px;
}

.scores-table {
  background: var(--panel-bg);
  border: 3px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  width: 100%;
  max-width: 420px;
  max-height: 50vh;
  overflow-y: auto;
  margin-bottom: 18px;
}
.scores-header, .scores-row {
  display: grid;
  grid-template-columns: 28px 1fr 90px 60px;
  gap: 8px;
  padding: 7px 0;
  font-size: 14px;
}
.scores-header {
  font-family: var(--font-display);
  font-weight: 700;
  border-bottom: 2px solid var(--ink);
}
.scores-row { border-bottom: 1px solid #e0e8f0; font-weight: 600; }
.scores-row:last-child { border-bottom: none; }
.empty-state {
  text-align: center;
  padding: 20px 0;
  color: #5a7188;
  font-weight: 600;
}

@media (max-width: 380px) {
  .title { font-size: 30px; }
  .jet-select { grid-template-columns: repeat(2, 1fr); }
  .color-select { grid-template-columns: repeat(3, 1fr); }
}
