/* ============================================
   CATCH THE FOOD — styles
   Colors intentionally reuse the portal's root variables:
   --choco-blue #3D6BFF · --dark-blue #1A0D78 · --midnight #18003F · --light-blue #C0D5FF
   ============================================ */

/* Portal tokens the game was built on, scoped so they don't leak into the portfolio. */
.ctf-stage {
  --choco-blue: #3D6BFF;
  --dark-blue: #1A0D78;
  --midnight: #18003F;
  --light-blue: #C0D5FF;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --font-display: 'CTFPixel', 'Geist', sans-serif;
}

@font-face {
  font-family: 'CTFPixel';
  src: url('sprites/pixel.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

.ctf-stage {
  position: relative;
  max-width: 960px;
  margin: 0 auto;
  aspect-ratio: 3 / 2;
  background: var(--dark-blue);
  border-radius: 12px;
  overflow: hidden;
  user-select: none;
  touch-action: none;
  font-family: 'CTFPixel', 'Work Sans', Georgia, serif;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.ctf-stage:focus {
  outline: none;
}
.ctf-stage:focus-visible {
  outline: 3px solid var(--light-blue);
  outline-offset: 4px;
}

.ctf-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

.ctf-hidden {
  display: none !important;
}

/* ── HUD ─────────────────────────────────────────────────────────────────── */
.ctf-hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: clamp(10px, 2.2vw, 26px);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ctf-hud-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.ctf-title {
  color: #fff;
  font-size: clamp(16px, 3.6vw, 32px);
  line-height: 1;
  letter-spacing: 0.02em;
  text-shadow: 3px 3px 0 var(--midnight);
  margin: 0;
}

.ctf-hud-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.ctf-score-label {
  font-size: clamp(9px, 1.4vw, 13px);
  color: var(--light-blue);
  letter-spacing: 0.08em;
}

.ctf-score-value {
  color: #fff;
  font-size: clamp(16px, 3vw, 26px);
}

.ctf-wasted {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--light-blue);
  font-size: clamp(9px, 1.4vw, 13px);
  letter-spacing: 0.06em;
}

.ctf-wasted-bar {
  width: clamp(70px, 12vw, 140px);
  height: 10px;
  border: 2px solid var(--light-blue);
  border-radius: 6px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}

.ctf-wasted-fill {
  height: 100%;
  width: 0%;
  background: var(--choco-blue);
  transition: width 0.25s var(--ease, ease);
}

.ctf-wasted--urgent .ctf-wasted-fill {
  background: #ff5b4d;
  animation: ctf-pulse 0.7s infinite;
}
.ctf-wasted--urgent .ctf-wasted-label::before {
  content: '⚠ ';
}
.ctf-wasted--urgent {
  color: #ffb4ac;
}

.ctf-shake {
  animation: ctf-shake-kf 0.26s;
}

.ctf-combo {
  align-self: flex-end;
  color: #ffd447;
  font-size: clamp(12px, 2vw, 18px);
  text-shadow: 2px 2px 0 var(--midnight);
}

.ctf-controls {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  pointer-events: auto;
  order: 2;
}
.ctf-title {
  order: 1;
}
.ctf-hud-right {
  order: 3;
}

.ctf-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 2px solid var(--light-blue);
  background: rgba(24, 0, 63, 0.55);
  color: #fff;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s var(--ease, ease), background 0.15s;
}
.ctf-icon-btn:hover {
  background: var(--choco-blue);
}
.ctf-icon-btn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}
.ctf-icon-btn:active {
  transform: scale(0.92);
}

/* ── Callouts ────────────────────────────────────────────────────────────── */
.ctf-callouts {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.ctf-callout {
  position: absolute;
  font-family: 'CTFPixel', 'Work Sans', Georgia, serif;
  white-space: pre-line;
  text-align: center;
  color: #fff;
  text-shadow: 2px 2px 0 var(--midnight);
  animation-timing-function: ease-out;
  animation-fill-mode: forwards;
}

.ctf-callout--floating {
  transform: translate(-50%, -100%);
  font-size: clamp(14px, 2.4vw, 22px);
  animation-name: ctf-float-up;
}
.ctf-callout--floating.ctf-callout--golden { color: #ffd447; }
.ctf-callout--floating.ctf-callout--bitten { color: #ff8f85; }

.ctf-callout--center {
  left: 50%;
  top: 42%;
  font-size: clamp(20px, 4.4vw, 40px);
  animation-name: ctf-center-pop;
}
.ctf-callout--center.ctf-callout--combo { color: #ffd447; }
.ctf-callout--center.ctf-callout--speedup { color: var(--light-blue); }
.ctf-callout--center.ctf-callout--waste { color: #ff8f85; }
.ctf-callout--center.ctf-callout--warn { color: #ff5b4d; }
.ctf-callout--center.ctf-callout--ai { color: var(--light-blue); }

@keyframes ctf-float-up {
  0% { opacity: 0; transform: translate(-50%, -80%) scale(0.85); }
  15% { opacity: 1; transform: translate(-50%, -100%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, calc(-100% - var(--rise, 90px))) scale(1); }
}

@keyframes ctf-center-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

@keyframes ctf-shake-kf {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

@keyframes ctf-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── "EXPIRY DATE AVOIDED" mega event ───────────────────────────────────────
   Fired when the yellow, green and red apple (spawned together) are all
   caught. Real-photo cutouts fly into three color bands with TriadeChoco
   headline text — a deliberate departure from the pixel-art palette for one
   flashy, rare moment. --trio-duration is set inline by game.js to match
   CONFIG.trioEvent.displayDuration. */
.ctf-trio-event {
  position: absolute;
  inset: 0;
  display: flex;
  pointer-events: none;
  --trio-duration: 2.6s;
}

.ctf-trio-event--active {
  animation: ctf-trio-fade var(--trio-duration) ease-in-out forwards;
}

.ctf-trio-band {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  overflow: hidden;
  opacity: 0;
  transform: translateY(30px);
  animation: ctf-trio-band-in 0.5s ease-out forwards;
}
.ctf-trio-band--yellow { background: #F5D949; animation-delay: 0s; }
.ctf-trio-band--green  { background: #2EBD82; animation-delay: 0.15s; }
.ctf-trio-band--red    { background: #F35B49; animation-delay: 0.3s; }

.ctf-trio-img {
  display: block;
  height: auto;
  opacity: 0;
  transform: scale(0.4) translateY(40px);
  animation: ctf-trio-img-in 0.6s cubic-bezier(0.2, 1.4, 0.4, 1) forwards;
}
.ctf-trio-band--yellow .ctf-trio-img { width: 86%; max-width: 343px; animation-delay: 0.15s; }
.ctf-trio-band--green  .ctf-trio-img { width: 108%; max-width: 429px; animation-delay: 0.3s; }
.ctf-trio-band--red    .ctf-trio-img { width: 132%; max-width: 543px; animation-delay: 0.45s; }

.ctf-trio-label {
  font-family: var(--font-display, 'TriadeChoco', 'Work Sans', Georgia, serif);
  font-size: clamp(18px, 4.4vw, 40px);
  letter-spacing: 0.02em;
  margin: 0;
  opacity: 0;
  animation: ctf-trio-label-in 0.5s ease-out forwards;
}
.ctf-trio-band--yellow .ctf-trio-label { color: #B4470F; animation-delay: 0.55s; }
.ctf-trio-band--green  .ctf-trio-label { color: #0E4F45; animation-delay: 0.7s; }
.ctf-trio-band--red    .ctf-trio-label { color: #6E1710; animation-delay: 0.85s; }

.ctf-trio-bonus {
  position: absolute;
  left: 50%;
  top: 10%;
  transform: translateX(-50%);
  margin: 0;
  font-family: 'CTFPixel', 'Work Sans', Georgia, serif;
  font-size: clamp(22px, 5vw, 46px);
  color: #fff;
  text-shadow: 3px 3px 0 var(--midnight);
  opacity: 0;
  animation: ctf-trio-bonus-in 0.5s ease-out 1.05s forwards;
}

@keyframes ctf-trio-fade {
  0%, 85% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes ctf-trio-band-in {
  from { opacity: 0; transform: translateY(30px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes ctf-trio-img-in {
  from { opacity: 0; transform: scale(0.4) translateY(40px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes ctf-trio-label-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes ctf-trio-bonus-in {
  from { opacity: 0; transform: translateX(-50%) scale(0.6); }
  to   { opacity: 1; transform: translateX(-50%) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .ctf-trio-band,
  .ctf-trio-img,
  .ctf-trio-label,
  .ctf-trio-bonus {
    animation-duration: 0.3s !important;
    transform: none !important;
  }
}

/* ── Screens (start / pause / game over) ────────────────────────────────── */
.ctf-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 24px;
  background: rgba(24, 0, 63, 0.82);
  color: #fff;
  overflow-y: auto;
}

.ctf-screen h2 {
  font-size: clamp(22px, 5vw, 44px);
  text-shadow: 3px 3px 0 var(--midnight);
  margin: 0;
}

.ctf-screen p {
  color: var(--light-blue);
  font-size: clamp(11px, 1.8vw, 16px);
  letter-spacing: 0.03em;
  margin: 0;
}

.ctf-hint {
  color: rgba(255, 255, 255, 0.7);
  font-size: clamp(10px, 1.5vw, 13px);
}

.ctf-btn {
  margin-top: 8px;
  padding: 12px 28px;
  background: var(--choco-blue);
  border: 3px solid #fff;
  border-radius: 10px;
  color: #fff;
  font-family: 'CTFPixel', 'Work Sans', Georgia, serif;
  font-size: clamp(13px, 2vw, 18px);
  cursor: pointer;
  box-shadow: 0 6px 0 var(--midnight);
  transition: transform 0.1s var(--ease, ease), box-shadow 0.1s;
}
.ctf-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 0 var(--midnight);
}
.ctf-btn:active {
  transform: translateY(2px);
  box-shadow: 0 3px 0 var(--midnight);
}
.ctf-btn:focus-visible {
  outline: 3px solid var(--light-blue);
  outline-offset: 3px;
}

.ctf-results {
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 4px 20px;
  font-size: clamp(11px, 1.8vw, 15px);
  color: #fff;
  margin: 4px 0;
}
.ctf-results dt { color: var(--light-blue); text-align: right; }
.ctf-results dd { margin: 0; text-align: left; font-weight: bold; }

/* ── Save score + leaderboard ────────────────────────────────────────────── */
.ctf-save-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.ctf-save-row {
  display: flex;
  gap: 8px;
}

.ctf-nickname-input {
  width: clamp(120px, 26vw, 180px);
  padding: 9px 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid var(--light-blue);
  border-radius: 8px;
  color: #fff;
  font-family: 'CTFPixel', 'Work Sans', Georgia, serif;
  font-size: clamp(11px, 1.6vw, 14px);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.ctf-nickname-input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}
.ctf-nickname-input:focus-visible {
  outline: 3px solid var(--light-blue);
  outline-offset: 2px;
}

.ctf-btn--small {
  margin-top: 0;
  padding: 9px 16px;
  font-size: clamp(11px, 1.6vw, 14px);
  box-shadow: 0 4px 0 var(--midnight);
}
.ctf-btn--small:hover { box-shadow: 0 6px 0 var(--midnight); }
.ctf-btn--small:active { box-shadow: 0 2px 0 var(--midnight); }
.ctf-btn--small:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.ctf-leaderboard {
  width: 100%;
  max-width: 280px;
}

.ctf-leaderboard-title {
  font-size: clamp(11px, 1.6vw, 14px);
  letter-spacing: 0.1em;
  color: var(--light-blue);
  margin: 0 0 6px;
}

.ctf-leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.ctf-leaderboard-row {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: clamp(11px, 1.6vw, 14px);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  padding: 5px 10px;
}

.ctf-leaderboard-rank {
  color: var(--light-blue);
  text-align: left;
}

.ctf-leaderboard-name {
  text-align: left;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ctf-leaderboard-score {
  color: #ffd447;
  text-align: right;
}

.ctf-leaderboard-empty {
  list-style: none;
  color: rgba(255, 255, 255, 0.45);
  font-size: clamp(10px, 1.5vw, 13px);
  padding: 6px 0;
}

.ctf-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.55);
  font-family: 'Roboto', sans-serif;
  font-size: 14px;
}

.ctf-debug {
  position: absolute;
  bottom: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.55);
  color: #7fffb0;
  font: 11px/1.5 'SF Mono', 'Fira Code', monospace;
  padding: 8px 10px;
  border-radius: 6px;
  white-space: pre;
  pointer-events: none;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .ctf-stage {
    max-width: 100%;
    border-radius: 8px;
  }
  .ctf-hud {
    padding: 10px;
  }
  .ctf-icon-btn {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }
  .ctf-wasted {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .ctf-results {
    grid-template-columns: 1fr;
    text-align: center;
  }
  .ctf-results dt {
    text-align: center;
  }
  .ctf-results dd {
    text-align: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ctf-callout--floating {
    animation-name: none;
    transition: opacity 0.4s ease-out;
  }
  .ctf-callout--center {
    animation-duration: 0.5s !important;
  }
  .ctf-shake {
    animation: none;
  }
  .ctf-wasted--urgent .ctf-wasted-fill {
    animation: none;
  }
  .ctf-btn:hover,
  .ctf-btn:active {
    transform: none;
  }
}

/* ── Portfolio: compact overlays for phone-sized stages ──────────────────── */
.ctf-hint--touch { display: none; }
@media (max-width: 640px) {
  .ctf-screen { justify-content: safe center; gap: 6px; padding: 12px; }
  .ctf-screen h2 { font-size: 20px; text-shadow: 2px 2px 0 var(--midnight); }
  .ctf-screen .ctf-leaderboard,
  .ctf-screen .ctf-save-score,
  .ctf-hint--keys { display: none !important; }
  .ctf-hint--touch { display: block; }
  .ctf-btn { padding: 8px 16px; font-size: 12px; margin-top: 4px; border-width: 2px; }
  .ctf-results { grid-template-columns: auto auto; gap: 2px 12px; font-size: 11px; }
}
