@font-face {
  font-family: 'Grenze';
  src: url('assets/fonts/Grenze.ttf') format('truetype');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
:root {
  font-family: 'Grenze', 'Songti SC', 'Noto Serif CJK SC', Georgia, serif;
  font-size: 19px;
  font-weight: 600;
  color: #344263;
  background: #edf1f8;
  font-synthesis: none;
}
* { box-sizing: border-box; }
html { overscroll-behavior: none; }
body { margin: 0; overscroll-behavior: none; }
body.modal-open { position: fixed; left: 0; right: 0; width: 100%; overflow: hidden; }
dialog { touch-action: pan-y; overscroll-behavior: contain; }
dialog::backdrop { touch-action: none; }
.level-grid { touch-action: pan-y; overscroll-behavior: contain; }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
button:focus-visible, a:focus-visible { outline: 3px solid #7186ef; outline-offset: 4px; }
button:hover { filter: brightness(.96); }
button:active { transform: translateY(1px); }
.app { width: min(100%, 506px); margin: auto; padding: 28px 18px 24px; }
header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 26px; gap: 10px; }
.brand { color: #33446a; font-size: 19px; font-weight: 950; line-height: 1.05; letter-spacing: -.8px; text-decoration: none; }
.brand span { display: block; color: #687dea; }
nav { display: flex; gap: 7px; }
.icon-btn { background: #ffffff; border: 1px solid #d6deef; border-radius: 10px; min-width: 36px; height: 36px; font-size: 21px; }
#language { font-size: 11px; padding: 0 8px; }
.board-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
#level-number { font-size: 15px; font-weight: 800; background: #ffffff; padding: 12px 15px; border-radius: 12px; box-shadow: 0 2px 0 #d6dfef; }
#level-number::after { content: ' ▾'; font-size: 10px; color: #8c9aba; }
.goal { display: flex; align-items: center; gap: 9px; font-size: 11px; font-weight: 700; }
.goal .sprite { width: 38px; height: 38px; }
.moves { display: flex; flex-direction: column; text-align: center; min-width: 63px; }
.moves strong { font-size: 28px; line-height: 1; font-variant-numeric: tabular-nums; }
.moves span { font-size: 10px; color: #7686a6; margin-top: 4px; }
.board { --gap: 9px; --pad: 11px; position: relative; aspect-ratio: 1; border-radius: 20px; background: #aabbd8; box-shadow: 0 5px 0 #8399be; touch-action: none; user-select: none; isolation: isolate; }
.cells, .tiles { position: absolute; inset: var(--pad); }
.cells { display: grid; grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(5, 1fr); gap: var(--gap); z-index: 0; }
.cell { border-radius: 12px; background: #cfdaeb; box-shadow: inset 0 2px 0 #8197bb26; }
.tiles { z-index: 1; pointer-events: none; }
.tile { position: absolute; width: calc((100% - 4 * var(--gap)) / 5); height: calc((100% - 4 * var(--gap)) / 5); left: calc(var(--col) * ((100% + var(--gap)) / 5)); top: calc(var(--row) * ((100% + var(--gap)) / 5)); }
.tile-face { width: 100%; height: 100%; border-radius: 12px; background: var(--tile-bg); box-shadow: inset 0 -4px 0 #00000010, inset 0 2px 0 #ffffff70; display: flex; align-items: center; justify-content: center; }
.sprite { display: block; background-image: url('assets/materials.png'); background-repeat: no-repeat; background-size: 736% 318%; width: 36px; height: 36px; image-rendering: pixelated; border-radius: 5px; flex-shrink: 0; }
.tile .sprite { width: 72%; height: 72%; border-radius: 6px; }
.tile.moving { will-change: transform; }
.tile.merged .tile-face { animation: merge-pop 260ms ease-out both; }
.tile.spawned .tile-face { animation: spawn-in 220ms ease-out both; }
@keyframes merge-pop { 0% { transform: scale(1); } 45% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes spawn-in { from { transform: scale(.55); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.under-board { display: flex; align-items: center; gap: 10px; margin: 18px 0 22px; }
.controls { display: flex; gap: 5px; }
.controls button { background: #dce4f1; width: 32px; height: 31px; border-radius: 8px; font-size: 18px; color: #687fa4; }
.control-space { flex: 1; }
#restart { background: transparent; }
.collection-title { display: flex; justify-content: space-between; font-size: 10px; color: #7384a3; margin: 0 1px 10px; }
#catalog { display: grid; grid-template-columns: repeat(9, 1fr); gap: 5px; }
.specimen { min-width: 0; padding: 0; background: none; }
.specimen-icon { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; border-radius: 9px; background: #ffffff; }
.specimen .sprite { width: 72%; height: 72%; border-radius: 3px; }
.specimen.locked .specimen-icon { background: #dce4f1; color: #9aaac3; font-size: 15px; }
dialog { border: 0; border-radius: 22px; padding: 35px 25px 28px; width: min(460px, calc(100% - 30px)); color: #344263; background: #f4f7ff; box-shadow: 0 20px 80px #26365330; text-align: center; }
dialog::backdrop { background: #25355766; }
.modal-close { position: absolute; right: 10px; top: 10px; }
.modal-icon { font-size: 36px; color: #7d91ed; margin: 10px 0; }
h2 { font-size: 24px; margin: 12px 0; }
p { font-size: 13px; line-height: 1.7; color: #7183a4; }
.eyebrow { font-size: 11px; color: #7b8da9; }
.primary, .secondary { border-radius: 11px; padding: 12px 22px; margin-top: 18px; font-weight: 700; }
.primary { background: #6b80e8; color: white; box-shadow: 0 3px 0 #4d62bb; }
.secondary { background: #e0e7f6; margin-left: 8px; }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 9px; max-height: 55vh; overflow: auto; margin-top: 20px; }
.level-grid button { background: #e3eafa; padding: 11px 0; border-radius: 10px; }
.level-grid button small { display: block; font-size: 9px; margin-top: 5px; color: #8392b5; }
.level-grid button:disabled { opacity: .4; cursor: default; }
.level-grid button.current { background: #7589e7; color: white; }
#toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 15px); padding: 12px 20px; background: #3c5079; color: #fff; border-radius: 12px; font-size: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 10; max-width: 90%; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.danger { color: #e54f65; }
@media(max-width: 520px) {
  .app { padding-top: 18px; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  header { margin-bottom: 22px; }
  .board { --gap: 7px; --pad: 9px; border-radius: 16px; }
  .cell, .tile-face { border-radius: 9px; }
  .brand { font-size: 17px; }
  #level-number { font-size: 13px; padding: 11px; }
}
@media(prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* One board, two layouts: side panels in landscape, compact HUD in portrait. */
main { position: relative; }
.goal-panel { position: absolute; top: 0; left: 50%; transform: translateX(-50%); }
.goal { height: 48px; }
#goal-name { display: none; }
.board-heading { min-height: 48px; }
.moves { min-width: 70px; }
.effects { position: absolute; inset: var(--pad); z-index: 3; pointer-events: none; overflow: hidden; border-radius: 12px; }
.merge-effect { position: absolute; width: calc((100% - 4 * var(--gap))/5); height: calc((100% - 4 * var(--gap))/5); left: calc(var(--col) * ((100% + var(--gap))/5)); top: calc(var(--row) * ((100% + var(--gap))/5)); }
.particle { position: absolute; top: 50%; left: 50%; width: 5px; height: 5px; background: var(--effect-color); animation: scatter 650ms ease-out both; }
.particle.chip { width: 7px; height: 3px; border-radius: 1px; }
.particle.dust { width: 4px; height: 4px; border-radius: 50%; }
.particle.spark { width: 2px; height: 10px; box-shadow: 0 0 6px var(--effect-color); }
.particle.shard { clip-path: polygon(50% 0,100% 50%,50% 100%,0 50%); width: 8px; height: 10px; }
.particle.flash,.particle.star { width: auto; height: auto; background: transparent; color: var(--effect-color); font-size: 18px; text-shadow: 0 0 8px white; }
.chain-float { position: absolute; left: 50%; top: 36%; transform: translateX(-50%); white-space: nowrap; font-weight: 950; line-height: 1; animation: chain-rise 900ms ease-out both; }
@keyframes scatter { from { opacity: 1; transform: translate(0,0) rotate(0); } to { opacity: 0; transform: translate(var(--dx),var(--dy)) rotate(var(--spin)); } }
@keyframes chain-rise { 0% { opacity: 0; transform: translate(-50%,10px) scale(.7); } 18% { opacity: 1; transform: translate(-50%,-3px) scale(1.08); } 65% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%,-42px) scale(1); } }
.discovery { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 16px; background: #273b62de; border-radius: inherit; color: white; pointer-events: none; }
.discovery[hidden] { display: none; }
.discovery .sprite { width: 104px; height: 104px; border-radius: 10px; box-shadow: 0 0 45px #a7d4ff60; animation: discover-pop 450ms cubic-bezier(.2,.8,.2,1) both; }
.discovery strong { font-size: 25px; }
.discovery-label { font-size: 11px; letter-spacing: 3px; color: #bad9ff; }
@keyframes discover-pop { 0% { transform: scale(.45) rotate(-8deg); opacity: 0; } 70% { transform: scale(1.15) rotate(3deg); opacity: 1; } 100% { transform: scale(1); } }
.specimen.unlocked-now .specimen-icon { animation: collection-light 1200ms ease-out both; }
@keyframes collection-light { 0% { transform: scale(.8); filter: brightness(1); } 30% { transform: scale(1.22); background: #d8edff; box-shadow: 0 0 20px #8ebfff; filter: brightness(1.3); } 100% { transform: scale(1); filter: brightness(1); } }
@media(min-width: 850px) and (orientation: landscape) {
  .app { width: min(100%,1100px); padding: 30px 36px; }
  header { margin-bottom: 32px; }
  main { display: grid; grid-template-columns: minmax(135px,1fr) minmax(300px,min(480px,calc(100dvh - 258px))) minmax(135px,1fr); gap: 38px; align-items: center; }
  .goal-panel { position: static; transform: none; }
  .goal { flex-direction: column; height: auto; gap: 20px; font-size: 12px; color: #798bad; }
  .goal .sprite { width: 85px; height: 85px; border-radius: 10px; }
  #goal-name { display: block; color: #435778; font-size: 20px; }
  .collection-title { font-size: 12px; margin-bottom: 18px; }
  #catalog { grid-template-columns: repeat(3,1fr); gap: 12px; }
  .specimen-icon { border-radius: 12px; }
  .under-board { margin-bottom: 0; }
}
@media(min-width: 850px) and (max-height: 760px) and (orientation: landscape) {
  main { grid-template-columns: minmax(130px,1fr) minmax(300px, min(480px,calc(100dvh - 198px))) minmax(130px,1fr); }
  .app { padding: 14px 36px; }
  header { margin-bottom: 12px; }
  .board-heading { margin-bottom: 12px; }
}
@media(prefers-reduced-motion: reduce) {
  .particle { display: none; }
  .chain-float { opacity: 1; }
}
#round-action { margin: 0; padding: 9px 16px; font-size: 12px; }
#round-action[hidden] { display: none; }
dialog.victory { overflow: hidden; padding-top: 30px; background: #f1f5ff; box-shadow: 0 0 0 5px #ffffff70,0 22px 100px #405baf66; animation: victory-enter 600ms cubic-bezier(.16,.8,.25,1.2) both; }
dialog.victory::backdrop { background: #233559b8; animation: victory-backdrop 500ms ease-out; }
.victory h2 { font-size: clamp(24px,5vw,34px); font-weight: 950; color: #536bdd; letter-spacing: -1px; animation: victory-title 600ms 180ms both; }
.victory .eyebrow,.victory h2,.victory p,.victory-stars,.result-actions { position: relative; z-index: 2; }
.victory .modal-close { z-index: 5; }
.victory-prize { position: relative; width: 112px; height: 112px; margin: 12px auto 22px; display: grid; place-items: center; z-index: 2; animation: prize-land 850ms cubic-bezier(.2,.7,.2,1.25) both; }
.victory-prize .sprite { width: 90px; height: 90px; border-radius: 10px; filter: drop-shadow(0 10px 8px #5c72ba40); }
.victory-orbit { position: absolute; top: -10px; left: calc(50% - 135px); width: 270px; height: 270px; border-radius: 50%; background: repeating-conic-gradient(from 0deg,#9fb8ff38 0deg 15deg,transparent 15deg 30deg); mask-image: radial-gradient(circle,black 15%,transparent 70%); animation: victory-spin 8s linear infinite; pointer-events: none; }
.victory-stars { display: flex; justify-content: center; gap: 13px; height: 57px; align-items: center; }
.victory-stars span { color: #d7dfef; font-size: 42px; }
.victory-stars .earned { color: #ffc941; text-shadow: 0 3px 0 #d49225,0 0 18px #ffe290; animation: star-land 550ms var(--delay) cubic-bezier(.16,.8,.2,1.4) both; }
.victory-stars span:nth-child(2) { font-size: 53px; }
.victory-confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 3; }
.victory-confetti i { position: absolute; left: var(--x); top: -18px; width: 8px; height: 15px; background: var(--color); border-radius: 2px; animation: confetti-fall 2100ms var(--delay) ease-out both; }
.victory-confetti i:nth-child(3n) { width: 9px; height: 9px; border-radius: 50%; }
@keyframes confetti-fall { 0% { transform: translate(0,-10px) rotate(0); opacity: 0; } 8% { opacity: 1; } 75% { opacity: 1; } 100% { transform: translate(var(--drift),520px) rotate(var(--turn)); opacity: 0; } }
@keyframes victory-enter { 0% { transform: scale(.65) rotate(-4deg); opacity: 0; } 65% { transform: scale(1.035) rotate(1deg); opacity: 1; } 100% { transform: scale(1); } }
@keyframes victory-title { 0% { transform: translateY(15px) scale(.8); opacity: 0; } 65% { transform: scale(1.06); opacity: 1; } 100% { transform: scale(1); } }
@keyframes prize-land { 0% { transform: translateY(-70px) scale(.35) rotate(-25deg); opacity: 0; } 55% { transform: translateY(5px) scale(1.18) rotate(5deg); opacity: 1; } 100% { transform: translateY(0) scale(1); } }
@keyframes star-land { from { transform: scale(2.5) rotate(-20deg); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes victory-backdrop { from { background: #23355900; } to { background: #233559b8; } }
@keyframes victory-spin { to { transform: rotate(360deg); } }

/* Dark workshop palette across gameplay, menus and celebrations. */
:root { color: #e2e7f5; background: #10131d; color-scheme: dark; }
.brand { color: #eef1ff; }.brand span { color: #92a2ff; }
.icon-btn,#level-number { background: #252c3e; border-color: #39415b; color: #dce4ff; box-shadow: none; }
.board { background: #3a445e; box-shadow: 0 5px 0 #232a3e; }
.cell { background: #252d40; box-shadow: inset 0 2px 0 #1b2232; position: relative; }
.controls button,.secondary,.level-grid button { background: #293249; color: #d5dffa; }
.specimen-icon { background: #2e374d; }.specimen.locked .specimen-icon { background: #1e2536; color: #68748e; }
.moves span,.collection-title,.goal { color: #a3afcb; }#goal-name { color: #e3eaff; }
dialog,dialog.victory { background: #1d2539; color: #e6edff; box-shadow: 0 0 0 3px #52628270,0 22px 100px #0009; }
dialog p,.eyebrow { color: #a8b8d9; }.victory h2 { color: #adbaff; }
.victory-stars span { color: #46516a; }dialog::backdrop { background: #060914b8; }
#toast { background: #34425f; }.discovery { background: #10182aeb; }
.discovery-label { color: #a6caff; }.specimen.unlocked-now .specimen-icon { background: #485c85; }
.terrain-art { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(24px,4vw,42px); font-weight: 900; pointer-events: none; }
.terrain-furnace { background: #612b19; outline: 3px solid #d56530; outline-offset: -3px; color: #ffac41; }
.terrain-furnace::after { content: ''; position: absolute; inset: 5px; border: 2px solid #ffb54b70; border-radius: 5px; }
.terrain-rock { background: repeating-linear-gradient(0deg,#262c37 0 12px,#353d4e 12px 16px); border: 4px solid #141922; color: #63728a; }
.terrain-rock.cracked::after { content: ''; position: absolute; inset: 4px; background: #d2def1; clip-path: polygon(20% 0,42% 0,57% 31%,43% 41%,76% 68%,63% 79%,85% 100%,68% 100%,44% 74%,55% 64%,26% 38%,40% 28%); }
.terrain-lava { background: repeating-conic-gradient(#bf3818 0% 25%,#f27926 0% 50%) 0 0/16px 16px; color: #ffd05f; box-shadow: inset 0 0 16px #ff4000; }
.tile:has(.tile-face) { z-index: 1; }.tile-face { border: 2px solid #ffffff20; }
.tile.heated .tile-face { animation: furnace-flare 500ms ease-out; }
.rock-hit { animation: rock-shake 300ms ease-out; }
@keyframes furnace-flare { 0% { filter: brightness(2); box-shadow: 0 0 22px #ff8c26; transform: scale(1.08); } 100% { filter: brightness(1); transform: scale(1); } }
@keyframes rock-shake { 20% { transform: translateX(-3px); } 50% { transform: translateX(3px); } 80% { transform: translateX(-2px); } }
.terrain-guide { background: none; display: flex; justify-content: center; gap: 18px; font-size: 11px; color: #acb7d0; padding: 10px 0; width: 100%; }
.terrain-guide span:first-child { color: #f4a554; }.terrain-guide span:last-child { color: #a4b0ca; }
#rock-goal { font-size: 12px; color: #b5c2df; }
@media(max-width:849px),(orientation:portrait){
 #rock-goal { position:absolute; top: 49px; width: 180px; text-align:center; font-size:10px; }
 .board-heading { margin-bottom: 25px; }
 .terrain-art { font-size: 28px; }
}

.tile.on-furnace .tile-face { outline: 3px solid #f39036; outline-offset: -3px; }
.tile.on-lava .tile-face { outline: 3px solid #f35329; outline-offset: -3px; }
.terrain-art { font-size: 0; inset: 5%; background-position: center; background-size: contain; background-repeat: no-repeat; image-rendering: pixelated; }
.terrain-furnace .terrain-art { background-image: url('assets/furnace.svg'); }
.terrain-rock .terrain-art { background-image: url('assets/rock.svg'); }
.terrain-lava .terrain-art { background-image: url('assets/lava.svg'); }

.icon-btn.muted { position: relative; opacity: .65; }
.icon-btn.muted::after { content: ''; position: absolute; width: 24px; height: 2px; background: #c8d3ee; left: 5px; top: 17px; transform: rotate(-45deg); }
/* Terrain cards share the same animated art as the board. */
.terrain-guide { gap: 12px; padding: 8px 0 14px; }
.terrain-card { background: none; padding: 0; min-width: 64px; display: flex; align-items: center; flex-direction: column; gap: 7px; font-size: 10px; color: #aebcd9; }
.terrain-thumb { display: block; width: 48px; height: 48px; border-radius: 9px; position: relative; overflow: hidden; }
.terrain-card>span:last-child { color: #acbad4; }
.terrain-card.locked { opacity: .45; }
.terrain-detail { width: 104px; height: 104px; margin: 12px auto 22px; border-radius: 16px; }
.terrain-furnace .terrain-art { transform-origin: 50% 85%; animation: flame-dance 900ms ease-in-out infinite alternate; }
.terrain-furnace::after { animation: furnace-glow 1500ms ease-in-out infinite alternate; }
.terrain-rock .terrain-art { animation: rock-glint 3200ms ease-in-out infinite; }
.terrain-rock::before { content: ''; position: absolute; inset: 0; z-index: 1; background: linear-gradient(115deg,transparent 35%,#b6d4ff38 48%,transparent 61%); background-size: 250% 100%; pointer-events: none; animation: rock-sheen 3500ms linear infinite; }
.terrain-rock.cracked::after { animation: crack-glow 1200ms ease-in-out infinite alternate; }
.terrain-lava { animation: lava-flow 2200ms linear infinite; }
.terrain-lava .terrain-art { animation: lava-boil 1400ms ease-in-out infinite alternate; }
@keyframes flame-dance { 0% { transform: scale(.94, .94) skewX(-3deg); filter: brightness(1); } 50% { transform: scale(1,1.05) skewX(2deg); filter: brightness(1.35); } 100% { transform: scale(.98,1) skewX(-1deg); filter: brightness(1.12); } }
@keyframes furnace-glow { from { box-shadow: inset 0 0 4px #ff8b2355; } to { box-shadow: inset 0 0 14px #ffad4599; } }
@keyframes rock-glint { 0%,100% { filter: brightness(.9); } 45% { filter: brightness(1.25); } }
@keyframes rock-sheen { from { background-position: 150% 0; } to { background-position: -100% 0; } }
@keyframes crack-glow { from { opacity: .65; } to { opacity: 1; filter: drop-shadow(0 0 3px #bfddff); } }
@keyframes lava-flow { to { background-position: 16px 16px; } }
@keyframes lava-boil { from { transform: translateY(1px) scale(.95); filter: brightness(1); } to { transform: translateY(-1px) scale(1.03); filter: brightness(1.5) saturate(1.2); } }
.tile.on-lava::after { background-image: url('assets/lava.svg'); animation-name: lava-boil; }

#terrain-markers { position: absolute; inset: var(--pad); z-index: 2; pointer-events: none; }
.terrain-marker { position: absolute; width: calc((100% - 4 * var(--gap))/5); height: calc((100% - 4 * var(--gap))/5); left: calc(var(--col)*((100% + var(--gap))/5)); top: calc(var(--row)*((100% + var(--gap))/5)); opacity: 0; background: none; outline: none; border: 0; box-shadow: none; }
.terrain-marker.occupied { opacity: 1; }
.terrain-marker .terrain-art { inset: auto 3px 3px auto; width: 20px; height: 20px; }
.terrain-marker::after { display: none; }
dialog.defeat { overflow: hidden; padding-top: 32px; background: #202538; border: 1px solid #6d5874; animation: defeat-enter 650ms cubic-bezier(.2,.8,.2,1) both; }
.defeat h2 { color: #f2b2a2; font-size: 29px; font-weight: 900; animation: defeat-text 550ms 180ms both; }
.defeat-prize { position: relative; width: 114px; height: 114px; margin: 10px auto 24px; display: grid; place-items: center; animation: defeat-land 850ms ease-out both; }
.defeat-prize .sprite { width: 86px; height: 86px; filter: saturate(.45) brightness(.7); transform: rotate(-9deg); }
.defeat-prize>.retry-badge { position: absolute; right: 0; bottom: -5px; width: 48px; height: 48px; border-radius: 50%; background: #c18a78; color: #1e2436; font-size: 36px; box-shadow: 0 0 22px #db9e6340; animation: retry-turn 800ms 300ms both; }
.defeat .primary { animation: retry-ready 1600ms 800ms ease-in-out 2; }
.defeat .modal-close,.defeat .result-actions { position: relative; z-index: 4; }
.defeat .modal-close { position: absolute; }
.defeat-dust { position: absolute; top: 135px; left: 50%; pointer-events: none; }
.defeat-dust i { position: absolute; width: 7px; height: 7px; border-radius: 2px; background: #c4b4da; animation: defeat-scatter 1200ms var(--delay) ease-out both; }
@keyframes defeat-enter { 0% { opacity: 0; transform: translateY(-28px) scale(.88); } 55% { opacity: 1; transform: translateY(5px) scale(1.02); } 75% { transform: translateX(-4px); } 90% { transform: translateX(3px); } 100% { transform: none; } }
@keyframes defeat-land { 0% { transform: translateY(-55px) rotate(-15deg); opacity: 0; } 60% { transform: translateY(8px) rotate(4deg); opacity: 1; } 100% { transform: none; } }
@keyframes defeat-text { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes retry-turn { from { transform: rotate(-180deg) scale(.4); opacity: 0; } to { transform: rotate(0) scale(1); opacity: 1; } }
@keyframes retry-ready { 50% { box-shadow: 0 0 18px #91a2ff70; transform: scale(1.04); } }
@keyframes defeat-scatter { 0% { opacity: 0; transform: translate(0,0); } 20% { opacity: .9; } 100% { opacity: 0; transform: translate(var(--dx),95px) rotate(150deg); } }

/* 1.1.2 layout: terrain guide sits in the right column on desktop, under the board on phones. */
.side { display: contents; }
.terrain-section .collection-title { display: none; }
@media(max-width:849px),(orientation:portrait){
  main { display: flex; flex-direction: column; }
  .play { order: 1; }
  .terrain-section { order: 2; }
  .collection { order: 3; }
}
@media(min-width: 850px) and (orientation: landscape) {
  .side { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
  .terrain-section .collection-title { display: flex; }
  .terrain-section .terrain-guide { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; padding: 0; width: 100%; }
  .terrain-section .terrain-card { min-width: 0; }
  .terrain-section .terrain-thumb { width: 100%; height: auto; aspect-ratio: 1; max-width: 64px; }
}

/* 1.1.3: finished board explains itself and asks for the next action. */
.round-hint { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 4; max-width: calc(100% - 28px); padding: 9px 14px; border-radius: 12px; background: #0f1526ee; border: 1px solid #47598a; color: #e3eaff; font-size: 12px; font-weight: 700; line-height: 1.35; text-align: center; pointer-events: none; animation: hint-in 260ms ease-out both; }
.round-hint[hidden] { display: none; }
@keyframes hint-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
#round-action:not([hidden]) { animation: action-nudge 1.5s ease-in-out infinite; }
@keyframes action-nudge { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2px); filter: brightness(1.12); } }
@media(prefers-reduced-motion: reduce) { #round-action:not([hidden]), .round-hint { animation: none; } }

/* First encounters: a compact tip, with no modal or interrupted terrain animation. */
.terrain-hint { display: flex; align-items: center; gap: 10px; margin-top: 14px; padding: 10px 12px; border: 1px solid #e7b76770; border-radius: 12px; background: #242938; color: #eef0f8; }
.terrain-hint[hidden] { display: none; }
.terrain-hint>div { flex: 1; min-width: 0; }
.terrain-hint strong { display: block; font-size: 12px; color: #ffd58a; margin-bottom: 3px; }
.terrain-hint span { display: block; font-size: 12px; line-height: 1.5; }
.terrain-hint button { flex-shrink: 0; width: 36px; height: 36px; border-radius: 8px; background: #343c50; color: #eef0f8; font-size: 22px; }
.cell.terrain-highlight { outline: 3px solid #ffd58a; outline-offset: -2px; box-shadow: 0 0 16px #ffd58a70; }

/* Larger, readable dungeon typography throughout the HUD and dialogs. */
.brand { font-size: 27px; font-weight: 900; letter-spacing: .3px; }
#language { font-size: 14px; }
#level-number { font-size: 21px; }
.moves strong { font-size: 38px; }
.moves span,.collection-title,.goal { font-size: 17px; }
#goal-name { font-size: 23px; }
#rock-goal { font-size: 16px; }
.terrain-card { font-size: 17px; }
.terrain-caption { line-height: 1.2; }
h2,.defeat h2 { font-size: 34px; }
.victory h2 { font-size: clamp(30px,5vw,40px); letter-spacing: 0; }
p { font-size: 18px; line-height: 1.5; }
.eyebrow,.discovery-label { font-size: 16px; }
.discovery strong { font-size: 32px; }
.primary,.secondary { font-size: 21px; }
#round-action { font-size: 18px; }
.level-grid button { font-size: 24px; }
.level-grid button small { font-size: 14px; }
#toast,.round-hint { font-size: 17px; }
.terrain-hint strong,.terrain-hint span { font-size: 17px; line-height: 1.3; }
.icon-btn,.controls button,.retry-badge { font-family: system-ui,sans-serif; }
.icon-btn { font-size: 23px; }
.controls button { font-size: 21px; }
@media(max-width:849px),(orientation:portrait){
  .play { width: 100%; }
  .goal-panel { position: static; transform: none; align-self: center; margin-bottom: 14px; }
  .goal { display: grid; grid-template-columns: auto auto auto; height: auto; justify-content: center; align-items: center; gap: 12px; }
  #goal-label { grid-column: 1; grid-row: 1; }
  #goal-icon { grid-column: 2; grid-row: 1; }
  #rock-goal { position: static; width: auto; grid-column: 3; grid-row: 1; margin-left: 6px; text-align: left; white-space: nowrap; }
  #rock-goal:empty { display: none; }
  .brand { font-size: 24px; }
  .terrain-section,.collection { width: 100%; }
}
@media(max-width:380px){
  .app { padding-left: 12px; padding-right: 12px; }
  .brand { font-size: 21px; }
  nav { gap: 4px; }
  .icon-btn { min-width: 32px; }
}
@media(min-width:850px) and (orientation:landscape){
  #goal-name { font-size: 28px; }
  main { grid-template-columns: minmax(140px,1fr) minmax(300px,min(480px,calc(100dvh - 250px))) minmax(140px,1fr); gap: 28px; }
}

/* Scroll the dialog itself while the page stays anchored. */
body { -webkit-user-select: none; user-select: none; }
dialog { max-height: calc(100dvh - 24px); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.swipe-cue { position: absolute; inset: 35% 15% auto; z-index: 3; pointer-events: none; text-align: center; color: #fff0cc; text-shadow: 0 2px 8px #000; }
.swipe-cue[hidden] { display: none; }
.swipe-cue>span { display: block; font: 48px system-ui; animation: swipe-demo 1.5s ease-in-out infinite; }
.swipe-cue small { font-size: 18px; background: #10131de6; padding: 3px 9px; border-radius: 8px; }
@keyframes swipe-demo { 0%,100% { transform: translateX(-15px); } 50% { transform: translateX(15px); } }
@media(prefers-reduced-motion:reduce){ .swipe-cue>span { animation: none; } }
/* Short landscape iframes need side panels even below the phone breakpoint. */
@media(min-width:640px) and (orientation:landscape) and (max-height:760px){
 .app { width: 100%; max-width: 1100px; padding: max(8px,env(safe-area-inset-top)) max(16px,env(safe-area-inset-right)) max(8px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left)); }
 header { margin-bottom: 8px; }
 .brand { font-size: 22px; }
 main { display: grid; grid-template-columns: minmax(110px,1fr) minmax(200px,min(480px,calc(100dvh - 210px))) minmax(130px,1fr); gap: 18px; align-items: center; }
 .play { width: 100%; order: initial; position: relative; }
 .goal-panel { position: static; transform: none; margin: 0; }
 .goal { display: flex; flex-direction: column; gap: 12px; height: auto; }
 .goal .sprite { width: 64px; height: 64px; }
 #goal-name { display: block; font-size: 24px; }
 #rock-goal { position: static; margin: 0; width: auto; white-space: normal; text-align: center; }
 .side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
 .collection { order: 0; }
 .terrain-section { order: 1; }
 .collection-title { margin-bottom: 8px; }
 #catalog { grid-template-columns: repeat(3,1fr); gap: 7px; max-width: 180px; margin: auto; }
 .specimen-icon { max-height: 52px; }
 .terrain-section .collection-title { display: flex; }
 .terrain-section .terrain-guide { display: grid; grid-template-columns: repeat(3,1fr); gap: 6px; padding: 0; }
 .terrain-card { min-width: 0; font-size: 15px; }
 .terrain-thumb { width: min(100%,48px); height: auto; aspect-ratio: 1; }
 .board-heading { margin-bottom: 8px; }
 .under-board { margin: 10px 0 0; }
 .terrain-hint { position: fixed; top: auto; bottom: 12px; left: 16px; right: auto; width: clamp(110px,22vw,210px); z-index: 5; margin: 0; padding: 5px 8px; }
 .terrain-hint strong,.terrain-hint span { font-size: 15px; }
}

/* Keep completed-round controls inside the board column. */
.play { min-width: 0; }
.under-board { min-width: 0; }
.under-board:has(#round-action:not([hidden])) .controls,
.under-board:has(#round-action:not([hidden])) #restart,
.under-board:has(#round-action:not([hidden])) .control-space { display: none; }
#round-action:not([hidden]) { width: 100%; min-width: 0; }
.round-hint { width: calc(100% - 28px); max-width: 360px; padding: 8px 12px; font-size: 16px; }
/* Result classes previously overrode the general dialog scrolling rule. */
dialog.victory,dialog.defeat { overflow-x: hidden; overflow-y: auto; max-height: calc(100dvh - 24px); }
.result-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; }
.result-actions .primary,.result-actions .secondary { margin: 8px 0 0; }
@media(max-height:600px){
 dialog.victory,dialog.defeat { padding: 20px 20px 16px; }
 .victory-prize,.defeat-prize { width: 76px; height: 76px; margin: 0 auto 6px; }
 .victory-prize .sprite,.defeat-prize .sprite { width: 64px; height: 64px; }
 .defeat-prize>.retry-badge { width: 34px; height: 34px; font-size: 26px; }
 .victory h2,.defeat h2 { font-size: 28px; line-height: 1.1; margin: 8px 0; }
 .victory p,.defeat p { margin: 6px 0; font-size: 16px; line-height: 1.3; }
 .victory-stars { height: 38px; }
 .victory-stars span { font-size: 30px; }
 .victory-stars span:nth-child(2) { font-size: 36px; }
 .result-actions .primary,.result-actions .secondary { padding: 8px 16px; font-size: 19px; }
 .victory-orbit { width: 180px; height: 180px; left: calc(50% - 90px); }
}
@media(min-width:640px) and (orientation:landscape) and (max-height:420px){
 .brand { font-size: 18px; }
 header { margin-bottom: 4px; }
 main { grid-template-columns: minmax(100px,1fr) minmax(130px,min(480px,calc(100dvh - 190px))) minmax(120px,1fr); gap: 14px; }
 .board-heading { min-height: 40px; }
 #level-number { font-size: 18px; padding: 8px; }
 .moves strong { font-size: 30px; }
 .moves span { font-size: 15px; }
 .side { gap: 8px; }
 #catalog { gap: 4px; max-width: 140px; }
 .specimen-icon { max-height: 36px; }
 .collection-title { font-size: 15px; margin-bottom: 5px; }
 .terrain-section .terrain-thumb { max-width: 36px; }
 .terrain-card { font-size: 14px; }
}

/* Scale the entire board HUD to its column, not the window width. */
.play { container-type: inline-size; }
.board-heading { gap: 8px; }
#level-number { white-space: nowrap; flex: 0 1 auto; min-width: 0; font-size: clamp(14px,7cqw,21px); padding: 8px clamp(6px,3cqw,15px); line-height: 1.2; }
.moves { min-width: 0; flex-shrink: 0; }
.moves strong { font-size: clamp(26px,12cqw,38px); }
.moves span { white-space: nowrap; font-size: clamp(12px,5.5cqw,17px); line-height: 1.2; }
.under-board { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: clamp(4px,2cqw,8px); }
.controls { display: contents; }
.control-space { display: none; }
.controls button,#restart { width: 100%; min-width: 0; height: 34px; padding: 0; font-size: clamp(18px,7cqw,23px); }
#round-action:not([hidden]) { grid-column: 1 / -1; }
.board { --gap: clamp(4px,2cqw,9px); --pad: clamp(6px,2.5cqw,11px); }
.cell,.tile-face { border-radius: clamp(4px,2cqw,12px); }
.terrain-marker .terrain-art { width: clamp(10px,6cqw,20px); height: clamp(10px,6cqw,20px); }
.round-hint { font-size: clamp(12px,5.5cqw,16px); line-height: 1.25; }
/* Subtle raised type; deeper extrusion is reserved for large headings. */
body { text-shadow: 0 1px 0 #0a0e1b,0 2px 2px #0008; }
button { text-shadow: inherit; }
.brand,h2,#goal-name,.moves strong,.discovery strong { text-shadow: 0 1px 0 #66708e,0 2px 0 #343e5a,0 3px 0 #171e32,0 5px 5px #0009; }
.brand span { text-shadow: 0 1px 0 #616fb9,0 2px 0 #3a4383,0 3px 0 #22284f,0 5px 5px #0009; }
.primary { text-shadow: 0 1px 0 #5362af,0 2px 0 #344176,0 3px 3px #16203d70; }
@media(min-width:640px) and (orientation:landscape) and (max-height:760px){
 main { grid-template-columns: minmax(110px,1fr) minmax(130px,min(480px,calc(100dvh - 160px))) minmax(130px,1fr); }
 .board-heading { min-height: 44px; }
 .goal { font-size: 15px; gap: 10px; }
 #goal-name { font-size: 22px; }
 .collection-title { font-size: 15px; }
 .terrain-card { font-size: 14px; }
}
@media(min-width:640px) and (orientation:landscape) and (max-height:420px){
 .board-heading { min-height: 40px; }
 .moves strong { font-size: 26px; }
 .moves span { font-size: 12px; }
 .goal .sprite { width: 52px; height: 52px; }
 .brand,h2,#goal-name,.moves strong { text-shadow: 0 1px 0 #485372,0 2px 0 #1b2236,0 3px 3px #0008; }
}

.wallet-balance { color: #ffe19a; font-size: 28px; }
.coin-reward { position: relative; z-index: 4; color: #ffdc78; font-size: 20px; margin: 10px 0; animation: discover-pop 450ms ease-out both; }
.continue-offer { position: relative; z-index: 4; margin: 8px 0; }
.continue-offer .primary { margin: 0; width: 100%; font-size: 19px; padding: 9px 12px; }
.continue-offer small { display: block; color: #a8b8d9; font-size: 14px; margin-top: 4px; }
button:disabled { cursor: default; opacity: .45; }
@media(max-height:420px){
 .victory:has(.coin-reward) .victory-prize { width: 40px; height: 40px; }
 .victory:has(.coin-reward) .victory-prize .sprite { width: 36px; height: 36px; }
 .defeat:has(.continue-offer) .defeat-prize { display: none; }
 .coin-reward { font-size: 16px; margin: 5px 0; }
}

.main-wallet { order: 1; flex-shrink: 0; background: #292c40; color: #ffdf83; border: 1px solid #685a37; border-radius: 12px; padding: 5px 10px; font-size: clamp(17px,2.4vw,23px); font-variant-numeric: tabular-nums; }
.board-heading .moves { order: 2; }
.coin-icon { text-shadow: none; }
.coin-celebration { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
.coin-celebration strong { position: absolute; left: 50%; top: 40%; transform: translate(-50%,-50%); color: #ffe08b; font-size: clamp(30px,6vw,48px); white-space: nowrap; text-shadow: 0 3px #825326,0 5px #302238,0 0 24px #f8ce4b; animation: coin-award 1450ms ease-out both; }
.reward-coin { position: absolute; color: #ffd45a; font-style: normal; font-size: 30px; line-height: 1; text-shadow: none; }
@keyframes coin-award { 0% { opacity: 0; scale: .6; } 20%,70% { opacity: 1; scale: 1; } 100% { opacity: 0; translate: 0 -35px; } }
@media(max-width:420px){ .board-heading { gap: 6px; } .main-wallet { padding: 4px 7px; } }

/* Keep all three counters inside the board width, including narrow embeds. */
.board-heading { display: grid; grid-template-columns: minmax(0,1fr) auto minmax(0,1fr); gap: clamp(4px,2cqw,10px); }
.board-heading #level-number { grid-column: 1; grid-row: 1; justify-self: start; max-width: 100%; padding: 7px clamp(4px,2cqw,10px); font-size: clamp(12px,5cqw,18px); white-space: normal; overflow-wrap: anywhere; }
.board-heading .main-wallet { grid-column: 2; grid-row: 1; padding: 5px clamp(4px,2cqw,8px); font-size: clamp(12px,5cqw,18px); white-space: nowrap; }
.board-heading .moves { grid-column: 3; grid-row: 1; justify-self: end; max-width: 100%; }
.board-heading .moves span { font-size: clamp(10px,4cqw,14px); white-space: normal; }
.board-heading .moves strong { font-size: clamp(24px,9cqw,34px); }

.item-shop h2 { margin: 8px 0 20px; }
.shop-coins { display: flex; flex-direction: column; gap: 3px; padding: 12px; background: #151b2b; border: 1px solid #49432e; border-radius: 14px; }
.shop-coins>span { color: #acb8d0; font-size: 17px; }
.shop-coins strong { color: #ffdf83; font-size: 34px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.item-shop .shop-earn { font-size: 15px; line-height: 1.4; margin: 10px 0 22px; }
.shop-items { display: grid; gap: 14px; }
.shop-item { background: #293149; border: 1px solid #46516e; border-radius: 14px; padding: 16px; text-align: left; }
.shop-item-heading { display: flex; align-items: center; gap: 14px; }
.ticket-icon { display: grid; place-items: center; font-size: 34px; width: 58px; height: 58px; background: #20263a; border-radius: 12px; flex-shrink: 0; }
.shop-item h3 { font-size: 24px; line-height: 1.2; margin: 0 0 4px; }
.item-owned { color: #b7c3dc; font-size: 17px; }
.shop-item p { font-size: 17px; line-height: 1.4; margin: 12px 0; }
.shop-item .primary { display: block; width: 100%; margin: 0; padding: 10px; font-size: 20px; }
@media(max-height:500px){ .item-shop h2 { margin: 0 0 10px; } .shop-coins { padding: 6px; } .item-shop .shop-earn { margin: 6px 0 12px; } .shop-item { padding: 12px; } }

.shop-item .ticket-price { font-size: 1.4em; font-weight: 900; vertical-align: baseline; }

/* Reserve the same control row before and after a round. */
.under-board { height: 34px; min-height: 34px; }
#round-action:not([hidden]) { justify-self: center; width: min(160px,100%); height: 34px; min-height: 0; padding: 0 14px; font-size: 18px; line-height: 1; animation: none; }
.meteor .tile-face { position: relative; box-shadow: inset 0 0 0 2px #b775cc; }
.meteor-age-1 .tile-face { background: #ed858c; }
.meteor-age-2 .tile-face { background: #ff3449; }
.meteor-count { position: absolute; right: 2px; top: 2px; min-width: 15px; padding: 0 3px; border-radius: 5px; background: #29152f; color: white; font: bold 12px/16px system-ui; }
.meteor-blast { position: absolute; left: calc((100% + var(--gap)) / 5 * var(--col)); top: calc((100% + var(--gap)) / 5 * var(--row)); width: calc((100% - 4 * var(--gap)) / 5); height: calc((100% - 4 * var(--gap)) / 5); background: radial-gradient(circle,#fff6bf,#ff853b 45%,#d52d3600 72%); animation: meteor-explode 600ms ease-out both; }
@keyframes meteor-explode { from { opacity:1;transform:scale(.4); } to { opacity:0;transform:scale(1.7); } }
.meteor-burst { position:absolute; left:calc((100% + var(--gap)) / 5 * (var(--col) + .5) - var(--gap) / 2); top:calc((100% + var(--gap)) / 5 * (var(--row) + .5) - var(--gap) / 2); width:0; height:0; pointer-events:none; }
.blast-core,.blast-ring { position:absolute; left:-60px; top:-60px; width:120px; height:120px; border-radius:50%; }
.blast-core { background:radial-gradient(circle,#fffbed 5%,#ffcd90 22%,#ff5260 45%,#ab254800 70%); animation:blast-core 550ms ease-out both; }
.blast-ring { border:4px solid #ffdbb5; box-shadow:0 0 14px #ff4d65,inset 0 0 12px #ff4d65; animation:blast-wave 650ms ease-out both; }
.blast-ring.echo { border:2px solid #e775ff; animation-delay:90ms; }
.blast-spark,.blast-shard { position:absolute; left:-3px; top:-3px; width:6px; height:6px; background:#ffe5b6; box-shadow:0 0 7px #ff5b66; animation:blast-debris 750ms cubic-bezier(.1,.65,.3,1) both; }
.blast-shard { width:10px; height:8px; background:#9c4b77; border:1px solid #ffc0ca; }
@keyframes blast-core { 0% {transform:scale(.1);opacity:1;} 25% {transform:scale(1.2);opacity:1;} 100% {transform:scale(1.7);opacity:0;} }
@keyframes blast-wave { from {transform:scale(.15);opacity:1;} to {transform:scale(1.8);opacity:0;} }
@keyframes blast-debris { from {transform:translate(0,0) rotate(0);opacity:1;} to {transform:translate(var(--dx),var(--dy)) rotate(var(--spin));opacity:0;} }
@media(prefers-reduced-motion:reduce){ .blast-ring {display:none;} .blast-core {animation:none;opacity:.5;} }
/* Discovery is a small, non-blocking notification rather than a board cover. */
.discovery { inset: 6px 6px auto; flex-direction: row; gap: 8px; padding: 6px 10px; border-radius: 10px; background: #10182ae6; }
.discovery .sprite { width: 32px; height: 32px; box-shadow: none; flex-shrink: 0; }
.discovery strong { font-size: 18px; }
.discovery-label { font-size: 11px; letter-spacing: 1px; }

.music-credits{border-top:1px solid #45506d;margin-top:24px;padding-top:12px}.music-credits h3{font-size:22px}.music-credits p{font-family:system-ui,sans-serif;font-size:16px;line-height:1.6;text-shadow:none;overflow-wrap:anywhere}.music-credits a{color:#b9c6ff;text-decoration:underline}

/* Purchase and continue share a green action treatment. */
#use-ticket.primary,#buy-ticket.primary{background:#328b59;box-shadow:0 5px 0 #1c593a;text-shadow:0 1px 0 #225c3d,0 2px 0 #17432d,0 3px 3px #10251b80}
#use-ticket.primary:hover:not(:disabled),#buy-ticket.primary:hover:not(:disabled){background:#3a9b65}

.mode-bar{display:flex;align-items:center;justify-content:space-between;gap:8px;min-width:0;margin:0 0 5px;font-size:14px;color:#aebad5;line-height:1.2}
#mode-switch{padding:4px 8px;border:1px solid #46536e;border-radius:8px;background:#252e43;font-size:14px;white-space:nowrap}
.endless-invite.primary{background:#328b59;box-shadow:0 3px 0 #1c593a;font-size:19px;width:100%;padding:10px}
.terrain-marker[data-life]:not([data-life=""])::after{content:attr(data-life);position:absolute;right:2px;top:2px;z-index:8;background:#142031;color:#fff;border-radius:50%;min-width:18px;text-align:center;font:700 13px/18px system-ui;box-shadow:0 0 0 1px #acbad6}
.cell{position:relative}.endless-mode #goal-name{font-size:clamp(24px,3vw,40px);overflow-wrap:anywhere}
.endless-mode #moves{font-size:clamp(20px,3vw,34px);overflow-wrap:anywhere}.endless-milestones{display:flex;flex-wrap:wrap;gap:8px;justify-content:center;font-size:17px}
@media(max-height:650px){.mode-bar{font-size:12px;margin-bottom:2px}#mode-switch{font-size:12px;padding:2px 6px}}

.endless-mode #level-number::after{content:none}.endless-mode #level-number:disabled{opacity:1;cursor:default}
.terrain-marker[data-life]:not([data-life=""]){opacity:1}
.terrain-marker[data-life]:not([data-life=""])::after{display:block}
.endless-mode #goal-name{display:block}
@media(max-width:759px) and (orientation:portrait){.endless-mode #goal-icon{display:none}.endless-mode #goal-name{font-size:24px}}
/* Reserve the mode bar and controls inside short platform frames. */
@media(min-width:640px) and (orientation:landscape) and (max-height:760px){main{grid-template-columns:minmax(110px,1fr) minmax(130px,min(480px,calc(100dvh - 210px))) minmax(130px,1fr)}}

/* Explicitly reset inherited terrain pseudo-element geometry. */
.terrain-marker[data-life]:not([data-life=""])::after{inset:2px 2px auto auto;width:20px;height:20px;min-width:0;padding:0;transform:none;animation:none;border:0;border-radius:6px;font:700 13px/20px system-ui;background:#142031dd;box-shadow:none}
.mode-bar{font-size:19px;gap:6px}#mode-switch{font-size:18px;white-space:normal;line-height:1.15}
@media(max-height:650px){.mode-bar{font-size:17px}#mode-switch{font-size:16px}}
.terrain-marker[data-life]:not(.occupied) .terrain-art{visibility:hidden}

.cell.hard-rock{outline:2px solid #a9bfd8;outline-offset:-3px}

.endless-mode #goal-label{font-size:clamp(24px,2.6vw,32px);line-height:1.2}.best-trophy{display:block;font-size:52px;line-height:1.2}
@media(max-height:500px) and (orientation:landscape){.endless-mode #goal-label{font-size:22px}.best-trophy{font-size:40px}}

/* A brief input lock must not flash the persistent mode control. */
#mode-switch:disabled{opacity:1;cursor:pointer}

/* First move invitation: prominent, but transparent to all board input. */
.swipe-cue{inset:29% 6% auto;padding:10px 8px 14px;border:2px solid #ffd575;border-radius:18px;background:#111a2eef;color:#fff2cd;box-shadow:0 5px 0 #11182780,0 0 24px #ffd57525;text-shadow:0 2px 3px #000;pointer-events:none}
.swipe-cue>span{font-size:clamp(44px,17cqw,78px);line-height:1.1;color:#ffda75;animation:swipe-invite 1.8s ease-in-out infinite}
.swipe-cue strong{display:block;font-size:clamp(22px,8cqw,36px);line-height:1.15;margin:4px 0 8px}
.swipe-cue small{display:block;background:none;padding:0;font-size:clamp(14px,5cqw,22px);line-height:1.25;color:#dae4ff}
@keyframes swipe-invite{0%,100%{transform:translateX(-9px)}50%{transform:translateX(9px)}}
@media(prefers-reduced-motion:reduce){.swipe-cue>span{animation:none}}
@media(max-height:500px) and (orientation:landscape){.swipe-cue{padding:5px;inset:23% 4% auto}.swipe-cue>span{font-size:36px}.swipe-cue strong{font-size:20px;margin:2px 0 4px}.swipe-cue small{font-size:13px}}#tool-targets{position:absolute;inset:var(--pad);z-index:6;pointer-events:auto}#tool-targets[hidden]{display:none}#tool-targets button{position:absolute;left:calc(var(--col)*((100% + var(--gap))/5));top:calc(var(--row)*((100% + var(--gap))/5));width:calc((100% - 4*var(--gap))/5);height:calc((100% - 4*var(--gap))/5);border:2px solid #ffe59b;background:#172336bb;border-radius:7px;color:#fff2b6;font-size:clamp(11px,3.5cqw,17px)}#tool-targets button:disabled{opacity:.35;border-color:transparent;background:#10131d99}.tool-shop article{padding:12px 0;border-top:1px solid #45506d}.tool-shop h3{margin:8px 0}.tool-shop p{margin:4px}.tool-shop .primary{margin-top:8px}
@media(min-width:640px) and (orientation:landscape) and (max-height:760px){.endless-mode main{grid-template-columns:minmax(110px,1fr) minmax(130px,min(480px,calc(100dvh - 245px))) minmax(130px,1fr)}}
/* Shared gold treatment for both mode-switch directions. */
body #mode-switch{background:linear-gradient(180deg,#ffe49a,#edb949);color:#3c290e;border:1px solid #ffe8ae;box-shadow:0 3px 0 #98702b,0 0 12px #f5c45b25;text-shadow:0 1px 0 #fff0bd;font-weight:900}
body #mode-switch:hover{filter:brightness(1.07)}
/* Direct-access pixel tools, independent of the item shop. */
#skill-panel[hidden]{display:none}#skill-panel{width:100%;margin-top:18px}#skill-title{margin:0 0 9px;font-size:19px;color:#aab7d3;text-align:left}#skill-list{display:grid;gap:10px}.skill-card{position:relative;display:flex;align-items:center;gap:10px;width:100%;padding:10px;border:2px solid transparent;border-radius:15px;background:#232d43;text-align:left;min-width:0}.skill-card.selected{border-color:#ff963f;box-shadow:0 0 0 1px #ff963f}.skill-card img{width:clamp(38px,4vw,64px);height:clamp(38px,4vw,64px);background:#182034;border-radius:10px;padding:4px;image-rendering:pixelated;flex-shrink:0}.skill-copy{display:flex;flex-direction:column;gap:4px;min-width:0;padding-right:12px}.skill-copy strong{font-size:clamp(15px,1.6vw,22px);line-height:1.1}.skill-price{font-size:18px;color:#ffda75}.skill-price.free{color:#53de96}.skill-card kbd{position:absolute;right:7px;top:6px;border:1px solid #52668b;border-radius:4px;font:12px/16px system-ui;color:#aabbd9;padding:0 3px}.endless-mode .goal-panel .goal{height:auto}.endless-mode #goal-icon{display:none}
@media(min-width:640px) and (orientation:landscape){.endless-mode .goal-panel{align-self:center;max-width:310px;justify-self:center;width:100%}.endless-mode .goal-panel .goal{padding:12px;background:#182035;border-radius:16px;gap:4px}.endless-mode #goal-label{font-size:24px}.endless-mode #goal-name{font-size:34px}.endless-mode main{grid-template-columns:minmax(175px,1fr) minmax(130px,min(480px,calc(100dvh - 210px))) minmax(130px,1fr)}}
@media(min-width:640px) and (orientation:landscape) and (max-height:550px){#skill-panel{margin-top:10px}#skill-list{gap:6px}.skill-card{padding:6px;gap:6px;border-radius:10px}.skill-card img{width:34px;height:34px}.skill-copy strong{font-size:14px}.skill-price{font-size:15px}#skill-title{font-size:16px;margin-bottom:5px}.endless-mode .goal-panel .goal{padding:6px}.endless-mode #goal-label{font-size:20px}.endless-mode #goal-name{font-size:26px}}
@media(max-width:639px),(orientation:portrait){.endless-mode .goal-panel{position:static;transform:none;width:100%;margin-bottom:12px}.endless-mode .goal-panel .goal{display:flex;flex-direction:row;justify-content:center;height:auto;gap:12px}.endless-mode .play{padding-top:0}.endless-mode #skill-panel{margin-top:10px}#skill-title{font-size:16px;margin-bottom:6px}#skill-list{grid-template-columns:repeat(3,minmax(0,1fr));gap:6px}.skill-card{flex-direction:column;padding:7px 3px;gap:4px;text-align:center;border-radius:12px}.skill-card img{width:40px;height:40px}.skill-copy{padding:0;gap:3px}.skill-copy strong{font-size:14px}.skill-price{font-size:14px}.skill-card kbd{display:none}}

/* Keep the board ahead of tools on phones; retain generous touch targets. */
@media(max-width:759px) and (orientation:portrait){
 .endless-mode .play>#skill-panel{margin:10px 0 0}
 #skill-panel #skill-title,.skill-card .skill-copy strong,.skill-card kbd{display:none}
 #skill-list{grid-template-columns:repeat(3,minmax(0,1fr));gap:6px}
 #skill-list .skill-card{flex-direction:row;justify-content:center;gap:5px;padding:4px;min-height:48px;border-radius:10px}
 #skill-list .skill-card img{width:32px;height:32px;padding:2px;border-radius:6px}
 .skill-copy{padding:0;gap:0}
 #skill-list .skill-price{font-size:0;white-space:nowrap}
 #skill-list .skill-price::after{content:attr(data-compact);font-size:16px}
 .under-board{display:flex;justify-content:flex-end;gap:8px}
 .under-board .controls,.under-board .control-space{display:none}
 .under-board #restart{width:44px;flex-shrink:0}
}
.endless-invite.primary{background:linear-gradient(180deg,#ffe49a,#edb949);color:#3c290e;border:1px solid #ffe8ae;box-shadow:0 4px 0 #98702b;text-shadow:0 1px 0 #fff0bd;margin-bottom:24px}
@media(max-width:759px) and (orientation:portrait){
 #skill-panel{position:relative}
}
/* Give the board the available height in short landscape game frames. */
@media(min-width:640px) and (orientation:landscape) and (max-height:760px){
 body .app{padding-top:8px;padding-bottom:8px;max-width:1200px}
 header{margin-bottom:4px;height:40px}
 header .icon-btn{height:36px;min-width:36px}
 body main,body.endless-mode main{grid-template-columns:minmax(140px,1fr) minmax(250px,min(480px,calc(100dvh - 142px))) minmax(120px,.8fr);gap:14px;align-items:center}
 .play{padding-top:0}
 .mode-bar{min-height:26px;margin-bottom:4px;font-size:16px}
 body #mode-switch{font-size:16px;padding:3px 6px}
 .board-heading{height:46px;margin-bottom:6px}
 .endless-mode #moves{font-size:27px;white-space:nowrap;overflow-wrap:normal}
 .moves{min-width:0}.moves span{font-size:13px}
 .under-board .controls,.under-board #restart,.under-board .control-space{display:none}
 .under-board{height:0;min-height:0;margin:0;position:relative}
 #round-action:not([hidden]){position:absolute;bottom:10px;left:50%;transform:translateX(-50%);z-index:5}
 .endless-mode .goal-panel{max-width:240px}
 .endless-mode .goal-panel .goal{padding:6px;gap:2px}
 .endless-mode #goal-label{font-size:21px}.endless-mode #goal-name{font-size:28px}
 #skill-panel{margin-top:8px}#skill-title{font-size:16px;margin-bottom:4px}
 #skill-list{gap:6px}.skill-card{padding:6px;gap:6px;border-radius:10px}
 .skill-card img{width:36px;height:36px}.skill-copy strong{font-size:15px}.skill-price{font-size:16px}
}
@media(min-width:640px) and (orientation:landscape) and (max-height:420px){
 body main,body.endless-mode main{grid-template-columns:minmax(140px,1fr) minmax(200px,calc(100dvh - 142px)) minmax(110px,.8fr);gap:10px}
 .endless-mode .goal-panel .goal{padding:4px;gap:0}
 .endless-mode #goal-label{font-size:18px}.endless-mode #goal-name{font-size:22px}
 #skill-panel{margin-top:5px}#skill-title{font-size:14px;margin-bottom:3px}
 #skill-list{gap:4px}.skill-card{padding:4px;gap:5px}
 .skill-card img{width:30px;height:30px}.skill-copy{gap:1px}
 .skill-copy strong{font-size:13px}.skill-price{font-size:14px}
}

/* Use the supplied pixel artwork without shrinking it with inset padding. */
#skill-list .skill-card img{padding:0;object-fit:contain;background:#232b41}

/* The final score is the focal point; motion never changes layout. */
.result-score{display:flex;flex-direction:column;align-items:center;margin:14px 0 8px;padding:12px 8px;border-radius:16px;background:radial-gradient(ellipse,#e8b95119,transparent 72%);animation:score-reveal 550ms cubic-bezier(.16,.8,.25,1.2) both}
.result-score>span{font-size:23px;color:#c8d3ee;line-height:1.2}
.result-score>strong{display:block;min-height:1.15em;max-width:100%;font-size:clamp(48px,12vw,80px);line-height:1.15;color:#ffdc79;font-variant-numeric:tabular-nums;overflow-wrap:anywhere;text-shadow:0 3px 0 #8e602b,0 6px 8px #0007;animation:score-glow 1200ms ease-out both}
.endless-result h2{margin-bottom:10px}
@keyframes score-reveal{from{opacity:0;transform:translateY(10px) scale(.9)}to{opacity:1;transform:translateY(0) scale(1)}}
@keyframes score-glow{0%,100%{filter:brightness(1)}60%{filter:brightness(1.25)}}
@media(max-height:500px){.result-score{margin:6px 0;padding:6px}.result-score>strong{font-size:48px}.result-score>span{font-size:20px}}
@media(prefers-reduced-motion:reduce){.result-score,.result-score>strong{animation:none}}

/* A celebratory backdrop for endless completion, isolated from the controls. */
dialog.endless-result{isolation:isolate;background:radial-gradient(ellipse at 50% 25%,#58463366,transparent 65%),#1d2539;animation:endless-welcome 600ms ease-out both}
.endless-result #modal-content{position:relative;isolation:isolate}
.result-celebration{position:absolute;inset:0;z-index:-1;pointer-events:none;overflow:hidden;border-radius:18px}
dialog.endless-result::before{content:"";position:absolute;inset:0;z-index:-1;pointer-events:none;border-radius:inherit;background:radial-gradient(ellipse at 50% 30%,#ffda7526,transparent 70%);animation:celebration-glow 2.4s ease-in-out 2 both}
.result-celebration i{position:absolute;left:var(--x);top:var(--y);width:6px;height:10px;border-radius:2px;background:#ffdc79;opacity:0;animation:celebration-spark 2.2s var(--delay) ease-out both}
.result-celebration i:nth-child(3n){background:#b8c5ff;width:5px;height:5px}
@keyframes endless-welcome{from{opacity:0;transform:translateY(10px) scale(.97)}to{opacity:1;transform:none}}
@keyframes celebration-glow{0%,100%{opacity:.25}50%{opacity:1}}
@keyframes celebration-spark{0%{opacity:0;transform:translateY(15px) rotate(var(--spin))}20%{opacity:.65}100%{opacity:0;transform:translateY(-70px) rotate(calc(var(--spin) + 100deg))}}
@media(prefers-reduced-motion:reduce){dialog.endless-result,dialog.endless-result::before{animation:none}.result-celebration i{display:none}}

/* Start a gentle continuous pulse once the score count has settled. */
.result-score>strong.score-breathing{animation:score-breathe 1.8s ease-in-out infinite;transform-origin:center}
@keyframes score-breathe{0%,100%{transform:scale(1)}50%{transform:scale(1.07)}}
@media(prefers-reduced-motion:reduce){.result-score>strong.score-breathing{animation:none}}
