* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #eef6e6;
  color: #264d44;
  font-family: 'Microsoft YaHei', 'PingFang SC', 'Noto Sans SC', sans-serif;
}

#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

#stage {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
}

.mobile-ranks { display: none; }
.mobile-ranks[hidden] { display: none; }

#view {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  touch-action: manipulation;
}
#view.browsing { cursor: grab; touch-action: none; }
#view.browsing.dragging { cursor: grabbing; }
#browseControls {
  position: absolute; z-index: 4; top: 10px; right: 10px;
  display: flex; gap: 5px; padding: 5px; border-radius: 14px;
  background: rgba(255,253,244,.96); box-shadow: 0 3px 14px rgba(38,77,68,.14);
}
#browseControls[hidden] { display: none; }
#browseControls button { min-width: 40px; min-height: 44px; padding: 6px 10px; font-size: 13px; }
#browseControls :is(#browseIn,#browseOut) { font-size: 20px; padding: 4px 10px; }

.cheer-layer { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 2; }
.cheer-bubble { position: absolute; object-fit: contain; pointer-events: none; user-select: none; }
.cheer-bubble.pop { animation: cheer-pop 1.35s ease-out both; }
@keyframes cheer-pop {
  0% { opacity: 0; transform: scale(.7) rotate(var(--cheer-tilt)); }
  14% { opacity: 1; transform: scale(1.03) rotate(var(--cheer-tilt)); }
  30%, 75% { opacity: 1; transform: scale(1) rotate(var(--cheer-tilt)); }
  100% { opacity: 0; transform: translateY(-7px) scale(.96) rotate(var(--cheer-tilt)); }
}
@media (prefers-reduced-motion: reduce) {
  .cheer-bubble.pop { animation: none; transform: none; }
}

#banner {
  position: absolute;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  padding: 10px 22px;
  border-radius: 999px;
  background: rgba(255, 253, 244, 0.94);
  box-shadow: 0 6px 18px rgba(60, 110, 90, 0.15);
  font-weight: bold;
  font-size: 16px;
  pointer-events: none;
  transition: opacity 0.3s;
  white-space: nowrap;
}

#banner:empty {
  opacity: 0;
}

#finishHud {
  position: absolute; top: var(--finish-hud-top, 21%); left: var(--finish-hud-left, 50%); transform: translate(-50%, -50%);
  width: max-content; max-width: calc(100% - 28px); text-align: center; pointer-events: none;
}
#finishHud[hidden] { display: none; }
#finishTitle { white-space: nowrap; font: 900 clamp(21px, min(2.7vw, 4.4vh), 42px)/1.3 'Arial Rounded MT Bold', 'Microsoft YaHei', 'PingFang SC', sans-serif; letter-spacing: .055em; }
#finishTitle span { display: inline-block; color: var(--ink); transform: translateY(var(--lift)) rotate(var(--tilt)); }
.finish-arrivals { display: flex; justify-content: center; align-items: baseline; gap: .12em; margin-top: 8px; font: 900 clamp(34px, min(4.5vw, 6.8vh), 64px)/1 'Arial Rounded MT Bold', sans-serif; color: #786746; }
#finishTitle span, .finish-arrivals > * {
  -webkit-text-stroke: 3px #fffdf4;
  paint-order: stroke fill;
  text-shadow: 1px 1px 0 #fffdf4, -1px 1px 0 #fffdf4, 1px -1px 0 #fffdf4, -1px -1px 0 #fffdf4;
}
.finish-arrivals strong { display: inline-block; transform: rotate(-5deg); }
.finish-slash { color: #a5a68b; font-size: 1.1em; transform: rotate(8deg); }
#finishTotal { color: #949578; font-size: .7em; transform: translateY(.2em) rotate(3deg); }
@media (max-width: 760px) {
  #finishHud { top: 21%; left: 50%; transform: translateX(-50%); }
  #finishTitle { font-size: clamp(20px, 5.6vw, 30px); }
  .finish-arrivals { font-size: clamp(36px, 10vw, 52px); }
  #finishTitle span, .finish-arrivals > * { -webkit-text-stroke-width: 2px; }
}

#panel {
  width: 340px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: #fffdf4;
  border-left: 1px solid #dfeadb;
  overflow: hidden;
}

#panelDetails { display: flex; flex-direction: column; gap: 12px; min-height: 0; flex: 1; }
.mobile-bar { display: none; }
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

header h1 {
  margin: 0;
  font-size: 32px;
  letter-spacing: 0.5px;
  font-family: 'Arial Rounded MT Bold', 'Microsoft YaHei', sans-serif;
}

.game-logo {
  display: block;
  width: min(100%, 270px);
  height: auto;
  object-fit: contain;
}

.picker-logo {
  width: min(78%, 370px);
  margin: 0 auto 18px;
}

.sub {
  font-size: 13px;
  color: #5f8076;
}

.controls .row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

button,
select {
  font: inherit;
  font-size: 13px;
  border: 1px solid #cfe0cc;
  background: #f4faf0;
  color: #264d44;
  border-radius: 10px;
  padding: 5px 11px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #e6f3df;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

button.primary {
  background: #fc9025;
  border-color: #fc9025;
  color: #fff;
  font-weight: bold;
}

button.primary:hover:not(:disabled) {
  background: #f07c10;
}

.land-status {
  margin-top: 6px;
  padding: 4px 8px;
  border-radius: 8px;
  background: #fff4c7;
  color: #8a6400;
  font-size: 12px;
}

.land-status[hidden] {
  display: none;
}

.seed {
  cursor: pointer;
  text-decoration: underline dotted;
}

label {
  font-size: 13px;
}

.meta {
  font-size: 12px;
  color: #5f8076;
}

.clock {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  font-weight: bold;
  color: #264d44;
}

h2 {
  margin: 0 0 6px;
  font-size: 15px;
}

h2 small {
  font-weight: normal;
  font-size: 11px;
  color: #8aa39a;
}

#standings {
  list-style: none;
  margin: 0;
  padding: 0;
}

#standings li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}

#standings li:hover,
#standings li.follow {
  background: #eef6e6;
}

.pos {
  width: 18px;
  text-align: right;
  font-weight: bold;
  color: #8aa39a;
  font-variant-numeric: tabular-nums;
}

.pos.final {
  color: #264d44;
}

.chip {
  width: 24px;
  height: 24px;
  flex: none;
  object-fit: contain;
}

#standings li.me {
  background: #fff4c7;
}

.tag.me {
  background: #ffd640;
  color: #5a3d00;
  font-weight: bold;
}

#events li.me {
  background: #fffaf0;
}

#banner.big {
  font-size: 56px;
  padding: 6px 34px;
  top: 38%;
  color: #e0645e;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(38, 77, 68, 0.28);
  backdrop-filter: blur(2px);
}

.overlay[hidden] {
  display: none;
}

.picker-card {
  width: min(720px, 92%);
  padding: 26px 28px 20px;
  border-radius: 28px;
  background: #fffdf4;
  box-shadow: 0 18px 50px rgba(30, 70, 55, 0.25);
  text-align: center;
}

.picker-card h2 {
  font-size: 24px;
  margin-bottom: 6px;
}

.picker-card p {
  margin: 0 auto 16px;
  max-width: 560px;
  font-size: 13px;
  color: #5f8076;
  line-height: 1.6;
}

#pickGrid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 6px 10px;
  border-radius: 18px;
  border: 3px solid transparent;
  background: #f4faf0;
  transition: transform 0.12s, border-color 0.12s;
}

.pick > img, .pick > .portrait {
  width: 86px;
  height: 86px;
  object-fit: contain;
}

.pick:hover {
  transform: translateY(-3px);
}

.pick.on {
  border-color: var(--c);
  background: #fff;
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.1);
}

.pick-name {
  font-size: 14px;
}

.picker-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
}

.picker-actions button {
  font-size: 15px;
  padding: 8px 22px;
  border-radius: 14px;
}

.hint {
  margin-top: 10px;
  font-size: 11px;
  color: #8aa39a;
}

.name {
  width: 36px;
}

.status {
  flex: 1;
  color: #5f8076;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status b {
  color: #264d44;
  font-variant-numeric: tabular-nums;
}

.tag {
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 6px;
  background: #e8f4f7;
  color: #3c8aa0;
}

.tag.slow {
  background: #f0f2f5;
  color: #6f8196;
}

.tag.warn {
  background: #fff1dd;
  color: #b8771d;
}

.tag.secret {
  background: #ffe9c2;
  color: #c2620a;
}

.events {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#events {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  font-size: 12px;
}

#events li {
  display: flex;
  gap: 6px;
  align-items: baseline;
  padding: 3px 0;
  border-bottom: 1px dashed #edf2e8;
}

#events .t {
  width: 42px;
  flex: none;
  color: #8aa39a;
  font-variant-numeric: tabular-nums;
}

#events .chip {
  width: 18px;
  height: 18px;
  font-size: 10px;
  align-self: center;
}

#events li.rescue {
  color: #b8771d;
}

#events li.finish {
  font-weight: bold;
}

footer {
  font-size: 11px;
  color: #8aa39a;
}

/* ---- 结算：橙色山谷、蓝紫树丛与方形伙伴领奖台 ---- */
.result {
  --accent: #ff941e;
  --paper: #fffaf0;
  --ink: #294d53;
  position: fixed;
  inset: 0;
  padding: 16px;
  background: rgba(20, 47, 42, .58);
  backdrop-filter: blur(6px);
  z-index: 25;
}
.result-card {
  position: relative;
  width: min(700px, 100%);
  max-height: 96%;
  overflow-y: auto;
  padding: 0;
  border-radius: 28px;
  background: var(--paper);
  box-shadow: 0 22px 70px rgba(16, 40, 34, .35);
  text-align: center;
  animation: card-pop .4s ease-out both;
  scrollbar-width: thin;
  scrollbar-color: #8fad97 var(--paper);
}
@keyframes card-pop { from { transform: translateY(18px); opacity: 0; } }
.res-scene {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: 23px 24px 20px;
  color: var(--ink);
  background: #c7e4e7 url("assets/imagegen-v2/result-garden.png") center / cover no-repeat;
  border-radius: 28px 28px 0 0;
}
.res-eyebrow { font-size: 13px; color: #426671; letter-spacing: .4px; }
.result-card h2 {
  margin: 6px 0; font-size: 46px; line-height: 1.12; font-weight: 900;
  letter-spacing: 3px; font-family: 'Arial Rounded MT Bold', 'Microsoft YaHei', sans-serif;
  color: #294d53;
}
.result.win .result-card h2 { color: #b95813; }
.result.medal2 .result-card h2 { color: #405e86; }
.result.medal3 .result-card h2 { color: #a8562a; }
.res-sub { margin: 0; font-size: 14px; color: #426671; }
.res-sub b { font-variant-numeric: tabular-nums; color: #294d53; font-size: 17px; }
.podium {
  display: flex; justify-content: center; align-items: flex-end; gap: 14px;
  margin: 36px auto 0; min-height: 228px;
}
.step { width: 140px; min-width: 0; display: flex; flex-direction: column; align-items: center; }
.step .who { position: relative; width: 100%; height: 103px; display: flex; align-items: flex-end; justify-content: center; }
.step .who > :is(img, .portrait) {
  width: 90px; height: 90px; object-fit: contain; transform-origin: 50% 100%;
  filter: drop-shadow(0 3px 1px rgba(22, 54, 47, .2));
  animation: jelly 2.8s ease-in-out infinite;
}
.step.p1 .who > :is(img, .portrait) { width: 108px; height: 108px; }
.step.p2 .who > :is(img, .portrait) { animation-delay: .35s; }
.step.p3 .who > :is(img, .portrait) { animation-delay: .7s; }
@keyframes jelly { 0%, 70%, 100% { transform: scale(1); } 82% { transform: scale(1.04,.96); } 90% { transform: translateY(-5px) scale(.98,1.02); } }
.step .rays { display: none; }
.step .crown { position: absolute; top: -28px; left: 50%; width: 38px; margin-left: -19px; z-index: 1; }
.step .you {
  position: absolute; top: 4px; left: 2px; padding: 3px 8px; border-radius: 12px;
  background: #ffe08d; color: #504323; font-size: 12px; font-weight: bold; z-index: 2;
}
.result-sprite { display: block; position: relative; overflow: hidden; }
.result-sprite > span { position: absolute; display: block; background-size: 100% 100%; background-repeat: no-repeat; }
.mound { position: relative; width: min(100%, 104px); color: #663c27; font: 900 27px 'Arial Rounded MT Bold', sans-serif; }
.podium-art { width: 100%; }
.place-number { position: absolute; bottom: 9%; left: 0; right: 0; }
.p1 .mound { color: #fff5d9; }
.p2 .mound { color: #35421a; }
.p3 .mound { color: #663c27; }
.p3 .place-number { bottom: 4px; font-size: 22px; line-height: 1; }
.podium-label { width: 100%; margin-top: 10px; padding: 8px 3px; min-height: 49px; border-radius: 12px; background: #fff9e9; }
.step .nm { margin: 0; font-size: 14px; font-weight: bold; line-height: 1.3; color: #293c50; }
.step .tm { margin-top: 2px; font: 12px 'Microsoft YaHei', sans-serif; font-variant-numeric: tabular-nums; color: #293c50; }
.step.empty .who { color: #34475d; font-size: 12px; align-items: center; }
.step.empty .mound { opacity: .5; }
.res-body { padding: 18px 24px 16px; }
.res-award { margin: 0 0 14px; padding: 13px 16px; border-radius: 16px; background: #edf0e1; color: #365847; text-align: center; }
.res-award-label { font-size: 10px; letter-spacing: .16em; color: #637e66; }
.res-award h3 { margin: 5px 0 6px; font-size: clamp(21px, 5.6vw, 27px); line-height: 1.3; font-weight: 800; }
.res-award p { margin: 0 auto; max-width: 34em; font-size: 12px; line-height: 1.7; overflow-wrap: anywhere; }
.res-record { font-size: 11px; color: #59766a; line-height: 1.8; }
.res-record .new { margin-left: 6px; padding: 2px 6px; border-radius: 5px; background: #c76f48; color: #fff; font-weight: bold; }
.res-all { margin-top: 8px; font-size: 12px; text-align: left; }
.res-all summary { cursor: pointer; text-align: center; color: #496d5d; padding: 4px; }
#resList { columns: 2; margin: 9px 0 0; padding-left: 22px; line-height: 1.7; }
#resList li.me { font-weight: bold; color: #9b6428; }
.result-card .picker-actions { display: grid; grid-template-columns: 1.15fr 1fr 1fr 1fr; gap: 8px; margin-top: 14px; }
.result-card .picker-actions button { font-size: 14px; padding: 10px 5px; border-radius: 12px; background: transparent; border-color: #cdd8c9; color: var(--ink); }
.result-card .picker-actions .primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.result-card .picker-actions button:hover { background: #e3eadb; }
.result-card .picker-actions .primary:hover { background: #e97c15; }
.result-card .hint { font-size: 10px; color: #778d7e; }
.result-card button:focus-visible, .picker-card button:focus-visible { outline: 3px solid #dfa748; outline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
  .result-card,
  .result-card h2,
  .step .who > :is(img, .portrait),
  .step .rays,
  .step .crown,
  .mound {
    animation: none !important;
  }
}

@media (max-width: 760px) {
  .result-card h2 {
    font-size: 40px;
  }
  .step {
    width: 100px;
  }
  .podium {
    min-height: 200px;
  }
}

/* Both rosters share a portrait frame; the animal atlas is clipped without pixel extraction. */
.portrait { display: inline-block; position: relative; overflow: hidden; flex: none; vertical-align: middle; }
.atlas-image { position: absolute; display: block; background-size: 100% 100%; background-repeat: no-repeat; pointer-events: none; }
.skin-switch { display: inline-flex; padding: 4px; gap: 4px; margin: 0 0 18px; background: #eaf0df; border-radius: 24px; }
#pickGrid[data-skin="animals"] .pick { background: #eae8f2; }
#pickGrid[data-skin="animals"] .pick.on { background: #f7f1da; }
.skin-switch button { border: 0; border-radius: 20px; padding: 9px 25px; font-weight: bold; background: transparent; color: #67816d; }
.skin-switch button[aria-pressed="true"] { background: #426956; color: #fffdf4; }
.skin-switch button:focus-visible, .pick:focus-visible { outline: 3px solid #e4a932; outline-offset: 3px; }
#standings .name { width: 78px; flex: none; }
.picker-card { max-height: 94%; overflow-y: auto; }
@media (max-width: 760px) { #picker { position: fixed; z-index: 20; } .picker-card { padding: 20px 16px; } .picker-card h2 { font-size: 20px; } #pickGrid { gap: 5px; } .pick > img, .pick > .portrait { width: 76px; height: 76px; } .pick-name { font-size: 11px; } .skin-switch { margin-bottom: 14px; } }
@media (max-width: 420px) { .pick > img, .pick > .portrait { width: 48px; height: 48px; } }

@media (max-width: 480px) {
  .result { padding: 10px; }
  .res-scene { padding: 21px 10px 17px; }
  .result-card h2 { font-size: 38px; }
  .podium { gap: 9px; margin-top: 36px; }
  .step { width: 30%; }
  .step .who > :is(img, .portrait) { width: 72px; height: 72px; }
  .step.p1 .who > :is(img, .portrait) { width: 86px; height: 86px; }
  .step .who { height: 87px; }
  .step .crown { top: -26px; width: 33px; margin-left: -16px; }
  .step .you { left: -2px; font-size: 10px; }
  .step .nm { font-size: 12px; }
  .res-body { padding: 16px 14px; }
  .result-card .picker-actions { grid-template-columns: 1fr 1fr; }
  #resList { columns: 1; }
}

/* Follow pale animal silhouettes in selection, standings and on the podium. */
.portrait.pale, .step .who > .portrait.pale {
  filter: drop-shadow(1px 0 0 var(--edge)) drop-shadow(-1px 0 0 var(--edge)) drop-shadow(0 1px 0 var(--edge)) drop-shadow(0 -1px 0 var(--edge));
}

/* Phone layout keeps the race visible while standings unfold above the dock. */
@media (max-width: 760px), (max-width: 980px) and (max-height: 500px) {
  html, body { overflow: hidden; overscroll-behavior: none; }
  #app { flex-direction: column; padding-top: env(safe-area-inset-top); }
  .mobile-ranks {
    display: block; flex: none; height: 52px; padding: 4px 6px;
    background: #fffdf4; border-bottom: 1px solid #e0e9dc;
  }
  #mobileRankList {
    display: grid; grid-template-columns: repeat(8, minmax(0,1fr));
    gap: 2px; height: 43px; margin: 0; padding: 0; list-style: none;
  }
  #mobileRankList li {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 1px; min-width: 0; padding: 2px 0; border: 1px solid transparent;
    border-radius: 8px; color: #607c71;
  }
  #mobileRankList li.me { background: #ffe3ae; border-color: #efb448; color: #694d20; }
  #mobileRankList .rank-portrait { display: block; width: 24px; height: 24px; object-fit: contain; flex: none; }
  #mobileRankList .rank-number { font-size: 10px; line-height: 11px; font-weight: bold; font-variant-numeric: tabular-nums; }
  #stage { flex: 1; margin-bottom: calc(66px + env(safe-area-inset-bottom)); }
  #panel {
    position: fixed; z-index: 10; inset: auto 0 0; width: 100%; height: auto;
    max-height: 68dvh; padding: 0 12px env(safe-area-inset-bottom);
    border: 0; border-top: 1px solid #dfeadb; border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 20px rgba(38,77,68,.08); gap: 0;
  }
  .mobile-bar { display: flex; align-items: center; gap: 8px; min-height: 66px; }
  .mobile-bar img { width: 80px; height: auto; flex: none; }
  #mobileSummary { flex: 1; min-width: 0; font-size: 11px; line-height: 1.5; }
  .mobile-bar button { min-height: 44px; padding: 9px 12px; font-size: 12px; flex: none; }
  #panelDetails { display: none; overflow-y: auto; padding-bottom: 12px; }
  #panel.expanded #panelDetails { display: flex; }
  #panelDetails header { display: none; }
  .controls button { min-height: 44px; }
  .controls .row { margin: 0; }
  .controls { display: flex; flex-wrap: wrap; gap: 6px; }
  #standings li { min-height: 44px; }
  #standings { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
  #standings .name { width: auto; flex: 1; font-size: 11px; }
  #standings .status { display: none; }
  #standings .chip { width: 28px; height: 28px; }
  .events { flex: none; }
  #events { max-height: 110px; min-height: 0; }
  #banner { width: max-content; max-width: calc(100% - 24px); white-space: nowrap; text-align: center; font-size: 13px; padding: 9px 15px; top: 12px; }
  #banner.big { font-size: clamp(32px, 10vw, 46px); padding: 6px 22px; }
  #picker { position: fixed; z-index: 20; padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); }
  .picker-card { width: min(640px,100%); max-height: 100%; padding: 20px 14px; border-radius: 24px; }
  .picker-logo { width: min(78%,280px); margin-bottom: 12px; }
  .picker-card h2 { font-size: 19px; }
  .picker-card p { font-size: 12px; margin-bottom: 12px; }
  #pickGrid { gap: 6px; }
  .pick { min-height: 92px; padding: 9px 2px; }
  .pick > img, .pick > .portrait { width: 58px; height: 58px; }
  .pick-name { font-size: 11px; }
  .skin-switch { margin-bottom: 12px; }
  .skin-switch button { min-height: 44px; }
  .picker-actions { gap: 8px; margin-top: 14px; }
  .picker-actions button { min-height: 44px; font-size: 13px; padding: 10px 14px; }
  .result { padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom)); }
  .result-card { max-height: 100%; }
}

@media (max-width: 360px) {
  .mobile-bar img { width: 65px; }
  .mobile-bar button { padding: 9px 8px; }
  .pick > img, .pick > .portrait { width: 48px; height: 48px; }
  .picker-card h2 { font-size: 17px; }
}
