:root {
  --ink: #1b2418;
  --paper: #f4efe2;
  --paper-2: #e7e0ce;
  --moss: #143028;
  --canopy: #1f6a45;
  --gold: #e2b15a;
  --lift: #d84b3a;
  --line: #1b2418;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  color: var(--paper);
  background: var(--moss);
}

button, input { font: inherit; }

#sky {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: safe center;
  min-height: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at 78% var(--sun, 18%), var(--sun-color, #fff1c4) 0 1.1rem, transparent 4.2rem),
    linear-gradient(180deg, var(--sky-top, #9fd0c4) 0%, var(--sky-mid, #2d6b4e) 46%, var(--sky-ground, #10241c) 100%);
  transition: background 700ms ease;
}

.canopy {
  position: absolute;
  inset: auto 0 0;
  height: 46%;
  opacity: var(--trees, 0.85);
  background:
    radial-gradient(ellipse at 12% 100%, #0c2418 0 18%, transparent 19%),
    radial-gradient(ellipse at 28% 100%, #145233 0 22%, transparent 23%),
    radial-gradient(ellipse at 48% 100%, #0e2c1e 0 26%, transparent 27%),
    radial-gradient(ellipse at 70% 100%, #18643c 0 20%, transparent 21%),
    radial-gradient(ellipse at 88% 100%, #0c2418 0 24%, transparent 25%);
  pointer-events: none;
  transition: opacity 700ms ease;
}

#passers {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

#passers {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

.lane {
  position: absolute;
  top: 12%;
  left: 0;
  animation: cruise 28s linear infinite;
  animation-delay: -6s;
}
.lane.slow {
  top: 36%;
  animation-duration: 36s;
  animation-delay: -14s;
}

.passer {
  width: 8.5rem;
  height: 8.5rem;
  background: center / contain no-repeat;
  animation: wave 6s ease-in-out infinite;
}
.lane.slow .passer { animation-duration: 8s; animation-delay: -3s; }

.passer[data-kind="bird"] { background-image: url("passers/bird.gif"); }
.passer[data-kind="gull"] { background-image: url("passers/gull.gif"); }
.passer[data-kind="eagle"] { background-image: url("passers/eagle.gif"); }
.passer[data-kind="plane"] { background-image: url("passers/plane.gif"); }
.passer[data-kind="balloon"] { background-image: url("passers/weatherballoon.gif"); }
.passer[data-kind="cloud"] { background-image: url("passers/cloud.gif"); }
.passer[data-kind="ufo"] { background-image: url("passers/ufo.gif"); }
.passer[data-kind="rocket"] { background-image: url("passers/rocket.gif"); width: 5.4rem; height: 5.4rem; animation: none; }
.lane:has(.passer[data-kind="rocket"]) {
  top: auto;
  left: 10%;
  animation: liftoff 14s linear infinite;
  animation-delay: -3s;
}

.rig {
  position: relative;
  z-index: 0;
  height: 4rem;
  margin: 0 auto;
}

.rig i {
  display: block;
  position: absolute;
  left: 50%;
  bottom: 1.2rem;
  width: 2.15rem;
  height: 2.7rem;
  margin-left: -1.075rem;
  border-radius: 50% 50% 50% 50% / 42% 42% 58% 58%;
  background: radial-gradient(circle at 35% 30%, #fff 0 12%, var(--balloon, #e23d3d) 13% 70%, #8e1d18 100%);
  transform-origin: 50% calc(100% + 1.2rem);
  animation: sway-mid 3.2s ease-in-out infinite;
}

.rig i:nth-child(1) { animation-name: sway-left; }
.rig i:nth-child(2) { --balloon: #f0c14e; z-index: 1; animation-delay: -1.1s; }
.rig i:nth-child(3) { --balloon: #3d8fdd; animation-name: sway-right; animation-delay: -2s; }

.rig i::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: 1px;
  height: 1.2rem;
  margin-left: -0.5px;
  background: rgba(244, 239, 226, 0.9);
}

.rider {
  position: relative;
  z-index: 1;
  width: 3.2rem;
  height: 2.5rem;
  margin: -0.15rem auto 0;
  border-radius: 45% 45% 40% 40%;
  background:
    radial-gradient(circle at 38% 42%, #1b2418 0 0.16rem, transparent 0.18rem),
    radial-gradient(circle at 62% 42%, #1b2418 0 0.16rem, transparent 0.18rem),
    #f3c1b0;
  box-shadow: inset 0 -0.4rem 0 rgba(0, 0, 0, 0.08);
}

.rider::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 58%;
  width: 0.7rem;
  height: 0.38rem;
  border: 2px solid #1b2418;
  border-top: 0;
  border-radius: 0 0 0.7rem 0.7rem;
  transform: translateX(-50%);
}

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 6;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem 0;
  align-items: flex-start;
}

.k {
  display: block;
  font-family: Rockwell, "Iowan Old Style", Palatino, serif;
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0.75;
}

#alt {
  display: block;
  font-family: Rockwell, "Iowan Old Style", Palatino, serif;
  font-size: 1.7rem;
  line-height: 1;
}

#zone, #progress {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.95rem;
}

.hud-right { display: flex; align-items: center; gap: 0.6rem; }

#lives { display: flex; gap: 0.28rem; }
#lives[hidden] { display: none; }
#lives[hidden] { display: none; }
#lives i {
  width: 0.7rem;
  height: 0.9rem;
  border-radius: 50%;
  background: #e23d3d;
  box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.2);
}
#lives i.off { background: transparent; box-shadow: inset 0 0 0 2px rgba(244, 239, 226, 0.45); }

#quit, #sound, .modes button, #begin, #multi, #pass, #climb, #next, #again, #name-join, #name-cancel {
  border: 2px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 4px 4px 0 rgba(8, 16, 12, 0.35);
}

#quit:active, #sound:active, .modes button:active, #begin:active, #multi:active,
#pass:active, #climb:not(:disabled):active, #next:active, #again:active,
#name-join:active, #name-cancel:active {
  transform: translate(4px, 4px);
  box-shadow: 0 0 0 rgba(8, 16, 12, 0.35);
}

#quit {
  padding: 0.35rem 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

#sound {
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  display: grid;
  place-items: center;
}
#sound svg { width: 1.15rem; height: 1.15rem; display: none; }
#sound[aria-pressed="true"] .on,
#sound[aria-pressed="false"] .off { display: block; }

#board {
  position: relative;
  z-index: 2;
  width: min(36rem, calc(100% - 11rem));
  margin: 8.5rem auto 1.5rem;
}

#climber {
  position: absolute;
  left: 50%;
  bottom: calc(100% - 2rem + var(--rise, 0px));
  z-index: 3;
  width: 9.2rem;
  transform: translateX(-50%);
  pointer-events: none;
  transition: bottom 900ms cubic-bezier(.2, .8, .2, 1);
  filter: drop-shadow(0 10px 0 rgba(0, 0, 0, 0.12));
}

#card {
  position: relative;
  z-index: 2;
  width: 100%;
  min-height: 16rem;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  border: 2px solid var(--line);
  box-shadow: 8px 8px 0 rgba(8, 16, 12, 0.35);
}

#sheet {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 16rem;
}

#ruler {
  position: absolute;
  z-index: 3;
  top: 4.8rem;
  right: 0.7rem;
  bottom: 1.4rem;
  width: 4.6rem;
  pointer-events: none;
}

#ruler::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0.2rem;
  width: 2px;
  background: rgba(244, 239, 226, 0.7);
}

#ruler-ticks span {
  position: absolute;
  right: 0.85rem;
  transform: translateY(50%);
  font-family: Rockwell, Palatino, serif;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

#ruler-ticks span::before {
  content: "";
  position: absolute;
  right: -0.7rem;
  top: 50%;
  width: 0.55rem;
  height: 2px;
  background: #f4efe2;
}

#ruler-now {
  position: absolute;
  right: 0;
  bottom: 0;
  transform: translateY(50%);
  background: #d84b3a;
  color: #fff8ee;
  font-family: Rockwell, Palatino, serif;
  font-size: 0.72rem;
  line-height: 1.2;
  padding: 0.12rem 0.35rem;
  transition: bottom 900ms cubic-bezier(.2, .8, .2, 1);
}

#ruler-now::before {
  content: "";
  position: absolute;
  left: -0.45rem;
  top: 50%;
  border: 0.32rem solid transparent;
  border-right-color: #d84b3a;
  transform: translateY(-50%);
}

#card section {
  background: transparent;
  padding: 1.25rem 1.3rem 1.15rem;
}

h1 {
  font-family: Rockwell, "Iowan Old Style", Palatino, serif;
  font-weight: 700;
  letter-spacing: 0.14em;
  font-size: clamp(2rem, 6vw, 3.1rem);
  margin: 0.2rem 0 0.35rem;
}

.lede, .hint, .cat {
  margin: 0;
}

.lede { font-size: 1.2rem; max-width: 28rem; }

.modes {
  display: flex;
  align-items: stretch;
  gap: 0.7rem;
  margin: 1.1rem 0 0.85rem;
}

.modes button {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  text-align: center;
}

.modes button, #begin, #multi, #next, #again, #pass, #climb, #name-join, #name-cancel {
  padding: 0.65rem 0.8rem;
}

.modes button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

#begin, #multi, #next, #again, #name-join {
  width: 100%;
  background: var(--lift);
  color: #fff8ee;
  border-color: #6e1c14;
  font-family: Rockwell, Palatino, serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#multi { margin: 0 0 0.75rem; }
#begin { margin-bottom: 0.45rem; }

.rules {
  display: flex;
  gap: 1rem;
  margin: 0.85rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.92rem;
}

#wait-list, #room-scores, #standings {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  max-height: 18rem;
  overflow: auto;
  text-align: left;
}

#wait-list li, #room-scores li, #standings li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.18rem 0;
  font-size: 0.95rem;
}

#room-scores li span:nth-child(2) {
  flex: 1;
  min-width: 0;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#name-gate {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  background: rgba(20, 48, 40, 0.55);
}

#name-gate[hidden] { display: none; }

#name-form {
  width: min(18rem, calc(100% - 2rem));
  display: grid;
  gap: 0.65rem;
  padding: 1.1rem;
  background: var(--paper);
  border: 2px solid var(--line);
  box-shadow: 6px 6px 0 rgba(8, 16, 12, 0.28);
}

#climber-name {
  width: 100%;
  box-sizing: border-box;
  border: 2px solid var(--line);
  background: #fff8ee;
  color: var(--ink);
  font: inherit;
  padding: 0.55rem 0.7rem;
}

#count-num {
  font-family: Rockwell, Palatino, serif;
  font-size: 4.5rem;
  line-height: 1;
  margin: 0;
}

#screen-count:not([hidden]) {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 0.45rem;
}
#screen-count .k,
#screen-count .hint { margin: 0; }

.cat {
  font-family: Rockwell, Palatino, serif;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

#question {
  font-size: clamp(1.35rem, 3vw, 1.85rem);
  line-height: 1.25;
  margin: 0.35rem 0 2.6rem;
}

.answer-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 0.7rem;
  align-items: center;
}

#timer {
  width: 2.8rem;
  height: 2.8rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: Rockwell, Palatino, serif;
  background: conic-gradient(#1b2418 calc(var(--p, 1) * 1turn), #e7e0ce 0);
  color: var(--paper);
  position: relative;
}

#timer span {
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  transform: translateY(-0.06em);
}

#answer {
  width: 100%;
  border: 2px solid var(--line);
  background: #fffdf6;
  color: var(--ink);
  padding: 0.7rem 0.75rem;
  font-size: 1.05rem;
}

#climb:disabled { opacity: 0.45; cursor: default; }

.hint { margin-top: 0.7rem; font-size: 0.95rem; }

#tier {
  font-family: Rockwell, Palatino, serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  margin: 0.2rem 0;
}

#meter {
  height: 0.7rem;
  background: linear-gradient(90deg, #c9c2ae, #e2b15a 70%, #d84b3a);
  border: 2px solid var(--line);
  margin: 0.8rem 0 0.3rem;
  position: relative;
}

#meter i {
  position: absolute;
  top: -0.35rem;
  left: var(--mark, 0%);
  width: 0.55rem;
  height: 1.25rem;
  background: var(--ink);
  transform: translateX(-50%);
}

.meter-labels, .round-pips {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}

#points { font-family: Rockwell, Palatino, serif; font-size: 1.4rem; margin: 0.4rem 0; }

#said { margin: 0.2rem 0 0; }

#next, #again { margin-top: 0.9rem; }

.round-pips { gap: 0.3rem; justify-content: flex-start; margin-top: 0.8rem; flex-wrap: wrap; }
.round-pips i {
  width: 0.85rem;
  height: 0.85rem;
  background: var(--pip, #1b2418);
  display: block;
}

@media (max-width: 560px) {
  #board { width: calc(100% - 4.2rem); margin-top: 8.5rem; }
  #climber { width: 6.4rem; }
  #ruler { width: 3.4rem; right: 0.2rem; }
  .lane { top: 6%; }
  .lane.slow { top: 20%; }
  .passer { width: 5.6rem; height: 5.6rem; }
  .answer-row { grid-template-columns: auto 1fr; }
  #pass, #climb { grid-column: span 1; }
  #card { margin-top: 3vh; }
}

@media (prefers-reduced-motion: reduce) {
  #climber, #sky, .lane, .passer, .passer::before, .passer::after { animation: none; transition: none; }
}

@keyframes sway-left {
  0%, 100% { transform: translateY(0) rotate(-36deg); }
  50% { transform: translateY(4px) rotate(-27deg); }
}

@keyframes sway-mid {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(4px) rotate(5deg); }
}

@keyframes sway-right {
  0%, 100% { transform: translateY(0) rotate(28deg); }
  50% { transform: translateY(4px) rotate(37deg); }
}

@keyframes liftoff {
  from { transform: translate3d(0, 62vh, 0); }
  to { transform: translate3d(18vw, -28vh, 0); }
}

@keyframes cruise {
  from { transform: translate3d(-30vw, 0, 0); }
  to { transform: translate3d(108vw, 0, 0); }
}

@keyframes wave {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(2.4rem); }
}
