/* town-hud.css (TW7; town DESIGN §2.2, §2.3): the island HUD on the core tokens. Every selector names a tw- class.
   Town buttons are circles: big 104 (6-8 Action), main 92 (9-10 Action), side 84, small 68, card 60; nothing below the core
   60 px target. Tablets (shortest side >= 700 px) scale every Town button by 1.15 with 24 px margins. Every position adds
   env(safe-area-inset-*); the bottom 24 px stay free for the system bar. The press: a scale to .94 in one frame
   (.is-down, set in the pointerdown itself) and back on the token spring over --t-micro. Hidden controls fade out (180 ms).
   Positions (phone, portrait): 6-8 Toy Box 84 at left 16 / bottom 32, Action 104 at right 20 / bottom 40, Wish 68 at
   left 16 / top 96, Sun 64 at top 16 centred; 9-10 Wish at top 96, Toy Box 68 at top 176, Action 92 at right 20 /
   bottom 36, Jump 84 centred 80 px left of and above Action's centre. Landscape: Sky and Wish top left, the Sun top centre,
   the Toy Box and Action at the bottom corners 24 px up; 9-10 puts Toy Box and Wish in the top row (clear of the joystick
   zone, freecam.inJoyZone) and Jump 76 px off Action's centre; the landscape Sun is 60 px (§2.3 says 56, under the core
   60 px target). hud.js logs these deviations from §2.3. */

.tw-island { position: relative; min-height: 100%; }
/* without WebGL2 (§2.13): the still behind, a felt card where the starters greet one at a time (core stage2d), the calm line
   under it, the Toy Box bottom left and the films shelf bottom right; nothing in the top corners (the grown-ups key) */
.tw-no3d-wrap { position: fixed; left: calc(16px + env(safe-area-inset-left)); right: calc(16px + env(safe-area-inset-right)); top: calc(88px + env(safe-area-inset-top));
  bottom: calc(148px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; pointer-events: none; }
.tw-no3d-card { flex: none; width: min(100%, 440px); margin: 0; overflow: hidden; border-radius: 28px; background: var(--paper);
  box-shadow: 0 0 0 6px var(--card), var(--shadow-lift); pointer-events: auto; }
.tw-no3d-card canvas { display: block; width: 100%; height: auto; touch-action: manipulation; }
.tw-no3d { flex: none; max-width: 440px; margin: 0; padding: 14px 18px; border-radius: var(--radius); background: var(--card); color: var(--ink); box-shadow: var(--shadow);
  font-size: var(--label); line-height: 1.3; text-align: center; pointer-events: auto; }
.tw-hud.tw-hud-no3d .tw-toybox { --s: 84px; top: auto; left: calc(var(--m) + var(--sl)); bottom: calc(40px + var(--sb)); }
.tw-hud.tw-hud-no3d .tw-films { --s: 84px; right: calc(20px + var(--sr)); bottom: calc(40px + var(--sb)); }
@media (orientation: landscape) {
  .tw-no3d-wrap { top: calc(16px + env(safe-area-inset-top)); bottom: calc(16px + env(safe-area-inset-bottom)); left: calc(120px + env(safe-area-inset-left));
    right: calc(120px + env(safe-area-inset-right)); flex-direction: row; }
  .tw-no3d-card { width: min(56%, calc((100dvh - 44px) * 4 / 3)); }
  .tw-no3d { flex: 1 1 0; min-width: 0; max-width: 260px; text-align: left; }
  .tw-hud.tw-hud-no3d .tw-toybox, .tw-hud.tw-hud-no3d .tw-films { --s: 76px; bottom: calc(24px + var(--sb)); }
}

.tw-hud { position: fixed; inset: 0; z-index: var(--z-view); pointer-events: none; --k: 1; --m: 16px;
  --sl: env(safe-area-inset-left, 0px); --sr: env(safe-area-inset-right, 0px); --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px);
  transition: opacity 300ms ease; }
.tw-hud.tw-hud-off { opacity: 0; }
.tw-hud.tw-hud-off .tw-btn { pointer-events: none; }

.tw-hud .tw-btn { position: absolute; --s: 68px; width: calc(var(--s) * var(--k)); height: calc(var(--s) * var(--k)); padding: 0; margin: 0;
  display: grid; place-items: center; border: 0; border-radius: 50%; background: var(--card); color: var(--ink); cursor: pointer; pointer-events: auto;
  box-shadow: var(--shadow-lift), var(--press); touch-action: manipulation; -webkit-tap-highlight-color: transparent; user-select: none;
  transition: transform var(--t-micro) var(--spring), opacity 180ms ease, box-shadow var(--t-micro) ease; }
.tw-hud .tw-btn[hidden] { display: none; }
.tw-hud .tw-btn.tw-out { opacity: 0; pointer-events: none; }
.tw-hud .tw-btn.is-down { transform: scale(.94); transition-duration: 0ms; }
.tw-hud .tw-btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.tw-hud .tw-btn .ico { width: 46%; height: 46%; }
.tw-hud .tw-btn .tw-pic { width: 62%; height: 62%; object-fit: contain; pointer-events: none; }
.tw-hud .tw-ico { display: grid; place-items: center; width: 100%; height: 100%; transition: opacity 60ms ease; }
.tw-hud .tw-ico.tw-swap { opacity: 0; }

/* Action: coral, the current verb; Keep (core check) in place mode */
.tw-hud .tw-action { --s: 104px; right: calc(20px + var(--sr)); bottom: calc(40px + var(--sb)); background: var(--coral); color: var(--ink); }
.tw-hud .tw-action .ico { width: 50%; height: 50%; stroke-width: 2.4; }
.tw-hud .tw-action[data-verb="keep"] { background: var(--signal); }
.tw-hud .tw-action.tw-focus { box-shadow: 0 0 0 4px var(--signal), var(--shadow-lift), var(--press); animation: tw-pulse 1.6s ease-in-out infinite; }
.tw-hud .tw-jump { --s: 84px; display: none; }
.tw-hud .tw-toybox { --s: 84px; left: calc(var(--m) + var(--sl)); bottom: calc(32px + var(--sb)); }
.tw-hud .tw-toybox.tw-cancel { --s: 68px; }
.tw-hud .tw-sky { left: calc(var(--m) + var(--sl)); top: calc(var(--m) + var(--st)); }
.tw-hud .tw-wish { left: calc(var(--m) + var(--sl)); top: calc(var(--m) + 80px * var(--k) + var(--st)); }
.tw-hud .tw-wish.tw-glow { box-shadow: 0 0 0 4px var(--signal), var(--shadow-lift), var(--press); }
.tw-hud .tw-sun { --s: 64px; left: 50%; top: calc(var(--m) + var(--st)); margin-left: calc(-32px * var(--k)); background: var(--butter); }
.tw-hud .tw-sky.tw-wiggle { animation: tw-wiggle 420ms ease; }
/* the sky pop (§2.4, Phase B): a row of round beat buttons under Sky (hud.js places it from Sky's rect), sliding down in
   200 ms; 6-8 84 px, 9-10 76 px (tablets × 1.15). The refill ring round Sky's edge while a beat runs and for 6 s after it
   (no numbers), and the felt cloud a refused tap puffs from it. */
.tw-hud .tw-sky .tw-ring { position: absolute; inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px); transform: rotate(-90deg); pointer-events: none; overflow: visible; }
.tw-hud .tw-sky .tw-ring[hidden] { display: none; }
.tw-hud .tw-ring circle { fill: none; stroke-width: 5; stroke-linecap: round; }
.tw-hud .tw-ring-track { stroke: color-mix(in srgb, var(--ink) 14%, transparent); }
.tw-hud .tw-ring-fill { stroke: var(--signal); transition: stroke-dasharray 120ms linear; }
.tw-hud .tw-sky.tw-open { box-shadow: 0 0 0 4px var(--signal), var(--shadow-lift), var(--press); }
.tw-hud .tw-skypop { position: absolute; left: 0; top: 0; z-index: 2; display: flex; gap: 10px; pointer-events: none; }
.tw-hud .tw-skypop[hidden] { display: none; }
.tw-hud .tw-skypop .tw-btn { position: relative; --s: 84px; flex: none; pointer-events: auto; }
.tw-hud.tw-band-older .tw-skypop .tw-btn { --s: 76px; }
.tw-hud .tw-skypop .tw-btn .ico { width: 52%; height: 52%; }
.tw-hud .tw-skypop.tw-pop-in { animation: tw-pop-in 200ms var(--spring) both; }
.tw-hud .tw-puff { position: absolute; width: 34px; height: 34px; margin: -17px 0 0 -17px; color: var(--ink); background: var(--card); border-radius: 50%;
  display: grid; place-items: center; box-shadow: var(--shadow); pointer-events: none; animation: tw-puff 700ms ease-out both; }
.tw-hud .tw-puff .ico { width: 24px; height: 24px; }

/* world-placed: the edge pointer (64 px) and the invite bubble (96 px), moved by hud.js with the translate property on every
   drawn frame. translate takes no transition (issue TW6-5): each sits on its projected spot in the frame it is drawn, and
   appears there, instead of trailing it on the button spring; the fade in and out stays. The press is the transform
   (.is-down, scale .94), which composes with translate, so these two answer a press like every other control. */
.tw-hud .tw-edge, .tw-hud .tw-invite { transition: transform var(--t-micro) var(--spring), opacity 180ms ease, box-shadow var(--t-micro) ease; }
.tw-hud .tw-edge { --s: 64px; left: 0; top: 0; box-shadow: 0 0 0 3px var(--signal), var(--shadow-lift); }
.tw-hud .tw-edge .tw-pic { width: 100%; height: 100%; transition: transform 200ms ease; }
.tw-hud .tw-invite { --s: 96px; left: 0; top: 0; background: transparent; box-shadow: none; }
.tw-hud .tw-invite .tw-pic { width: 100%; height: 100%; filter: drop-shadow(0 6px 10px rgba(93, 63, 26, .22)); }

/* the hint line (9-10) and the fix toast, top centre */
.tw-hud .tw-pill, .tw-hud .tw-toast { position: absolute; left: 50%; top: calc(92px + var(--st)); transform: translateX(-50%); max-width: min(320px, calc(100vw - 32px));
  display: flex; align-items: center; gap: 10px; border-radius: 999px; background: var(--overlay-bg); color: var(--overlay-ink); box-shadow: var(--shadow); }
.tw-hud .tw-pill { min-height: 52px; padding: 6px 18px 6px 8px; font-size: var(--label); font-weight: 700; line-height: 1.2; pointer-events: auto; }
.tw-hud .tw-pill[hidden], .tw-hud .tw-toast[hidden] { display: none; }
.tw-hud .tw-pill-ico { flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--card); display: grid; place-items: center; }
.tw-hud .tw-pill-ico .ico { width: 24px; height: 24px; }
.tw-hud .tw-toast { height: 64px; padding: 4px 20px 4px 4px; font-size: var(--body); font-weight: 800; }
.tw-hud .tw-toast-pic { width: 56px; height: 56px; object-fit: contain; }
.tw-hud .tw-toast-ico { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 50%; background: var(--butter); }
.tw-hud .tw-toast-ico .ico { width: 30px; height: 30px; }
.tw-hud .tw-toast:not(:has(.tw-toast-word)) { padding-right: 4px; }
.tw-hud .tw-toast.tw-toast-in { animation: tw-toast-in 300ms var(--spring) both; }
.tw-hud .tw-toast.tw-toast-out { animation: tw-toast-out 220ms ease both; }

/* 9-10 (html.older), phone portrait */
html.older .tw-hud .tw-action { --s: 92px; right: calc(20px + var(--sr)); bottom: calc(36px + var(--sb)); }
html.older .tw-hud .tw-jump { display: grid; --s: 84px; right: calc(20px + 46px + 80px - 42px + var(--sr)); bottom: calc(36px + 46px + 80px - 42px + var(--sb)); }
html.older .tw-hud .tw-jump[hidden] { display: none; }
html.older .tw-hud .tw-toybox { --s: 68px; bottom: auto; top: calc(var(--m) + 160px * var(--k) + var(--st)); }

/* phone landscape */
@media (orientation: landscape) {
  .tw-hud .tw-sky { top: calc(12px + var(--st)); }
  .tw-hud .tw-wish { top: calc(88px + var(--st)); }
  .tw-hud .tw-sun { --s: 60px; top: calc(12px + var(--st)); margin-left: calc(-30px * var(--k)); }
  .tw-hud .tw-pill, .tw-hud .tw-toast { top: calc(76px + var(--st)); }
  .tw-hud .tw-toybox { --s: 76px; bottom: calc(24px + var(--sb)); }
  .tw-hud .tw-action { --s: 96px; right: calc(20px + var(--sr)); bottom: calc(24px + var(--sb)); }
  html.older .tw-hud .tw-toybox { --s: 68px; top: calc(12px + var(--st)); bottom: auto; left: calc(92px + var(--sl)); }
  html.older .tw-hud .tw-wish { top: calc(12px + var(--st)); left: calc(168px + var(--sl)); }
  html.older .tw-hud .tw-action { --s: 84px; right: calc(16px + var(--sr)); bottom: calc(24px + var(--sb)); }
  html.older .tw-hud .tw-jump { --s: 76px; right: calc(16px + 42px + 76px - 38px + var(--sr)); bottom: calc(24px + 42px + 76px - 38px + var(--sb)); }
}

/* tablets: the phone layout of the orientation, 24 px margins, buttons × 1.15 */
@media (min-width: 700px) and (min-height: 700px) {
  .tw-hud { --k: 1.15; --m: 24px; }
  .tw-hud .tw-action { right: calc(24px + var(--sr)); }
  html.older .tw-hud .tw-action { right: calc(24px + var(--sr)); }
  html.older .tw-hud .tw-jump { right: calc(24px + 53px + 80px - 48.3px + var(--sr)); bottom: calc(36px + 53px + 80px - 48.3px + var(--sb)); }
  html.older .tw-hud .tw-wish { top: calc(24px + 92px + var(--st)); }
  html.older .tw-hud .tw-toybox { top: calc(24px + 92px + var(--st)); left: calc(24px + 78px + 16px + var(--sl)); }
}
@media (min-width: 700px) and (min-height: 700px) and (orientation: landscape) {
  .tw-hud .tw-sky { top: calc(24px + var(--st)); }
  .tw-hud .tw-wish { top: calc(24px + 78px + 16px + var(--st)); }
  .tw-hud .tw-sun { top: calc(24px + var(--st)); }
  .tw-hud .tw-pill, .tw-hud .tw-toast { top: calc(24px + 64px + 16px + var(--st)); }
  .tw-hud .tw-toybox { bottom: calc(24px + var(--sb)); }
  .tw-hud .tw-action { right: calc(24px + var(--sr)); bottom: calc(24px + var(--sb)); }
  html.older .tw-hud .tw-toybox { top: calc(24px + var(--st)); left: calc(24px + 78px + 16px + var(--sl)); }
  html.older .tw-hud .tw-wish { top: calc(24px + var(--st)); left: calc(24px + 2 * (78px + 16px) + var(--sl)); }
  html.older .tw-hud .tw-action { right: calc(24px + var(--sr)); bottom: calc(24px + var(--sb)); }
  html.older .tw-hud .tw-jump { right: calc(24px + 48.3px + 87.4px - 43.7px + var(--sr)); bottom: calc(24px + 48.3px + 87.4px - 43.7px + var(--sb)); }
}


@keyframes tw-pulse { 0%, 100% { box-shadow: 0 0 0 4px var(--signal), var(--shadow-lift), var(--press); } 50% { box-shadow: 0 0 0 9px color-mix(in srgb, var(--signal) 35%, transparent), var(--shadow-lift), var(--press); } }
@keyframes tw-wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-9deg); } 60% { transform: rotate(7deg); } }
@keyframes tw-toast-in { from { transform: translate(-50%, -16px); opacity: 0; } }
@keyframes tw-toast-out { to { transform: translate(-50%, -12px); opacity: 0; } }
@keyframes tw-pop-in { from { transform: translateY(-28px); opacity: 0; } }
@keyframes tw-puff { 0% { transform: scale(.4); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 100% { transform: translate(18px, -26px) scale(1.25); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .tw-hud .tw-action.tw-focus { animation: none; }
  .tw-hud .tw-btn.is-down { transform: none; filter: brightness(.92); }
  .tw-hud .tw-toast.tw-toast-in, .tw-hud .tw-toast.tw-toast-out, .tw-hud .tw-sky.tw-wiggle { animation: none; }
  .tw-hud .tw-skypop.tw-pop-in { animation: tw-fade-in 200ms ease both; }
  .tw-hud .tw-puff { animation: tw-fade-out 700ms ease both; }
  .tw-hud .tw-ring-fill { transition: none; }
}
.tw-hud .tw-pill-pic { width: 34px; height: 34px; object-fit: contain; }
@keyframes tw-fade-in { from { opacity: 0; } }
@keyframes tw-fade-out { from { opacity: 1; } to { opacity: 0; } }
