:root {
  color-scheme: dark;
  font-family: system-ui, "Microsoft YaHei", sans-serif;
  color: #fff5d8;
  background: #182b25;
  --text-mute: #d1c5a7;
  --edge: #65715a;
  --surface: #24342c;
  --depth: #121b17;
  --gold: #f5cc78;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }

.map-actions { display:flex; flex-wrap:wrap; justify-content:flex-end; gap:.65rem; }
.map-actions button { white-space:nowrap; }
.run-dialog {
  width:min(33rem,calc(100% - 2rem));
  max-height:calc(100% - 2rem);
  color:#f5efdb;
  background:#203229;
  border:2px solid #9f9873;
  box-shadow:0 0 0 4px #18241e;
  padding:1.25rem;
}
.run-dialog::backdrop { background:#0b1715c9; }
.run-dialog h2 { margin:0 0 .9rem; }
.run-dialog label { display:block; margin-bottom:.3rem; }
.run-dialog input {
  padding:.65em;
  width:100%;
  color:inherit;
  background:#18241e;
  border:1px solid #a5a48b;
  font:inherit;
}
.run-controls-list { display:grid; grid-template-columns:auto 1fr; gap:.5rem 1rem; }
.run-controls-list dt { color:#ffdf91; font-weight:700; }
.run-controls-list dd { margin:0; }
#race-hud { grid-column:1/-1; color:#b3f0f2; font-weight:800; }
#race-bomb:disabled { opacity:.55; }
#chest-balance { color:#ffdf91; float:right; }
.outfit-icon { image-rendering:pixelated; }
body { margin: 0; }
button {
  color: inherit; font: inherit; font-weight: 700; cursor: pointer;
  background: var(--surface); padding: .66rem 1rem;
  border: 2px solid var(--edge); border-bottom-color: var(--depth); border-right-color: var(--depth);
  box-shadow: 0 0 0 1px #18201a; border-radius: 0;
}
button:hover { background: #3c5243; }
button:focus-visible { outline: 3px solid #f5cc78; outline-offset: 3px; }
button:disabled { cursor: default; opacity: .55; }
.primary { background: #83a849; color: #172612; border-color: #c1d17f #39512c #39512c #c1d17f; text-shadow: 0 1px #f1f1ba63; }
.primary:hover { background: #a4c45f; }
.runner { width: 100%; height: 100vh; height: 100dvh; position: relative; overflow: hidden; background: radial-gradient(ellipse at top right,#8b9978,#172923 66%); }
#course-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
.home, .result { position: absolute; inset: 0; z-index: 1; overflow: auto; }
.result { display: grid; align-items: center; padding: clamp(1rem,7vw,7rem); }
.home {
  background: linear-gradient(180deg,#14221bbd 0%,#14221be8 17rem,#141e19f5 42rem);
  scrollbar-color: #87986e #17231b;
}
.home-card { width: min(57rem,calc(100% - 2 * clamp(.8rem,4vw,2rem))); margin: 0 auto; padding: clamp(1.25rem,4vw,3rem) 0 max(2.4rem,env(safe-area-inset-bottom)); }
h1, h2, h3, p { margin: 0; }
.map-header { display: flex; align-items: end; justify-content: space-between; gap: 1rem; padding-bottom: 1.65rem; border-bottom: 2px solid #84966080; }
.home h1 { font-size: clamp(1.85rem,4.7vw,3.6rem); line-height: 1.1; font-weight: 900; letter-spacing: .025em; text-shadow: 2px 4px #23241a, 4px 6px #111611; }
.home h1:focus { outline: none; }
.home-route { margin-top: .75rem; color: #efe6cc; font-size: .93rem; text-shadow: 0 2px #171e17; }
.warehouse { display: flex; flex-direction: column; align-items: end; gap: .42rem; flex-shrink: 0; }
.level-section { margin-top: 1.55rem; }
.level-intro { display: flex; align-items: baseline; justify-content: space-between; gap: .6rem; padding-bottom: .85rem; }
.level-intro h2 { font-size: 1.4rem; }
.level-intro p { font-size: .85rem; color: #d9d5bd; }
.level-map { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .85rem; }
.level-card { text-align: left; display: block; min-width: 0; padding: 0; background: #22352b; border-color: #78896b #131e17 #131e17 #78896b; }
.level-card[aria-pressed="true"] { border-color: #e7c879; box-shadow: 0 0 0 1px #e7c87970, 0 5px #152319; }
.level-card:disabled { background: #1e2b25; border-color: #57665b #101813 #101813 #57665b; opacity: 1; }
.level-card-heading { display: flex; align-items: center; gap: .65rem; padding: .58rem .65rem .55rem; }
.level-number { color: #f0d18c; font-size: .79rem; white-space: nowrap; }
.level-card-heading strong { flex: 1; min-width: 0; font-size: 1.02rem; color: #fff3d7; }
.level-state { color: #c3df9c; font-size: .75rem; white-space: nowrap; }
.level-card:disabled .level-state { color: #e5cfab; }
.level-preview { display: block; position: relative; overflow: hidden; background: #5b7954; }
.level-preview canvas { width: 100%; height: auto; display: block; aspect-ratio: 252 / 76; image-rendering: pixelated; }
.level-biomes { display: block; padding: .48rem .65rem .55rem; color: #ddd5bc; font-size: .77rem; font-weight: 600; }
.level-lock { position: absolute; inset: 0; display: none; background: #111b1e71; align-items: center; justify-content: center; }
.level-card:disabled .level-lock { display: flex; }
.chain { display: flex; position: absolute; width: 114%; gap: 1px; align-items: center; transform-origin: center; }
.chain-down { rotate: 17deg; }
.chain-up { rotate: -17deg; }
.chain i { flex: 1; height: 15px; background: #64717c20; border: 3px solid #9aa4a9; border-radius: 7px; box-shadow: 0 0 0 1px #354651, inset 0 1px #d3dde1; }
.chain i:nth-child(even) { height: 7px; border: 0; border-radius: 1px; background: #778691; box-shadow: 0 0 0 1px #32414c, inset 0 2px #bec9d0; }
.padlock {
  width: 34px; height: 27px; position: relative; margin-top: 11px; background: #8997a0;
  border: 3px solid #334049; box-shadow: inset 2px 2px #d8d9d5, inset -3px -3px #637381, 0 2px #273742;
}
.padlock::before { content: ""; position: absolute; width: 20px; height: 14px; left: 1px; top: -16px; border: 4px solid #c3cbcb; border-bottom: 0; box-shadow: 0 0 0 2px #3b4950; border-radius: 6px 6px 0 0; }
.padlock::after { content: ""; position: absolute; left: 11px; top: 6px; width: 6px; height: 10px; background: #283039; clip-path: polygon(0 0,100% 0,100% 60%,67% 60%,67% 100%,33% 100%,33% 60%,0 60%); }
.map-start {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1.25rem;
  padding: .95rem 1rem; background: #28392d; border: 2px solid #8a9b75; box-shadow: 0 4px #14201a;
}
#home-track { margin-bottom: .34rem; color: var(--gold); font-size: .95rem; font-weight: 750; }
.map-rule { color: #dad2b6; font-size: .83rem; }
#start-run { flex-shrink: 0; min-width: min(12rem,100%); font-size: 1.1rem; padding: .8rem 1.05rem; }
.warehouse h2 { font-size: .96rem; color: var(--text-mute); }
.chest-trigger { display: inline-flex; align-items: center; gap: .65rem; background: #513a28; border-color: #96724a #271d17 #231b14 #96724a; }
.chest-trigger:hover { background: #6c4a32; }
.chest-mark {
  width: 26px; height: 19px; position: relative; display: inline-block;
  border: 2px solid #221912; background: linear-gradient(#d09754 0 32%,#5d3822 32% 48%,#a97440 48% 88%,#82522d 88%);
  box-shadow: inset 2px 0 #d5a064, inset -2px 0 #8b552d;
}
.chest-mark::after { content: ""; position: absolute; left: 8px; top: 4px; width: 6px; height: 7px; background: #f1cc78; border-bottom: 2px solid #8b6d3b; }
#run-error { max-width: 24rem; color: #ffcd9d; margin-top: 1rem; }
.hud { position: absolute; inset: 0; pointer-events: none; display: grid; grid-template-columns: 1fr minmax(7rem,20rem) 1fr; align-items: start; gap: .8rem; padding: clamp(.7rem, 2.1vw, 1.6rem); }
.hud button, .touch-controls { pointer-events: auto; }
.health, .journey, .instructions, #run-toast, #truck-warning { background: #18251ee8; border: 1px solid #687459; box-shadow: 0 2px #14211c90; }
.health { padding: .52rem .72rem; width: max-content; }
.stars { display: flex; gap: .28rem; }
.stars i {
  width: 22px; height: 20px; background: #655743; clip-path: polygon(45% 0,55% 0,55% 15%,65% 15%,65% 30%,100% 30%,100% 42%,85% 42%,85% 54%,75% 54%,75% 70%,85% 70%,85% 94%,72% 94%,72% 84%,60% 84%,60% 77%,40% 77%,40% 84%,28% 84%,28% 94%,15% 94%,15% 70%,25% 70%,25% 54%,15% 54%,15% 42%,0 42%,0 30%,35% 30%,35% 15%,45% 15%);
}
.stars i.filled { background: linear-gradient(145deg,#fff4af,#ffd33e 58%,#e79825); }
.stars i.half { background: linear-gradient(90deg,#ffd33e 50%,#655743 50%); }
#run-items { display: block; color: #ffdd9a; font-size: .77rem; margin-top: .33rem; }
#run-items:empty { display: none; }
#run-gadgets { display:block; margin-top:.3rem; color:#ecdd9e; font-size:.76rem; white-space:nowrap; }
#run-coins { color: #ffdc68; font-weight: 800; font-variant-numeric: tabular-nums; }
#run-speed { text-align: right; color: #e1dfc4; font-variant-numeric: tabular-nums; white-space: nowrap; }
.journey { display: grid; grid-template-columns: 1fr auto; gap: .35rem .6rem; padding: .5rem .65rem; font-size: .82rem; }
#run-distance { font-variant-numeric: tabular-nums; color: var(--gold); white-space: nowrap; }
#run-progress { accent-color: #b1c774; width: 100%; height: .5rem; grid-column: 1 / -1; }
.tools { display: flex; justify-content: end; gap: .45rem; }
.tools button { white-space: nowrap; font-size: .82rem; padding: .48rem .62rem; }
.instructions, #run-toast, #truck-warning { position: absolute; margin: 0; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 2rem); text-align: center; padding: .48rem .78rem; font-size: .84rem; }
.instructions { bottom: 1.3rem; }
#run-toast { color: #ffe299; bottom: 4rem; }
#truck-warning { top: 6.55rem; color: #fff2c0; background: #592c1be8; border: 1px solid #eba65d; box-shadow: 0 2px #25180f90; }
#truck-warning[data-kind="ramp"] { background:#16423ded; border-color:#85caa7; color:#e2fbd3; }
#run-toast:empty, #truck-warning:empty { display: none; }
.touch-controls { display: none; }
.result { z-index: 2; place-items: center; text-align: center; background: #14221ebb; }
.result-card { width: min(24rem,100%); background: #24342c; border: 2px solid #93a477; box-shadow: 0 3px #151c12; padding: 2rem; display: grid; gap: .8rem; }
#speed-shoe-reward { width: 64px; height: 64px; justify-self: center; image-rendering: pixelated; }
.result-card h2 { font-size: 2rem; }
.result-card p { color: var(--text-mute); margin-bottom: .25rem; }
#chest-dialog { color: inherit; width: min(52rem, calc(100% - 1.6rem)); max-height: calc(100dvh - 2rem); padding: 0; background: #25271f; border: 3px solid #a38a60; box-shadow: 0 7px #141711, 0 27px 85px #0008; }
#chest-dialog::backdrop { background: #0a1814c9; }
.chest-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid #705e43; background: #373325; }
.chest-header p { color: #dec49c; font-size: .8rem; }
.chest-header h2 { font-size: 1.75rem; color: #ffe2a7; }
.chest-content { display: grid; grid-template-columns: minmax(0,1fr) minmax(11rem,.45fr); gap: 1rem; padding: 1.15rem 1.25rem .6rem; }
.chest-content h3 { margin-bottom: .65rem; font-size: .92rem; letter-spacing: .02em; color: #e7d5aa; }
.loot-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .45rem; margin-bottom: 1rem; }
.loot { display: flex; align-items: center; gap: .45rem; min-width: 0; padding: .38rem .42rem; background: #171e19; border: 1px solid #63563e; }
.loot canvas { width: 34px; height: 34px; flex: 0 0 auto; image-rendering: pixelated; }
.loot div { flex: 1; min-width: 0; }
.loot b, .loot small { display: block; font-size: .78rem; line-height: 1.3; }
.loot small { color: #c7b596; }
.loot button { padding: .31rem .38rem; font-size: .75rem; white-space: nowrap; }
.empty-chest { color: var(--text-mute); font-size: .82rem; grid-column: 1 / -1; }
.chest-player { background: radial-gradient(ellipse at 50% 32%,#415241,#19241e 75%); border: 1px solid #68634d; padding: .75rem; align-self: start; text-align: center; }
#chest-avatar { width: min(100%,160px); height: auto; display: block; margin: auto; image-rendering: pixelated; }
#chest-worn { text-align: left; white-space: pre-line; font-size: .78rem; line-height: 1.55; color: #eadcbd; border-top: 1px solid #52624f; padding-top: .5rem; }
#chest-status { padding: 0 1.25rem .8rem; color: var(--gold); font-size: .85rem; }
#run-hud.blast::after, #run-hud.hurt::after { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 min(12vw,130px) #b51825ad; animation: hit .32s both; }
#run-hud.blast::after { box-shadow: inset 0 0 min(12vw,130px) #ffab4eab; }
@keyframes hit { to { opacity: 0; } }
@media (max-width: 42rem) {
  .map-header { padding-bottom: 1rem; }
  .warehouse { gap: .3rem; }
  .warehouse h2 { font-size: .75rem; }
  .chest-trigger { padding: .45rem .65rem; font-size: .85rem; }
  .level-map { grid-template-columns: minmax(0,1fr); gap: .7rem; }
  .map-start { align-items: stretch; flex-direction: column; gap: .75rem; }
  #start-run { width: 100%; }
  .chest-content { grid-template-columns: minmax(0,1fr) minmax(7.5rem,.5fr); padding-inline: .7rem; gap: .6rem; }
  .loot-grid { grid-template-columns: minmax(0,1fr); }
  .chest-player { padding: .4rem; }
  .hud { gap: .3rem; grid-template-columns: auto minmax(5rem,1fr) auto; }
  .stars i { width: 16px; height: 16px; }
  .health { padding: .31rem; }
  .journey { font-size: .67rem; padding: .3rem; gap: .15rem .35rem; }
  #run-region { grid-column: 1 / -1; }
  #run-distance { grid-column: 1 / -1; }
  .health { max-width: 8.6rem; }
  #run-gadgets { white-space: normal; font-size: .68rem; }
  .tools { gap: .25rem; flex-wrap: wrap; }
  .tools button { padding: .31rem; font-size: .7rem; }
}
@media (pointer: coarse) {
  .touch-controls { position: absolute; bottom: max(.9rem,env(safe-area-inset-bottom)); left: .75rem; right: .75rem; display: flex; justify-content: space-between; gap: .5rem; }
  .touch-controls div { display: grid; grid-template-columns: repeat(2,1fr); gap: .3rem; }
  .touch-controls button { min-width: 2.75rem; min-height: 2.75rem; padding: .2rem .38rem; touch-action: none; }
  #run-toast { bottom: 9.8rem; }
  #truck-warning { top: 7rem; }
  .instructions { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  #run-hud.blast::after, #run-hud.hurt::after { animation-duration: .12s; }
}

.gallery-entry { display:inline-block; margin-top:.6rem; color:#ffe096; text-underline-offset:.23rem; font-size:.88rem; }
.gallery-entry:hover { color:#fff5c7; }

.title-screen { position:absolute; inset:0; z-index:2; display:flex; align-items:center; background:linear-gradient(90deg,#14241a 0%,#17291bd9 23%,#18271a46 48%,#11180d08 79%); }
.title-content { margin-left:clamp(1.5rem,10vw,10rem); display:grid; justify-items:start; gap:1.15rem; padding-bottom:2.5rem; }
.title-content h1 { font-size:clamp(4.5rem,11vw,9rem); line-height:.97; color:#fff2c7; font-weight:950; text-shadow:3px 5px #233923,7px 9px #152817; letter-spacing:.055em; }
.title-content h1 span { display:block; font-size:clamp(1.25rem,4.3vw,3.3rem); letter-spacing:.13em; color:#e5d6a9; margin-bottom:.48rem; }
#intro-start { min-width:10rem; margin-top:.55rem; font-size:1.3rem; }
.title-content .gallery-entry { margin-top:.05rem; }
.game-loader { position:absolute; inset:0; z-index:5; display:grid; place-items:center; background:#15271ef9; text-align:center; }
.loader-content { width:min(37rem,calc(100% - 2rem)); }
.loader-content h2 { color:#fff0c9; font-size:clamp(1.1rem,3.4vw,1.8rem); margin-bottom:.5rem; }
.loader-content p { margin-top:1.3rem; color:#d9c99d; }
.loader-road { height:122px; position:relative; border-bottom:9px solid #7a8c55; box-shadow:0 5px #53653c,inset 0 -3px #29392c; }
#loader-steve { position:absolute; bottom:0; left:6%; width:94px; height:91px; translate:-50% 0; image-rendering:pixelated; z-index:1; }
.loader-marker { position:absolute; bottom:-9px; left:50%; width:5px; height:39px; background:#efca73; box-shadow:2px 0 #7c6644; }
.loader-marker::before { content:""; position:absolute; top:0; width:16px; height:10px; left:5px; background:#e1ac49; }
@media(max-width:42rem) {
  .title-screen { align-items:end; background:linear-gradient(0deg,#15241df7 1%,#152421d8 22%,#15242122 57%); }
  .title-content { margin-left:1.35rem; padding-bottom:2.05rem; gap:.7rem; }
  .title-content h1 { font-size:3.7rem; }
  #intro-start { min-width:8rem; font-size:1.1rem; }
}

.level-speed { display:block; margin-top:.23rem; color:#ebcd87; }

#finish-meter {
  display:flex; grid-column:1 / -1; align-items:center; gap:.4rem;
  margin-top:.1rem; padding:.24rem .35rem; color:#fff0af; background:#6c5229;
  font-weight:820; font-variant-numeric:tabular-nums;
}
#finish-meter::before, #finish-banner::before {
  content:""; display:block; flex:none; width:1rem; height:.75rem;
  background:conic-gradient(#24302c 0 25%,#fff3cb 0 50%,#24302c 0 75%,#fff3cb 0) 0 0/.5rem .5rem;
  border:1px solid #eee1b3;
}
#finish-banner {
  position:absolute; left:50%; bottom:5.5rem; transform:translateX(-50%);
  display:flex; align-items:center; justify-content:center; gap:.7rem;
  max-width:90%; padding:.60rem 1.17rem; white-space:nowrap; color:#17231a;
  background:#f3cb77; border:3px solid #fff0b6; box-shadow:0 4px #745b32,0 9px 29px #18231b99;
  text-align:center; font-size:clamp(1.12rem,3vw,1.85rem); font-weight:950;
}
#finish-banner::before { width:1.5rem; height:1.12rem; background-size:.75rem .75rem; border-color:#766143; }
#run-hud.finish-view .touch-controls, #run-hud.finish-view .instructions { visibility:hidden; }
