:root {
  --choc: #3b1f14;
  --choc-dark: #1f0e07;
  --cream: #fff4e0;
  --penguin: #ffc72c;
  --timtam: #ff9a6b;
  --ease: cubic-bezier(0.34, 1.3, 0.5, 1);
  --morph: 1.1s;
}

* { box-sizing: border-box; }

html { background: var(--choc-dark); }

body {
  margin: 0;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  color: var(--cream);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(ellipse at 50% -10%, #8a4726 0%, transparent 60%),
    radial-gradient(circle at 50% 120%, #2a130a 0%, transparent 60%),
    var(--choc);
  overflow-x: hidden;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(1.5rem, 5vw, 3.5rem) 16px 1rem;
  text-align: center;
}

h1 {
  margin: 0;
  max-width: 20ch;
  font-family: "Lilita One", system-ui, sans-serif;
  font-weight: 400;
  font-size: clamp(2rem, 6.2vw, 3.9rem);
  line-height: 1.05;
  letter-spacing: 0.01em;
  text-shadow: 0 4px 0 var(--choc-dark), 0 10px 30px rgba(0, 0, 0, 0.4);
  text-wrap: balance;
}
.name-penguin { color: var(--penguin); }
.name-timtam { color: var(--timtam); }

.prompt {
  margin: 1.25rem 0 0;
  min-height: 1.3em;
  font-family: "Lilita One", system-ui, sans-serif;
  font-size: clamp(1.4rem, 3.6vw, 2.2rem);
  transition: opacity 0.3s;
}
.prompt.swap { opacity: 0; }

/* The arena holds both bars. In the "vote" state they hover mid-air; in the
   "results" state the same elements morph into the columns of a bar chart. */
.arena {
  --chart-h: clamp(180px, 38vh, 420px);
  --w: min(40vw, 360px);                        /* bar width while hovering */
  --h: calc(var(--w) * 0.304);                  /* wrapper aspect ratio ~3.3:1 */
  --thick: min(calc(var(--chart-h) * 0.304), 28vw); /* column thickness in the chart */
  width: 100%;
  height: calc(var(--chart-h) + 8rem);
  margin-top: 0.5rem;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(1.25rem, 7vw, 6rem);
}

.bar {
  appearance: none;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  padding: 0 0 calc((var(--chart-h) - var(--h)) / 2 + 2.5rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: padding var(--morph) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.bar:focus-visible { outline: none; }
.bar:focus-visible .bar-fill { outline: 3px solid var(--cream); outline-offset: 10px; border-radius: 8px; }

.bar-fill {
  position: relative;
  width: var(--w);
  height: var(--h);
  animation: hover 3.4s ease-in-out infinite;
  transition: width var(--morph) var(--ease), height var(--morph) var(--ease);
}
.bar[data-choice="timtam"] .bar-fill { animation-delay: -1.7s; }
/* keep each logo in view when a short column crops the wrapper */
.bar[data-choice="penguin"] img { object-position: 55% 50%; }
.bar[data-choice="timtam"] img { object-position: 36% 50%; }

.bar-fill img {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--w);
  height: var(--h);
  object-fit: cover;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 22px 16px rgba(0, 0, 0, 0.45));
  transition: width var(--morph) var(--ease), height var(--morph) var(--ease),
    transform var(--morph) var(--ease), filter 0.3s;
}

@keyframes hover {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-16px) rotate(2deg); }
}

@media (hover: hover) {
  .arena[data-state="vote"] .bar:hover img {
    transform: translate(-50%, -50%) scale(1.08) rotate(-2deg);
    filter: drop-shadow(0 28px 20px rgba(0, 0, 0, 0.5)) brightness(1.06);
  }
}
.arena[data-state="vote"] .bar:active img { transform: translate(-50%, -50%) scale(0.96); }

.label {
  margin-top: 1rem;
  font-family: "Lilita One", system-ui, sans-serif;
  font-size: clamp(1.1rem, 2.6vw, 1.6rem);
}
.bar[data-choice="penguin"] .label { color: var(--penguin); }
.bar[data-choice="timtam"] .label { color: var(--timtam); }

.count {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 0.6rem;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.5s 0.6s, transform 0.5s 0.6s;
}
.count-n {
  font-family: "Lilita One", system-ui, sans-serif;
  font-size: clamp(1.8rem, 5vw, 3rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.count-pct { font-size: 0.95rem; opacity: 0.8; font-variant-numeric: tabular-nums; }
.crown { position: absolute; left: 100%; top: -0.2rem; margin-left: 0.3rem; font-size: 1.5rem; line-height: 1; visibility: hidden; }
.bar.leading .crown { visibility: visible; animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-4px) rotate(8deg); } }

/* ---- Results: morph into a bar chart ---- */
.arena[data-state="results"] .bar { padding-bottom: 0; cursor: default; }
.arena[data-state="results"] .bar-fill {
  animation: none;
  width: var(--thick);
  height: calc(var(--chart-h) * var(--pct, 0.1));
}
.arena[data-state="results"] .bar-fill img {
  /* the image is rotated, so its width runs along the column's height */
  width: calc(var(--chart-h) * var(--pct, 0.1));
  height: var(--thick);
  transform: translate(-50%, -50%) rotate(-90deg);
  filter: drop-shadow(10px 0 14px rgba(0, 0, 0, 0.45));
}
.arena[data-state="results"] .count { opacity: 1; transform: none; }
.arena[data-state="results"] .bar.mine .label::after { content: " ✓"; }

.note {
  min-height: 1.5em;
  margin: 0.5rem 0 0;
  opacity: 0.85;
}

footer {
  padding: 1rem 16px 1.5rem;
  text-align: center;
  font-size: 0.85rem;
  opacity: 0.6;
}

@media (max-width: 520px) {
  .arena { --w: 45vw; gap: 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  .arena { --morph: 0s; }
  .bar-fill, .bar.leading .crown { animation: none; }
  .count { transition: none; }
}
