/* Higher: everything sits inside the game card. */
.gamecard.higher {
  --hud: #0D2547;
  --accent: #FF5A1F;
  container-type: size;
  container-name: game;
  color: var(--hud);
  background: var(--top);
  transition: color 900ms ease;
}

/* ---------- Ladder: white rails and rungs, fading out under the question ---------- */
.ladder {
  position: absolute;
  top: 0; bottom: 0; left: 50%;
  z-index: 1;
  width: 76px;
  transform: translateX(-50%);
  background: linear-gradient(to right, transparent 12px, #FFFFFF 12px 17px, transparent 17px 59px, #FFFFFF 59px 64px, transparent 64px);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, transparent var(--fade-from, 22%), #000 var(--fade-to, 40%), #000 var(--end-from, calc(100% - 250px)), transparent var(--end-to, calc(100% - 196px)));
  mask-image: linear-gradient(to bottom, transparent 0, transparent var(--fade-from, 22%), #000 var(--fade-to, 40%), #000 var(--end-from, calc(100% - 250px)), transparent var(--end-to, calc(100% - 196px)));
}
.ladder::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 17px; right: 17px;
  background: repeating-linear-gradient(to bottom, transparent 0 40px, #FFFFFF 40px 44px);
  background-position-y: var(--rungs, 0px);
}
.menu .ladder { --fade-from: 46%; --fade-to: 66%; --end-from: 100%; --end-to: 100%; }

/* ---------- Climber: one bright figure drawn by the rig in assets/climber.js ---------- */
.climber {
  position: absolute;
  inset: 0;
  z-index: 2;
  color: var(--accent);
  pointer-events: none;
  filter: drop-shadow(0 8px 12px rgba(5, 25, 60, 0.25));
  transform-origin: var(--ox, 50%) var(--oy, 50%);
}
.climber svg { position: absolute; inset: 0; overflow: visible; }
.climber .limb { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }
.climber .arm, .t-rig .arm { stroke-width: var(--arm, 9px); }
.climber .leg, .t-rig .leg { stroke-width: var(--leg, 11px); }
.climber .torso { stroke: currentColor; stroke-width: var(--body, 18px); stroke-linecap: round; }
.climber .head { fill: currentColor; }
.menu .climber { z-index: 6; }

@media (prefers-reduced-motion: no-preference) {
  .climber.falling { animation: fall 1150ms cubic-bezier(.45,0,.85,.55) forwards; }
}
@keyframes fall {
  0% { transform: none; }
  16% { transform: translateY(-14px) rotate(-5deg); }
  100% { transform: translate(30px, 85cqh) rotate(120deg); opacity: 0; }
}

[data-space] .hud, [data-space] .question, [data-space] .screen { text-shadow: 0 2px 14px rgba(0, 0, 0, 0.45); }

/* ---------- Playing ---------- */
.play {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  padding: 20px 18px 18px;
  pointer-events: none;
}
.play > * { pointer-events: auto; }

/* HUD: zone and progress on the left, altitude on the right */
.hud { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.hud-left { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding-top: 2px; }
.zone {
  margin: 0;
  padding: 7px 12px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--hud) 10%, transparent);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1;
  text-shadow: none !important;
}
.progress { display: flex; align-items: center; gap: 10px; padding-left: 2px; }
.pips { display: flex; gap: 4px; margin: 0; padding: 0; list-style: none; }
.pips li { width: 18px; height: 6px; border-radius: 6px; background: color-mix(in srgb, var(--hud) 20%, transparent); transition: background-color 300ms ease, transform 300ms cubic-bezier(.2,.9,.3,1.5); }
.pips li.on { background: var(--accent); transform: scaleY(1.2); }
.rung { margin: 0; font-size: 13px; font-weight: 600; opacity: 0.7; font-variant-numeric: tabular-nums; }

.alt { margin: 0; display: flex; align-items: baseline; gap: 5px; font-weight: 800; line-height: 0.9; letter-spacing: -0.05em; font-variant-numeric: tabular-nums; }
.alt span:first-child { display: inline-block; font-size: clamp(46px, 14cqw, 62px); transform-origin: right center; }
.alt-unit { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; opacity: 0.75; }

.question { margin-top: 22px; max-width: 78%; transition: opacity 300ms ease; }
.kind { margin: 0; font-size: 14px; font-weight: 600; opacity: 0.7; }
.ask { margin: 4px 0 0; font-size: clamp(28px, 8cqw, 34px); font-weight: 800; line-height: 1.02; letter-spacing: -0.045em; text-wrap: balance; }
.dim .question { opacity: 0.1; }

/* Tray: the timer and the two answers */
.tray { margin-top: auto; display: grid; gap: 12px; }
.timer { height: 8px; border-radius: 8px; background: rgba(255, 255, 255, 0.55); overflow: hidden; }
.timer i { display: block; height: 100%; width: 100%; border-radius: 8px; background: var(--hud); transform-origin: left; transition: background-color 200ms ease; }
.timer.low i { background: var(--bad); }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice {
  --edge: #C9D6E8;
  position: relative;
  min-height: 132px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 16px 16px;
  padding-right: 44px;
  border: 0;
  border-radius: 20px;
  background: #FFFFFF;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 1px 0 var(--edge), 0 1px 2px rgba(5, 20, 50, 0.08), 0 16px 30px -18px rgba(5, 20, 50, 0.5);
  transition: transform 280ms cubic-bezier(.3, 1.35, .5, 1), box-shadow 220ms cubic-bezier(.2, .8, .2, 1), background-color 200ms ease, color 200ms ease;
}
.choice:hover:not(:disabled) { transform: translateY(-3px); box-shadow: 0 1px 0 var(--edge), 0 2px 4px rgba(5, 20, 50, 0.08), 0 26px 38px -20px rgba(5, 20, 50, 0.55); }
.choice:active:not(:disabled) { transform: scale(0.97); transition-duration: 80ms; box-shadow: 0 1px 0 var(--edge), 0 6px 14px -10px rgba(5, 20, 50, 0.5); }
.choice:disabled { cursor: default; }
.c-key { position: absolute; top: 12px; right: 12px; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; background: #EEF2F8; color: #5B6B82; font-size: 14px; font-weight: 700; }
.c-name { font-size: clamp(19px, 5.4cqw, 22px); font-weight: 800; line-height: 1.05; letter-spacing: -0.035em; text-wrap: balance; }
.c-val { min-height: 1.3em; font-size: 13px; font-weight: 600; color: var(--ink-2); opacity: 0; transition: opacity 240ms ease; }
.c-bar { width: 100%; height: 6px; border-radius: 6px; background: rgba(10, 10, 11, 0.08); overflow: hidden; opacity: 0; transition: opacity 240ms ease; }
.c-bar i { display: block; height: 100%; width: 0; border-radius: 6px; background: currentColor; transition: width 600ms cubic-bezier(.2,.8,.2,1) 80ms; }
.revealed .c-val, .revealed .c-bar { opacity: 1; }
.choice.right { --edge: #11803A; background: var(--good); color: #FFFFFF; }
.choice.wrong { --edge: #B42323; background: var(--bad); color: #FFFFFF; }
.choice.right .c-val, .choice.wrong .c-val { color: rgba(255, 255, 255, 0.92); }
.choice.right .c-bar, .choice.wrong .c-bar { background: rgba(255, 255, 255, 0.25); }
.choice.right .c-key, .choice.wrong .c-key { background: rgba(255, 255, 255, 0.2); color: #FFFFFF; }
/* New question: hide old values instantly so nothing leaks while fading */
.choices.instant .c-val, .choices.instant .c-bar, .choices.instant .c-bar i, .choices.instant .choice { transition: none; }
@media (hover: none) { .c-key { display: none; } .choice { padding-right: 16px; } }

/* Last two seconds: a red glow pulses around the card */
.gamecard.higher::after { content: ""; position: absolute; inset: 0; z-index: 4; border-radius: inherit; box-shadow: inset 0 0 0 0 rgba(239, 68, 68, 0); pointer-events: none; transition: box-shadow 300ms ease; }
.gamecard.higher.low::after { box-shadow: inset 0 0 60px 6px rgba(239, 68, 68, 0.45); }

@media (prefers-reduced-motion: no-preference) {
  .play.fall .choices { animation: shake 420ms ease; }
  .gamecard.higher.low::after { animation: danger 500ms ease-in-out infinite alternate; }
  .alt.pop span:first-child { animation: pop 420ms cubic-bezier(.2,.9,.3,1.4); }
  .choice.right { animation: bounce 380ms cubic-bezier(.2,.9,.3,1.4); }
}
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }
@keyframes danger { to { box-shadow: inset 0 0 30px 2px rgba(239, 68, 68, 0.25); } }
@keyframes pop { 30% { transform: scale(1.14); } }
@keyframes bounce { 40% { transform: scale(1.04); } }

/* ---------- Zone arrival ---------- */
.arrive {
  position: absolute;
  left: 20px; right: 20px;
  top: 28%;
  z-index: 4;
  color: #FFFFFF;
  text-align: center;
  text-shadow: 0 4px 24px rgba(0, 20, 60, 0.45);
  pointer-events: none;
  opacity: 0;
  transform: translateY(10px) scale(0.96);
  transition: opacity 400ms ease, transform 600ms cubic-bezier(.2,.9,.3,1.3);
}
.arrive.show { opacity: 1; transform: none; }
.arrive p { margin: 0; }
.arrive-k { font-size: 15px; font-weight: 700; opacity: 0.9; }
.arrive-name { margin-top: 6px !important; font-size: clamp(40px, 12cqw, 56px); font-weight: 800; line-height: 0.95; letter-spacing: -0.05em; text-wrap: balance; }
.arrive-alt { margin-top: 10px !important; font-size: 16px; font-weight: 700; opacity: 0.9; }

/* ---------- Start and result screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 28px 24px 22px;
}

.s-kicker { margin: 0; font-size: 15px; font-weight: 700; opacity: 0.75; }
.s-title { margin: 4px 0 14px; font-size: clamp(68px, 21cqw, 96px); font-weight: 800; line-height: 0.85; letter-spacing: -0.07em; }
.s-text { margin: 0 0 8px; max-width: 30ch; font-size: 17px; font-weight: 500; line-height: 1.4; opacity: 0.85; }
.s-note { margin: 14px 0 0; display: inline-block; padding: 10px 14px; border-radius: 14px; background: rgba(255, 255, 255, 0.6); font-size: 15px; font-weight: 600; }

.s-big { margin: 4px 0 0; display: flex; align-items: baseline; gap: 8px; font-weight: 800; line-height: 0.85; letter-spacing: -0.07em; font-variant-numeric: tabular-nums; }
.s-big span:first-child { font-size: clamp(72px, 22cqw, 104px); }
.s-big-unit { font-size: 24px; font-weight: 700; letter-spacing: -0.03em; opacity: 0.75; }
.s-zone { margin: 12px 0 4px; font-size: 20px; font-weight: 800; letter-spacing: -0.03em; }

/* Near miss: how close you were to the next zone */
.near { margin: 18px 0 14px; max-width: 300px; }
.near-k { margin: 0 0 8px; font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.near-bar { height: 10px; border-radius: 10px; background: color-mix(in srgb, var(--hud) 14%, transparent); overflow: hidden; }
.near-bar i { display: block; height: 100%; width: 0; border-radius: 10px; background: var(--accent); transition: width 900ms cubic-bezier(.2,.8,.2,1) 200ms; }
.higher .chip { background: color-mix(in srgb, var(--hud) 10%, transparent); }
.higher .chip.hot { background: var(--accent); color: #FFFFFF; }
.higher .chip.gold { background: #FFD23F; color: #1A1300; }
.s-text + .chips { margin-top: 16px; }
.key { margin-left: 8px; padding: 3px 7px; border-radius: 7px; background: rgba(13, 37, 71, 0.08); font-size: 12px; font-weight: 600; }
/* Keyboard hints mean nothing on a touch screen */
@media (hover: none) { .key { display: none; } }

.s-actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.s-actions .pill { min-height: 56px; }
.menu .play { visibility: hidden; }

.float.quick { font-size: 14px; font-weight: 800; letter-spacing: 0.02em; color: var(--accent); }

/* ---------- The route: hidden on narrow cards ---------- */
.route { display: none; }

/* ---------- Wide stage: the game fills the screen ---------- */
@container game (min-width: 860px) {
  .menu .ladder { --fade-from: 8%; --fade-to: 30%; }
  .ladder { --fade-from: 28%; --fade-to: 44%; }
  .skyline { height: 34cqh; }

  /* Playing: HUD in the corners, question centred, answers centred at the bottom */
  .play { padding: 32px 40px 36px; }
  .zone { padding: 9px 16px; font-size: 16px; }
  .pips li { width: 24px; height: 7px; }
  .rung { font-size: 14px; }
  .alt span:first-child { font-size: 88px; }
  .alt-unit { font-size: 22px; }
  .question { position: absolute; left: 50%; top: 13%; width: min(680px, 60cqw); max-width: none; margin: 0; transform: translateX(-50%); text-align: center; }
  .kind { font-size: 16px; }
  .ask { margin-top: 6px; font-size: clamp(40px, 4.4cqw, 56px); }
  .tray { width: min(760px, 100%); margin: auto auto 0; gap: 16px; }
  .timer { height: 10px; }
  .choices { gap: 16px; }
  .choice { min-height: 168px; padding: 22px; padding-right: 56px; border-radius: 24px; }
  .c-key { top: 16px; right: 16px; width: 32px; height: 32px; border-radius: 10px; font-size: 16px; }
  .c-name { font-size: clamp(24px, 2.4cqw, 30px); }
  .c-val { font-size: 15px; }
  .ladder { --end-from: calc(100% - 300px); --end-to: calc(100% - 236px); }
  .arrive { top: 34%; }
  .arrive-name { font-size: 88px; }

  /* Start and result: a left column, the ladder in the middle, the route on the right */
  .screen { justify-content: center; gap: 40px; padding: 56px 64px; background: linear-gradient(to right, color-mix(in srgb, var(--top) 55%, transparent), transparent 46%); }
  .screen > div, .s-actions { width: min(440px, 36cqw); }
  .s-title { font-size: 128px; }
  .s-text { font-size: 19px; }
  .s-big span:first-child { font-size: 140px; }
  .s-big-unit { font-size: 32px; }
  .s-zone { font-size: 26px; }
  .near { max-width: none; }
  .s-actions .pill { min-height: 60px; font-size: 17px; }

  /* The route up the right side */
  .route {
    position: absolute;
    right: 40px; top: 50%;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 22px;
    margin: 0;
    padding: 0;
    list-style: none;
    transform: translateY(-50%);
    color: var(--hud);
    transition: color 900ms ease;
  }
  .route::before { content: ""; position: absolute; left: 7px; top: 8px; bottom: 8px; width: 2px; border-radius: 2px; background: color-mix(in srgb, var(--hud) 22%, transparent); }
  .route li { position: relative; display: grid; grid-template-columns: 16px auto; column-gap: 14px; align-items: center; }
  .route i { grid-row: span 2; width: 16px; height: 16px; border-radius: 50%; background: var(--top); box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--hud) 35%, transparent); }
  .route b { font-size: 16px; font-weight: 700; letter-spacing: -0.02em; }
  .route span { font-size: 13px; font-weight: 600; opacity: 0.65; font-variant-numeric: tabular-nums; }
  .route .past { opacity: 0.55; }
  .route .past i { background: var(--hud); box-shadow: none; }
  .route .ahead { opacity: 0.8; }
  .route .here i { background: var(--accent); box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 30%, transparent); }
  .route .here b { font-size: 19px; }
  [data-space] .route { text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45); }
}
@media (prefers-reduced-motion: no-preference) {
  .route .here i { animation: beacon 1.6s ease-in-out infinite; }
}
@keyframes beacon { 50% { box-shadow: 0 0 0 9px color-mix(in srgb, var(--accent) 10%, transparent); } }

/* ---------- Screens arrive in sequence ---------- */
@media (prefers-reduced-motion: no-preference) {
  .screen.enter > div > *, .screen.enter > .s-actions { animation: rise 640ms cubic-bezier(.2,.8,.2,1) both; }
  .screen.enter > div > :nth-child(2) { animation-delay: 70ms; }
  .screen.enter > div > :nth-child(3) { animation-delay: 140ms; }
  .screen.enter > div > :nth-child(4) { animation-delay: 210ms; }
  .screen.enter > div > :nth-child(5) { animation-delay: 280ms; }
  .screen.enter > div > :nth-child(6) { animation-delay: 350ms; }
  .screen.enter > div > :nth-child(n+7) { animation-delay: 420ms; }
  .screen.enter > .s-actions { animation-delay: 420ms; }
  .route li { transition: opacity 500ms ease; }
}
@keyframes rise { from { opacity: 0; transform: translateY(24px); } }
