/* Calcipede — retro arcade styling.
   The play field is a fixed 800x600 canvas; the container scales to fit the
   viewport while keeping aspect ratio. HUD is a non-interactive overlay. */

:root {
  --cyan: #56d8ff;
  --green: #5dff9b;
  --yellow: #fff15c;
  --red: #ff5d73;
  --panel: rgba(10, 16, 30, 0.72);
  --panel-border: rgba(86, 216, 255, 0.5);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #02030a;
  color: #e8f0ff;
  font-family: "Consolas", "SF Mono", "Menlo", "Courier New", monospace;
  overflow: hidden;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Scale the whole 4:3 field to fit the window, preserving aspect ratio. */
#game-container {
  position: relative;
  width: min(100vw, 133.333vh);
  aspect-ratio: 4 / 3;
  box-shadow: 0 0 60px rgba(86, 216, 255, 0.15);
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  border: 1px solid rgba(86, 216, 255, 0.25);
  border-radius: 6px;
}

/* ---- HUD ---- */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  font-size: clamp(11px, 1.6vw, 16px);
}

#hud-top-left {
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* 2x larger than the rest of the HUD */
  font-size: clamp(20px, 3.0vw, 30px);
}

.stat {
  display: flex;
  gap: 8px;
  align-items: baseline;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 4px 12px;
  min-width: 7em;
}

.stat .label {
  color: var(--cyan);
  letter-spacing: 1px;
  font-size: 0.78em;
}

#hud-top-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  /* 2x larger problem panel */
  font-size: 2em;
}

#problem-panel {
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 8px;
  padding: 10px 16px;
  text-align: right;
  min-width: 220px;
  box-shadow: 0 0 24px rgba(86, 216, 255, 0.12);
}

#hud-bucket {
  font-size: 0.72em;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--green);
}

#hud-problem {
  font-size: 1.9em;
  font-weight: bold;
  color: #fff;
  margin: 2px 0 6px;
  text-shadow: 0 0 12px rgba(255, 255, 255, 0.25);
}

#answer-line {
  font-size: 1.4em;
  color: var(--yellow);
  letter-spacing: 1px;
}

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

.caret {
  animation: blink 1s steps(2, start) infinite;
  color: var(--yellow);
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

#hud-feedback {
  font-size: 1em;
  min-height: 1.2em;
  text-shadow: 0 0 10px currentColor;
}

/* ---- Out-of-ammo banner (centred, flashing) ---- */
#low-ammo {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  text-align: center;
  padding: 0 20px;
}

#low-ammo.show {
  display: flex;
  animation: blink-big 0.7s steps(2, start) infinite;
}

#low-ammo-text {
  color: var(--red);
  font-weight: bold;
  font-size: clamp(28px, 6.5vw, 64px);
  letter-spacing: 2px;
  text-shadow: 0 0 24px rgba(255, 93, 115, 0.8);
}

@keyframes blink-big {
  50% {
    opacity: 0.18;
  }
}

/* ---- Full-screen red damage flash ---- */
#screen-flash {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(255, 40, 60, 0.35) 0%, rgba(255, 30, 50, 0.9) 100%);
}

/* ---- Centred celebration flash (correct answer) ---- */
#center-flash {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  text-align: center;
  padding: 0 20px;
}

#center-flash.show {
  display: flex;
}

#center-flash-text {
  font-weight: bold;
  font-size: clamp(30px, 6.5vw, 64px);
  letter-spacing: 2px;
  text-shadow: 0 0 26px currentColor;
  animation: correct-pop 0.45s ease-out;
}

@keyframes correct-pop {
  0% {
    transform: scale(0.6);
    opacity: 0;
  }
  60% {
    transform: scale(1.12);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ---- Overlay (menu / pause / game over) ---- */
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 4, 12, 0.78);
  backdrop-filter: blur(2px);
}

#overlay.hidden {
  display: none;
}

#overlay-card {
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 12px;
  padding: 28px 40px;
  text-align: center;
  max-width: 82%;
  max-height: 90%;
  overflow-y: auto;
  box-shadow: 0 0 50px rgba(86, 216, 255, 0.25);
}

#overlay-title {
  margin: 0 0 16px;
  font-size: clamp(28px, 5vw, 48px);
  color: var(--cyan);
  letter-spacing: 3px;
  text-shadow: 0 0 18px rgba(86, 216, 255, 0.6);
}

#overlay-body {
  line-height: 1.7;
  font-size: clamp(12px, 1.8vw, 16px);
  color: #cde0ff;
}

#overlay-buttons {
  margin-top: 22px;
  display: flex;
  gap: 14px;
  justify-content: center;
}

button {
  font-family: inherit;
  font-size: 1em;
  cursor: pointer;
  border-radius: 6px;
  padding: 9px 20px;
  border: 1px solid var(--panel-border);
  background: rgba(86, 216, 255, 0.12);
  color: var(--cyan);
  letter-spacing: 1px;
  transition: background 0.15s, transform 0.05s;
}

button:hover {
  background: rgba(86, 216, 255, 0.25);
}

button:active {
  transform: translateY(1px);
}

#reset-btn {
  border-color: rgba(255, 93, 115, 0.5);
  background: rgba(255, 93, 115, 0.1);
  color: var(--red);
}

#reset-btn:hover {
  background: rgba(255, 93, 115, 0.22);
}

#overlay-buttons.hidden {
  display: none;
}

/* ---- Leaderboard ---- */
.leaderboard {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0 4px;
  font-size: clamp(12px, 1.7vw, 16px);
}

.leaderboard td {
  padding: 3px 10px;
  border-bottom: 1px solid rgba(86, 216, 255, 0.12);
}

.leaderboard .lb-rank {
  width: 2.5em;
  text-align: right;
  color: var(--cyan);
  opacity: 0.75;
}

.leaderboard .lb-name {
  text-align: left;
  letter-spacing: 1px;
}

.leaderboard .lb-score {
  text-align: right;
  color: var(--yellow);
  font-variant-numeric: tabular-nums;
}

.leaderboard tr.hi td,
.leaderboard tr.hi .lb-rank,
.leaderboard tr.hi .lb-score {
  color: var(--green);
}

.leaderboard tr.hi td {
  background: rgba(93, 255, 155, 0.1);
}

.leaderboard-empty {
  margin: 16px 0;
  opacity: 0.8;
}

.hint {
  margin-top: 12px;
  font-size: 0.85em;
  opacity: 0.85;
}
