/* 🏝️ CASTAWAY PIG — sea and sand: chunky rounded panels the colour of a
   beach, with a sea-glass edge. The canvas fills the screen; everything else
   floats over it, out of the way of your thumbs. */
:root {
  --sand: #f7e6bc; --sand2: #efd59a; --sand3: #e2bf73; --wood: #8a5a32; --wood2: #5f3a1e; --ink: #3a2618;
  --sea: #1f8fbf; --sea2: #136a94; --deep: #0b3d5c; --foam: #f4fbff; --coral: #ff7a6b; --leaf: #4caf50; --gold: #ffcf4a;
  --r: 18px; --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px); --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
#title-cv { z-index: 10; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--deep); color: var(--ink); font: 16px/1.35 "Trebuchet MS", "Segoe UI", system-ui, sans-serif; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
body { position: fixed; inset: 0; touch-action: manipulation; }
button, a.btn { font: inherit; }
#cv { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; }
#cv.dim { opacity: 0; }
.muted { color: #6d5a43; } .small { font-size: 0.85em; }
kbd { display: inline-block; padding: 0 6px; border-radius: 6px; background: #fff7df; border: 2px solid var(--sand3); border-bottom-width: 3px; font: bold 0.85em system-ui, sans-serif; color: var(--ink); }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px; border-radius: 14px; border: 3px solid var(--wood2); background: linear-gradient(#fff6dc, var(--sand2)); color: var(--ink); font-weight: bold; text-decoration: none; cursor: pointer; box-shadow: 0 4px 0 var(--wood2), 0 6px 14px rgba(0,0,0,.25); transition: transform .08s; }
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--wood2); }
.btn.hot { background: linear-gradient(#ffe48a, #ffb340); }
.btn.big { min-height: 56px; font-size: 1.15em; padding: 10px 22px; }
.btn.small { min-height: 36px; padding: 4px 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.close { min-height: 40px; min-width: 40px; padding: 4px 10px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; align-items: center; margin-top: 10px; }
.row.between { justify-content: space-between; margin-top: 0; }

/* ---------- full screens ---------- */
.screen { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: calc(12px + var(--safe-t)) 12px calc(12px + var(--safe-b)); overflow: auto; }
.screen[hidden] { display: none; }
.bg-scene { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: -1; background: linear-gradient(#7fd3ff, #1f8fbf); }
.title-box { text-align: center; max-width: 560px; width: 100%; padding: 14px 18px 12px; margin-bottom: 4vh; border-radius: 28px; background: rgba(247,230,188,.86); border: 4px solid var(--wood2); box-shadow: 0 10px 0 rgba(95,58,30,.55), 0 20px 50px rgba(0,0,0,.35); margin-top: auto; }
.logo { margin: 0 0 6px; font-size: clamp(2.2rem, 9vw, 4.2rem); line-height: .95; letter-spacing: 1px; text-shadow: 0 4px 0 rgba(0,0,0,.18); }
.logo .l1 { color: #1478a8; -webkit-text-stroke: 2px #08304a; }
.logo .l2 { color: #ff8fb0; -webkit-text-stroke: 2px #5a1f33; }
.lead { margin: 4px 0 12px; }
.title-btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.pvsb-cookie-note { margin: 12px 0 0; font-size: .8em; color: #5b4630; }
.build-tag { position: fixed; right: calc(8px + var(--safe-r)); bottom: calc(6px + var(--safe-b)); font: bold 12px system-ui; color: #fff; opacity: .7; }
.card-box { width: min(640px, 100%); padding: 18px; border-radius: 26px; background: var(--sand); border: 4px solid var(--wood2); box-shadow: 0 10px 0 rgba(95,58,30,.55), 0 20px 50px rgba(0,0,0,.35); text-align: center; }
.card-box h2 { margin: 0 0 6px; }
.diffs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 10px 0 12px; }
.diff { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 8px; border-radius: 16px; border: 3px solid var(--sand3); background: #fff8e4; cursor: pointer; color: var(--ink); min-height: 44px; }
.diff b { font-size: 1.1em; } .diff small { font-size: .8em; color: #6d5a43; }
.diff.on { border-color: var(--sea2); background: linear-gradient(#e5f8ff, #bfe9fb); box-shadow: 0 0 0 3px rgba(31,143,191,.35); }
.warn { color: #a3361f; font-weight: bold; }
#s-story { align-items: flex-end; }
.story-cap { width: min(760px, 100%); padding: 14px 16px; border-radius: 22px; background: rgba(247,230,188,.93); border: 4px solid var(--wood2); box-shadow: 0 8px 0 rgba(95,58,30,.5); text-align: center; }
.story-cap p { margin: 0; font-size: 1.15em; font-weight: bold; }

/* ---------- the HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#hud[hidden] { display: none; }
#hud > * { pointer-events: auto; }
.hud-left { position: absolute; left: calc(10px + var(--safe-l)); top: calc(10px + var(--safe-t)); width: 220px; pointer-events: none; }
.hud-left > * { pointer-events: auto; }
.meters { display: flex; flex-direction: column; gap: 5px; }
.meter { display: flex; align-items: center; gap: 6px; height: 28px; padding: 2px 8px 2px 4px; border-radius: 14px; border: 3px solid var(--wood2); background: rgba(247,230,188,.92); cursor: pointer; box-shadow: 0 3px 0 rgba(95,58,30,.6); }
.meter b { font-size: 16px; width: 20px; text-align: center; }
.meter .bar { flex: 1; height: 12px; border-radius: 7px; background: rgba(58,38,24,.22); overflow: hidden; }
.meter .bar i { display: block; height: 100%; width: 50%; border-radius: 7px; transition: width .25s; }
.meter.food i { background: linear-gradient(#ffb070, #ff6b4a); }
.meter.water i { background: linear-gradient(#8fe4ff, #2a9ad6); }
.meter.energy i { background: linear-gradient(#fff08a, #ffc21a); }
.meter.low { background: rgba(255,214,200,.95); }
.meter.pulse { animation: pulse .7s ease-in-out infinite alternate; }
/* (glow is for things centred with a transform: it must not touch transform) */
@keyframes glow { from { box-shadow: 0 4px 0 rgba(95,58,30,.6); filter: brightness(1); } to { box-shadow: 0 0 0 5px rgba(255,220,90,.7), 0 4px 0 rgba(95,58,30,.6); filter: brightness(1.12); } }
@keyframes pulse { from { transform: scale(1); box-shadow: 0 3px 0 rgba(95,58,30,.6); } to { transform: scale(1.06); box-shadow: 0 0 0 4px rgba(255,90,70,.6), 0 3px 0 rgba(95,58,30,.6); } }
.clock { display: inline-block; margin-top: 6px; padding: 2px 10px; border-radius: 12px; background: rgba(11,61,92,.72); color: #fff; font-weight: bold; font-size: 14px; }
.goals { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.goals.flash { animation: flash .8s; }
@keyframes flash { 0% { transform: scale(1.06); filter: brightness(1.4); } 100% { transform: none; } }
.goal { display: flex; gap: 6px; align-items: center; padding: 4px 9px; border-radius: 12px; background: rgba(255,248,226,.9); border: 2px solid var(--sand3); font-size: 13px; font-weight: bold; line-height: 1.2; }
.goal .ge { font-size: 15px; }
.goal.done { background: rgba(200,255,210,.92); }
.hud-right { position: absolute; right: calc(10px + var(--safe-r)); top: calc(10px + var(--safe-t)); display: flex; flex-direction: column; align-items: flex-end; gap: 6px; pointer-events: none; }
.hud-right > * { pointer-events: auto; }
.topbtns { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; max-width: 330px; }   /* v2.0: 7 buttons (🏆) in one row */
.ibtn { width: 42px; height: 42px; border-radius: 13px; border: 3px solid var(--wood2); background: linear-gradient(#fff6dc, var(--sand2)); font-size: 20px; cursor: pointer; box-shadow: 0 3px 0 var(--wood2); padding: 0; }
.ibtn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--wood2); }
.minimap { width: 150px; height: 150px; border-radius: 50%; border: 4px solid var(--wood2); box-shadow: 0 4px 0 rgba(95,58,30,.6), 0 6px 18px rgba(0,0,0,.3); background: var(--sea2); }
.bossbar, .shipbar { position: absolute; left: 50%; transform: translateX(-50%); top: calc(10px + var(--safe-t)); width: min(420px, 46vw); padding: 5px 10px; border-radius: 14px; background: rgba(60,10,20,.82); border: 3px solid #ffcf4a; color: #fff; text-align: center; font-size: 14px; }
.shipbar { top: calc(54px + var(--safe-t)); background: rgba(11,61,92,.85); border-color: #fff; }
.shipbar.close { background: rgba(30,120,40,.9); animation: glow .5s infinite alternate; }
.bossbar .bar, .shipbar .bar { display: block; height: 10px; margin-top: 3px; border-radius: 6px; background: rgba(255,255,255,.2); overflow: hidden; }
.bossbar .bar i { display: block; height: 100%; background: linear-gradient(90deg, #ffcf4a, #ff6b4a); }
.shipbar .bar i { display: block; height: 100%; background: linear-gradient(90deg, #9cf, #5f5); }
.hint { position: absolute; left: 50%; bottom: calc(16px + var(--safe-b)); transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 16px; background: rgba(247,230,188,.94); border: 3px solid var(--wood2); box-shadow: 0 4px 0 rgba(95,58,30,.6); font-weight: bold; white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.hint[hidden] { display: none; }
.hint.hot { background: linear-gradient(#ffe48a, #ffb340); animation: glow .6s infinite alternate; }
.hint.no { opacity: .8; }
#hud.building .hint { display: none; }
#hud.woozy .meters { animation: wobble 1.2s ease-in-out infinite; }
@keyframes wobble { 0%,100% { transform: rotate(-1deg); } 50% { transform: rotate(1.5deg); } }
.ico { display: block; flex: none; }
.ico.big { margin: 0 auto; }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 50%; top: calc(70px + var(--safe-t)); transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; align-items: center; gap: 5px; pointer-events: none; width: min(560px, 70vw); }
.toast { display: flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 14px; background: rgba(247,230,188,.95); border: 3px solid var(--wood2); font-weight: bold; font-size: 14px; box-shadow: 0 3px 0 rgba(95,58,30,.5); text-align: center; transition: opacity .4s, transform .4s; }
.toast.pop { animation: pop .35s; }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.08); } 100% { transform: none; opacity: 1; } }
.toast.out { opacity: 0; transform: translateY(-10px); }
.toast.good { background: rgba(214,255,214,.96); border-color: #2e7d32; }
.toast.warn { background: rgba(255,240,200,.96); border-color: #c77800; }
.toast.danger { background: rgba(255,214,206,.97); border-color: #b3261e; }
.toast.gold { background: linear-gradient(#fff3a8, #ffcf4a); border-color: #9a6a00; }
.toast.got { background: rgba(255,255,255,.95); border-color: var(--sea2); }

/* ---------- touch ---------- */
#touch { position: fixed; inset: auto 0 0 0; height: 0; z-index: 8; }
#touch[hidden] { display: none; }
.stick { position: fixed; left: calc(18px + var(--safe-l)); bottom: calc(18px + var(--safe-b)); width: 132px; height: 132px; border-radius: 50%; background: radial-gradient(circle, rgba(255,255,255,.25), rgba(11,61,92,.35)); border: 4px solid rgba(255,255,255,.55); touch-action: none; }
.knob { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #fff6dc, var(--sand3)); border: 3px solid var(--wood2); box-shadow: 0 4px 10px rgba(0,0,0,.35); }
.tbtns { position: fixed; right: calc(14px + var(--safe-r)); bottom: calc(16px + var(--safe-b)); display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; gap: 10px; align-items: end; justify-items: center; }
.tbtn { width: 64px; height: 64px; border-radius: 50%; border: 4px solid var(--wood2); background: linear-gradient(#fff6dc, var(--sand2)); font-size: 26px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; box-shadow: 0 4px 0 var(--wood2); touch-action: none; padding: 0; cursor: pointer; }
.tbtn span { font-size: 10px; font-weight: bold; margin-top: 2px; max-width: 74px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tbtn.big { width: 86px; height: 86px; font-size: 32px; background: linear-gradient(#ffe48a, #ffb340); }
.tbtn.small { width: 50px; height: 50px; font-size: 20px; }
.tbtn.hot { animation: pulse .6s infinite alternate; }
.tbtn.down { transform: scale(.92); }
.tbtn.dim { opacity: .55; }
body.touch .hint { bottom: calc(172px + var(--safe-b)); }
body.touch .hint .kb { display: none; }

/* ---------- build mode ---------- */
.buildbar { position: fixed; left: 50%; bottom: calc(10px + var(--safe-b)); transform: translateX(-50%); z-index: 9; width: min(760px, 96vw); padding: 8px 10px; border-radius: 20px; background: rgba(247,230,188,.95); border: 4px solid var(--wood2); box-shadow: 0 6px 0 rgba(95,58,30,.55); }
.buildbar[hidden] { display: none; }
.bb-top { display: flex; gap: 8px; align-items: center; }
.build-info { flex: 1; min-width: 0; text-align: center; }
.build-info p { margin: 2px 0 0; font-size: 13px; }
.bi-h { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; }
.build-list { display: flex; gap: 6px; overflow-x: auto; padding: 6px 2px; scrollbar-width: thin; }
.bitem { flex: none; width: 74px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px; border-radius: 12px; border: 3px solid var(--sand3); background: #fff8e4; font-size: 11px; font-weight: bold; color: var(--ink); cursor: pointer; opacity: .6; }
.bitem.can { opacity: 1; }
.bitem { position: relative; }
.bitem .kit-n { position: absolute; top: -4px; right: -3px; background: #ffcf4a; border: 2px solid #9a6a00; border-radius: 10px; padding: 0 4px; font-size: 11px; line-height: 16px; }
.kit-free { background: linear-gradient(#fff3a8, #ffcf4a); border: 2px solid #9a6a00; border-radius: 10px; padding: 2px 8px; font-weight: bold; }
p.kits { margin-top: 8px; padding: 6px 10px; border-radius: 10px; background: #fff3c4; border: 2px dashed #c79a2a; font-weight: bold; }
.bitem.on { border-color: var(--sea2); background: linear-gradient(#e5f8ff, #bfe9fb); opacity: 1; }
.bitem span { line-height: 1.1; text-align: center; }
body.touch .buildbar { bottom: calc(170px + var(--safe-b)); }

/* ---------- panels ---------- */
.panel { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: calc(10px + var(--safe-t)) calc(10px + var(--safe-r)) calc(10px + var(--safe-b)) calc(10px + var(--safe-l)); background: rgba(8,30,48,.55); }
.panel[hidden] { display: none; }
.panel-box { width: min(440px, 100%); max-height: 100%; overflow: auto; padding: 14px 16px 16px; border-radius: 24px; background: var(--sand); border: 4px solid var(--wood2); box-shadow: 0 8px 0 rgba(95,58,30,.55), 0 20px 50px rgba(0,0,0,.4); text-align: center; }
.panel-box.wide { width: min(860px, 100%); }
.panel-box h2 { margin: 2px 0 8px; }
.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.menu .big { grid-column: 1 / -1; }
.tabs { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.tab { flex: 1; min-height: 44px; border-radius: 14px; border: 3px solid var(--sand3); background: #fff8e4; font-weight: bold; color: var(--ink); cursor: pointer; }
.tab[aria-selected="true"] { border-color: var(--wood2); background: linear-gradient(#ffe48a, #ffc35a); }
.bag-wrap { display: flex; gap: 12px; align-items: flex-start; }
.bag-grid { display: grid; grid-template-columns: repeat(6, 58px); gap: 6px; justify-content: center; }
.slot { position: relative; width: 58px; height: 58px; border-radius: 12px; border: 3px solid var(--sand3); background: radial-gradient(circle at 50% 40%, #fffaf0, #f1dca8); display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; }
.slot.empty { opacity: .45; cursor: default; }
.slot.sel { border-color: var(--sea2); box-shadow: 0 0 0 3px rgba(31,143,191,.4); }
.slot .n { position: absolute; right: 3px; bottom: 1px; font-size: 13px; color: #fff; text-shadow: 0 0 3px #000, 0 0 2px #000; }
.item-info { flex: 1; min-width: 160px; padding: 10px; border-radius: 16px; background: rgba(255,255,255,.55); border: 2px dashed var(--sand3); text-align: left; }
.item-info .info-h { display: flex; gap: 8px; align-items: center; }
.cats { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-bottom: 8px; }
.cat { position: relative; min-height: 40px; padding: 4px 12px; border-radius: 12px; border: 3px solid var(--sand3); background: #fff8e4; font-weight: bold; cursor: pointer; color: var(--ink); }
.cat.on { border-color: var(--sea2); background: linear-gradient(#e5f8ff, #bfe9fb); }
.cat .dot { position: absolute; right: -4px; top: -4px; width: 12px; height: 12px; border-radius: 50%; background: #2fbf4f; border: 2px solid #fff; }
.recipes { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; text-align: left; }
.recipe { display: flex; gap: 8px; align-items: center; padding: 8px; border-radius: 16px; background: #fffaf0; border: 3px solid var(--sand3); }
.recipe.cant { background: #f7efd9; }
.recipe.locked { opacity: .6; }
.r-ico { flex: none; width: 56px; height: 56px; border-radius: 14px; background: radial-gradient(circle, #fff, #f1dca8); display: flex; align-items: center; justify-content: center; }
.r-ico.locked { font-size: 28px; font-weight: bold; color: #b9a27a; }
.r-body { flex: 1; min-width: 0; }
.r-body p { margin: 2px 0; font-size: 12px; }
.needs { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.need { display: inline-flex; align-items: center; gap: 2px; padding: 1px 6px 1px 2px; border-radius: 10px; font-size: 12px; background: #e8f7e8; border: 2px solid #8fd08f; }
.need.miss { background: #ffe4dc; border-color: #e88b74; color: #a3361f; }
.btn.make { flex: none; min-height: 40px; padding: 4px 10px; }
.map-box { display: flex; flex-direction: column; }
.map-wrap { width: 100%; height: min(70vh, 640px); border-radius: 16px; overflow: hidden; border: 4px solid var(--wood2); background: var(--sea2); }
#map-cv { display: block; margin: 0 auto; }
.card { width: min(560px, 100%); }
.card-pic { display: flex; justify-content: center; }
.card-scene { width: 100%; max-width: 560px; height: auto; aspect-ratio: 56 / 30; border-radius: 16px; border: 3px solid var(--wood2); }
#card-text { font-size: 1.08em; }
.how-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; text-align: left; }
.how-grid h3 { margin: 0 0 4px; }
.how-grid p { margin: 0; font-size: 14px; }
.how-grid > div { padding: 10px; border-radius: 14px; background: #fffaf0; border: 2px solid var(--sand3); }

/* ---------- the rescue and the results ---------- */
.cinema { position: fixed; inset: 0; z-index: 35; background: #000; }
.cinema[hidden] { display: none; }
.cinema canvas { width: 100%; height: 100%; display: block; }
.cine-text { position: absolute; left: 50%; bottom: calc(26px + var(--safe-b)); transform: translateX(-50%); margin: 0; padding: 8px 16px; border-radius: 18px; background: rgba(247,230,188,.92); border: 3px solid var(--wood2); font-weight: bold; font-size: 1.2em; text-align: center; width: max-content; max-width: 92vw; }
.results { max-height: 100%; overflow: auto; }
.res-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0; }
.stat { display: flex; flex-direction: column; align-items: center; padding: 6px; border-radius: 14px; background: #fffaf0; border: 2px solid var(--sand3); font-size: 12px; }
.stat .se { font-size: 20px; } .stat strong { font-size: 18px; }
.res-trophies { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.trophy { width: 42px; height: 42px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 22px; background: #ddd; filter: grayscale(1); opacity: .45; border: 3px solid #bbb; }
.trophy.got { background: radial-gradient(circle, #fff6b0, #ffcf4a); filter: none; opacity: 1; border-color: #9a6a00; }
.coins { font-weight: bold; color: #7a5200; }

/* ---------- phones and small screens ---------- */
@media (max-width: 600px) {
  .hud-left { width: 150px; }
  .meter { height: 24px; } .meter b { font-size: 13px; width: 16px; }
  .goal { font-size: 11px; padding: 3px 7px; }
  .clock { font-size: 12px; }
  .topbtns { max-width: 190px; gap: 4px; }
  .ibtn { width: 36px; height: 36px; font-size: 17px; border-width: 2px; border-radius: 11px; }
  .minimap { width: 92px; height: 92px; border-width: 3px; }
  .diffs { grid-template-columns: 1fr; }
  .bag-wrap { flex-direction: column; align-items: stretch; }
  .bag-grid { grid-template-columns: repeat(auto-fill, 50px); gap: 5px; }
  .slot { width: 50px; height: 50px; }
  .recipes { grid-template-columns: 1fr; }
  .res-stats { grid-template-columns: repeat(3, 1fr); }
  .toasts { width: 92vw; top: calc(246px + var(--safe-t)); }
  .toast { font-size: 12px; }
  .bossbar, .shipbar { width: 92vw; top: calc(196px + var(--safe-t)); bottom: auto; font-size: 13px; }
}
@media (max-height: 520px) {
  .hud-left { width: 170px; }
  .meters { gap: 3px; }
  .meter { height: 22px; border-width: 2px; } .meter b { font-size: 13px; }
  .goal { font-size: 11px; padding: 2px 7px; }
  .goals { gap: 3px; margin-top: 4px; }
  .clock { margin-top: 4px; font-size: 12px; padding: 1px 8px; }
  .topbtns { max-width: none; flex-wrap: nowrap; gap: 4px; }
  .ibtn { width: 34px; height: 34px; font-size: 16px; border-width: 2px; border-radius: 10px; }
  .minimap { width: 84px; height: 84px; border-width: 3px; }
  .toasts { top: calc(8px + var(--safe-t)); width: min(420px, 46vw); }
  .toast { font-size: 12px; padding: 3px 10px; }
  .stick { width: 112px; height: 112px; left: calc(12px + var(--safe-l)); bottom: calc(10px + var(--safe-b)); }
  .knob { width: 50px; height: 50px; margin: -25px 0 0 -25px; }
  .tbtns { bottom: calc(10px + var(--safe-b)); gap: 6px; }
  .tbtn { width: 56px; height: 56px; } .tbtn.big { width: 74px; height: 74px; } .tbtn.small { width: 44px; height: 44px; }
  body.touch .hint { bottom: calc(10px + var(--safe-b)); max-width: 44vw; font-size: 13px; }
  /* build mode on a short screen: the bar goes to the TOP, the goals and minimap step aside */
  .buildbar, body.touch .buildbar { top: calc(4px + var(--safe-t)); bottom: auto; width: min(500px, 58vw); padding: 4px 8px; border-width: 3px; }
  #hud.building .goals, #hud.building .minimap, #hud.building .clock { display: none; }
  .buildbar .row { margin-top: 2px; } .buildbar .row .btn { min-height: 34px; padding: 2px 12px; }
  .bitem { width: 58px; font-size: 10px; padding: 2px; } .build-list { padding: 3px 2px; gap: 4px; }
  .build-info p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11px; }
  .bb-top .btn.small { min-height: 30px; padding: 2px 8px; }
  /* the results: compact cards so the buttons fit on a landscape phone */
  .results { padding: 8px 12px; } .results h2 { font-size: 1.2em; margin: 0; } .results h3 { margin: 4px 0; font-size: 1em; }
  .res-stats { gap: 4px; margin: 4px 0; } .stat { flex-direction: row; gap: 6px; justify-content: center; padding: 2px 6px; font-size: 11px; }
  .stat .se { font-size: 14px; } .stat strong { font-size: 13px; }
  .trophy { width: 30px; height: 30px; font-size: 16px; border-width: 2px; }
  .results .row { margin-top: 4px; } .results .btn.big { min-height: 40px; font-size: 1em; }
  #res-diff, .coins { margin: 2px 0; font-size: .85em; }
  .bossbar, .shipbar { top: calc(6px + var(--safe-t)); bottom: auto; width: min(300px, 34vw); font-size: 12px; padding: 3px 8px; }
  .toasts { top: calc(56px + var(--safe-t)); }
  .panel-box h2 { margin: 0 0 4px; font-size: 1.2em; }
  .map-wrap { height: 62vh; }
  .title-box { padding: 10px 14px; } .logo { font-size: 2.4rem; } .lead { margin: 2px 0 8px; font-size: .9em; }
  .btn.big { min-height: 46px; }
  .card-scene { max-height: 40vh; width: auto; }
  .story-cap { padding: 8px 12px; } .story-cap p { font-size: 1em; }
}
@media (max-height: 520px) { body.building .toasts { top: auto; bottom: calc(10px + var(--safe-b)); } }
@media (prefers-reduced-motion: reduce) { .meter.pulse, .hint.hot, .tbtn.hot, .shipbar.close { animation: none; } }

/* ---------- 📱📺 phones and TVs (devices.js sets --ui and the body classes) ---------- */
/* a sofa-size HUD on a big screen: --ui is 1 on phones, tablets and laptops, up to 1.7 on a TV */
#hud > .hud-left, #hud > .hud-right, #hud > .hint, #hud > .bossbar, #hud > .shipbar, .toasts, .panel-box, .buildbar { zoom: var(--ui, 1); }   /* (the build bar too: a remote picks from it) */
/* a TV's own browser: televisions crop the edges of the picture, so keep everything in from them */
body.tvbox { --safe-t: 3vh; --safe-b: 3vh; --safe-l: 3vw; --safe-r: 3vw; }
.menu .quick { background: linear-gradient(#f3ffe6, #c9eca6); border-color: #3f7a2a; box-shadow: 0 4px 0 #3f7a2a; }
.how-now { font-weight: bold; color: var(--wood2); background: #fff3c4; border-radius: 10px; padding: 4px 8px; margin: 0 0 6px !important; }
.how-keys p + p { margin-top: 6px; }
@media (max-height: 520px) { .menu { grid-template-columns: repeat(4, 1fr); } }   /* v2.0: 4 across, so 14 buttons fit a sideways phone */
@media (max-height: 520px) { #p-pause .panel-box { width: min(800px, 100%); } }
/* 🏆 v2.0: the trophy screen */
.tro-sum { margin: 2px 0 8px; font-weight: bold; font-size: 1.05em; }
.tro-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; text-align: left; max-height: 62vh; overflow: auto; padding: 4px; }
.tro-card { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 16px; border: 3px solid var(--sand3, #e2c58c); background: #f7efd9; font: inherit; color: inherit; text-align: left; cursor: default; }
.tro-card.got { background: linear-gradient(135deg, #fffbe6, #ffeeb0); border-color: #e0a800; }
.tro-card .trophy { flex: none; width: 48px; height: 48px; font-size: 26px; }
.tro-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tro-name { font-size: 1em; }
.tro-what { font-size: .82em; opacity: .85; }
.tro-status { font-size: .8em; font-weight: bold; }
.tro-card.got .tro-status { color: #3a7a10; }
.tro-bar { display: block; height: 8px; border-radius: 5px; background: #e2d4b4; overflow: hidden; margin-top: 2px; }
.tro-bar > i { display: block; height: 100%; background: linear-gradient(90deg, #ffc21a, #ff9a2a); }
@media (max-width: 600px) { .tro-list { grid-template-columns: 1fr; max-height: 66vh; } .tro-card .trophy { width: 40px; height: 40px; font-size: 21px; } }
@media (max-height: 520px) { .tro-list { max-height: 54vh; } }
