/* ================= Base ================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sky-top: #aee3ff;
  --sky-bottom: #e8f9ff;
  --grass: #7ecb5f;
  --grass-dark: #6bb84e;
  --dirt: #c9a36b;
  --panel-bg: #ffffff;
  --ink: #33414d;
  --accent: #ff7b54;
  --accent-dark: #e85f38;
  --radius: 14px;
}

html, body { height: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: linear-gradient(var(--sky-top), var(--sky-bottom));
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ================= Header ================= */
.topbar {
  text-align: center;
  padding: 14px 16px 6px;
}
.topbar h1 {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  letter-spacing: 1px;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.7);
}
.tagline { opacity: 0.75; font-size: 0.95rem; }

/* ================= Layout ================= */
.layout {
  flex: 1;
  display: flex;
  gap: 16px;
  padding: 16px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  align-items: stretch;
  min-height: 0;
}

/* ================= Sidebar panel ================= */
.panel {
  width: 270px;
  flex-shrink: 0;
  background: var(--panel-bg);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 6px 20px rgba(50, 80, 120, 0.15);
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}
.panel h2 { font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.count-badge {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 0.75rem;
  padding: 2px 9px;
}
.hint { font-size: 0.8rem; opacity: 0.65; }

#nameInput {
  width: 100%;
  min-height: 160px;
  resize: vertical;
  border: 2px solid #dde7ee;
  border-radius: 10px;
  padding: 10px;
  font: inherit;
  line-height: 1.5;
}
#nameInput:focus { outline: none; border-color: var(--accent); }
#nameInput:disabled { background: #f2f5f7; color: #98a5af; }

.panel-buttons { display: flex; gap: 8px; }

.btn {
  flex: 1;
  border: none;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 3px 0 var(--accent-dark);
}
.btn-primary:hover { background: #ff8d6b; }
.btn-primary:disabled {
  background: #ccd6dd;
  box-shadow: 0 3px 0 #b4c0c9;
  cursor: not-allowed;
}
.btn-ghost {
  background: #eef3f7;
  color: var(--ink);
}
.btn-ghost:hover { background: #e2eaf0; }

.option-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 0.85rem;
  cursor: pointer;
}
.option-row small { opacity: 0.6; }
.option-row select {
  margin-left: auto;
  font: inherit;
  border: 1px solid #dde7ee;
  border-radius: 8px;
  padding: 3px 6px;
}
.option-row input[type="checkbox"] {
  width: 17px; height: 17px;
  accent-color: var(--accent);
  margin-top: 2px;
  flex-shrink: 0;
}

.hall-of-fame.hidden { display: none; }
.hall-of-fame ol { padding-left: 22px; font-size: 0.88rem; line-height: 1.7; }

/* ================= Track ================= */
.track-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  min-width: 0;
}

.track {
  flex: 1;
  position: relative;
  background: var(--grass);
  border-radius: var(--radius);
  border: 4px solid #5da344;
  box-shadow: 0 6px 20px rgba(50, 80, 120, 0.18);
  overflow: hidden; /* everyone fits in one frame — bunnies shrink instead */
  min-height: 340px;
  max-height: calc(100vh - 160px);
}

.track-inner {
  position: relative;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background:
    repeating-linear-gradient(
      180deg,
      var(--grass) 0px, var(--grass) 46px,
      var(--grass-dark) 46px, var(--grass-dark) 92px
    );
}

.finish-line {
  position: absolute;
  top: 0; bottom: 0;
  right: 56px;
  width: 22px;
  background:
    repeating-conic-gradient(#222 0% 25%, #fff 0% 50%)
    0 0 / 22px 22px;
  opacity: 0.9;
  z-index: 2;
}
.finish-line::after {
  content: "🥕";
  position: absolute;
  right: -34px;
  top: 8px;
  font-size: 1.4rem;
}

.lanes {
  flex: 1; /* fill the track when there are few racers */
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  padding: 6px 0;
}

.lane {
  position: relative;
  flex: 1;
  min-height: 0; /* big fields squeeze together into a cute crowd */
  max-height: 100px;
}
.lane::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  border-bottom: 2px dashed rgba(255, 255, 255, 0.35);
}
.lane:last-child::after { display: none; }
/* Lane separators are just noise once the field gets crowded */
.lanes.crowded .lane::after { display: none; }
/* Crowded fields: name tag rides beside the bunny so every bunny stays visible */
.lanes.crowded .bunny {
  flex-direction: row;
  align-items: center;
  gap: 3px;
}
.lanes.crowded .bunny .name-tag { margin-bottom: 0; }

/* ---- Bunny size tiers (set by racer count in game.js) ---- */
.lanes.size-md .bunny svg { width: 44px; height: 34px; }
.lanes.size-md .bunny .name-tag { font-size: 0.68rem; }

.lanes.size-sm .bunny svg { width: 36px; height: 28px; }
.lanes.size-sm .bunny .name-tag { font-size: 0.62rem; padding: 0 7px; }

.lanes.size-xs .bunny svg { width: 29px; height: 22px; }
.lanes.size-xs .bunny .name-tag { font-size: 0.55rem; padding: 0 6px; }
.lanes.size-xs .bunny.hopping svg { animation-name: hop-small; }

.lanes.size-xxs .bunny svg { width: 22px; height: 17px; }
.lanes.size-xxs .bunny .name-tag { font-size: 0.5rem; padding: 0 5px; }
.lanes.size-xxs .bunny.hopping svg { animation-name: hop-small; }
@keyframes hop-small {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  30%      { transform: translateY(-6px) rotate(-6deg); }
  60%      { transform: translateY(-2px) rotate(2deg); }
}

/* ================= Bunny ================= */
.bunny {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translate(0, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  will-change: transform;
  z-index: 3;
}

.bunny .name-tag {
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  background: rgba(40, 60, 45, 0.75);
  padding: 1px 8px;
  border-radius: 999px;
  white-space: nowrap;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 1px;
}

.bunny svg {
  width: 52px;
  height: 40px;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.25));
}

.bunny.hopping svg {
  animation: hop 0.45s ease-in-out infinite;
}
@keyframes hop {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  30%      { transform: translateY(-11px) rotate(-7deg); }
  60%      { transform: translateY(-3px) rotate(3deg); }
}

.bunny.finished svg { animation: victory-bounce 0.6s ease-in-out infinite; }
@keyframes victory-bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-14px) scale(1.08); }
}

.rank-badge {
  position: absolute;
  top: -8px;
  right: -12px;
  font-size: 1rem;
  z-index: 4;
}

/* ================= Big race clock ================= */
.big-timer {
  position: sticky;
  top: 0;
  height: 0; /* takes no lane space; content overflows below */
  display: flex;
  justify-content: center;
  align-items: flex-start; /* don't stretch the pill into the 0-height row */
  z-index: 8;
  pointer-events: none;
}
.big-timer.hidden { display: none; }
.big-timer span {
  margin-top: 12px;
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
  color: #fff;
  background: rgba(20, 30, 40, 0.68);
  padding: 6px 26px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  animation: timer-pulse 1s ease-in-out infinite;
}
@keyframes timer-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}
/* Past the expected finish time — things are getting tense! */
.big-timer.urgent span {
  background: rgba(205, 40, 40, 0.9);
  border-color: rgba(255, 200, 200, 0.7);
  box-shadow: 0 0 22px rgba(255, 70, 70, 0.75);
  animation-duration: 0.45s;
}
/* Winner crossed — clock freezes gold */
.big-timer.finished span {
  background: linear-gradient(#ffd93d, #f7a924);
  color: #4a3200;
  border-color: #fff3c4;
  box-shadow: 0 0 24px rgba(255, 200, 60, 0.8);
  animation: none;
  transform: scale(1.08);
}

/* ================= Fullscreen race mode ================= */
.fullscreen-btn {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 9;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 999px;
  padding: 6px 14px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: #fff;
  background: rgba(20, 30, 40, 0.55);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.08s ease;
}
.fullscreen-btn:hover { background: rgba(20, 30, 40, 0.8); }
.fullscreen-btn:active { transform: scale(0.94); }

/* Everything but the race disappears — pure track, edge to edge */
body.fullscreen-race .topbar,
body.fullscreen-race .panel { display: none; }
body.fullscreen-race .layout {
  max-width: none;
  padding: 10px;
  gap: 8px;
}
body.fullscreen-race .track {
  max-height: none;
  border-width: 5px;
}
/* Bigger clock and leaderboard so the back row can read them */
body.fullscreen-race .big-timer span {
  font-size: clamp(2rem, 4.5vw, 3.2rem);
  padding: 8px 36px;
}
body.fullscreen-race .leader-board {
  font-size: 1.15rem;
  padding: 12px 20px;
}
body.fullscreen-race .countdown { font-size: clamp(6rem, 20vw, 14rem); }

/* ================= Empty state ================= */
.empty-msg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  font-weight: 600;
  z-index: 1;
}
.empty-bunny { font-size: 3rem; animation: hop 1.2s ease-in-out infinite; display: inline-block; }
.empty-msg.hidden { display: none; }

/* ================= Countdown ================= */
.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(4rem, 14vw, 9rem);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  z-index: 10;
  pointer-events: none;
}
.countdown.hidden { display: none; }
.countdown.pop { animation: count-pop 0.9s ease-out; }
@keyframes count-pop {
  0%   { transform: scale(0.3); opacity: 0; }
  25%  { transform: scale(1.15); opacity: 1; }
  70%  { transform: scale(1); opacity: 1; }
  100% { transform: scale(1); opacity: 0; }
}

/* ================= Leader board strip ================= */
.leader-board {
  background: var(--panel-bg);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.9rem;
  box-shadow: 0 3px 10px rgba(50, 80, 120, 0.12);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.leader-board.hidden { visibility: hidden; }
.lb-label { opacity: 0.6; }
#leaderName { font-weight: 700; }
#raceTimer { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ================= Winner overlay ================= */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 40, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.overlay.hidden { display: none; }
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.winner-card {
  position: relative;
  background: var(--panel-bg);
  border-radius: 20px;
  padding: 34px 42px 26px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  animation: card-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1);
  max-width: 90vw;
}
@keyframes card-in {
  from { transform: scale(0.5) translateY(60px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.winner-bunny { font-size: 4.2rem; animation: victory-bounce 0.7s ease-in-out infinite; }
.winner-crown {
  font-size: 1.8rem;
  margin-top: -74px;
  margin-bottom: 34px;
  animation: victory-bounce 0.7s ease-in-out infinite;
}
.winner-card h2 { font-size: 1.3rem; opacity: 0.7; margin-top: 6px; }
.winner-name {
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  font-weight: 800;
  color: var(--accent);
  margin: 4px 0 14px;
  max-width: 70vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.winner-time {
  font-size: 1rem;
  opacity: 0.7;
  margin: -8px 0 12px;
}
.podium {
  list-style: none;
  margin-bottom: 18px;
  font-size: 0.95rem;
  line-height: 1.8;
}
.podium .p-time { opacity: 0.55; font-size: 0.85em; margin-left: 6px; }

/* ================= Responsive ================= */
@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .panel { width: 100%; max-height: none; }
  .track { min-height: 300px; }
  #nameInput { min-height: 110px; }
}
