:root {
  --bg: #0b0b0d;
  --ink: #f2f1ee;
  --muted: #8b8d94;
  --line: #212227;
  --accent: #8b8d94;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: "Iowan Old Style", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  background-image: radial-gradient(120% 90% at 50% 0%, #16171b 0%, #0b0b0d 60%);
  color: var(--ink);
  font-family: var(--sans);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6vh 24px;
  -webkit-font-smoothing: antialiased;
  transition: background-color 700ms ease, color 700ms ease;
}

/* --- Moods: set by the Celebrate! and Cry about it. buttons -------------- */

/* Every mood just re-points the palette tokens, so the detail line, footer
   and buttons stay legible without any per-element overrides. */
body.mood-celebrate {
  --bg: #ffffff;
  --ink: #16171b;
  --muted: #5c6169;
  --line: #d9dce1;
  background-image: none;
}

body.mood-cry {
  --bg: #5b5f64;
  --ink: #1a1b1d;
  --muted: #2b2d31;
  --line: #6f7378;
  background-image: none;
}

.stage {
  width: 100%;
  max-width: 44rem;
  text-align: center;
}

.verdict {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(3rem, 13vw, 7.5rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--accent);
  transition: color 500ms ease;
}

[data-state="loading"] .verdict {
  color: var(--muted);
  opacity: 0.55;
  animation: breathe 2.2s ease-in-out infinite;
}

/* Rainbow verdict, painted through the text itself. */
body.mood-celebrate .verdict {
  background: linear-gradient(
    90deg,
    #ff0040, #ff7a00, #ffd400, #35c759,
    #00a8ff, #7b3fe4, #ff0040
  );
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  animation: rainbow 5s linear infinite;
}

body.mood-cry .verdict {
  background: none;
  color: #000;
  -webkit-text-fill-color: #000;
}

@keyframes rainbow {
  to { background-position: -200% 0; }
}

.detail {
  margin: 1.75rem auto 0;
  max-width: 34rem;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--muted);
  min-height: 1.6em;
}

[hidden] { display: none !important; }

.mood-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 2.25rem;
}

/* Both buttons share one fixed fill and text colour, deliberately NOT palette
   tokens: they have to stay legible on the dark default page, the white
   celebrate page and the gray cry page.

   No flat fill can reach 3:1 against all three, because the cry gray sits
   between white and black: clearing it needs a luminance below 0.004 or above
   0.44, while white caps the fill at 0.30 and black floors it at 0.114. So the
   violet carries the two extremes (5.7:1 on white, 3.5:1 on black, and 5.7:1
   for its white label) and the light ring defines the edge on gray (6.4:1),
   where the fill alone would only manage 1.1:1. */
.celebrate,
.cry {
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  border-radius: 999px;
  padding: 0.8em 2em;
  cursor: pointer;
  color: #ffffff;
  background: #7c3aed;
  border: 0;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.7);
  transition: transform 160ms ease, filter 160ms ease, box-shadow 160ms ease;
}

.celebrate:hover,
.cry:hover {
  filter: brightness(1.12);
  transform: translateY(-1px);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.9),
              0 8px 22px -12px rgba(124, 58, 237, 0.95);
}

.celebrate:active,
.cry:active {
  transform: translateY(0) scale(0.98);
}

/* --- Rain: runs until the mood changes ----------------------------------- */

.rain {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 45;
}

.raindrop {
  position: absolute;
  top: -14vh;
  width: 1.5px;
  border-radius: 1px;
  background: linear-gradient(to bottom, rgba(226, 233, 241, 0), rgba(226, 233, 241, 0.85));
  animation-name: rain-fall;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  will-change: transform;
}

@keyframes rain-fall {
  from { transform: translate3d(0, 0, 0); }
  to   { transform: translate3d(-4vw, 128vh, 0); }
}

/* --- Celebration: confetti falling, balloons rising ---------------------- */

.celebration {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 50;
}

.confetti {
  position: absolute;
  top: -12vh;
  animation-name: confetti-fall;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
  will-change: transform;
}

.confetti-face {
  width: 9px;
  height: 15px;
  animation-name: confetti-flutter;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}

@keyframes confetti-fall {
  from { transform: translate3d(0, 0, 0) rotate(0deg); opacity: 1; }
  85%  { opacity: 1; }
  to   { transform: translate3d(var(--drift, 0), 124vh, 0) rotate(var(--spin, 720deg)); opacity: 0; }
}

@keyframes confetti-flutter {
  from { transform: rotateX(0deg) rotateY(0deg); }
  to   { transform: rotateX(360deg) rotateY(360deg); }
}

.balloon {
  position: absolute;
  bottom: -24vh;
  animation-name: balloon-rise;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
  will-change: transform;
}

.balloon-sway {
  animation-name: balloon-sway;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-direction: alternate;
}

.balloon-body {
  position: relative;
  width: 46px;
  height: 58px;
  border-radius: 50% 50% 46% 46%;
  background:
    radial-gradient(circle at 32% 26%, rgba(255, 255, 255, 0.5), transparent 45%),
    var(--balloon, #e8433f);
  transform: scale(var(--scale, 1));
}

/* Knot under the balloon. */
.balloon-body::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 6px solid var(--balloon, #e8433f);
}

/* Curved string, drawn as one rounded border. */
.balloon-body::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  margin-top: 4px;
  width: 14px;
  height: 56px;
  transform: translateX(-50%);
  /* Dark: the celebration only ever runs on the white celebrate background. */
  border-left: 1px solid rgba(20, 22, 27, 0.3);
  border-bottom-left-radius: 90% 100%;
}

@keyframes balloon-rise {
  from { transform: translate3d(0, 0, 0); }
  to   { transform: translate3d(0, -136vh, 0); }
}

@keyframes balloon-sway {
  from { transform: translateX(-15px) rotate(-4deg); }
  to   { transform: translateX(15px) rotate(4deg); }
}

.meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-top: 4rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.cache-note {
  letter-spacing: 0.02em;
}

.refresh {
  font: inherit;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.45em 1.1em;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease;
}

.refresh:hover:not(:disabled) {
  color: var(--ink);
  border-color: var(--muted);
}

.refresh:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Verdict colour is driven entirely by the state on .stage. */
[data-state="alive"]   { --accent: #63d9a0; }
[data-state="dead"]    { --accent: #e8433f; }
[data-state="unknown"] { --accent: #e0a83c; }
[data-state="error"]   { --accent: #7b7d85; }

@keyframes breathe {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 0.28; }
}

@media (prefers-reduced-motion: reduce) {
  .verdict { animation: none !important; }
  * { transition-duration: 1ms !important; }
}
