:root {
  --bg: #f2ede3; --surface: #fbf8f1; --ink: #23271f; --muted: #6d6a5d; --line: #ddd5c4;
  --moss: #4e6b3a; --moss-ink: #fff; --clay: #b4532f; --clay-bg: #f0dfd5;
  --moss-bg: #e3e3d4; --sky-top: #f4e3c6; --sky-bottom: #e4ebe3; --sun: #f1c27d; --cloud: #fbf8ef;
  --ridge: #b9c3a4; --ridge2: #a7b48f; --rock: #8a9a6f; --rock-shade: #6f8058; --snow: #fbf8ef; --tuft: #5d7444;
  --climber: #2a2a24; --pack: #c0582f; --hint-bg: #e6e3d3; --hint-line: #c9c6ad;
  --badge: rgba(80, 74, 60, .55);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121510; --surface: #1b1f19; --ink: #ece6d8; --muted: #a39e8e; --line: #30362b;
    --moss: #8db069; --moss-ink: #10140e; --clay: #e27c55; --clay-bg: #2e1f19;
    --moss-bg: #222a1e; --sky-top: #1a2433; --sky-bottom: #263330; --sun: #e8e2cf; --cloud: #b9b9ae;
    --ridge: #2b3628; --ridge2: #34412f; --rock: #475a3b; --rock-shade: #384830; --snow: #dcdccf; --tuft: #5b7346;
    --climber: #ece6d8; --pack: #e27c55; --hint-bg: #1f2619; --hint-line: #4a5a35;
    --badge: rgba(16, 20, 14, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 Geist, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

#app { max-width: 448px; margin: 0 auto; padding: 14px 16px 40px; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.hdr-group { display: flex; gap: 8px; width: 84px; }
.hdr-group:last-child { justify-content: flex-end; }
/* home logo: keep the help/mute buttons clear of the pinned tile on desktop; tighten the top gap under the in-flow logo on smaller screens */
.top .hdr-group:first-child { margin-left: max(0px, calc(var(--site-logo-space, 0px) - (100vw - 448px) / 2 - 16px)); }
@media (max-width: 1000px) { #app { padding-top: 4px; } }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: transparent;
  display: grid; place-items: center; font-weight: 600; font-size: 15px; color: var(--ink); padding: 0;
  transition: background .15s;
}
.icon-btn:hover { background: var(--surface); }
.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg.solid { fill: currentColor; stroke: none; }
.brand { text-align: center; }
.logo { display: flex; align-items: center; gap: 6px; justify-content: center; }
.logo svg { width: 28px; height: 28px; }
.lg-ridge { fill: var(--moss); } .lg-snow { fill: var(--snow); } .lg-pole { stroke: var(--ink); stroke-width: 2; } .lg-flag { fill: var(--clay); }
h1 { margin: 0; font-size: 25px; font-weight: 800; letter-spacing: -.02em; }
.sub { font-size: 12px; color: var(--muted); margin-top: 1px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.prompt { text-align: center; padding: 13px 16px 12px; margin-bottom: 16px; }
.eyebrow { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.prompt h2 { margin: 3px 0 2px; font-size: 19px; font-weight: 700; line-height: 1.25; letter-spacing: -.01em; }
.prompt p { margin: 0; font-size: 14px; color: var(--muted); }

/* scene */
.scene-wrap { position: relative; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); aspect-ratio: 400 / 260; margin-bottom: 14px; }
.scene { display: block; width: 100%; height: 100%; }
@media (prefers-color-scheme: dark) { .scene { filter: brightness(.9) saturate(.92); } }
.sky-top { stop-color: var(--sky-top); } .sky-bottom { stop-color: var(--sky-bottom); }
.sun { fill: var(--sun); }
.cloud ellipse { fill: var(--cloud); opacity: .75; }
.c1 { animation: drift 46s linear infinite; }
.c2 { animation: drift 64s linear -30s infinite; }
.c1 ellipse { transform: translateY(78px); } .c2 ellipse { transform: translateY(42px); }
@keyframes drift { from { transform: translateX(-40px); } to { transform: translateX(440px); } }
.ridge-a { fill: var(--ridge); } .ridge-b { fill: var(--ridge2); } .peak-snow { fill: var(--snow); }
#world, #far { transition: transform .9s cubic-bezier(.45, .05, .25, 1); }
.step-face { fill: var(--rock); }
.step-side { fill: var(--rock-shade); }
.step-top { stroke: var(--tuft); stroke-width: 2.4; stroke-linecap: round; fill: none; }
.tuft { stroke: var(--tuft); stroke-width: 1.3; stroke-linecap: round; fill: none; }
.pebble { fill: var(--rock-shade); }
.flag-pole { stroke: var(--climber); stroke-width: 1.6; } .flag-cloth { fill: var(--pack); }
#climber { transition: transform .9s cubic-bezier(.45, .05, .25, 1); }
/* climber: body poses + limb motions */
.limb { stroke: var(--climber); stroke-width: 2.5; stroke-linecap: round; fill: none; transform-box: fill-box; }
.head { fill: var(--climber); } .pack { fill: var(--pack); }
.hair { stroke: var(--pack); stroke-width: 2.7; stroke-linecap: round; fill: none; }
.leg-l, .arm-l { transform-origin: 100% 0; }   /* pivot at hip / shoulder */
.leg-r, .arm-r { transform-origin: 0 0; }
#climber-body { transform-box: fill-box; transform-origin: 50% 100%; }

.idle .pack { transform-box: fill-box; transform-origin: 50% 100%; animation: breathe 2.6s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scaleY(1.06); } }

#climber-body.hop { animation: hop .9s ease-in-out both; }
@keyframes hop {
  14% { transform: translateY(1px) scale(1.07, .88); }
  50% { transform: translateY(-24px) rotate(-6deg); }
  86% { transform: translateY(1px) scale(1.05, .9); }
}
.hop .leg-l { animation: tuck-l .9s ease-in-out both; }
.hop .leg-r { animation: tuck-r .9s ease-in-out both; }
.hop .arm-l { animation: reach-l .9s ease-in-out both; }
.hop .arm-r { animation: reach-r .9s ease-in-out both; }
@keyframes tuck-l { 35%, 65% { transform: rotate(48deg); } }
@keyframes tuck-r { 35%, 65% { transform: rotate(-48deg); } }
@keyframes reach-l { 40%, 60% { transform: rotate(95deg); } }
@keyframes reach-r { 40%, 60% { transform: rotate(-95deg); } }

#climber-body.tumble { animation: tumble 1.4s cubic-bezier(.5, 0, .9, .6) .2s forwards; }
@keyframes tumble {
  15% { transform: translate(-18px, -14px) rotate(-60deg); }
  35% { transform: translate(-56px, 30px) rotate(-180deg); }
  50% { transform: translate(-80px, 20px) rotate(-250deg); }
  75% { transform: translate(-115px, 62px) rotate(-400deg); }
  100% { transform: translate(-160px, 115px) rotate(-520deg); opacity: 0; }
}
.tumble .arm-l, .tumble .leg-r { animation: flail .16s linear 8 alternate; }
.tumble .arm-r, .tumble .leg-l { animation: flail-back .16s linear 8 alternate; }
@keyframes flail { from { transform: rotate(-35deg); } to { transform: rotate(35deg); } }
@keyframes flail-back { from { transform: rotate(35deg); } to { transform: rotate(-35deg); } }

#climber-body.cheer { animation: cheer .6s ease-in-out 3; }
@keyframes cheer { 40% { transform: translateY(-10px); } }
.cheer .arm-l { animation: wave-l .3s ease-in-out infinite alternate; }
.cheer .arm-r { animation: wave-r .3s ease-in-out infinite alternate; }
@keyframes wave-l { from { transform: rotate(120deg); } to { transform: rotate(160deg); } }
@keyframes wave-r { from { transform: rotate(-120deg); } to { transform: rotate(-160deg); } }
.flag-cloth { transform-box: fill-box; transform-origin: 0 50%; animation: flag-wave .7s ease-in-out infinite alternate; }
@keyframes flag-wave { to { transform: skewY(8deg) scaleX(.9); } }

.altitude {
  position: absolute; top: 12px; left: 12px; background: var(--badge); color: #fff;
  border-radius: 10px; padding: 6px 10px 5px; line-height: 1.1; backdrop-filter: blur(3px);
}
.altitude span { display: block; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; font-weight: 700; opacity: .85; }
.altitude b { font-size: 17px; font-weight: 800; }
.watermark {
  position: absolute; right: 12px; bottom: 9px; font-size: 13px; font-weight: 700; color: #fff; opacity: .85;
  letter-spacing: .02em; pointer-events: none; text-shadow: 0 1px 3px rgba(0, 0, 0, .45);
}

/* last answer */
.last {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 14px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--moss-bg); margin-bottom: 14px; font-weight: 600; font-size: 15px;
  animation: pop .35s ease-out;
}
.last .val { color: var(--moss); font-weight: 700; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.last.bad { background: var(--clay-bg); border-color: color-mix(in srgb, var(--clay) 45%, var(--line)); }
.last.bad .val { color: var(--clay); }
.last.top .val { color: var(--moss); }
@keyframes pop { from { transform: scale(.97); opacity: 0; } }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.hint {
  text-align: center; font-size: 14px; padding: 10px 14px; border-radius: 12px; margin-bottom: 14px;
  background: var(--hint-bg); border: 1px solid var(--hint-line);
}

/* input */
.step-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; min-height: 30px; }
.step-row label { font-weight: 700; font-size: 14px; }
.beat { font-size: 13px; font-weight: 600; border: 1px solid var(--line); background: var(--surface); padding: 4px 11px; border-radius: 999px; }
.beat b { color: var(--moss); }
.combo { position: relative; }
#answer {
  width: 100%; font: inherit; font-size: 16px; padding: 13px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); outline: none;
}
#answer:focus { border-color: var(--moss); box-shadow: 0 0 0 3px color-mix(in srgb, var(--moss) 18%, transparent); }
#answer::placeholder { color: var(--muted); }
.suggest {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); margin: 0; padding: 5px; list-style: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .14);
  max-height: 248px; overflow-y: auto;
}
.suggest li { padding: 9px 11px; border-radius: 8px; cursor: pointer; font-size: 15px; }
.suggest li.on { background: var(--moss-bg); }
.suggest li small { color: var(--muted); margin-left: 6px; }
.suggest li.none { color: var(--muted); cursor: default; }
.suggest mark { background: none; color: inherit; font-weight: 700; }

/* result */
.result { padding: 20px 18px; text-align: center; animation: pop .4s ease-out; }
.result h3 { margin: 0; font-size: 23px; font-weight: 700; letter-spacing: -.01em; }
.big { margin: 4px 0 8px; font-size: 16px; color: var(--muted); }
.big b { font-size: 36px; font-weight: 800; color: var(--ink); margin-right: 3px; vertical-align: -3px; }
.why { margin: 0 0 16px; font-size: 14px; }
.btn {
  display: block; width: 100%; border: 0; border-radius: 12px; padding: 13px; font-weight: 700; font-size: 16px;
  background: var(--moss); color: var(--moss-ink); transition: filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); margin-top: 8px; }
.could { margin-top: 18px; text-align: left; }
.could h4, .whole h4 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); text-align: center; }
.chips { display: flex; gap: 8px; }
.chip { flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 8px; text-align: center; font-size: 13px; font-weight: 600; line-height: 1.25; }
.chip span { display: block; color: var(--moss); font-weight: 700; margin-top: 2px; }
.linkish { background: none; border: 0; color: var(--muted); text-decoration: underline; font-size: 14px; margin-top: 14px; padding: 4px; }
.whole { margin-top: 10px; text-align: left; }
.whole ol { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.whole li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 12px; font-size: 14px; border-bottom: 1px solid var(--line); }
.whole li:last-child { border-bottom: 0; }
.whole li .v { color: var(--muted); white-space: nowrap; }
.whole li.mine { background: var(--moss-bg); font-weight: 600; }
.whole li.miss { background: var(--clay-bg); font-weight: 600; }
.whole li.mine::before { content: '✓'; color: var(--moss); margin-right: -4px; }
.whole li.miss::before { content: '✕'; color: var(--clay); margin-right: -4px; }
.whole li > span:first-of-type { flex: 1; }

.source { text-align: center; color: var(--muted); font-size: 12px; margin: 22px 0 0; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: center; padding: 16px; z-index: 20; }
.dialog {
  position: relative; width: 100%; max-width: 400px; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: 16px; padding: 20px 22px; font-size: 14px; animation: pop .25s ease-out;
}
.dialog h3 { margin: 0 0 10px; font-size: 18px; }
.dialog ol { padding-left: 20px; margin: 10px 0; } .dialog li { margin-bottom: 6px; }
.dialog .tip { background: var(--hint-bg); border-radius: 10px; padding: 10px 12px; margin: 12px 0 0; }
.close { position: absolute; top: 10px; right: 12px; border: 0; background: none; font-size: 24px; line-height: 1; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; margin: 6px 0 14px; }
.tiles b { display: block; font-size: 26px; font-weight: 800; }
.tiles span { font-size: 11px; color: var(--muted); }
.bars { display: grid; gap: 4px; }
.bar { display: grid; grid-template-columns: 52px 1fr; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.bar i { display: block; height: 18px; border-radius: 4px; background: var(--moss); color: var(--moss-ink); font-style: normal; font-weight: 700; font-size: 11px; text-align: right; padding: 1px 6px; min-width: 22px; }

.toast {
  position: fixed; left: 50%; top: 18px; transform: translate(-50%, -20px); opacity: 0; pointer-events: none; z-index: 30;
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-weight: 600; font-size: 14px; transition: .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
