* { box-sizing: border-box; }
:root { font-family: system-ui, sans-serif; color-scheme: light; color: #542d19; background: #173f40; }
body { margin: 0; }
[hidden] { display: none !important; }
.spring {
  --water: #49aba3;
  --scene: url("spring.webp");
  --wood: repeating-linear-gradient(176deg, #96512e, #ad6138 11px, #9d522e 15px);
  --ceramic: linear-gradient(#fff5de, #f2c996);
  --orange: linear-gradient(#ffc24e, #e76e0c);
  width: min(100%, 640px);
  height: 100vh;
  height: 100dvh;
  margin: auto;
  display: flex;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 0 max(14px, env(safe-area-inset-bottom));
  overflow: hidden;
  background: var(--water) var(--scene) center / cover no-repeat;
}
.spring[data-scene="home"] {
  --scene: url("home-pool-plate.webp");
  width: min(100%, 560px, max(320px, 56dvh));
  background-size: 100% 100%;
}
.spring[data-scene="yuzu"] { --water: #65beb1; --scene: url("yuzu.webp"); }
.spring[data-scene="maple"] { --water: #3cafa3; --scene: url("maple.webp"); }
header { text-align: center; flex-shrink: 0; padding: 4px 0 7px; }
h1, h2 {
  margin: 0;
  color: #fff0cb;
  padding: 7px 21px 9px;
  border: 2px solid #de9b5f;
  border-radius: 24px;
  background: repeating-linear-gradient(176deg, #96512e, #ad6138 11px, #9d522e 15px);
  box-shadow: 0 4px 0 #67351c, 0 5px 14px #163b3e55;
  text-shadow: 0 2px #683819;
}
h1 { display: inline-block; font-size: clamp(1.7rem, 8vw, 2.6rem); letter-spacing: .04em; }
#home, #game { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.stage-line { display: flex; align-items: center; justify-content: space-between; gap: 5px; padding: 0 8px; }
.stage { display: grid; text-align: center; padding: 3px 8px; border-radius: 18px; background: #ffebc4; }
.stage span { font-size: .8rem; }
.stage-line button { padding-inline: 8px; }
#pool {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 3px 5%;
  overflow: visible;
  direction: ltr;
}
.cap, .rock { position: absolute; }
button.cap {
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  display: grid;
  place-items: center;
  -webkit-tap-highlight-color: transparent;
  z-index: 1;
}
.cap-art {
  width: var(--sprite-width);
  height: var(--sprite-height);
  position: absolute;
  transform: rotate(var(--heading));
  pointer-events: none;
  filter: drop-shadow(0 3px 3px #103d4370);
}
.cap.selected { outline: 3px solid #ffe4a1; outline-offset: -1px; }
.cap:active .cap-art { filter: drop-shadow(0 0 3px #ffec9c) drop-shadow(0 2px 3px #103d4370); }
.rock {
  border: 2px solid #77905b;
  border-radius: 42% 55% 45% 39%;
  background: radial-gradient(ellipse at 28% 24%, #9eb36f 6%, #748d52 31%, #76746b 48%, #4b5d50 80%);
  box-shadow: 0 4px 6px #1b514baa;
}
.route { position: absolute; width: var(--length); height: 3px; transform: rotate(var(--angle)); transform-origin: left center; background: repeating-linear-gradient(90deg, #fff3ae 0 7px, transparent 7px 12px); z-index: 2; pointer-events: none; }
footer { padding: 0 10px; }
#status {
  display: grid;
  place-items: center;
  width: fit-content;
  min-height: calc(2lh + 6px);
  margin: 0 auto 7px;
  padding: 3px 9px;
  border-radius: 20px;
  background: #eafff6ed;
  color: #143c35;
  text-align: center;
  font-size: .875rem;
  font-weight: 700;
  line-height: 1.25;
}
.tools { display: flex; justify-content: space-between; gap: 8px; margin: auto; width: min(89%, 300px); }
button {
  font: inherit;
  font-weight: 800;
  color: inherit;
  min-height: 44px;
  padding: 4px 12px 6px;
  border: 2px solid #ffebc7;
  border-radius: 18px 22px 17px 21px;
  background: linear-gradient(#fff0cc, #edc091);
  box-shadow: 0 3px #9c613b, 0 4px 7px #16393444;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #242f26; outline-offset: 2px; }
button.primary, button[aria-pressed="true"] { background: linear-gradient(#ffbe58, #ef832d); color: #4a2410; }
button:disabled { cursor: default; opacity: .72; }
dialog {
  color: #542d19;
  width: min(89%, 380px);
  max-height: 90dvh;
  background: #fff0d0;
  border: 3px solid #d4955a;
  border-radius: 25px;
  text-align: center;
  padding: 15px 15px 20px;
}
dialog::backdrop { background: #092d30ae; }
dialog h2 { margin: 0 0 15px; font-size: 1.45rem; }
dialog p { margin: 10px 0; }
dialog button { width: 100%; margin-top: 8px; }
dialog input, dialog select { font: inherit; color: inherit; max-width: 100%; border: 1px solid #b2784a; background: #fffaf1; border-radius: 9px; min-height: 42px; padding: 4px 8px; }
dialog input { width: 100%; }
#copy-status { min-height: 1lh; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stats div { background: #f8dcb0; padding: 8px; border-radius: 12px; }
.stats strong { display: block; font-size: 1.3rem; }
#record { color: #86511b; font-weight: 800; }
table { border-collapse: collapse; width: 100%; background: #fbe2bb; font-variant-numeric: tabular-nums; }
th, td { padding: 5px 3px; }
tr { border-bottom: 1px solid #d7a575; }
thead, tbody tr:first-child { background: #f6cb90; }
.tools button {
  display: grid;
  justify-items: center;
  width: clamp(60px, 18vw, 74px);
  min-height: 0;
  padding: 2px 3px 5px;
  font-size: .875rem;
  line-height: 1.05;
  border: 3px solid #fff4d6;
  border-radius: 17px;
  background: linear-gradient(#ffdc88, #e9a454);
  box-shadow: inset 0 0 0 2px #bb783f, 0 3px #834f31, 0 5px 9px #183f4655;
}
.tools button[aria-pressed="true"] {
  background: linear-gradient(#ffd587, #f08439);
  outline: 2px solid #783d20;
  outline-offset: 2px;
}
.tool-art {
  width: clamp(44px, 14vw, 56px);
  aspect-ratio: 1;
  background: url("tool-capybaras.png") 0 center / 300% 100% no-repeat;
  pointer-events: none;
}
#shuffle .tool-art { background-position-x: 50%; }
#flip .tool-art { background-position-x: 100%; }
@media (max-height: 600px) {
  .tool-art { width: 44px; }
}

header { position: relative; padding-right: 66px; padding-left: 6px; }
#sound {
  position: absolute;
  right: 6px;
  bottom: 8px;
  padding-inline: 5px;
  font-size: .78rem;
}
.water-effect { position: absolute; pointer-events: none; z-index: 2; }
.wake {
  width: 33px; height: 26px; border-radius: 50%;
  border: 2px solid #d8ffffbe; border-right-color: transparent;
  box-shadow: -5px 0 0 -2px #b8ffff9c;
}
.splash {
  width: 29px; height: 33px;
  background:
    radial-gradient(ellipse at 48% 49%, #e9ffff 0 10%, transparent 14%),
    radial-gradient(ellipse at 62% 18%, #f6ffff 0 8%, transparent 12%),
    radial-gradient(ellipse at 68% 80%, #caffff 0 9%, transparent 13%),
    radial-gradient(ellipse at 88% 46%, #e9ffff 0 6%, transparent 10%);
}

@media (prefers-reduced-motion: no-preference) {
  .cap:not(.is-moving, .selected) .cap-art {
    animation: cap-float 3.2s ease-in-out var(--float-delay, 0s) infinite;
  }
}
@keyframes cap-float {
  0%, 100% { translate: 0 1px; }
  50% { translate: 0 -1.5px; }
}
/* Pool-edge decoration sits behind the playable board. */
.spring { position: relative; isolation: isolate; }
.scene-motion { position: absolute; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.scene-motion > div { position: absolute; inset: 0; display: none; }
.scene-motion i { position: absolute; display: block; }
@media (prefers-reduced-motion: no-preference) {
  [data-scene="sakura"] .petals,
  [data-scene="yuzu"] .inlet-ripples,
  [data-scene="maple"] .lantern-reflections { display: block; }

  .petals i {
    left: 5%; top: 16%; width: 9px; height: 6px;
    border-radius: 78% 22% 65% 35%;
    background: linear-gradient(145deg, #fff0ea, #f8a9bd);
    animation: petal-drift 15s linear infinite;
  }
  .petals i:nth-child(2) { left: auto; right: 6%; top: 26%; animation-delay: -6s; animation-direction: reverse; }
  .petals i:nth-child(3) { left: 8%; top: 62%; width: 7px; animation-delay: -10s; }

  .inlet-ripples i {
    right: 10%; top: 12%; width: 23px; height: 10px;
    border: 1px solid #dafff4;
    border-radius: 50%;
    animation: inlet-flow 4.5s ease-out infinite;
  }
  .inlet-ripples i:nth-child(2) { animation-delay: -1.5s; }
  .inlet-ripples i:nth-child(3) { animation-delay: -3s; }

  .lantern-reflections i {
    left: 9%; top: 16%; width: 34px; height: 62px;
    background: repeating-linear-gradient(0deg, transparent 0 4px, #ffce78 5px 6px, transparent 8px 10px);
    mask-image: radial-gradient(ellipse, #000 6%, transparent 70%);
    animation: lantern-sway 5.5s ease-in-out infinite alternate;
  }
  .lantern-reflections i:nth-child(2) { left: auto; right: 7%; top: 15%; animation-delay: -2.5s; }
}
@keyframes petal-drift {
  0% { opacity: 0; transform: translate(0, 0) rotate(-24deg); }
  16%, 76% { opacity: .55; }
  55% { transform: translate(8px, 36px) rotate(38deg); }
  100% { opacity: 0; transform: translate(-4px, 75px) rotate(105deg); }
}
@keyframes inlet-flow {
  0% { opacity: .52; transform: scale(.55); }
  100% { opacity: 0; transform: translate(-11px, 11px) scale(2.1); }
}
@keyframes lantern-sway {
  from { opacity: .17; transform: skewX(-7deg) scaleX(.82); }
  to { opacity: .38; transform: translateX(4px) skewX(6deg) scaleX(1.08); }
}

/* Warm wood, ceramic and moss use the same palette as the springs. */
header h1 {
  position: relative;
  border-radius: 27% 24% 21% 23% / 42%;
  padding-inline: 26px;
  border-color: #e6aa69;
  box-shadow: inset 0 0 0 2px #b97649, 0 4px #67351c, 0 6px 12px #173b3e55;
}
header h1::before, header h1::after {
  content: "";
  position: absolute;
  top: 48%; width: 5px; height: 5px;
  border-radius: 50%;
  background: #f1c18a;
  box-shadow: 0 1px #683819;
}
header h1::before { left: 11px; }
header h1::after { right: 11px; }
.stage-line { margin: 4px 4px 0; }
.stage {
  border: 1px solid #ffe7ba;
  border-radius: 24px;
  background: linear-gradient(#fff5dc, #f3d2a1);
  padding: 4px 12px;
  box-shadow: 0 2px #b5764d, 0 3px 9px #245a5347;
}
.stage span { color: #704732; }
.stage-line button, #sound {
  border-radius: 999px;
  background: linear-gradient(160deg, #fff5de, #f3d2a5 80%);
}
#home-back::before, #reset::before, #sound::before {
  display: inline-block;
  margin-right: 3px;
  color: #875035;
  font-size: .95em;
}
#home-back::before { content: '⌂'; }
#reset::before { content: '↻'; }
#sound::before { content: '♫'; }
#sound[aria-pressed="false"]::before { opacity: .48; }
.cap img { filter: drop-shadow(0 3px 3px #113d4e82) drop-shadow(0 0 2px #dbfff883); }
.rock {
  border: 0;
  border-radius: 0;
  background: url("moss-rock.png") center / 100% 100% no-repeat;
  box-shadow: none;
  filter: drop-shadow(0 3px 3px #123d4e80);
}
.tools {
  padding: 5px 13px;
  border: 1px solid #e7fff389;
  border-radius: 28px;
  background: #d8fff149;
  box-shadow: inset 0 1px #f1fffa7a;
}
.tools button {
  border-radius: 22% 30% 23% 27%;
  border-color: #fff3d1;
  background: radial-gradient(ellipse at 35% 15%, #ffe8ac, #f7c476 72%);
  box-shadow: inset 0 0 0 2px #ca8a52, 0 3px #955938, 0 4px 6px #244d4959;
}
.tools button[aria-pressed="true"] { background: linear-gradient(#ffe296, #ffa65b); }
button:active:not(:disabled, .cap) { translate: 0 1px; }
@media (max-width: 360px) {
  .stage-line { margin-inline: 0; padding-inline: 5px; }
  .stage-line button { padding-inline: 5px; }
}

.tools button {
  position: relative;
  isolation: isolate;
  border-color: #fff9e8;
  background: radial-gradient(ellipse at 46% 29%, #fff6ce 1%, #ffd889 72%);
}
.tools button:nth-child(2) {
  background: radial-gradient(ellipse at 46% 29%, #fff6d5 1%, #ffd29d 75%);
}
.tools button:nth-child(3) {
  background: radial-gradient(ellipse at 46% 29%, #fff4da 1%, #f9c7a0 75%);
}
.tools button::before {
  content: "";
  position: absolute;
  inset: 5px 6px 17px;
  z-index: -1;
  border-radius: 40% 44% 42% 47%;
  background: radial-gradient(ellipse, #fff7d8ad, transparent 72%);
  pointer-events: none;
}
.tool-art {
  transform: translateY(-1px) scale(1.23);
  filter: drop-shadow(0 1px 0 #fff8dd) drop-shadow(0 2px 1px #a75e2844);
}
.tool-label {
  position: relative;
  z-index: 1;
  padding-inline: 5px;
  border-radius: 999px;
  background: #fff3d3;
  color: #6e371f;
  box-shadow: 0 1px #dd9d6660;
  overflow-wrap: anywhere;
  text-wrap: balance;
}
.tools button[aria-pressed="true"] {
  background: radial-gradient(ellipse at 45% 30%, #fff0b8, #ffab64 75%);
}

.cap-art img { display: block; width: 100%; height: 100%; object-fit: fill; }
/* Match the centers of the two eyes baked into the sprite. */
.cap-art[data-skin="capybara"]::before, .cap-art[data-skin="capybara"]::after {
  content: "";
  position: absolute;
  z-index: 1;
  left: 67.61%;
  width: var(--eye-size);
  height: var(--eye-size);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #392014 radial-gradient(circle at 38% 37%, #ffe3ba 0 14%, transparent 22%);
}
.cap-art[data-skin="capybara"]::before { top: 30.55%; }
.cap-art[data-skin="capybara"]::after { top: calc(30.55% + var(--eye-spacing)); }

header { padding-inline: 67px; }
header h1 { padding-inline: 14px; font-size: clamp(1.35rem, 6.9vw, 2.6rem); }
header h1::before { left: 5px; }
header h1::after { right: 5px; }
#skins {
  position: absolute;
  left: 6px;
  bottom: 8px;
  min-height: 44px;
  padding-inline: 5px;
  font-size: .78rem;
  border-radius: 999px;
  background: linear-gradient(160deg, #fff5de, #f3d2a5 80%);
}
.cap-art:not([data-skin="capybara"]) img { object-fit: contain; }

#home-ranking { display: none; }
.spring[data-scene="home"] header,
.spring[data-scene="home"] #home { position: static; padding: 0; }

.spring[data-scene="home"] .home-art-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Position the independent artwork on the same grid as the approved mockup. */
.spring[data-scene="home"] h1,
.spring[data-scene="home"] :is(#home-ranking, #sound, #start, #skins, #level-select, #invite) {
  position: absolute;
  top: var(--home-top);
  left: var(--home-left);
  right: auto;
  bottom: auto;
  width: var(--home-width);
  height: var(--home-height);
  min-height: 0;
  display: block;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--home-image) center / 100% 100% no-repeat;
  box-shadow: none;
  filter: drop-shadow(0 4px 4px #16494065);
}
.spring[data-scene="home"] :is(#home-ranking, #sound, #start, #skins, #level-select, #invite) { min-height: 44px; }
.spring[data-scene="home"] :is(h1, #sound)::before,
.spring[data-scene="home"] h1::after { content: none; }
.spring[data-scene="home"] #sound[aria-pressed="false"] {
  filter: grayscale(.9) brightness(.86) drop-shadow(0 4px 4px #16494065);
}
.spring[data-scene="home"] button:focus-visible {
  outline: 3px solid #fff4c1;
  outline-offset: 3px;
}

.spring[data-scene="home"] h1 {
  --home-image: url("home-title-art.png");
  --home-left: 13.3919%;
  --home-top: max(10.8671%, calc(4.3931dvh + 51px));
  --home-width: 73.1065%;
  --home-height: 10.6936%;
}

.spring[data-scene="home"] #home-ranking {
  --home-image: url("home-ranking-art.png");
  --home-left: 5.7080%;
  --home-top: 4.3931%;
  --home-width: 23.9297%;
  --home-height: 4.3931%;
}

.spring[data-scene="home"] #sound {
  --home-image: url("home-sound-art.png");
  --home-left: 69.1548%;
  --home-top: 4.3931%;
  --home-width: 25.6861%;
  --home-height: 4.3931%;
}

.spring[data-scene="home"] #start {
  --home-image: url("home-start-art.png");
  --home-left: 3.9517%;
  --home-top: 65.8960%;
  --home-width: 91.6575%;
  --home-height: 17.3988%;
}

.spring[data-scene="home"] #skins {
  --home-image: url("home-skins-art.png");
  --home-left: 6.0373%;
  --home-top: 86.1272%;
  --home-width: 21.9539%;
  --home-height: 4.5665%;
}

.spring[data-scene="home"] #level-select {
  --home-image: url("home-levels-art.png");
  --home-left: 30.7355%;
  --home-top: 84.9133%;
  --home-width: 38.7486%;
  --home-height: 7.3410%;
}

.spring[data-scene="home"] #invite {
  --home-image: url("home-invite-art.png");
  --home-left: 71.7892%;
  --home-top: 86.1272%;
  --home-width: 22.2832%;
  --home-height: 4.5665%;
}

/* Keep small controls easy to tap at the shortest phone sizes. */
.spring[data-scene="home"] :is(#home-ranking, #sound, #skins, #invite)::after {
  content: "";
  position: absolute;
  inset: 50% 0 auto;
  height: max(100%, 44px);
  transform: translateY(-50%);
}

.language-picker { display: none; }
.spring[data-scene="home"] .language-picker {
  position: absolute;
  inset: 4.3931% 32% auto;
  display: grid;
}
.language-picker > span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.language-picker select {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 4px 6px;
  padding-inline-end: 19px;
  border: 1px solid #fff1d2;
  border-radius: 999px;
  color: #633518;
  background: var(--ceramic);
  box-shadow: 0 2px #ac6d43, 0 3px 7px #16393444;
  font: 700 1rem/1.15 system-ui, sans-serif;
  text-align: center;
}
.language-picker::after {
  content: "";
  position: absolute;
  inset-block-start: calc(50% - 5px);
  inset-inline-end: 9px;
  width: 6px;
  height: 6px;
  border: solid #885335;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  pointer-events: none;
}

/* Home dialogs share the carved wood and ceramic assets from the approved mockups. */
.spa-dialog[open] {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 9px;
  width: min(calc(100% - 34px), 364px);
  max-height: min(86dvh, 720px);
  padding: 8px 14px 15px;
  overflow: auto;
  color: #5b321b;
  border: 3px solid #f9d398;
  border-radius: 30px;
  background: radial-gradient(ellipse at 48% 2%, #fff7e5, #ffe9c7 75%, #f7ca92);
  box-shadow: inset 0 0 0 3px #fff1d8, inset 0 -6px #e7b58265, 0 6px #987051, 0 12px 26px #102b2a75;
  scrollbar-width: thin;
  scrollbar-color: #c98b57 transparent;
}
.spa-dialog::backdrop { background: #14242199; }
.spa-dialog .spa-title {
  position: relative;
  flex: 0 0 auto;
  margin: 0;
  padding: 0;
  width: 100%;
  height: clamp(62px, 18vw, 82px);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: var(--spa-title-art) center / contain no-repeat;
  filter: drop-shadow(0 3px 2px #66381730);
}
#level-dialog { --spa-title-art: url("dialog-art/title-levels.png"); }
#ranking { --spa-title-art: url("dialog-art/title-ranking.png"); }
#skin-dialog { --spa-title-art: url("dialog-art/title-skins.png"); }
#invite-dialog { --spa-title-art: url("dialog-art/title-invite.png"); }
.spa-art-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.spa-dialog .spa-actions { flex: 0 0 auto; text-align: center; }
.spa-dialog :is(.spa-return, .spa-close, .spa-copy) {
  position: relative;
  margin: 0 auto;
  border: 0;
  border-radius: 999px;
  background: var(--spa-button-art) center / 100% 100% no-repeat;
  box-shadow: none;
  filter: drop-shadow(0 2px 2px #9b66495a);
}
.spa-dialog .spa-return {
  --spa-button-art: url("dialog-art/return.png");
  width: min(56%, 170px);
  height: 47px;
}
.spa-dialog .spa-close {
  --spa-button-art: url("dialog-art/close.png");
  width: min(51%, 152px);
  height: 46px;
}
.spa-dialog .spa-copy {
  --spa-button-art: url("dialog-art/copy.png");
  width: min(100%, 278px);
  flex: 0 0 auto;
  height: clamp(50px, 16vw, 64px);
}
#level-list {
  min-height: 0;
  overflow-y: auto;
  padding: 3px 6px 7px 3px;
  scrollbar-width: thin;
  scrollbar-color: #ce8b50 transparent;
}
#level-list:focus-visible { outline: 2px solid #86512e; outline-offset: 1px; }
#level-dialog h3 {
  --scene-art: url("dialog-art/scene-sakura.png");
  --scene-art-size: contain;
  margin: 10px 0 6px;
  min-height: 43px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 2px 9px;
  color: #683d21;
  border-radius: 15px;
  background: linear-gradient(95deg, #ffdfaa, #fff0d3);
  text-align: start;
  font-size: 1rem;
}
#level-dialog h3:first-child { margin-top: 0; }
#level-dialog h3[data-theme="yuzu"] { --scene-art: url("dialog-art/scene-yuzu.png"); }
#level-dialog h3[data-theme="maple"] { --scene-art: url("home-actions.png"); --scene-art-size: 200% 100%; }
#level-dialog h3::before {
  content: "";
  width: 60px;
  height: 33px;
  flex: 0 0 auto;
  background: var(--scene-art) left center / var(--scene-art-size) no-repeat;
  mask-image: radial-gradient(ellipse 70% 80%, black 58%, transparent 100%);
}
.level-grid { display: flex; flex-direction: column; gap: 6px; }
.level-grid button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  margin: 0;
  padding: 5px 9px;
  font-size: .91rem;
  text-align: start;
  border-radius: 14px;
  border: 1px solid #ecc596;
  background: linear-gradient(#fff6e2, #f2d5ae);
  box-shadow: inset 0 1px #fff9eb, 0 2px #d1a575;
}
.level-grid strong { min-width: 0; overflow-wrap: anywhere; }
.level-grid span { flex: 0 0 auto; font-size: .75rem; color: #774b2e; }
.level-grid [data-state="zero"] { background: linear-gradient(#fff4c4, #f9dfa0); }
.level-grid [data-state="continue"] {
  background: linear-gradient(#fff2b6, #f7cc72);
  border-color: #dfa747;
}
.level-grid [data-state="continue"] span {
  padding: 3px 7px;
  border-radius: 999px;
  color: #512809;
  background: #ffbf60;
  box-shadow: inset 0 1px #ffedae, 0 1px #d59042;
}
.level-grid [data-state="locked"] {
  opacity: 1;
  color: #745d48;
  background: #f3e2ca;
  box-shadow: inset 0 1px #fff3df;
}
.level-grid [data-state="locked"] span::after { content: " · 🔒"; }
#ranking-level, #ranking-layout {
  flex: 0 0 auto;
  min-height: 44px;
  margin-inline: auto;
  width: min(100%, 266px);
  padding-inline: 12px;
  border-radius: 16px;
  border: 1px solid #d7a367;
  background: #fff3dc;
  box-shadow: inset 0 0 0 2px #fff8e7, 0 2px #dbaf7d;
  text-align: center;
  font-weight: 750;
}
.spa-dialog .spa-note { margin: 0; color: #785137; font-size: .82rem; }
.spa-rank-table {
  min-height: 52px;
  overflow: auto;
  border: 1px solid #e8bf8c;
  border-radius: 15px;
  background: #fff2dc;
  box-shadow: 0 2px 4px #b6824b40;
}
.spa-rank-table table { width: 100%; background: transparent; }
.spa-rank-table th, .spa-rank-table td { padding: 8px 4px; font-size: .9rem; }
.spa-rank-table thead { background: #f6d5aa; }
.spa-rank-table tbody tr:first-child { color: #673213; background: #ffd198; font-weight: 800; }
.spa-rank-table tr:last-child { border-bottom: 0; }
#skin-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  overflow: auto;
  padding: 3px 2px 6px;
}
#skin-list button {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 1px;
  margin: 0;
  padding: 6px 4px 7px;
  color: #643719;
  border: 2px solid #f7dab2;
  border-radius: 18px;
  background: linear-gradient(#fff5de, #f5dbb6);
  box-shadow: inset 0 0 0 2px #fff6e2, 0 3px #c59565;
}
#skin-list img {
  display: block;
  width: min(100%, 122px);
  height: clamp(54px, 19vw, 84px);
  object-fit: contain;
  mask-image: radial-gradient(ellipse 68% 70% at 50% 60%, black 58%, transparent 96%);
}
#skin-list button span {
  padding: 2px 12px;
  border-radius: 999px;
  background: #fff1d5;
  overflow-wrap: anywhere;
  text-wrap: balance;
}
#skin-list button[aria-pressed="true"] {
  border-color: #e79b32;
  background: linear-gradient(#fff0b8, #ffd184);
  box-shadow: inset 0 0 0 2px #fff0bd, 0 3px #bc7c36;
}
#skin-list button[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 20px;
  height: 20px;
  border: 1px solid #fff2cc;
  border-radius: 50%;
  background: #ae5017;
}
#skin-list button[aria-pressed="true"]::before {
  content: "";
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 1;
  width: 5px;
  height: 9px;
  border: solid #fff9e9;
  border-width: 0 2px 2px 0;
  transform: rotate(43deg);
}
#scores tr:first-child td:first-child::before {
  content: "";
  display: inline-block;
  vertical-align: middle;
  width: 20px;
  height: 20px;
  margin-right: 2px;
  background: url("home-utility-icons.png") left center / 400% 100% no-repeat;
}
.spa-invite-art {
  align-self: center;
  display: block;
  width: min(100%, 270px);
  aspect-ratio: 271 / 132;
  object-fit: contain;
  mask-image: radial-gradient(ellipse 65% 74% at 50% 51%, black 65%, transparent 100%);
}
.spa-dialog .spa-invite-note { margin: 0; font-weight: 750; }
.spa-link {
  display: flex;
  align-items: center;
  padding: 3px 6px 3px 9px;
  border: 1px solid #dca977;
  border-radius: 15px;
  background: #ffe6bf;
  box-shadow: inset 0 1px #fff4dc;
}
.spa-link label { flex: 0 0 auto; font-size: .82rem; font-weight: 750; }
.spa-dialog .spa-link input {
  min-width: 0;
  min-height: 35px;
  margin-inline-start: 7px;
  padding-inline-start: 7px;
  border: 0;
  border-inline-start: 1px solid #dca977;
  border-radius: 0;
  background: transparent;
  font-size: .87rem;
  direction: ltr;
}
.spa-dialog #copy-status { margin: 0; min-height: 0; font-size: .82rem; }
.spa-dialog #copy-status:empty { display: none; }

#result { --spa-title-art: url("dialog-art/title-result.png"); }
.spa-result-hero {
  display: block;
  align-self: center;
  flex: 0 0 auto;
  width: min(100%, 278px);
  height: auto;
  max-height: 19dvh;
  object-fit: contain;
  mask-image: radial-gradient(ellipse 68% 76% at 50% 55%, black 60%, transparent 100%);
}
.spa-dialog #result-level, .spa-dialog #result-final-label {
  width: fit-content;
  max-width: 100%;
  align-self: center;
  margin: 0;
  padding: 4px 12px;
  color: #653914;
  border: 1px solid #e9bb73;
  border-radius: 999px;
  background: #fff1cd;
  box-shadow: inset 0 0 0 2px #fff9e3, 0 2px #d9ad71;
  font-weight: 800;
}
#result .stats {
  gap: 0;
  padding: 5px 6px;
  border: 1px solid #ecd0a5;
  border-radius: 15px;
  background: linear-gradient(#fff0d5, #ffe6c3);
  box-shadow: inset 0 1px #fff9e9, 0 2px #dbb58a;
}
#result .stats div {
  padding: 3px 6px 4px;
  border-radius: 0;
  background: transparent;
  font-size: .84rem;
  font-weight: 750;
}
#result .stats div + div { border-inline-start: 1px solid #e6bb8c; }
#result .stats strong {
  margin: 3px 0 0;
  border-radius: 10px;
  color: #5a2a0c;
  background: #ffd3a1;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}
#result-awards {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
}
.spa-result-badge {
  position: relative;
  display: inline-block;
  width: min(46%, 146px);
  height: clamp(30px, 9.3vw, 38px);
  background: var(--spa-badge) center / contain no-repeat;
}
#result-zero { --spa-badge: url("dialog-art/result-zero.png"); }
#result-best { --spa-badge: url("dialog-art/result-record.png"); }
.spa-dialog #record { margin: 0; font-size: .78rem; }
.spa-dialog #record:empty { display: none; }
.spa-dialog .spa-result-button {
  position: relative;
  flex: 0 0 auto;
  align-self: center;
  margin: 0;
  border: 0;
  border-radius: 999px;
  background: var(--spa-button-art) center / contain no-repeat;
  box-shadow: none;
  filter: drop-shadow(0 3px 2px #9b66495a);
}
#result #next {
  --spa-button-art: url("dialog-art/result-next.png");
  width: min(100%, 284px);
  height: clamp(48px, 16vw, 62px);
  padding: 0;
  border-radius: 999px;
  background: var(--spa-button-art) center / contain no-repeat;
}
#result #next[data-final="true"] { --spa-button-art: url("dialog-art/result-home.png"); }
#result #result-ranking {
  --spa-button-art: url("dialog-art/result-ranking.png");
  width: min(70%, 184px);
  height: 46px;
}

.tool-remaining {
  position: absolute;
  top: -4px;
  inset-inline-end: -4px;
  display: grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding-inline: 2px;
  color: #fff9e6;
  border: 1px solid #ffdf8d;
  border-radius: 999px;
  background: #aa451d;
  box-shadow: 0 1px 2px #63331b60;
  font: 800 .69rem/1 system-ui, sans-serif;
}
.tools [data-spent="true"] { filter: grayscale(.7); }

#status[data-stuck="true"] {
  background: #fff0ca;
  color: #74351f;
  box-shadow: inset 0 0 0 1px #e0a768;
}

/* The level toolbar uses the same cut-out artwork as the approved home screen. */
.spring:not([data-scene="home"]) header {
  display: grid;
  justify-items: center;
  padding: 1px 7px 3px;
}
.spring:not([data-scene="home"]) header h1 {
  display: block;
  width: min(68%, 258px);
  height: clamp(48px, 15vw, 68px);
  padding: 0;
  border: 0;
  border-radius: 0;
  background: url("home-title-art.png") center / contain no-repeat;
  box-shadow: none;
  filter: drop-shadow(0 3px 3px #17463e66);
}
.spring:not([data-scene="home"]) header .home-art-label,
.game-art-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.stage-line :is(#home-back, #reset) {
  position: relative;
  inset: auto;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--game-button-art) center / contain no-repeat;
  box-shadow: none;
  filter: drop-shadow(0 3px 2px #17463e55);
}
.spring:not([data-scene="home"]) header h1::before,
.spring:not([data-scene="home"]) header h1::after,
.stage-line :is(#home-back, #reset)::before { content: none; }
.stage-line :is(#home-back, #reset) { width: clamp(58px, 17vw, 78px); flex: 0 0 auto; }
.stage-line #home-back { --game-button-art: url("game-home-art.png"); }
.stage-line #reset { --game-button-art: url("game-replay-art.png"); }
.stage-line .stage {
  padding: 4px 10px 5px;
  border: 2px solid #fff1cd;
  border-radius: 23px;
  background: linear-gradient(#fff4d8, #f5d5a4);
  box-shadow: inset 0 1px #fffbe8, inset 0 -2px #edbe86, 0 3px #a96c42, 0 4px 6px #18453f50;
}
.stage-line #level { font-size: clamp(.77rem, 3.7vw, 1rem); }
.stage-line #count { font-size: clamp(.67rem, 3vw, .8rem); }

@media (max-height: 650px) {
  .spring:not([data-scene="home"]) {
    padding-block: max(4px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-bottom));
  }
  .spring:not([data-scene="home"]) header { display: none; }
  #pool { margin-inline: 3%; }
  #status { margin-bottom: 4px; font-size: .78rem; }
  .tools { padding-block: 3px; }
}

.chapter-summary {
  display: grid;
  gap: 1px;
}
.chapter-totals {
  color: #805030;
  font-size: .745rem;
  font-weight: 700;
}
#ranking-layout {
  width: min(100%, 185px);
  font-size: .87rem;
}

/* Carved labels are available in Simplified Chinese. The buttons use live
   text in other languages and for the current saved level. */
html:not(:lang(zh-CN)) :is(.spring[data-scene="home"] .home-art-label,
  .spring:not([data-scene="home"]) header .home-art-label, .game-art-label, .spa-art-label),
.spring[data-scene="home"] #start[data-resume="true"] .home-art-label {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip-path: none;
  white-space: normal;
  overflow-wrap: anywhere;
  text-wrap: balance;
}
html:not(:lang(zh-CN)) .spring :is(header h1, .spa-dialog .spa-title) {
  width: min(86%, 430px);
  height: auto;
  min-height: 48px;
  display: grid;
  place-items: center;
  margin-inline: auto;
  padding: 5px 12px;
  border: 2px solid #e6aa69;
  border-radius: 19px;
  color: #fff0cb;
  background: var(--wood);
  box-shadow: inset 0 0 0 2px #b97649, 0 3px #67351c;
  font-size: clamp(1.2rem, 5vw, 1.8rem);
  line-height: 1.15;
}
html:not(:lang(zh-CN)) .spring[data-scene="home"] header h1 {
  --home-left: 7%;
  --home-top: max(12%, calc(4.3931dvh + 51px));
}
html:not(:lang(zh-CN)) .spa-dialog .spa-title {
  width: 100%;
  font-size: clamp(1.15rem, 5vw, 1.5rem);
}
html:not(:lang(zh-CN)) .spring[data-scene="home"] :is(#home-ranking, #sound, #skins, #level-select, #invite),
html:not(:lang(zh-CN)) .stage-line :is(#home-back, #reset),
html:not(:lang(zh-CN)) .spa-dialog :is(.spa-return, .spa-close, .spa-copy),
html:not(:lang(zh-CN)) #result #result-ranking {
  height: auto;
  min-height: 44px;
  padding: 4px 7px;
  border: 1px solid #fff5db;
  color: #65351b;
  background: var(--ceramic);
  box-shadow: 0 3px #a66b45;
  font-size: clamp(.72rem, 3.4vw, .96rem);
  line-height: 1.15;
}
html:not(:lang(zh-CN)) .stage-line :is(#home-back, #reset) {
  width: clamp(69px, 23vw, 100px);
}
html:not(:lang(zh-CN)) .game-art-label {
  overflow-wrap: normal;
  hyphens: auto;
}
html:not(:lang(zh-CN)) .spring[data-scene="home"] :is(#home-ranking, #sound) {
  --home-left: 2%;
  --home-width: 28%;
}
html:not(:lang(zh-CN)) .spring[data-scene="home"] :is(#home-ranking, #sound, #skins, #level-select, #invite) {
  font-size: clamp(.73rem, 3.4vw, .91rem);
}
html:not(:lang(zh-CN)) .spring[data-scene="home"] :is(#home-ranking, #sound, #skins, #level-select, #invite) .home-art-label {
  overflow-wrap: normal;
  hyphens: auto;
}
html:not(:lang(zh-CN)) .spring[data-scene="home"] #sound { --home-left: 70%; }
html:not(:lang(zh-CN)) .spring[data-scene="home"] #sound[aria-pressed="false"] {
  filter: saturate(.55) drop-shadow(0 4px 4px #16494065);
}
html:not(:lang(zh-CN)) .spring[data-scene="home"] #home-shortcuts {
  position: absolute;
  inset: auto 4% 6%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}
html:not(:lang(zh-CN)) .spring[data-scene="home"] #home-shortcuts button {
  position: static;
  width: 100%;
}
html:not(:lang(zh-CN)) .spring[data-scene="home"] :is(#home-ranking, #sound, #skins, #invite) {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}
html:not(:lang(zh-CN)) .spring[data-scene="home"] :is(#home-ranking, #sound, #skins, #invite)::before {
  content: "";
  flex: 0 0 19px;
  width: 19px;
  height: 19px;
  margin: 0;
  background: url("home-utility-icons.png") var(--utility-offset, 0%) center / 400% 100% no-repeat;
}
#sound { --utility-offset: 33.333%; }
#skins { --utility-offset: 66.667%; }
#invite { --utility-offset: 100%; }
@media (max-width: 520px) {
  html:not(:lang(zh-CN)) .spring[data-scene="home"] :is(#home-ranking, #sound, #skins, #invite)::before {
    display: none;
  }
}

html:not(:lang(zh-CN)) .spring[data-scene="home"] #start,
.spring[data-scene="home"] #start[data-resume="true"],
html:not(:lang(zh-CN)) #result #next {
  height: auto;
  min-height: 48px;
  padding: 8px 12px;
  border: 2px solid #ffe3a0;
  color: #fff7d9;
  background: var(--orange);
  box-shadow: 0 4px #b95816;
  text-shadow: 0 1px 2px #934208;
  line-height: 1.16;
}
html:not(:lang(zh-CN)) .spring[data-scene="home"] #start,
.spring[data-scene="home"] #start[data-resume="true"] {
  --home-left: 6%;
  --home-width: 88%;
  --home-top: 71%;
  min-height: clamp(48px, 9dvh, 78px);
  font-size: clamp(1.2rem, 5.5vw, 1.8rem);
}
html:not(:lang(zh-CN)) .spa-result-badge {
  width: auto;
  max-width: 100%;
  height: auto;
  padding: 4px 9px;
  border: 1px solid #d5a15e;
  border-radius: 999px;
  background: #fff1b5;
  color: #6c401d;
  font-size: .76rem;
  font-weight: 750;
}
.stage-line { align-items: center; }
.stage-line .stage { min-width: 0; overflow-wrap: anywhere; }
.stage-line :is(#home-back, #reset) { min-width: 44px; }
.tools button { flex: 1 1 0; min-width: 0; min-height: 44px; }
#status { max-width: 100%; overflow-wrap: anywhere; }

@media (max-width: 360px), (max-height: 515px) {
  .spa-dialog[open] { gap: 6px; }
  .spa-link { flex-direction: column; align-items: stretch; padding-inline: 7px; }
  .spa-dialog .spa-link input {
    margin-inline-start: 0;
    padding-inline: 4px;
    border-inline-start: 0;
    border-block-start: 1px solid #dca977;
  }
  .tools { width: min(96%, 300px); padding-inline: 7px; }
  .tools .tool-art { width: 34px; }
  .tool-label { padding-inline: 3px; font-size: .74rem; }
}

@media (max-height: 515px) {
  .spring[data-scene="home"] :is(#skins, #level-select, #invite) {
    top: min(var(--home-top), calc(100% - 52px));
  }
  #result[open] {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: min(calc(100% - 18px), 440px);
    max-height: calc(100dvh - 18px);
    padding: 5px 9px 9px;
  }
  #result[open] > :not(.spa-result-button) { grid-column: 1 / -1; }
  #result[open] > :is(#next, #result-ranking) {
    width: 100%;
    min-height: 44px;
    height: auto;
    align-self: stretch;
  }
  #result .spa-title { height: 42px; min-height: 42px; }
  .spa-result-hero { max-height: 11dvh; justify-self: center; }
}

@media (max-height: 515px) and (min-width: 525px) {
  .spring,
  .spring[data-scene="home"] {
    width: min(100%, 820px);
    padding-left: max(7px, env(safe-area-inset-left));
    padding-right: max(7px, env(safe-area-inset-right));
  }
  .spring[data-scene="home"] { width: min(100%, 540px); background-size: cover; }
  .spring[data-scene="home"] h1 { --home-top: max(18%, calc(4.3931dvh + 51px)); --home-height: 19%; }
  html:not(:lang(zh-CN)) .spring[data-scene="home"] header h1 { --home-top: max(18%, calc(4.3931dvh + 51px)); }
  .spring[data-scene="home"] #start {
    --home-left: 17%;
    --home-top: 63%;
    --home-width: 66%;
    --home-height: 19%;
  }
  :lang(zh-CN) .spring[data-scene="home"] :is(h1, #home-ranking, #sound, #start, #skins, #level-select, #invite) {
    background-size: contain;
  }
  html:not(:lang(zh-CN)) .spring[data-scene="home"] #start,
  .spring[data-scene="home"] #start[data-resume="true"] { --home-top: 62%; }
  #game {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(172px, 36%);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
  }
  .stage-line {
    grid-area: 1 / 2;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 0;
    padding: 0;
  }
  .stage-line .stage {
    grid-area: 1 / 1 / 2 / -1;
    padding: 3px 7px;
    line-height: 1.15;
  }
  .stage-line #level { font-size: .81rem; }
  .stage-line #count { font-size: .73rem; }
  .stage-line :is(#home-back, #reset) { justify-self: stretch; width: auto; max-width: none; }
  #pool { grid-area: 1 / 1 / 3 / 2; margin: 0; }
  #game footer { grid-area: 2 / 2; align-self: end; padding: 0; }
  #game footer .tools { width: 100%; }
}

/* In landscape, put the toolbox beside the board so longer labels keep
   readable text and the board uses the full available height. */
@media (min-height: 310px) and (max-height: 515px) and (min-width: 525px) {
  #game footer .tools {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 5px;
    padding: 3px 5px 5px;
  }
  .tools button {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 3px 8px;
    gap: 5px;
    border-radius: 999px;
  }
  .tools .tool-art { flex: 0 0 auto; width: 28px; }
  .tools .tool-label {
    background: transparent;
    box-shadow: none;
    overflow-wrap: normal;
  }
}
