/* Map screen. Tokens in styles.css per design/UI-SPEC.md. The terrain is one SVG; the grid above it is tap targets. */

.play {
  --cols: 10; --rows: 7;
  --chrome: calc(clamp(34px, 6vh, 60px) + 118px); /* horizon + mnemonic + legend; play.js measures the real figure */
  display: grid;
  grid-template-columns: minmax(170px, 210px) minmax(0, 1fr);
  gap: 14px;
  width: min(100%, calc(224px + (100dvh - 32px - var(--chrome)) * var(--cols) / var(--rows)));
  height: auto;
  align-items: stretch;
  text-align: left;
}
.scene-root { position: relative; isolation: isolate; width: 100%; display: grid; place-items: center; min-height: calc(100dvh - 32px); }
@media (orientation: portrait) {
  .play { grid-template-columns: 1fr; grid-template-rows: auto 1fr; width: 100%; }
}

/* ---------- panel ---------- */
.panel {
  display: grid;
  gap: 18px;
  align-content: start;
  padding: 16px 14px;
  border-radius: 26px;
  background: var(--panel);
  color: var(--panel-ink);
  box-shadow: 0 14px 40px var(--shadow);
}
@media (orientation: portrait) {
  .panel { grid-template-columns: 1fr auto; align-items: center; gap: 10px 14px; }
  .panel .hint, .panel .guide { grid-column: 1 / -1; }
}

.wordbox { display: flex; flex-wrap: wrap; gap: 4px; }
.slot {
  width: 30px; height: 38px;
  border-radius: 8px;
  background: var(--panel-edge);
  display: grid; place-items: center;
  font-size: 22px; font-weight: 800; text-transform: lowercase;
  color: var(--panel-ink);
  transition: background .2s, transform .2s var(--ease);
}
.slot.on { background: var(--accent); color: var(--next-ink); animation: pop .35s var(--ease); }
.lenny .slot { width: 44px; height: 54px; font-size: 32px; }

.btn-speak { min-width: var(--tap-min); padding: 0; justify-self: start; box-shadow: 0 6px 18px var(--shadow), inset 0 -3px 0 var(--surface-edge); }
.btn-speak svg { width: 28px; height: 28px; fill: currentColor; }
.lenny .btn-speak { min-width: var(--tap-big); min-height: var(--tap-big); }
.lenny .btn-speak svg { width: 40px; height: 40px; }

.guide { display: grid; gap: 6px; justify-items: center; }
.bubble {
  margin: 0;
  position: relative;
  background: var(--surface);
  color: #214a73;
  border-radius: 16px;
  padding: 10px 14px;
  font-size: 17px; font-weight: 700;
  width: 100%;
  text-align: center;
  box-shadow: 0 6px 18px var(--shadow);
}
.bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -8px;
  width: 16px; height: 16px; background: var(--surface);
  transform: translateX(-50%) rotate(45deg); border-radius: 3px;
}
.guide .owl { width: 110px; height: 120px; margin-top: 6px; }
@media (orientation: portrait) { .guide { grid-template-columns: 1fr auto; align-items: end; } .guide .owl { width: 80px; height: 88px; } }

.hint { margin: 0; font-size: 18px; font-weight: 800; }
.hint .clue { font-size: 56px; line-height: 1; }
.ending { padding: 0 .3em; border-radius: 6px; }
.ending-er  { color: var(--ending-er);  background: var(--ending-er-bg); }
.ending-est { color: var(--ending-est); background: var(--ending-est-bg); }
:root .panel .btn-back { justify-self: start; border-color: var(--panel-ink); color: var(--panel-ink); }

/* ---------- the map ---------- */
.map {
  display: grid; place-items: center; min-height: 0;
  border-radius: 26px;
  overflow: hidden;
  background: var(--snow);
  box-shadow: 0 14px 40px var(--shadow);
}
.grid {
  --cols: 10; --rows: 7;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  width: 100%;
  position: relative;
  touch-action: manipulation;
  align-self: center;
  align-content: start;
  grid-auto-rows: max-content;
}

.terrain { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; }
.terrain .snowfield { fill: var(--snow); }
.terrain .speck { fill: var(--speck); }
.terrain .shore rect { fill: var(--shore); }
.terrain .water rect { fill: var(--water); }
.terrain .ripple { fill: none; stroke: var(--ripple); stroke-width: 3; stroke-linecap: round; }
.terrain .ice-slab { fill: var(--ice); }
.terrain .ice-line { fill: none; stroke: var(--ice-line); stroke-width: 2; stroke-linecap: round; }
.terrain .ground-shadow { fill: var(--ground-shadow); }
.terrain .tree-body { fill: var(--tree); }
.terrain .tree-dark { fill: var(--tree-2); opacity: .5; }
.terrain .tree-snow { fill: var(--tree-snow); opacity: .9; }
.terrain .trunk { fill: var(--trunk); }
.terrain .rock-body { fill: var(--rock); }
.terrain .rock-line { fill: none; stroke: var(--rock-2); stroke-width: 3; stroke-linecap: round; opacity: .6; }
.terrain .raft-body { fill: var(--raft); }
.terrain .raft-line { stroke: var(--raft-line); stroke-width: 2; opacity: .5; }
.terrain .raft-rope { fill: var(--rope); stroke: var(--rope); stroke-width: 3; }
.terrain .raft-flag { fill: var(--accent); }

.tile {
  appearance: none; border: 0; margin: 0; padding: 0;
  font: inherit; color: inherit;
  background: transparent;
  display: grid; place-items: center;
  position: relative; z-index: 1;
  width: 100%;
  aspect-ratio: 1 / 1;
  min-width: 0; min-height: 0;
}
button.tile { cursor: pointer; border-radius: 16px; }
button.tile:focus-visible { outline: 3px solid var(--focus); outline-offset: -6px; }

/* letter pillows */
.tile.letter::before {
  content: ""; position: absolute; inset: 14%;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--outline-soft), 0 4px 0 var(--surface-edge), 0 8px 18px var(--shadow);
  transition: background .2s, box-shadow .2s;
}
.tile.letter { color: #214a73; }
.tile.letter .glyph { position: relative; font-size: clamp(13px, 2.8vmin, 30px); font-weight: 800; }
.tile.letter.next::before { background: var(--next); box-shadow: 0 4px 0 color-mix(in srgb, var(--next), #000 18%), 0 0 24px 6px var(--next-glow); }
.tile.letter.next { color: var(--next-ink); animation: pulse 1.4s ease-in-out infinite; }
.lenny .tile.letter .glyph { font-size: clamp(24px, 7vmin, 56px); }
.tile.wobble { animation: wobble .4s ease-in-out; }
.tile.collected::before { display: none; }
.tile.collected::after {
  content: ""; position: absolute; inset: 36%; border-radius: 50%;
  border: 3px solid var(--accent); opacity: .45;
}

/* avatar */
.avatar {
  position: absolute; left: 0; top: 0;
  width: calc(100% / var(--cols));
  height: calc(100% / var(--rows));
  display: grid; place-items: center;
  pointer-events: none;
  z-index: 2;
}
.avatar svg { display: block; width: 100%; height: 100%; }
/* A definite tile-sized box prevents the portrait SVG's intrinsic aspect
   ratio from stretching the walking wrapper beyond the occupied tile. */
.avatar-stride { position:absolute; inset:5% 0; display:block; min-width:0; min-height:0; transform-origin:50% 90%; }
/* Keep walking separate from the SVG's facing direction and raft scale. */
@media (prefers-reduced-motion: no-preference) {
  .avatar.stepping:not(.aboard) .avatar-stride { animation: explorer-walk .32s ease-in-out infinite; }
}
@keyframes explorer-walk {
  0%, 50%, 100% { transform:translateY(0) rotate(0); }
  25% { transform:translateY(-4%) rotate(-3deg); }
  75% { transform:translateY(-4%) rotate(3deg); }
}
.done .avatar svg { animation: cheer .6s var(--ease) 1; }

.sparkle {
  position: absolute; inset: 0; pointer-events: none; z-index: 3;
  background: radial-gradient(circle, var(--next) 0 18%, transparent 20%) center / 100% 100% no-repeat;
  animation: sparkle .7s ease-out forwards;
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@keyframes pop { from { transform: scale(.6); } to { transform: scale(1); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }
@keyframes wobble { 0%, 100% { transform: translateX(0) rotate(0); } 25% { transform: translateX(-4px) rotate(-4deg); } 75% { transform: translateX(4px) rotate(4deg); } }
@keyframes cheer { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-30%) scale(1.1); } }
@keyframes sparkle { from { transform: scale(.2); opacity: 1; } to { transform: scale(2.2); opacity: 0; } }
@keyframes glow { from { box-shadow: 0 0 0 4px var(--next) inset; } to { box-shadow: 0 0 0 7px var(--next) inset; } }

@media (prefers-reduced-motion: reduce) {
  .tile.letter.next, .done .avatar svg, .tile.raft-glow { animation: none; }
  .avatar { transition: none !important; }
}

/* ---------- word box with picture clue (Lenny) ---------- */
.wordbox-wrap { display: grid; gap: 8px; justify-items: start; }
.wordbox-wrap .clue { font-size: 64px; line-height: 1; }
@media (orientation: portrait) { .wordbox-wrap { grid-template-columns: auto 1fr; align-items: center; gap: 12px; } }
.lenny .panel { gap: 14px; }
.lenny .bubble { font-size: 19px; }

/* ---------- celebration ---------- */
.celebrate {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg-2) 70%, transparent);
  animation: fade .3s var(--ease);
}
.celebrate-card {
  position: relative;
  display: grid; gap: 10px; justify-items: center;
  padding: 36px 48px 40px;
  border-radius: 32px;
  background: var(--surface);
  color: #214a73;
  box-shadow: 0 24px 60px var(--shadow);
  animation: pop .45s var(--ease);
  text-align: center;
}
.celebrate-clue { font-size: 96px; line-height: 1; }
.celebrate-word { margin: 0; font-size: clamp(44px, 10vw, 84px); font-weight: 800; letter-spacing: .04em; }
.celebrate-note { margin: 0 0 8px; font-size: 18px; font-weight: 700; color: #4e6a82; font-variant-numeric: tabular-nums; }
.confetti {
  position: absolute; top: -10px; left: var(--x);
  width: 12px; height: 12px; border-radius: 3px;
  background: var(--accent);
  animation: confetti 1.6s var(--d) ease-in forwards;
}
.confetti:nth-child(even) { background: var(--next); border-radius: 50%; }
.confetti:nth-child(3n) { background: var(--accent-2); }
@keyframes confetti { from { transform: translateY(0) rotate(0); opacity: 1; } to { transform: translateY(110vh) rotate(540deg); opacity: 0; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .confetti { display: none; } .celebrate, .celebrate-card { animation: none; } }

/* ---------- things on the map ---------- */
.entity {
  position: absolute; left: 0; top: 0;
  width: calc(100% / var(--cols));
  height: calc(100% / var(--rows));
  display: grid; place-items: center;
  pointer-events: none;
  z-index: 2;
  transition: opacity .4s var(--ease);
}
.entity svg { width: 100%; height: 100%; }
.entity.bear { z-index: 3; }
.entity.bear svg { animation: lumber 1s ease-in-out infinite alternate; }
.entity.bear.flip svg { transform: scaleX(-1); }
.entity.bear.flip svg { animation-name: lumber-flip; }
.entity.snowball svg { transition: transform .26s var(--ease); }
.entity.snowball.sink svg { animation: sink .6s var(--ease) forwards; }
.entity.fish svg { animation: flop 1.6s ease-in-out infinite; }
.entity.fish.taken { opacity: 0; transform: translateY(-20%) !important; }
.entity.penguin.waddle svg { animation: waddle .3s ease-in-out infinite alternate; }
.entity.gone { opacity: 0; }
.caught .avatar svg { animation: shiver .12s ease-in-out 8; }

.terrain .wall-body { fill: var(--wall); }
.terrain .wall-stone { fill: var(--wall-2); opacity: .55; }
.terrain .wall-snow { fill: none; stroke: var(--tree-snow); stroke-width: 6; stroke-linecap: round; opacity: .9; }
.terrain .drift { fill: var(--tree-snow); opacity: .35; }
.tile.wall, .tile.water, .tile.tree, .tile.rock { pointer-events: none; }

/* carrying the fish */
.carry { display: flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 700; min-height: 32px; }
.carry svg { width: 40px; height: 40px; }
.carry:empty { display: none; }

@keyframes lumber { from { transform: rotate(-3deg); } to { transform: rotate(3deg); } }
@keyframes lumber-flip { from { transform: scaleX(-1) rotate(-3deg); } to { transform: scaleX(-1) rotate(3deg); } }
@keyframes sink { to { transform: translateY(25%) scale(.5); opacity: 0; } }
@keyframes flop { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-8deg) translateY(-4%); } }
@keyframes waddle { from { transform: rotate(-6deg); } to { transform: rotate(6deg); } }
@keyframes shiver { from { transform: translateX(-4%); } to { transform: translateX(4%); } }
@media (prefers-reduced-motion: reduce) { .entity.bear svg, .entity.fish svg, .entity.penguin.waddle svg { animation: none; } }

/* ---------- the world pass: signboard panel, horizon, slick ice, shrubs ---------- */
.panel {
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--wood) 92%, #fff) 0 14px, transparent 14px),
    repeating-linear-gradient(180deg, var(--wood) 0 34px, color-mix(in srgb, var(--wood) 86%, #000) 34px 36px);
  color: var(--wood-ink);
  box-shadow: inset 0 0 0 4px color-mix(in srgb, var(--wood) 70%, #000), 0 14px 40px var(--shadow);
  position: relative;
  padding-top: 22px;
}
.panel::before {
  /* snow on top of the board */
  content: ""; position: absolute; left: 6px; right: 6px; top: -6px; height: 18px;
  background: var(--tree-snow); border-radius: 12px 12px 6px 6px / 12px 12px 10px 10px;
  box-shadow: 0 3px 0 rgba(0,0,0,.08);
}
.panel .wordbox-wrap, .panel .guide, .panel .hint, .panel .trip {
  background: var(--surface); color: #214a73;
  border-radius: 12px; padding: 10px;
  box-shadow: inset 0 -3px 0 var(--surface-edge);
}
.panel .wordbox-wrap { padding: 10px; }
.panel .slot { background: #e8dcbb; color: #214a73; }
.panel .slot.on { background: var(--accent); color: var(--next-ink); }
.panel .guide { padding: 10px 8px 6px; }
.panel .bubble { box-shadow: none; background: transparent; padding: 0 0 6px; }
.panel .bubble::after { display: none; }
.panel .hint { font-size: 17px; }
.panel .carry { font-size: 14px; }
/* the board fills its height: free space sits under the owl, the trip and the buttons stay at the foot */
@media (orientation: landscape) {
  .panel { grid-template-rows: auto auto minmax(0, 1fr) auto auto; }
  .panel .guide { align-self: start; }
}
.say-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; align-items: center; }
.say-row .hint { margin: 0; min-height: var(--tap-min); display: flex; align-items: center; }
.say-row .hint:empty { display: none; }
.trip { display: grid; gap: 6px; font-size: 14px; font-weight: 700; }
.trip-line { margin: 0; }
.trip-stops { display: flex; flex-wrap: wrap; gap: 4px; }
.trip-stops .stop { width: 10px; height: 10px; border-radius: 50%; background: #e8dcbb; box-shadow: inset 0 0 0 1.5px var(--outline-soft); }
.trip-stops .stop.done { background: var(--accent); }
.trip-stops .stop.now { background: var(--next); box-shadow: 0 0 0 2px var(--next-ink); }
.trip-stats { margin: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.trip-stats .coins { display: inline-flex; align-items: center; gap: 4px; }
.trip-stats .coins svg { width: 18px; height: 18px; }
.trip-stats .coin { fill: var(--next); stroke: var(--outline-soft); stroke-width: 1.5; }
.trip-stats .coin-in { fill: none; stroke: color-mix(in srgb, var(--next), #000 25%); stroke-width: 1.5; }
.trip .carry { min-height: 0; }
.trip .carry svg { width: 28px; height: 28px; }
.sign-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
:root .panel .btn-sign {
  min-height: 48px; padding: 0 10px; font-size: 16px; border-radius: 10px;
  background: var(--surface); color: #214a73; border: 0; opacity: 1;
  box-shadow: inset 0 -3px 0 var(--surface-edge), 0 4px 10px var(--shadow);
}
:root .panel .btn-sign:active { transform: translateY(2px); box-shadow: inset 0 -1px 0 var(--surface-edge); }
:root .lenny .panel .btn-sign { min-height: var(--tap-big); font-size: 20px; }
@media (orientation: portrait) {
  .panel { padding-top: 18px; }
  .sign-actions { grid-column: 1 / -1; }
}

.map-wrap { display: grid; grid-template-rows: auto 1fr; min-height: 0; min-width: 0; gap: 0; }
.map { min-width: 0; }
.horizon { display: block; width: 100%; height: clamp(34px, 6vh, 60px); }
.horizon .peak { fill: var(--peak); }
.horizon .peak-snow { fill: var(--tree-snow); opacity: .9; }
.horizon .far-tree { fill: var(--tree-2); opacity: .8; }
.horizon .horizon-snow { fill: var(--snow); }
.map { border-radius: 0 0 26px 26px; }
@media (orientation: portrait) { .horizon { display: none; } .map { border-radius: 26px; } }

.terrain .shrub-body { fill: var(--shrub); }
.terrain .berry { fill: var(--accent); opacity: .85; }
.terrain .slick-body { fill: var(--slick); }
.terrain .slick-sheen { fill: none; stroke: var(--slick-sheen); stroke-width: 4; stroke-linecap: round; opacity: .8; }
.terrain .slick-arrow { fill: none; stroke: var(--slick-arrow); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; opacity: .7; }
.terrain .water-light rect { fill: var(--water-light); }
.sliding .avatar svg { animation: none; transform: rotate(-6deg); }
.tile.slick, .tile.shrub { }


/* ---------- contrast pass: outlines on the world, the owl on a sky card ---------- */
.terrain .tree-body, .terrain .rock-body, .terrain .shrub-body, .terrain .wall-body,
.terrain .raft-body, .terrain .ice-slab, .terrain .slick-body, .terrain .trunk {
  stroke: var(--outline-soft); stroke-width: 2.5; stroke-linejoin: round; paint-order: stroke fill;
}
.terrain .tree-dark { opacity: .6; }
.terrain .shore rect { fill: var(--shore); }
.panel .guide { background: var(--guide-bg); }
.panel .bubble { color: var(--ink); }
.test-guide .bubble { background: var(--guide-bg); }
.celebrate-card { box-shadow: 0 0 0 3px var(--outline-soft), 0 24px 60px var(--shadow); }

/* ---------- from the Let's Play: mnemonic strip, deep snow, sleeping bear, tappable objects ---------- */
.map-wrap { grid-template-rows: auto 1fr auto auto; }
.mnemonic {
  margin: 8px 0 0; padding: 10px 16px;
  border-radius: 14px;
  background: var(--surface); color: #214a73;
  font-size: clamp(16px, 2.2vw, 20px); font-weight: 600; text-align: center;
  box-shadow: inset 0 -3px 0 var(--surface-edge), 0 0 0 2px var(--outline-soft);
}
.mnemonic .lit { color: #214a73; font-weight: 800; text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 3px; text-underline-offset: 3px; }
@media (orientation: portrait) { .mnemonic { font-size: 15px; } }
.terrain .deep-snow rect { fill: var(--deep); }
.terrain .deep-fleck { fill: none; stroke: var(--deep-fleck); stroke-width: 3; stroke-linecap: round; opacity: .8; }
.entity.bear.asleep svg { animation: snooze 2.4s ease-in-out infinite; }
.entity.bear.asleep::after { content: "z z"; position: absolute; top: 8%; right: 10%; font-size: clamp(12px, 2vmin, 18px); font-weight: 800; color: var(--ink); animation: zz 2.4s ease-in-out infinite; }
@keyframes snooze { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04) translateY(2%); } }
@keyframes zz { 0% { opacity: 0; transform: translateY(0); } 40% { opacity: 1; } 100% { opacity: 0; transform: translateY(-40%); } }
button.tile.object { cursor: help; }
button.tile.object:focus-visible { outline: 3px solid var(--focus); outline-offset: -6px; }
.tile.wall, .tile.water, .tile.tree, .tile.rock, .tile.shrub { pointer-events: auto; }
@media (prefers-reduced-motion: reduce) { .entity.bear.asleep svg, .entity.bear.asleep::after { animation: none; } }

/* ---------- the jeopardy stage: raft, water life, floes, sailing off ---------- */
.entity.raft { z-index: 1; }
.entity.raft svg { animation: bobbing 3s ease-in-out infinite; }
.avatar.aboard svg { transform: translateY(-26%) scale(.72); }
.avatar.face-left svg { transform: scaleX(-1); }
.avatar.aboard.face-left svg { transform: translateY(-26%) scale(.72) scaleX(-1); }
.entity.raft svg { transform: scale(1.18); }
.avatar.aboard { z-index: 3; }
.entity.orca svg { animation: swim 1.6s ease-in-out infinite; }
.entity.seal svg { animation: swim 2.2s ease-in-out infinite; }
.entity.orca.flip svg, .entity.seal.flip svg { animation-name: swim-flip; }
.entity.floe { z-index: 1; }
.entity.floe svg { animation: bobbing 4s ease-in-out infinite; }
.tile.raft-glow { box-shadow: 0 0 0 4px var(--next) inset; border-radius: 22px; animation: glow 1.2s ease-in-out infinite alternate; }
.sailing-off .avatar svg { animation: none; }
.terrain .water-light rect { fill: var(--water-light); }
@keyframes swim { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-6%) rotate(-3deg); } }
@keyframes swim-flip { 0%, 100% { transform: scaleX(-1) translateY(0) rotate(0); } 50% { transform: scaleX(-1) translateY(-6%) rotate(3deg); } }
@media (prefers-reduced-motion: reduce) { .entity.raft svg, .entity.orca svg, .entity.seal svg, .entity.floe svg { animation: none; } }

/* ---------- the legend: what to avoid, what helps, and how ---------- */
.legend {
  list-style: none; margin: 8px 0 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: 6px 8px; justify-content: center;
}
.legend-chip {
  appearance: none; border: 0; font: inherit; cursor: pointer;
  display: grid; grid-template-columns: 34px auto; align-items: center; gap: 8px;
  min-height: 48px; padding: 3px 10px 3px 6px;
  border-radius: 14px;
  background: var(--surface); color: #214a73;
  box-shadow: inset 0 -3px 0 var(--surface-edge), 0 0 0 2px var(--outline-soft);
  text-align: left;
  transition: transform .2s var(--ease);
}
.legend-chip:active { transform: scale(.97); }
.legend-chip:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.legend-icon { width: 28px; height: 28px; display: grid; place-items: center; position: static; pointer-events: none; }
.legend-icon svg { width: 100%; height: 100%; }
.legend-text { display: grid; line-height: 1.15; }
.legend-text b { font-size: 14px; font-weight: 800; }
.legend-how { font-size: 12px; font-weight: 600; color: var(--ink-muted); }
.legend-chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; position: absolute; }
.legend li { position: relative; }
/* the group is a sign on the picture, not a word: a round "no" badge to avoid, a round tick that helps */
.legend-icon-wrap { position: relative; width: 34px; height: 34px; display: grid; place-items: center; }
.legend-icon-wrap .legend-icon { width: 30px; height: 30px; }
.legend-badge { position: absolute; right: -6px; bottom: -6px; width: 18px; height: 18px; }
.legend-badge .badge-ring { fill: #fff6dc; stroke: #a4201c; stroke-width: 3; }
.legend-badge .badge-ring-ok { stroke: #146c3a; }
.legend-badge .badge-mark { fill: none; stroke: #a4201c; stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }
.legend-helps .legend-badge .badge-mark { stroke: #146c3a; }
.legend-swatch { border-radius: 9px; box-shadow: inset 0 0 0 2px var(--outline-soft); }
.legend-slick { background: var(--ice); background-image: linear-gradient(135deg, transparent 40%, var(--ice-line) 40% 48%, transparent 48%); }
.legend-ice { background: var(--ice); }
.legend-deep { background: var(--deep); background-image: radial-gradient(var(--deep-fleck) 1.5px, transparent 2px); background-size: 8px 8px; }
@media (orientation: portrait) { .legend-how { display: none; } .legend-chip { min-height: 40px; } }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .legend-chip { color: #0b1626; } :root:not([data-theme="light"]) .legend-how { color: #2b4a6b; } }

/* ---------- the d-pad: touch screens only, in the signboard (landscape) or floating (portrait) ---------- */
.dpad {
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 4px;
  width: 100%; max-width: 168px; aspect-ratio: 1 / 1; justify-self: center;
  grid-template-areas: ". up ." "left . right" ". down .";
}
.dpad-btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-size: 22px; line-height: 1;
  min-width: 48px; min-height: 48px; border-radius: 14px;
  background: var(--surface); color: #214a73;
  box-shadow: inset 0 -3px 0 var(--surface-edge), 0 4px 10px var(--shadow);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.dpad-btn:active { transform: translateY(2px); box-shadow: inset 0 -1px 0 var(--surface-edge); }
.dpad-btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.dpad-up { grid-area: up; } .dpad-down { grid-area: down; } .dpad-left { grid-area: left; } .dpad-right { grid-area: right; }
.lenny .dpad { max-width: 220px; } .lenny .dpad-btn { min-width: 64px; min-height: 64px; font-size: 28px; }
@media (orientation: landscape) {
  .panel { grid-template-rows: auto auto minmax(0, 1fr) auto auto auto; }
  .panel:not(:has(.dpad)) { grid-template-rows: auto auto minmax(0, 1fr) auto auto; }
}
@media (orientation: portrait) {
  /* beside the trip block in the signboard, so it never covers the map */
  .dpad { width: 150px; justify-self: end; align-self: center; }
  .lenny .dpad { width: 200px; }
}

/* ---------- the way out ---------- */
.terrain .buoy { fill: var(--accent); stroke: var(--outline-soft); stroke-width: 2; paint-order: stroke fill; }
.terrain .buoy-shadow { fill: var(--ground-shadow); opacity: .5; }
.terrain .pole { fill: var(--wood); }
.terrain .flag { fill: var(--next); stroke: var(--outline-soft); stroke-width: 2; paint-order: stroke fill; }
.tile.exit-glow { box-shadow: 0 0 0 4px var(--next) inset; border-radius: 22px; animation: glow 1.2s ease-in-out infinite alternate; }
.grid.splashed .avatar svg { animation: shiver .12s ease-in-out 5; }

/* the menu sheet */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(7,16,32,.45); display: grid; align-items: end; justify-items: center; animation: fade .2s var(--ease); }
.sheet-card { width: min(100%, 720px); max-height: 85dvh; overflow: auto; background: var(--surface); color: #214a73; border-radius: 26px 26px 0 0; padding: 18px 18px max(18px, env(safe-area-inset-bottom)); display: grid; gap: 14px; box-shadow: 0 -14px 40px rgba(0,0,0,.3); }
.sheet-body { display: grid; gap: 14px; }
.handheld .sheet .hint { display: flex; font-size: 20px; margin: 0; justify-content: center; }
.handheld .sheet .mnemonic { display: block; margin: 0; }
.handheld .sheet .legend { display: flex; margin: 0; }
.handheld .sheet .legend-text { display: grid; }
.handheld .sheet .legend-chip { grid-template-columns: 34px auto; padding: 3px 10px 3px 6px; min-width: 0; justify-items: start; }
.handheld .sheet .legend-icon-wrap { width: 34px; height: 34px; }
.handheld .sheet .sign-actions { display: grid; }
.sheet .sheet-done { justify-self: center; min-height: 56px; font-size: 22px; }
.sheet-open .map-wrap, .sheet-open .dpad, .sheet-open .say-row { pointer-events: none; }
.btn-sign.armed { background: var(--next) !important; color: var(--next-ink) !important; }

/* Desktop controls belong beside the world, not in a giant sign above it.
   A compact top deck is used only where a sidebar would make the tiles too small. */
.play:not(.handheld) {
  --desktop-hud: 0px;
  grid-template-columns: 224px minmax(0, 1fr);
  grid-template-rows: auto;
  width: min(100%, calc(238px + (100dvh - 32px - var(--chrome)) * var(--cols) / var(--rows)));
  align-items: start;
}
.play:not(.handheld) .panel {
  min-width: 0; margin-top: 8px; padding: 14px;
  grid-template-columns: minmax(0, 1fr); grid-template-rows: auto;
  gap: 12px; align-content: start; align-items: start;
  background: #92b9cb; color: #253e50; border-radius: 22px;
  border: 1px solid #6e97aa;
  box-shadow: inset 0 2px 0 #e4f0f580, inset 0 -4px 0 #54778955, 0 12px 28px var(--shadow);
}
.play:not(.handheld) .panel::before { display: none; }
.play:not(.handheld) .panel > * { grid-column: auto; min-width: 0; }
.play:not(.handheld) .panel .wordbox-wrap { display:flex; flex-wrap:wrap; align-items:center; gap:8px; padding:10px; background:#263841; box-shadow:inset 0 2px 4px #13252e55; }
.play:not(.handheld) .panel .wordbox { gap:4px; }
.play:not(.handheld) .panel .slot { width:28px; height:34px; background:#f1eee4; font-size:22px; }
.play:not(.handheld) .panel .slot.on { background:var(--next); color:var(--next-ink); }
.play:not(.handheld) .panel .btn-speak { display:flex; align-items:center; justify-content:center; gap:5px; padding:8px; min-height:48px; border-radius:14px; font-size:16px; }
.play:not(.handheld) .panel .btn-speak svg { width:24px; height:24px; }
.play:not(.handheld) .panel .hint { padding:8px; font-size:15px; min-height:48px; }
.play:not(.handheld) .panel .guide { grid-template-columns:48px minmax(0,1fr); gap:8px; align-items:center; padding:10px; }
.play:not(.handheld) .panel .guide .owl { order:-1; width:48px; height:56px; margin:0; }
.play:not(.handheld) .panel .bubble { font-size:15px; line-height:1.4; text-align:left; padding:0; }
.play:not(.handheld) .panel .trip { gap:7px; background:none; padding:4px; box-shadow:none; color:#253e50; }
.play:not(.handheld) .panel .sign-actions { grid-template-columns:1fr; gap:8px; }
.play:not(.handheld) .panel .btn-sign { min-height:48px; }
.play:not(.handheld) .map-wrap { grid-template-rows:auto auto auto; align-content:start; }
.play:not(.handheld) .horizon { display:block; height:36px; }
.play:not(.handheld) .map { border-radius:0 0 22px 22px; }
.play:not(.handheld).lenny .panel .slot { width:38px; height:46px; font-size:30px; }
.play:not(.handheld).lenny .panel .btn-speak,.play:not(.handheld).lenny .panel .btn-sign { min-height:72px; }
.play:not(.handheld).lenny .panel .btn-speak { min-width:72px; }
@media(max-width:999px) {
  .play:not(.handheld) {
    grid-template-columns:minmax(0,1fr); grid-template-rows:auto auto; gap:10px;
    width:min(100%,calc((100dvh - 212px - var(--chrome)) * var(--cols) / var(--rows)));
  }
  .play:not(.handheld) .panel { margin-top:0; padding:12px; grid-template-columns:minmax(0,1fr) auto auto; grid-template-rows:auto auto; gap:10px; }
  .play:not(.handheld) .panel .wordbox-wrap { grid-column:1; grid-row:1; }
  .play:not(.handheld) .panel .say-row { grid-column:2; grid-row:1; }
  .play:not(.handheld) .panel .sign-actions { grid-column:3; grid-row:1; display:flex; }
  .play:not(.handheld) .panel .guide { grid-column:1 / 3; grid-row:2; padding:6px 10px; }
  .play:not(.handheld) .panel .trip { grid-column:3; grid-row:2; align-self:center; }
  .play:not(.handheld) .panel .guide .owl { width:36px; height:42px; }
  .play:not(.handheld) .panel .guide { grid-template-columns:36px minmax(0,1fr); }
  .play:not(.handheld) .horizon { display:none; }
  .play:not(.handheld) .map { border-radius:22px; }
}
@media(max-width:650px) {
  .play:not(.handheld) { width:100%; }
  .play:not(.handheld) .panel { grid-template-columns:minmax(0,1fr) auto; }
  .play:not(.handheld) .panel .sign-actions { grid-column:1 / -1; grid-row:3; }
  .play:not(.handheld) .panel .guide { grid-column:1; }
  .play:not(.handheld) .panel .trip { grid-column:2; }
}
@media(min-width:651px) and (max-width:999px) {
  .play:not(.handheld) .panel .say-row { display:flex; }
}
