:root {
  --ink: #1a2b22;
  --muted: #5c6f63;
  --bg-top: #cdeaff;
  --bg-bottom: #eafff0;
  --amber: #ff9b3d;
  --tail: #ff5d5d;
  --accent: #1f9d63;
  --panel: #ffffffdd;
  --panel-border: #cfe8d9;
  --track: #d7f3df;
  --lane-line: #ffffffb0;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg-bottom);
  color: var(--ink);
}

body {
  position: relative;
  overflow-x: hidden;
}

.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse at 80% -10%, #ffe08a55, transparent 55%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
}

a { color: var(--accent); }

.screen { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- landing ---------- */

.landing-card {
  flex: 1;
  max-width: 560px;
  margin: 0 auto;
  padding: 12vh 24px 24px;
  text-align: center;
}

.landing-card h1 {
  font-size: 2.6rem;
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}

.walk-emoji { display: inline-block; animation: bob 1s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-6deg); } 50% { transform: translateY(-4px) rotate(6deg); } }

.tagline { color: var(--muted); font-size: 1rem; margin-bottom: 28px; }

#start-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 8px 24px #1a2b2214;
}

#start-form label {
  text-align: left;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#handle-input {
  font: inherit;
  padding: 12px 14px;
  border-radius: 9px;
  border: 1px solid var(--panel-border);
  background: #fff;
  color: var(--ink);
}

#handle-input:focus { outline: 2px solid var(--accent); }

#start-btn, #share-btn, .start-race-btn, #me-edit {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 9px;
  padding: 12px 16px;
  background: var(--accent);
  color: #f4fff8;
  font-weight: 700;
  transition: transform 0.1s ease;
}
#start-btn:hover, #share-btn:hover, .start-race-btn:hover { transform: translateY(-1px); }
#start-btn:active, .start-race-btn:active { transform: translateY(1px); }

.status { min-height: 1.4em; color: var(--accent); font-size: 0.9rem; }
.status.error { color: var(--tail); }

.explainer { color: var(--muted); font-size: 0.85rem; line-height: 1.5; margin-top: 22px; }

.credit { text-align: center; padding: 18px; color: var(--muted); font-size: 0.78rem; }

/* ---------- walk screen layout ---------- */

/* Unlike .landing-card, the walk screen had no width cap — on any
   normal-to-wide desktop viewport it stretched edge to edge, flinging the
   header's right-aligned identity block far from the title and blowing the
   panels up into mostly-empty boxes. Cap and center it like the landing
   card so it reads as one contained layout at any width. */
.walk-header,
.track-wrap,
.controls,
.foot-controls,
.panels,
#walk .credit {
  max-width: 1000px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

#walk-status,
.ghost-note {
  max-width: 1000px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  padding-left: 20px;
  padding-right: 20px;
  box-sizing: border-box;
}

.walk-header {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--panel-border);
  background: #ffffffcc;
  backdrop-filter: blur(4px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { font-weight: 800; text-decoration: none; color: var(--ink); font-size: 1.05rem; }
.walk-title { font-size: 0.95rem; }
.pill {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #1f9d6318;
  color: var(--accent);
  font-size: 0.72rem;
}

.identity { margin-left: auto; font-size: 0.85rem; color: var(--muted); }
#me-name { color: var(--ink); }
#me-edit {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--muted);
  padding: 4px 10px;
  font-size: 0.75rem;
  margin-left: 6px;
}
.share-btn { padding: 8px 14px; font-size: 0.85rem; }
.copy-btn {
  padding: 8px 14px;
  font-size: 0.85rem;
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--muted);
  border-radius: 9px;
  cursor: pointer;
  font-family: inherit;
}
.copy-btn.copied { color: var(--accent); border-color: var(--accent); }

/* ---------- track ---------- */

.track-wrap { padding: 22px 20px 8px; }

.track {
  position: relative;
  background: var(--track);
  border-radius: 14px;
  border: 2px solid var(--panel-border);
  padding: 10px 0;
  overflow: hidden;
}

.finish-line {
  position: absolute;
  right: 14px;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: repeating-linear-gradient(180deg, #1a2b22 0 8px, #fff 8px 16px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  font-size: 1.1rem;
}
.finish-line::before { content: "🏁"; position: absolute; top: -22px; }

.walkers { display: flex; flex-direction: column; gap: 6px; padding: 4px; }

.lane {
  position: relative;
  height: 46px;
  border-radius: 8px;
  background: repeating-linear-gradient(90deg, var(--lane-line) 0 18px, transparent 18px 40px);
}

.walker {
  position: absolute;
  top: 2px;
  left: 0;
  width: 42px;
  height: 42px;
  transition: left 0.12s linear;
  text-align: center;
}

.walker .figure {
  width: 36px;
  height: 36px;
  margin: 0 auto;
  border-radius: 50%;
  border: 2px solid #ffffff;
  overflow: hidden;
  background: #ffffffcc;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  box-shadow: 0 3px 8px #1a2b2233;
  opacity: 0.55;
  filter: grayscale(30%);
  transition: opacity 0.2s ease, filter 0.2s ease, transform 0.1s ease;
}
.walker .figure img { width: 100%; height: 100%; object-fit: cover; display: block; }
.walker.awake .figure { opacity: 1; filter: none; }
.walker.is-you .figure { box-shadow: 0 0 0 3px var(--amber), 0 3px 8px #1a2b2244; }
.walker.stepping .figure { animation: step-bounce 0.18s ease; }
@keyframes step-bounce {
  0% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
  100% { transform: translateY(0); }
}

.walker .tag {
  position: absolute;
  top: 44px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.58rem;
  color: var(--ink);
  background: #ffffffcc;
  border-radius: 4px;
  padding: 1px 4px;
  white-space: nowrap;
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.walker.ghost .figure { opacity: 0.45; filter: grayscale(60%); border-style: dashed; border-color: #bb86fc; box-shadow: none; }
.walker.ghost .tag { opacity: 0.7; font-style: italic; }
.walker.ghost.finished .figure { box-shadow: 0 0 0 2px #bb86fc; }

.walker.finished .figure { box-shadow: 0 0 0 3px var(--accent); }
.walker.eliminated .figure { opacity: 0.25; filter: grayscale(100%); }
.walker.eliminated::after {
  content: "✕";
  position: absolute;
  top: -6px;
  right: -6px;
  color: var(--tail);
  font-weight: 800;
  font-size: 0.85rem;
}

.walker .place-flag {
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--amber);
  color: #2a1400;
  font-size: 0.6rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 999px;
  white-space: nowrap;
}

.walker .cheer-bubble {
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.1rem;
  animation: pop-fade 1.1s ease forwards;
  pointer-events: none;
}
@keyframes pop-fade {
  0% { opacity: 0; transform: translate(-50%, 6px) scale(0.7); }
  20% { opacity: 1; transform: translate(-50%, -4px) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -14px) scale(0.95); }
}

/* ---------- controls ---------- */

.controls {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  flex-wrap: wrap;
}
.start-race-btn { font-size: 1rem; }
.start-race-btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.countdown { font-size: 1.4rem; font-weight: 800; color: var(--amber); }
.race-status-line { color: var(--muted); font-size: 0.85rem; }
.ghost-note { color: #8a5fd6; font-size: 0.8rem; margin-top: -6px; min-height: 1.2em; }

.foot-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 10px 20px 20px;
}
.foot-btn {
  font: inherit;
  font-weight: 800;
  font-size: 1.3rem;
  cursor: pointer;
  border: none;
  border-radius: 14px;
  padding: 20px 30px;
  background: var(--amber);
  color: #2a1400;
  user-select: none;
  touch-action: manipulation;
  transition: transform 0.06s ease;
}
.foot-btn:active { transform: scale(0.94); }
.foot-hint { color: var(--muted); font-size: 0.75rem; text-align: center; max-width: 160px; }

/* ---------- panels ---------- */

.panels {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  padding: 8px 20px 24px;
}

.panel {
  flex: 1 1 320px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
}
.panel h2 { margin: 0 0 10px; font-size: 1rem; }
.panel h3 { margin: 14px 0 8px; font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.record-line { color: var(--accent); font-weight: 700; font-size: 0.95rem; margin: 0; }

.history-list, .results-list, .roster-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
}
.results-list { list-style: decimal; padding-left: 20px; }
.history-list li, .roster-list li {
  padding: 6px 8px;
  border-radius: 8px;
  background: #ffffff0a;
  border: 1px solid var(--panel-border);
}
.results-list li { padding: 4px 2px; }
.results-list .eliminated-tag { color: var(--tail); font-size: 0.7rem; margin-left: 6px; }
.roster-hint { color: var(--muted); font-size: 0.78rem; margin: 0 0 10px; }
.roster-list .you-tag { color: var(--amber); font-weight: 800; font-size: 0.7rem; margin-left: 4px; }

/* ---------- flying cheers ---------- */

#cheer-fly-layer { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }

.race-over-banner {
  position: fixed;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  background: var(--accent);
  color: #f4fff8;
  font-weight: 800;
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 60;
  animation: pop-fade 3.4s ease forwards;
}
