:root {
  color-scheme: dark;
  --bg: #0b1220;
  --panel: #131c30;
  --text: #e7ecf5;
  --muted: #8fa0bf;
  --accent: #f97316;
  --accent2: #fb923c;
  --green: #22c55e;
  --red: #ef4444;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

@keyframes bounce {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-4px) rotate(-12deg); }
}
@keyframes panelIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@keyframes choiceIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@keyframes popIn {
  0% { transform: scale(1); }
  40% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
@keyframes shake {
  10%, 90% { transform: translateX(-3px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}
@keyframes scorePop {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); color: var(--green); }
  100% { transform: scale(1); }
}
@keyframes flashCorrect {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); }
  100% { box-shadow: 0 0 0 16px rgba(34, 197, 94, 0); }
}
@keyframes flashWrong {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
  100% { box-shadow: 0 0 0 16px rgba(239, 68, 68, 0); }
}
@keyframes scoreReveal {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: scale(1); }
}

body {
  margin: 0;
  padding: 12px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background:
    radial-gradient(circle at 50% 0%, #182647 0%, var(--bg) 60%);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  max-width: 480px;
  margin-inline: auto;
}

header { text-align: center; margin-bottom: 12px; }
header h1 { margin: 0; font-size: 1.4rem; letter-spacing: 0.01em; }
#ball { display: inline-block; animation: bounce 1.6s ease-in-out infinite; }

#status { margin-bottom: 12px; }
#status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 6px;
}
#timer {
  background: var(--panel);
  padding: 2px 10px;
  border-radius: 999px;
  transition: color 0.3s;
}
#timer.timer-warn { color: var(--red); }
#score {
  background: var(--panel);
  padding: 2px 10px;
  border-radius: 999px;
  transition: transform 0.25s;
}
#score.pop { animation: scorePop 0.35s ease; }

#timer-track {
  height: 6px;
  border-radius: 999px;
  background: var(--panel);
  overflow: hidden;
}
#timer-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 1s linear, background 0.3s;
}
#timer-fill.timer-warn { background: var(--red); }

#photo-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 280px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
#photo-wrap.flash-correct { animation: flashCorrect 0.6s ease-out; }
#photo-wrap.flash-wrong { animation: flashWrong 0.6s ease-out; }
#photo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 1;
  transition: opacity 0.25s ease;
}
#photo.entering { opacity: 0; }

#choices-label { text-align: center; color: var(--muted); font-size: 0.9rem; margin: 0 0 8px; }

#choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
#choices button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid #26314a;
  border-radius: 10px;
  padding: 16px 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 56px;
  animation: choiceIn 0.25s ease both;
}
#choices button:hover { border-color: var(--accent); background: #1b2740; }
#choices button:active { transform: scale(0.97); }
#choices button.correct { background: var(--green); color: #06210f; border-color: var(--green); animation: popIn 0.3s ease; }
#choices button.wrong { background: var(--red); color: #2a0505; border-color: var(--red); animation: shake 0.3s ease; }
#choices button:disabled { cursor: default; }

#panel {
  background: var(--panel);
  border-radius: 12px;
  padding: 24px 14px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  animation: panelIn 0.3s ease;
}
#panel-message { margin: 0 0 6px; font-weight: 600; font-size: 1.05rem; }

#result-card { margin: 4px 0 6px; }
#result-number {
  font-size: 3.4rem;
  font-weight: 800;
  line-height: 1;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: scoreReveal 0.4s ease both;
}
#result-label {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}
#result-rank { margin: 0; font-size: 1.05rem; font-weight: 700; }
#result-new-best {
  display: inline-block;
  margin: 8px 0 0;
  background: rgba(34, 197, 94, 0.15);
  color: var(--green);
  border: 1px solid rgba(34, 197, 94, 0.4);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  animation: popIn 0.4s ease 0.2s both;
}

#best-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 14px 0 16px;
}
.stat-chip {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid #26314a;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.8rem;
  color: var(--muted);
}
.stat-chip strong { color: var(--text); }

#action-btn, #reward-btn {
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  color: #1a0d00;
  border: none;
  border-radius: 8px;
  padding: 12px 26px;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(249, 115, 22, 0.35);
  transition: transform 0.15s, box-shadow 0.15s;
}
#action-btn:hover, #reward-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(249, 115, 22, 0.45); }
#action-btn:active, #reward-btn:active { transform: translateY(0) scale(0.98); }

@media (max-width: 380px) {
  header h1 { font-size: 1.2rem; }
  #choices button { font-size: 0.85rem; padding: 14px 8px; }
}

/* ponytail: Y8 registers this game as a 1360x720 landscape frame (no portrait
   override exists in their dashboard), so its mobile player renders us inside
   a landscape-shaped iframe. Counter-rotate on touch devices so it displays
   upright and portrait. Rotation direction is the standard CSS orientation-lock
   trick; flip -90/90 and the top/left <-> right offsets if it's mirrored on
   the live Y8 page. */
@media screen and (orientation: landscape) and (pointer: coarse) and (max-width: 926px) {
  html {
    transform: rotate(-90deg);
    transform-origin: left top;
    width: 100vh;
    height: 100vw;
    overflow-x: hidden;
    position: absolute;
    top: 100%;
    left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  #ball, #choices button, #panel, #score.pop,
  #photo-wrap.flash-correct, #photo-wrap.flash-wrong,
  #choices button.correct, #choices button.wrong,
  #result-number, #result-new-best {
    animation: none !important;
  }
  #photo, #action-btn, #reward-btn { transition: none !important; }
}

.photo-credits { color: var(--muted); font-size: 0.8rem; }
#action-btn:disabled, #reward-btn:disabled { cursor: wait; opacity: 0.65; }

#reward-btn {
  background: linear-gradient(135deg, #34d36b, #15803d);
  color: #04210f;
  box-shadow: 0 4px 14px rgba(34, 197, 94, 0.35);
  display: block;
  margin: 0 auto 10px;
}
#reward-btn:hover { box-shadow: 0 6px 18px rgba(34, 197, 94, 0.45); }
