:root {
  --ink: #0f1317;
  --panel: rgba(15, 19, 23, 0.86);
  --panel-2: rgba(28, 34, 40, 0.92);
  --line: rgba(241, 236, 226, 0.14);
  --text: #f1ece2;
  --dim: #a9a79f;
  --accent: #f0a73c;
  --accent-ink: #1b1408;
  --hp: #e2574c;
  --water: #4aa3e0;
  --food: #e9b23a;
  --ok: #5fd08a;
  --r: 12px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --u: clamp(13px, 1.05vw + 9px, 17px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: var(--text); overscroll-behavior: none; }
body { font: 500 var(--u)/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; user-select: none; -webkit-user-select: none; touch-action: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; }
[hidden] { display: none !important; }
svg.i { width: 1.5em; height: 1.5em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* shared pieces */
.label { font-size: 0.72em; letter-spacing: 0.09em; text-transform: uppercase; color: var(--dim); font-weight: 600; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.5em; min-height: 2.9em; padding: 0 1.3em; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.small { min-height: 2.3em; padding: 0 0.95em; font-size: 0.9em; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.round { width: 3.5em; height: 3.5em; border-radius: 50%; background: var(--panel); border: 1px solid var(--line); display: grid; place-items: center; pointer-events: auto; }
.round.big { width: 4.9em; height: 4.9em; background: rgba(240, 167, 60, 0.92); color: var(--accent-ink); border-color: transparent; }
.round.big svg.i { width: 2em; height: 2em; }
.round:active { transform: scale(0.95); }

/* loading and title */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: calc(1.2em + var(--sat)) calc(1.2em + var(--sar)) calc(1.2em + var(--sab)) calc(1.2em + var(--sal)); }
#loading { background: var(--ink); z-index: 50; text-align: center; }
#loading h1, #title h1 { margin: 0; font-size: clamp(3rem, 12vw, 7rem); letter-spacing: 0.16em; font-weight: 800; line-height: 1; padding-left: 0.16em; }
#loading p, #title p.tag { margin: 0.7em 0 1.6em; color: var(--dim); letter-spacing: 0.12em; text-transform: uppercase; font-size: 0.86em; }
.bar { width: min(22em, 70vw); height: 6px; border-radius: 6px; background: rgba(255, 255, 255, 0.12); overflow: hidden; margin: 0 auto; }
.bar > i { display: block; height: 100%; width: 0%; background: var(--accent); transition: width 0.25s ease; }
#load-text { margin-top: 0.9em; color: var(--dim); font-size: 0.86em; min-height: 1.4em; }
#title { z-index: 40; text-align: center; background: linear-gradient(180deg, rgba(15, 19, 23, 0.25), rgba(15, 19, 23, 0.72)); }
#title .stack { display: grid; gap: 0.8em; justify-items: center; }
#title .row { display: flex; gap: 0.7em; flex-wrap: wrap; justify-content: center; }
#title small { color: var(--dim); display: block; margin-top: 1.4em; max-width: 30em; }

/* creator */
#creator { z-index: 30; display: grid; grid-template-columns: minmax(11em, 15em) 1fr minmax(15em, 21em); grid-template-rows: 1fr auto; gap: 0.9em; place-items: stretch; pointer-events: none; }
#creator > * { pointer-events: auto; }
.cr-rail, .cr-opts, .cr-foot { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 0.8em; }
.cr-rail { grid-column: 1; grid-row: 1; display: flex; flex-direction: column; gap: 0.35em; overflow: auto; align-self: center; }
.cr-rail button { display: flex; align-items: center; gap: 0.7em; padding: 0.6em 0.7em; border-radius: 9px; text-align: left; font-weight: 600; }
.cr-rail button.on { background: var(--accent); color: var(--accent-ink); }
.cr-opts { grid-column: 3; grid-row: 1; align-self: center; display: grid; gap: 0.8em; max-height: 100%; overflow: auto; }
.cr-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.45em; }
.cr-grid button { padding: 0.75em 0.5em; border-radius: 9px; background: var(--panel-2); border: 1px solid var(--line); font-weight: 600; }
.cr-grid button.on { border-color: var(--accent); color: var(--accent); }
.swatches { display: flex; gap: 0.5em; flex-wrap: wrap; }
.swatches button { width: 2.1em; height: 2.1em; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.18); }
.swatches button.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--ink), 0 0 0 4px var(--accent); }
.cr-foot { grid-column: 1 / -1; grid-row: 2; display: flex; gap: 0.8em; align-items: center; flex-wrap: wrap; justify-content: space-between; }
.cr-foot .grp { display: flex; gap: 0.5em; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button { padding: 0.5em 1em; border-radius: 999px; font-weight: 600; display: inline-flex; gap: 0.45em; align-items: center; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.seg button .dot { width: 0.7em; height: 0.7em; border-radius: 50%; }
.field { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 0.6em 1em; color: var(--text); width: 11em; outline: none; user-select: text; -webkit-user-select: text; }
.field:focus { border-color: var(--accent); }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#goal { position: absolute; top: calc(0.8em + var(--sat)); left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 0.5em 1.1em; display: flex; gap: 0.6em; align-items: center; max-width: min(92vw, 34em); text-align: center; }
#goal .n { color: var(--accent); font-weight: 700; }
#top-right { position: absolute; top: calc(0.8em + var(--sat)); right: calc(0.8em + var(--sar)); display: flex; gap: 0.5em; align-items: center; pointer-events: auto; }
#embers { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 0.45em 0.9em 0.45em 0.7em; display: flex; gap: 0.4em; align-items: center; font-weight: 700; }
#embers svg { color: var(--accent); }
#top-left { position: absolute; top: calc(0.8em + var(--sat)); left: calc(0.8em + var(--sal)); display: flex; gap: 0.5em; pointer-events: auto; }
#status { position: absolute; top: calc(4.4em + var(--sat)); left: calc(0.8em + var(--sal)); color: var(--dim); font-size: 0.78em; }
#map { position: absolute; left: calc(0.9em + var(--sal)); bottom: calc(0.9em + var(--sab)); width: 8.4em; height: 8.4em; border-radius: 50%; border: 2px solid rgba(241, 236, 226, 0.5); background: #1a2126; overflow: hidden; }
#map canvas { width: 100%; height: 100%; display: block; }
#stats { position: absolute; right: calc(0.9em + var(--sar)); bottom: calc(0.9em + var(--sab)); display: grid; gap: 0.32em; width: 11em; }
.stat { display: grid; grid-template-columns: 1.3em 1fr 2.2em; gap: 0.4em; align-items: center; font-size: 0.82em; font-weight: 700; }
.stat svg.i { width: 1.2em; height: 1.2em; }
.stat .track { height: 7px; border-radius: 7px; background: rgba(10, 12, 14, 0.7); overflow: hidden; }
.stat .track i { display: block; height: 100%; border-radius: 7px; }
.stat.hp svg, .stat.hp i { color: var(--hp); background: var(--hp); } .stat.hp svg { background: none; }
.stat.water svg { color: var(--water); } .stat.water i { background: var(--water); }
.stat.food svg { color: var(--food); } .stat.food i { background: var(--food); }
#tool { position: absolute; right: calc(0.9em + var(--sar)); bottom: calc(6.6em + var(--sab)); background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 0.4em 0.9em 0.4em 0.6em; display: flex; gap: 0.5em; align-items: center; font-weight: 600; font-size: 0.88em; }
#tool b { color: var(--accent); }
#prompt { position: absolute; left: 50%; bottom: calc(22% + var(--sab)); transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 0.5em 1em; display: flex; gap: 0.6em; align-items: center; font-weight: 600; white-space: nowrap; }
#prompt kbd { font: inherit; background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: 0.05em 0.5em; font-weight: 800; }
#toasts { position: absolute; left: 50%; top: calc(4.2em + var(--sat)); transform: translateX(-50%); display: grid; gap: 0.35em; justify-items: center; }
.toast { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 0.4em 0.95em; font-weight: 600; font-size: 0.9em; animation: toast 2.6s ease forwards; white-space: nowrap; }
.toast.good { border-color: var(--ok); color: var(--ok); } .toast.bad { border-color: var(--hp); color: #ffb3ac; } .toast.gold { border-color: var(--accent); color: var(--accent); }
@keyframes toast { 0% { opacity: 0; transform: translateY(-6px); } 8%, 82% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-6px); } }
.floaty { position: absolute; font-weight: 800; font-size: 1.15em; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7); pointer-events: none; animation: floaty 0.95s ease-out forwards; transform: translate(-50%, -50%); white-space: nowrap; }
@keyframes floaty { from { opacity: 1; margin-top: 0; } to { opacity: 0; margin-top: -3.2em; } }
#cross { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px; border-radius: 50%; background: rgba(241, 236, 226, 0.85); box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35); }

/* timing meter */
#meter { position: absolute; left: 50%; top: 50%; transform: translate(4.2em, -50%); display: flex; gap: 0.7em; align-items: center; }
#meter svg { width: 5.6em; height: 5.6em; overflow: visible; }
#meter .txt { font-weight: 800; line-height: 1.1; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7); }
#meter .txt b { display: block; color: var(--accent); font-size: 1.2em; letter-spacing: 0.04em; }

/* outpost banner */
#outpost { position: absolute; top: calc(4.3em + var(--sat)); left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 0.55em 0.9em; width: min(22em, 80vw); display: grid; gap: 0.35em; text-align: center; }
#outpost .cap { height: 8px; border-radius: 8px; background: rgba(10, 12, 14, 0.7); position: relative; overflow: hidden; }
#outpost .cap i { position: absolute; top: 0; bottom: 0; left: 50%; width: 0; }
#outpost .cap::after { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: rgba(241, 236, 226, 0.7); }

/* touch controls */
#stick { position: fixed; width: 112px; height: 112px; margin: -56px 0 0 -56px; border-radius: 50%; border: 2px solid rgba(241, 236, 226, 0.35); background: rgba(15, 19, 23, 0.3); display: none; z-index: 11; pointer-events: none; }
#stick.on { display: block; }
#stick-nub { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px; border-radius: 50%; background: rgba(241, 236, 226, 0.8); }
#pad { position: absolute; right: calc(0.9em + var(--sar)); bottom: calc(5.4em + var(--sab)); display: grid; grid-template-columns: repeat(3, auto); gap: 0.5em; align-items: end; justify-items: end; pointer-events: none; }
#pad .col { display: grid; gap: 0.5em; }
body:not(.touch) #pad { display: none; }
body.touch #tool { bottom: auto; top: calc(4.3em + var(--sat)); right: calc(0.9em + var(--sar)); }
body.touch #stats { bottom: calc(0.9em + var(--sab)); }
body.touch #prompt kbd { display: none; }
body.touch #cross { display: none; }

/* build bar */
#buildbar { position: absolute; left: 50%; bottom: calc(0.9em + var(--sab)); transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 0.6em; display: grid; gap: 0.5em; pointer-events: auto; max-width: min(96vw, 46em); }
#buildbar .tabs { display: flex; gap: 0.4em; justify-content: space-between; align-items: center; flex-wrap: wrap; }
#buildbar .pieces { display: flex; gap: 0.4em; overflow-x: auto; }
.piece { min-width: 5.2em; padding: 0.5em 0.4em; border-radius: 9px; background: var(--panel-2); border: 1px solid var(--line); display: grid; gap: 0.2em; justify-items: center; font-size: 0.82em; font-weight: 600; }
.piece.on { border-color: var(--accent); color: var(--accent); }
.piece small { color: var(--dim); font-weight: 600; white-space: nowrap; }
.piece.short small { color: #ffb3ac; }

/* wheels */
#wheel { position: fixed; inset: 0; z-index: 25; display: grid; place-items: center; background: rgba(8, 10, 12, 0.5); pointer-events: auto; }
#wheel svg.w { width: min(74vmin, 25em); height: min(74vmin, 25em); overflow: visible; }
#wheel path.seg { fill: rgba(15, 19, 23, 0.9); stroke: rgba(241, 236, 226, 0.2); stroke-width: 1.2; cursor: pointer; transition: fill 0.1s; }
#wheel path.seg.on { fill: var(--accent); }
#wheel path.seg.locked { fill: rgba(15, 19, 23, 0.55); }
#wheel g.ic { pointer-events: none; color: var(--text); }
#wheel g.ic.on { color: var(--accent-ink); }
#wheel g.ic.locked { color: #6b6f73; }
#wheel text { fill: var(--dim); font-size: 6px; font-weight: 700; pointer-events: none; }
#wheel .mid { fill: rgba(15, 19, 23, 0.95); stroke: rgba(241, 236, 226, 0.2); }
#wheel .name { fill: var(--text); font-size: 6.4px; font-weight: 700; text-anchor: middle; }
#wheel .sub { fill: var(--dim); font-size: 4.6px; text-anchor: middle; }

/* panels */
#panel { position: fixed; inset: 0; z-index: 26; display: grid; place-items: center; background: rgba(8, 10, 12, 0.6); pointer-events: auto; padding: calc(0.8em + var(--sat)) calc(0.8em + var(--sar)) calc(0.8em + var(--sab)) calc(0.8em + var(--sal)); }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); width: min(58em, 100%); max-height: 100%; display: grid; grid-template-rows: auto 1fr; overflow: hidden; }
.sheet header { display: flex; align-items: center; gap: 0.6em; padding: 0.7em 0.9em; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.sheet header h2 { margin: 0; font-size: 1.1em; letter-spacing: 0.08em; text-transform: uppercase; margin-right: auto; }
.sheet .body { overflow: auto; padding: 0.9em; display: grid; gap: 1em; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.tabs2 { display: flex; gap: 0.35em; flex-wrap: wrap; }
.tabs2 button { padding: 0.45em 0.95em; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); font-weight: 600; font-size: 0.9em; }
.tabs2 button.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.6em, 1fr)); gap: 0.55em; }
.slot { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 0.7em 0.6em; display: grid; gap: 0.25em; justify-items: center; text-align: center; }
.slot svg.i { width: 2em; height: 2em; }
.slot b { font-size: 1.15em; }
.slot .btn { width: 100%; margin-top: 0.2em; }
.recipe { display: grid; grid-template-columns: 2.6em 1fr auto; gap: 0.7em; align-items: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 0.6em 0.7em; }
.recipe svg.i { width: 2em; height: 2em; }
.recipe p { margin: 0; color: var(--dim); font-size: 0.86em; }
.recipe .cost span { margin-right: 0.7em; white-space: nowrap; }
.recipe .cost span.short { color: #ffb3ac; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 1em; }
.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: grid; grid-template-rows: 6.4em auto; text-align: left; }
.card .art { display: grid; place-items: center; position: relative; }
.card .art svg.i { width: 3em; height: 3em; color: rgba(255, 255, 255, 0.92); }
.card .art .rar { position: absolute; left: 0.5em; top: 0.5em; font-size: 0.66em; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 800; padding: 0.15em 0.5em; border-radius: 999px; background: rgba(10, 12, 14, 0.7); }
.card .info { padding: 0.55em 0.6em 0.65em; display: grid; gap: 0.35em; }
.card .info b { line-height: 1.15; }
.card .price { display: flex; gap: 0.3em; align-items: center; color: var(--accent); font-weight: 700; font-size: 0.9em; }
.card .price svg.i { width: 1.1em; height: 1.1em; }
.btn .price { color: inherit; }
.crate { display: grid; grid-template-columns: 1fr auto; gap: 1em; align-items: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 0.9em; }
.crate p { margin: 0.2em 0 0; color: var(--dim); font-size: 0.9em; }
.rows { display: grid; gap: 0.5em; }
.rowi { display: flex; align-items: center; justify-content: space-between; gap: 0.8em; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 0.6em 0.8em; flex-wrap: wrap; }
.rowi p { margin: 0; color: var(--dim); font-size: 0.86em; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 0.3em 0.9em; font-size: 0.9em; }
.keys kbd { font: inherit; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 0 0.5em; font-weight: 700; justify-self: start; }
.score { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6em; }
.score div { border-radius: 10px; padding: 0.8em; text-align: center; background: var(--panel-2); border: 1px solid var(--line); }
.score b { display: block; font-size: 2em; line-height: 1.1; }

/* reveal and death */
#reveal, #death { position: fixed; inset: 0; z-index: 35; display: grid; place-items: center; text-align: center; pointer-events: auto; }
#reveal { background: radial-gradient(circle at 50% 46%, rgba(240, 167, 60, 0.28), rgba(8, 10, 12, 0.9) 60%); }
#reveal .rv { display: grid; gap: 0.6em; justify-items: center; animation: pop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both; }
#reveal .rv .big { width: 9em; height: 9em; border-radius: 22px; display: grid; place-items: center; }
#reveal .rv .big svg.i { width: 4.6em; height: 4.6em; color: #fff; }
#reveal h3 { margin: 0; font-size: clamp(1.8rem, 6vw, 3rem); letter-spacing: 0.06em; text-transform: uppercase; line-height: 1.05; }
@keyframes pop { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: none; } }
#death { background: rgba(60, 8, 8, 0.6); }
#death h3 { margin: 0 0 0.6em; font-size: clamp(1.8rem, 6vw, 3rem); letter-spacing: 0.1em; text-transform: uppercase; }
#flash { position: fixed; inset: 0; z-index: 9; pointer-events: none; background: radial-gradient(circle, transparent 55%, rgba(226, 87, 76, 0.55)); opacity: 0; transition: opacity 0.25s; }

/* narrow screens: phones held upright */
@media (max-width: 720px) {
  #creator { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto auto; }
  .cr-rail { grid-column: 1; grid-row: 1; flex-direction: row; overflow-x: auto; align-self: start; padding: 0.5em; }
  .cr-rail button { flex: none; padding: 0.5em 0.7em; }
  .cr-rail button span { display: none; }
  .cr-opts { grid-column: 1; grid-row: 3; align-self: end; max-height: 34vh; padding: 0.6em; }
  .cr-grid { grid-template-columns: repeat(4, 1fr); }
  .cr-grid button { padding: 0.6em 0.2em; font-size: 0.82em; }
  .cr-foot { grid-row: 4; padding: 0.6em; }
  .field { width: 8.5em; }
  .two { grid-template-columns: 1fr; }
  #map { width: 6.2em; height: 6.2em; }
  #stats { width: 8.6em; }
  #goal { top: calc(4em + var(--sat)); font-size: 0.88em; }
  #toasts { top: calc(7.2em + var(--sat)); }
  #outpost { top: calc(7.2em + var(--sat)); }
  body.touch #tool { top: calc(7.2em + var(--sat)); }
}
@media (max-height: 460px) {
  #map { width: 6.4em; height: 6.4em; }
  .cr-opts { max-height: 62vh; }
  #goal { font-size: 0.86em; }
}
@media (prefers-reduced-motion: reduce) { .toast, .floaty, #reveal .rv { animation-duration: 0.01s; } }

/* ── clarity pass: labelled buttons, goal steps, guide marker, key strip, help card ── */
.round { width: auto; min-width: 3.9em; height: auto; padding: 0.5em 0.5em 0.35em; border-radius: 14px; display: grid; justify-items: center; gap: 0.1em; position: relative; }
.round small { font-size: 0.66em; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; line-height: 1.1; white-space: nowrap; }
.round .ri { display: grid; }
.round kbd { position: absolute; top: -0.5em; right: -0.4em; font: inherit; font-size: 0.6em; font-weight: 800; background: var(--text); color: var(--ink); border-radius: 5px; padding: 0 0.4em; line-height: 1.5; }
.round.big { width: auto; min-width: 5.6em; height: auto; padding: 0.85em 0.6em 0.55em; border-radius: 20px; }
.round.big small { font-size: 0.78em; }
.round.pulse { animation: pulse 1.1s ease-in-out infinite; border-color: var(--accent); }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(240, 167, 60, 0.75); } 50% { box-shadow: 0 0 0 0.6em rgba(240, 167, 60, 0); } }
#top-left, #top-right { gap: 0.45em; align-items: flex-start; }
#goal { display: grid; gap: 0.3em; border-radius: var(--r); padding: 0.6em 0.95em; text-align: left; max-width: min(92vw, 30em); top: calc(0.7em + var(--sat)); }
#goal .g-top { display: flex; gap: 0.6em; align-items: baseline; flex-wrap: wrap; }
#goal .n { font-size: 0.7em; letter-spacing: 0.09em; text-transform: uppercase; white-space: nowrap; }
#goal b { font-size: 1.05em; }
#goal-how { color: var(--text); opacity: 0.86; font-size: 0.9em; line-height: 1.3; }
#goal-list { display: flex; gap: 0.4em; flex-wrap: wrap; }
#goal-list:empty { display: none; }
#goal-list span { display: inline-flex; align-items: center; gap: 0.3em; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 0.15em 0.6em 0.15em 0.4em; font-size: 0.82em; font-weight: 700; }
#goal-list span em { font-style: normal; }
#goal-list span svg.i { width: 1.1em; height: 1.1em; }
#goal-list span.done { border-color: var(--ok); color: var(--ok); }
#guide { position: absolute; left: 0; top: 0; pointer-events: none; display: grid; justify-items: center; gap: 0.15em; margin: -2.6em 0 0 -3em; width: 6em; z-index: 2; }
#guide i { width: 1.5em; height: 1.5em; display: block; background: var(--accent); clip-path: polygon(50% 100%, 0 20%, 50% 42%, 100% 20%); filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6)); animation: bob 1s ease-in-out infinite; }
#guide span { background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 0.78em; border-radius: 999px; padding: 0.05em 0.6em; white-space: nowrap; }
#guide.edge { margin: -1.4em 0 0 -3em; }
#guide.edge i { animation: none; }
@keyframes bob { 0%, 100% { translate: 0 0; } 50% { translate: 0 -0.35em; } }
#keys { position: absolute; left: 50%; bottom: calc(0.7em + var(--sab)); transform: translateX(-50%); display: flex; gap: 0.9em; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 0.4em 1em; font-size: 0.82em; font-weight: 600; white-space: nowrap; max-width: 62vw; overflow: hidden; }
#keys span { display: inline-flex; gap: 0.4em; align-items: center; }
#keys kbd, #prompt kbd { font: inherit; background: var(--text); color: var(--ink); border-radius: 5px; padding: 0 0.45em; font-weight: 800; }
#prompt kbd { background: var(--accent); color: var(--accent-ink); }
body.touch #keys, body.building #keys { display: none; }
#prompt { font-size: 1.05em; padding: 0.55em 1.1em; border-color: var(--accent); }
#meter .txt small { display: block; font-size: 0.72em; font-weight: 700; opacity: 0.9; }
#wheel { grid-template-rows: auto auto; align-content: center; gap: 0.6em; }
#wheel .w-title { text-align: center; font-weight: 800; font-size: 1.1em; }
#wheel .w-title small { display: block; font-weight: 600; opacity: 0.8; font-size: 0.78em; }
#helpcard { position: fixed; inset: 0; z-index: 45; display: grid; place-items: center; background: rgba(8, 10, 12, 0.72); padding: calc(0.8em + var(--sat)) calc(0.8em + var(--sar)) calc(0.8em + var(--sab)) calc(0.8em + var(--sal)); pointer-events: auto; overflow: auto; }
.hc { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 1.2em; width: min(46em, 100%); display: grid; gap: 1em; justify-items: center; text-align: center; }
.hc h2 { margin: 0; font-size: 1.3em; letter-spacing: 0.08em; text-transform: uppercase; }
.hc-steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.7em; width: 100%; }
.hc-step { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 0.9em 0.7em; display: grid; gap: 0.35em; justify-items: center; align-content: start; }
.hc-step .hc-i { color: var(--accent); }
.hc-step .hc-i svg.i { width: 2.2em; height: 2.2em; }
.hc-step p { margin: 0; font-size: 0.88em; line-height: 1.35; opacity: 0.9; }
.hc-more { margin: 0; font-size: 0.88em; opacity: 0.85; max-width: 38em; }
#pad { bottom: calc(5.6em + var(--sab)); gap: 0.45em; }
body.touch #stats { width: 9.4em; }
@media (max-width: 720px) {
  .hc-steps { grid-template-columns: 1fr 1fr; }
  #goal { top: calc(4.9em + var(--sat)); max-width: 94vw; font-size: 0.92em; }
  #toasts { top: calc(11.5em + var(--sat)); }
  #outpost { top: calc(11.5em + var(--sat)); }
  body.touch #tool { top: auto; bottom: calc(18.5em + var(--sab)); }
  .round { min-width: 3.5em; }
}
@media (max-height: 460px) {
  #goal { font-size: 0.82em; padding: 0.4em 0.8em; max-width: 44vw; }
  #goal-how { font-size: 0.86em; }
  .hc { padding: 0.8em; gap: 0.6em; }
  .hc-step { padding: 0.5em; }
  .hc-step p { font-size: 0.8em; }
  .round { padding: 0.35em 0.4em 0.25em; min-width: 3.4em; }
  .round.big { min-width: 4.8em; padding: 0.6em 0.5em 0.4em; }
  #pad { bottom: calc(4.6em + var(--sab)); }
}

/* ── weapon bar, target bar, flying controls ── */
#hotbar { position: absolute; left: 50%; bottom: calc(3.4em + var(--sab)); transform: translateX(-50%); display: flex; gap: 0.35em; pointer-events: auto; }
.hb { position: relative; width: 4.3em; padding: 0.45em 0.2em 0.3em; border-radius: 12px; background: var(--panel); border: 2px solid var(--line); display: grid; justify-items: center; gap: 0.05em; }
.hb small { font-size: 0.62em; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; white-space: nowrap; overflow: hidden; max-width: 100%; text-overflow: ellipsis; }
.hb kbd { position: absolute; top: -0.55em; left: 50%; transform: translateX(-50%); font: inherit; font-size: 0.62em; font-weight: 800; background: var(--text); color: var(--ink); border-radius: 5px; padding: 0 0.45em; line-height: 1.5; }
.hb.on { border-color: var(--accent); background: rgba(240, 167, 60, 0.94); color: var(--accent-ink); }
.hb.locked { opacity: 0.5; }
body.touch #hotbar { bottom: calc(0.7em + var(--sab)); gap: 0.25em; }
body.touch .hb { width: 3.3em; padding: 0.35em 0.1em 0.25em; }
body.touch .hb small { display: none; }
body.building #hotbar { display: none; }
#target { position: absolute; top: calc(0.8em + var(--sat)); left: 50%; transform: translateX(-50%); width: min(26em, 70vw); background: var(--panel); border: 2px solid var(--hp); border-radius: var(--r); padding: 0.5em 0.8em 0.6em; display: grid; gap: 0.35em; }
#target .t-top { display: flex; justify-content: space-between; align-items: baseline; gap: 0.8em; }
#target b { font-size: 1.1em; letter-spacing: 0.04em; text-transform: uppercase; }
#target span { font-size: 0.8em; font-weight: 700; opacity: 0.9; }
#target .t-bar { height: 12px; border-radius: 12px; background: rgba(10, 12, 14, 0.75); overflow: hidden; }
#target .t-bar i { display: block; height: 100%; background: var(--hp); border-radius: 12px; transition: width 0.15s; }
#target.alert { border-color: #fff; animation: alert 0.3s steps(2) infinite; }
#target.alert span { color: #ffd0cb; }
@keyframes alert { 50% { background: rgba(160, 30, 22, 0.92); } }
#goal.away { display: none; }
#flypad { position: absolute; right: calc(0.9em + var(--sar)); bottom: calc(6.6em + var(--sab)); display: flex; gap: 0.5em; pointer-events: none; }
#flypad .round { min-width: 4.8em; padding: 0.7em 0.6em 0.5em; touch-action: none; }
body.touch.flying #pad { display: none; }
body.touch #flypad { bottom: calc(5.6em + var(--sab)); }
#stats { width: 12.5em; gap: 0.4em; }
.stat { font-size: 0.9em; }
.stat .track { height: 10px; }
#keys { bottom: calc(0.6em + var(--sab)); }
@media (max-width: 720px) {
  body.touch #hotbar { bottom: calc(9.4em + var(--sab)); left: calc(0.6em + var(--sal)); transform: none; flex-wrap: wrap; max-width: 46vw; }
  body.touch .hb { width: 2.9em; }
  #target { top: calc(4.9em + var(--sat)); width: 92vw; }
}
@media (max-height: 460px) {
  body.touch .hb { width: 3em; padding: 0.25em 0.1em 0.2em; }
  #target { width: min(22em, 46vw); padding: 0.35em 0.7em 0.45em; }
}

/* ── missions and the gunship ── */
#goal { cursor: pointer; pointer-events: auto; color: inherit; font: inherit; }
#goal .g-top { align-items: center; }
#goal .n { order: 2; margin-left: auto; padding-left: 0.8em; font-size: 0.78em; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--dim); }
#goal .g-open { order: 3; display: grid; color: var(--dim); }
#goal .g-open svg.i { width: 1em; height: 1em; }
#goal.wild { border-color: #ff5a4a; }
#goal.wild .n { color: #ff8d80; }
#mission { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); width: min(30em, 88vw); background: var(--panel); border: 1px solid var(--accent); border-left-width: 6px; border-radius: var(--r); padding: 0.9em 1.2em 1em; display: grid; gap: 0.3em; text-align: left; z-index: 4; animation: mission 5.2s ease forwards; }
#mission[hidden] { display: none; }
#mission b { font-size: 1.5em; line-height: 1.15; }
#mission p { margin: 0; line-height: 1.35; opacity: 0.92; }
#mission small { color: var(--dim); font-weight: 600; }
#mission small:empty, #mission p:empty { display: none; }
#mission.done { border-color: var(--ok); animation-duration: 3.4s; }
#mission.done b { color: var(--ok); }
#mission.wild { border-color: #ff5a4a; }
#mission.wild b { color: #ff8d80; }
@keyframes mission { 0% { opacity: 0; transform: translate(-50%, -0.8em); } 7%, 88% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -0.5em); } }
.rowi.ms { align-items: flex-start; flex-wrap: nowrap; }
.rowi.ms .ms-main { display: grid; gap: 0.35em; min-width: 0; }
.rowi.ms b { font-size: 1.08em; }
.rowi.ms.on { border-color: var(--accent); }
.rowi.ms.wild { border-color: #ff5a4a; }
.rowi.ms.done { opacity: 0.72; }
.ms-steps { display: grid; gap: 0.2em; }
.ms-steps span { display: flex; gap: 0.4em; align-items: center; font-size: 0.9em; }
.ms-steps span svg.i { width: 1em; height: 1em; flex: none; color: var(--dim); }
.ms-steps span em { font-style: normal; }
.ms-steps span.done { color: var(--ok); }
.ms-steps span.done svg.i { color: var(--ok); }
.rowi.ms .ms-rw { color: var(--accent); font-weight: 600; }
#helihud { position: absolute; left: 50%; bottom: calc(3.4em + var(--sab)); transform: translateX(-50%); display: flex; gap: 1.1em; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 0.5em 1em; }
#helihud[hidden], #helipad[hidden] { display: none; }
#helihud .hh { display: grid; gap: 0.2em; min-width: 6.5em; }
#helihud .hh.n { min-width: 0; }
#helihud small { font-size: 0.7em; font-weight: 700; color: var(--dim); white-space: nowrap; }
#helihud b { font-size: 1em; white-space: nowrap; }
#helihud .track { height: 9px; border-radius: 9px; background: rgba(10, 12, 14, 0.75); overflow: hidden; }
#helihud .track i { display: block; height: 100%; border-radius: 9px; background: var(--ok); transition: width 0.12s linear; }
#helihud #hh-heat { background: var(--accent); }
#helihud .track i.low { background: var(--hp); }
#helipad { position: absolute; right: calc(0.9em + var(--sar)); bottom: calc(5.6em + var(--sab)); display: grid; gap: 0.5em; justify-items: end; pointer-events: none; }
#helipad .round { touch-action: none; }
body:not(.touch) #helipad { display: none; }
body.heli #hotbar, body.heli #tool, body.heli #pad, body.heli #prompt { display: none; }
body.heli #flypad { right: calc(7.6em + var(--sar)); }
body.heli:not(.touch) #flypad { display: none; }
body.heli #cross { display: block; width: 34px; height: 34px; margin: -17px; background: none; border: 2px solid rgba(241, 236, 226, 0.9); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(0, 0, 0, 0.45); }
body.heli #cross::after { content: ""; position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px; border-radius: 50%; background: rgba(241, 236, 226, 0.95); }
body.heli #cross.lock { border-color: #ff5a4a; }
body.heli #cross.lock::after { background: #ff5a4a; }
@media (max-width: 720px) {
  #mission { top: 30%; }
  #mission b { font-size: 1.25em; }
  body.touch #helihud { bottom: auto; top: calc(4.9em + var(--sat)); gap: 0.7em; padding: 0.4em 0.7em; font-size: 0.9em; }
  body.touch #helihud .hh { min-width: 4.6em; }
  body.heli #goal { top: calc(9.6em + var(--sat)); }
  body.heli #goal-how { display: none; }
}
@media (max-height: 460px) {
  #mission { top: 20%; font-size: 0.9em; }
  body.touch #helihud { bottom: auto; top: calc(0.6em + var(--sat)); font-size: 0.82em; }
  body.heli.touch #goal { top: calc(5.2em + var(--sat)); }
  body.heli #goal-how { display: none; }
}
@media (prefers-reduced-motion: reduce) { #mission { animation-name: none; } }

/* The top bar and the mission prompt share a row only when the window is wide enough for both. */
@media (max-width: 1180px) and (min-height: 461px) {
  #goal, #target { top: calc(4.9em + var(--sat)); }
  #toasts { top: calc(11.5em + var(--sat)); }
}

/* Narrow phones: the top row keeps to what fits. Tribes moves into the menu. */
@media (max-width: 480px) {
  #b-tribe { display: none; }
  #top-left, #top-right { gap: 0.3em; }
  #top-left .round, #top-right .round { min-width: 3.5em; padding: 0.45em 0.35em 0.3em; }
  #embers { padding: 0.4em 0.65em 0.4em 0.5em; }
  #status { display: none; }
}
/* Phones held sideways: Tribes lives in the menu, and the prompt moves aside while flying the gunship. */
@media (max-height: 460px) {
  #b-tribe { display: none; }
  body.heli.touch #goal { left: calc(0.8em + var(--sal)); transform: none; max-width: 34vw; }
}
