/* TUSKY - field terminal for a 1999 WJ.
   Identity: UNSC / off-road tactical. Gunmetal plate, sand + champagne light (Tusky's paint),
   amber signal, red for critical only. Wide Michroma labels, condensed Saira numerals.
   Shapes: chamfered plates, corner brackets, hazard tape. No rounded corners anywhere.
   This page deliberately uses its own palette (owner's choice, Oct 2026), not the site purple. */
:root {
  --gunmetal: #2a2e2b;
  --steel: #4d5450;
  --olive: #5b6346;
  --sand: #c9b48a;
  --champagne: #e3d3b1;
  --amber: #ffb000;
  --red: #ff4a32;
  --go: #a7c06a;
  --panel: rgba(30, 33, 31, 0.62);   /* glass: the backdrop filter darkens what is behind, so text contrast holds */
  --red-t: #ffa08c;          /* red for text only (contrast); fills use --red */
  --edge: rgba(201, 180, 138, 0.36);
  --wide: 'Michroma', 'Eurostile', 'Microgramma', 'Arial Black', sans-serif;
  --cond: 'Saira Condensed', 'Arial Narrow', 'Roboto Condensed', sans-serif;
  --ch: 11px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--gunmetal); color: var(--champagne); font: 500 16px/1.3 var(--cond); -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; padding: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

[data-level="ok"]   { --lv: var(--go); }
[data-level="info"] { --lv: var(--sand); }
[data-level="up"]   { --lv: var(--champagne); }
[data-level="warn"] { --lv: var(--amber); }
[data-level="bad"]  { --lv: var(--red); --lvt: var(--red-t); }
em { font: 400 9px/1.2 var(--wide); letter-spacing: .16em; text-transform: uppercase; color: var(--sand); font-style: normal; }

/* ---- Plate: chamfered panel with 1px sand rim, scanlines and corner brackets ---- */
.pl { position: relative; isolation: isolate; }
.pl::before, .pl::after { content: ''; position: absolute; pointer-events: none; }
.pl::before {
  inset: 0; z-index: -2; background: var(--edge);
  clip-path: polygon(var(--ch) 0, 100% 0, 100% calc(100% - var(--ch)), calc(100% - var(--ch)) 100%, 0 100%, 0 var(--ch));
}
.pl::after {
  inset: 1px; z-index: -1;
  clip-path: polygon(calc(var(--ch) - .5px) 0, 100% 0, 100% calc(100% - var(--ch) + .5px), calc(100% - var(--ch) + .5px) 100%, 0 100%, 0 calc(var(--ch) - .5px));
  background:
    linear-gradient(var(--sand), var(--sand)) top right / 14px 2px no-repeat,
    linear-gradient(var(--sand), var(--sand)) top right / 2px 14px no-repeat,
    linear-gradient(var(--sand), var(--sand)) bottom left / 14px 2px no-repeat,
    linear-gradient(var(--sand), var(--sand)) bottom left / 2px 14px no-repeat,
    repeating-linear-gradient(0deg, rgba(227, 211, 177, .035) 0 1px, transparent 1px 3px),
    var(--panel);
  -webkit-backdrop-filter: blur(14px) saturate(1.15) brightness(.45); backdrop-filter: blur(14px) saturate(1.15) brightness(.45);
}
/* no backdrop-filter (older browsers): fall back to a solid plate */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) { :root { --panel: rgba(42, 46, 43, 0.93); } }

/* ---- Icon buttons: one style for every control inside a container ---- */
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.ib { position: relative; flex: none; width: 34px; height: 34px; display: inline-grid; place-items: center; color: var(--champagne);
  border: 1px solid var(--edge); background: rgba(16, 18, 17, .35); transition: border-color .15s, color .15s, box-shadow .15s, transform .12s; }
.ib:hover { border-color: var(--sand); box-shadow: 0 0 0 1px rgba(201, 180, 138, .25), inset 0 0 12px rgba(201, 180, 138, .12); }
.ib:active { transform: scale(.94); border-color: var(--amber); color: var(--amber); }
.ib.primary { color: var(--amber); border-color: rgba(255, 176, 0, .6); }
.ib.armed { color: var(--red-t); border-color: var(--red); box-shadow: inset 0 0 12px rgba(255, 74, 50, .25); }
.ib[hidden] { display: none !important; }
.btn:active, #cmd > button:active { transform: scale(.97); }
.tape { background: repeating-linear-gradient(-45deg, var(--amber) 0 9px, var(--gunmetal) 9px 18px); }

/* ---- World layers ---- */
#world { position: fixed; inset: 0; }
#world canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#labels, #reticles { position: fixed; inset: 0; pointer-events: none; }
body:not(.xray) #labels { visibility: hidden; }   /* part labels belong to the X-ray / Cut views only */
#leader { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; }
#leader polyline { fill: none; stroke: var(--amber); stroke-width: 1.5; stroke-dasharray: 6 3; }
#leader circle { fill: none; stroke: var(--amber); stroke-width: 2; }
#leader.fresh { animation: leaderin .35s ease-out; }
@keyframes leaderin { from { opacity: 0; } to { opacity: 1; } }
#leader:not(.on) { display: none; }

#loading { position: fixed; inset: 0; z-index: 30; display: grid; place-content: center; justify-items: center; gap: 14px; background: var(--gunmetal); transition: opacity .6s; }
#loading b { font: 400 clamp(28px, 7vw, 64px)/1 var(--wide); letter-spacing: .3em; color: var(--champagne); }
#loading span { font: 400 10px var(--wide); letter-spacing: .25em; text-transform: uppercase; color: var(--sand); }
#loading q { max-width: min(560px, 84vw); margin-top: 6px; text-align: center; font: 500 clamp(15px, 2.2vw, 19px)/1.4 var(--cond); color: var(--champagne); }
#loading cite { margin-bottom: 10px; font: 400 10px var(--wide); letter-spacing: .3em; text-transform: uppercase; font-style: normal; color: var(--amber); }
#loading cite::before { content: '- '; }
#loading::after { content: ''; width: min(320px, 60vw); height: 3px; background: linear-gradient(90deg, var(--amber) 0 30%, var(--steel) 30%); background-size: 200% 100%; animation: load 1.2s linear infinite; }
@keyframes load { to { background-position: -200% 0; } }
body.ready #loading { opacity: 0; pointer-events: none; }

/* ---- HUD grid ---- */
#hud {
  position: fixed; inset: 0; z-index: 5; pointer-events: none; display: grid; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  grid-template-columns: minmax(196px, 22vw) minmax(0, 1fr) minmax(214px, 25vw);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "top top top" "drive mid mods" "tape tape tape" "cmd cmd cmd";
}
#hud > * { pointer-events: auto; }
#hud > #card { pointer-events: auto; }

/* top strip */
#top { grid-area: top; display: flex; align-items: stretch; gap: 8px; min-width: 0; overflow: hidden; }
#top > .pl { padding: 6px 14px; display: flex; align-items: center; gap: 10px; min-height: 46px; }
#nameplate { flex-direction: column; align-items: flex-start !important; justify-content: center; gap: 2px !important; --ch: 14px; padding-right: 24px !important; }
#nameplate b { font: 400 19px/1 var(--wide); letter-spacing: .32em; color: #fff; }
#nameplate span { font: 600 12px/1 var(--cond); letter-spacing: .08em; color: var(--sand); white-space: nowrap; }
.link { text-align: left; }
.link span { display: flex; flex-direction: column; }
.link b { font: 700 16px/1.3 var(--cond); color: var(--champagne); white-space: nowrap; max-width: 30vw; overflow: hidden; text-overflow: ellipsis; }
.sig { display: flex; align-items: flex-end; gap: 2px; height: 18px; }
.sig s { width: 4px; background: var(--steel); }
.sig s:nth-child(1) { height: 25%; } .sig s:nth-child(2) { height: 50%; } .sig s:nth-child(3) { height: 75%; } .sig s:nth-child(4) { height: 100%; }
.link[data-state="live"] .sig s { background: var(--go); }
.link[data-state="connecting"] .sig s { background: var(--amber); animation: sig 1.2s infinite; }
.link[data-state="connecting"] .sig s:nth-child(2) { animation-delay: .15s; } .link[data-state="connecting"] .sig s:nth-child(3) { animation-delay: .3s; } .link[data-state="connecting"] .sig s:nth-child(4) { animation-delay: .45s; }
.link[data-state="lost"] .sig s, .link[data-state="error"] .sig s { background: var(--red); }
@keyframes sig { 50% { opacity: .2; } }
.odo { gap: 16px !important; }
.odo span { display: flex; flex-direction: column; }
.odo b { font: 700 20px/1.05 var(--cond); color: #fff; letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.wx { margin-left: auto; min-width: 0; }
.wx-temp { font: 800 30px/1 var(--cond); color: #fff; }
.wx-mid { display: flex; flex-direction: column; min-width: 0; }
.wx-sky { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 18vw; }
.wx-road { font: 700 15px/1.1 var(--cond); color: var(--lvt, var(--lv)); white-space: nowrap; }
.wx-alert { color: var(--gunmetal); padding: 0 10px; height: 30px; font: 800 13px var(--cond); letter-spacing: .04em; text-transform: uppercase; max-width: 20vw; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.wx-alert span { background: var(--amber); padding: 2px 6px; }
.top-btns { display: flex; gap: 6px; }
.sq { width: 46px; justify-content: center; padding: 0 !important; display: grid; place-items: center; }
.sq svg, .gear svg { width: 20px; height: 20px; fill: none; stroke: var(--champagne); stroke-width: 1.8; }
#btn-labels[aria-pressed="true"] svg { stroke: var(--amber); }
#btn-labels[aria-pressed="true"]::before { background: var(--amber); }

/* drive cluster */
#drive { grid-area: drive; align-self: center; min-width: 0; min-height: 0; overflow: hidden; display: grid; gap: 10px; padding: 14px 14px 12px; --ch: 16px; }
.spd { display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: stretch; }
.ladder { width: 30px; height: 100%; min-height: 110px; overflow: visible; }
.ladder line { stroke: var(--steel); stroke-width: 1.5; }
.ladder line.maj { stroke: var(--sand); stroke-width: 2; }
.ladder text { fill: var(--sand); font: 400 7px var(--wide); }
.ladder polygon { fill: var(--amber); transition: transform .25s linear; }
.spd-read { display: flex; flex-direction: column; justify-content: center; }
.spd-read b { font: 800 clamp(56px, 7vw + 4vh, 104px)/.86 var(--cond); color: #fff; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.spd-read small, .rpm-head small { font: 400 9px var(--wide); letter-spacing: .2em; color: var(--sand); text-transform: uppercase; }
.rpm-head { display: flex; align-items: baseline; gap: 8px; }
.rpm-head b { font: 700 24px/1 var(--cond); color: #fff; font-variant-numeric: tabular-nums; margin-left: auto; }
.segs { display: grid; grid-template-columns: repeat(30, minmax(0, 1fr)); gap: 2px; height: 20px; margin-top: 5px; padding: 0 4px; }  /* padding keeps the skewed end segments inside */
.segs i { background: var(--steel); transform: skewX(-18deg); opacity: .55; transition: background .12s, opacity .12s; }
.segs i.red { background: repeating-linear-gradient(-45deg, rgba(255, 74, 50, .55) 0 2px, transparent 2px 4px); opacity: 1; }
.segs i.on { background: var(--sand); opacity: 1; }
.segs i.on.hot { background: var(--amber); }
.segs i.on.red { background: var(--red); }
.bars { display: flex; gap: 14px; }
.vbar { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 2px 8px; flex: 1; }
.vbar em { grid-column: 1 / 3; }
.vsegs { display: flex; gap: 2px; height: 12px; }
.vsegs i { flex: 1; background: var(--steel); opacity: .5; }
.vsegs i.on { background: var(--champagne); opacity: 1; }
.vbar b { grid-column: 1 / 3; font: 700 15px/1 var(--cond); color: var(--champagne); }

/* modules */
#mods { grid-area: mods; align-self: center; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; min-height: 0; min-width: 0; }
.mod { padding: 6px 9px 4px 11px; display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto auto; align-items: baseline; --ch: 8px; min-width: 0; }
.mod em { grid-column: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notch { grid-column: 2; grid-row: 1; width: 8px; height: 8px; background: var(--lv, var(--steel)); align-self: center; }
.mod[data-level="warn"] .notch, .mod[data-level="bad"] .notch { box-shadow: 0 0 8px var(--lv); }
.mod.flash::before { animation: edgeflash .65s ease-out; }
@keyframes edgeflash { 0%, 30% { background: var(--lv); } 100% { background: var(--edge); } }
.mod b { grid-column: 1; font: 800 25px/1.05 var(--cond); color: #fff; font-variant-numeric: tabular-nums; }
.mod[data-level="warn"] b, .mod[data-level="bad"] b { color: var(--lvt, var(--lv)); }
.mod small { grid-column: 2; grid-row: 2; font: 400 8px var(--wide); color: var(--sand); letter-spacing: .1em; }
.mod canvas { grid-column: 1 / 3; width: 100%; height: 16px; display: block; }
.mod.wide { grid-column: span 2; }
.mod.wide b { font-size: 17px; }

/* cutaway slider */
#cutbar { position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 6; display: flex; align-items: center; gap: 10px; padding: 8px 14px; width: min(360px, 60vw); --ch: 8px; }
#cutbar input { flex: 1; accent-color: var(--amber); padding: 0; border: 0; background: none; }

/* alert tape */
#tape { grid-area: tape; display: flex; align-items: stretch; min-height: 32px; background: var(--panel); -webkit-backdrop-filter: blur(14px) brightness(.45); backdrop-filter: blur(14px) brightness(.45); border-top: 1px solid var(--edge); border-bottom: 1px solid var(--edge); cursor: pointer; overflow: hidden; }
#tape > i { width: 54px; flex: none; background: var(--lv, var(--go)); }
#tape[data-level="warn"] > i, #tape[data-level="bad"] > i { background: repeating-linear-gradient(-45deg, var(--lv) 0 8px, var(--gunmetal) 8px 16px); animation: tape 1s linear infinite; background-size: 22.6px 100%; }
@keyframes tape { to { background-position: 22.6px 0; } }
#tape > span { flex: 1; display: flex; align-items: center; gap: 22px; padding: 0 14px; font: 700 16px var(--cond); letter-spacing: .03em; white-space: nowrap; overflow: hidden; }
#tape b { color: var(--lvt, var(--lv)); font-weight: 800; }
#tape b::before { content: '▲ '; }

/* command bar */
#cmd { grid-area: cmd; position: relative; display: flex; gap: 4px; min-width: 0; }
#cmd-ind { position: absolute; bottom: -3px; height: 3px; left: 0; width: 0; background: var(--amber); opacity: 0; pointer-events: none; transition: left .28s cubic-bezier(.2, .8, .2, 1), width .28s cubic-bezier(.2, .8, .2, 1), opacity .2s; }
#cmd > button { position: relative; flex: 1; min-width: 0; min-height: 46px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px;
  clip-path: polygon(14px 0, 100% 0, calc(100% - 14px) 100%, 0 100%); background: var(--panel); border-top: 2px solid var(--steel);
  -webkit-backdrop-filter: blur(14px) brightness(.45); backdrop-filter: blur(14px) brightness(.45); transition: background .2s, transform .12s; }
#cmd > button span { font: 400 10px var(--wide); letter-spacing: .2em; text-transform: uppercase; color: var(--champagne); }
#cmd > button.on { background: var(--champagne); border-top-color: var(--amber); }
#cmd > button.on span, #cmd > button.on b { color: var(--gunmetal); }
#cmd > button.on svg { stroke: var(--gunmetal); }
#cmd .gear { flex: 0 0 64px; }
#cmd .scan.on { background: var(--amber); }
#badge { font: 800 13px/20px var(--cond); font-style: normal; min-width: 22px; height: 20px; padding: 0 5px; background: var(--amber); color: var(--gunmetal); text-align: center; }
#pct { font: 800 16px var(--cond); color: #fff; }
.minisheet { display: flex; gap: 1px; height: 14px; width: min(120px, 12vw); }
.minisheet i { flex: 1; background: var(--steel); }
.minisheet i[data-st="rep"] { background: var(--go); }
.minisheet i[data-st="warn"] { background: var(--amber); }
.minisheet i[data-st="bad"] { background: var(--red); }

/* part callout card */
#card { position: absolute; z-index: 6; width: min(340px, 44vw); top: 64px; padding: 12px 14px 10px; --ch: 16px; display: grid; gap: 8px; max-height: calc(100% - 160px); overflow-y: auto; overscroll-behavior: contain; }
#card header { display: flex; align-items: flex-start; gap: 10px; padding-bottom: 8px; background: linear-gradient(90deg, rgba(201, 180, 138, .35), transparent 75%) bottom / 100% 1px no-repeat; }
#card.opening { animation: cardin .24s cubic-bezier(.2, .8, .2, 1); }
@keyframes cardin { from { clip-path: inset(0 0 100% 0); opacity: .3; } to { clip-path: inset(0 0 0 0); opacity: 1; } }
#card header span { flex: 1; display: flex; flex-direction: column; gap: 3px; }
#card-name { font: 400 15px/1.25 var(--wide); letter-spacing: .04em; color: #fff; }
.chev { width: 12px; height: 26px; flex: none; background: var(--lv, var(--sand)); clip-path: polygon(0 0, 100% 50%, 0 100%, 0 70%, 50% 50%, 0 30%); }
.x { width: 32px; height: 32px; display: grid; place-items: center; color: var(--sand); border: 1px solid var(--steel); font-size: 14px; flex: none; }
.card-status { font: 800 15px var(--cond); letter-spacing: .04em; color: var(--lvt, var(--lv, var(--sand))); text-transform: uppercase; }
#card dl { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#card dt { font: 400 8px var(--wide); letter-spacing: .16em; color: var(--sand); text-transform: uppercase; }
#card dd { margin: 2px 0 0; font: 700 18px var(--cond); color: #fff; }
.life20 { display: grid; grid-template-columns: repeat(20, 1fr); gap: 2px; height: 14px; }
.life20 i { background: var(--steel); opacity: .5; }
.life20 i.on { background: var(--lv, var(--go)); opacity: 1; }
.lifecap { font: 600 13px var(--cond); color: var(--sand); }
.pnplate { border: 1px dashed var(--sand); padding: 6px 10px; font: 700 15px var(--cond); color: var(--champagne); letter-spacing: .06em; display: flex; justify-content: space-between; gap: 8px; }
.pnplate:empty { display: none; }
.pnplate em { align-self: center; }
.card-log { display: grid; gap: 4px; }
.card-log div { font: 500 14px/1.25 var(--cond); color: var(--champagne); padding-left: 10px; border-left: 2px solid var(--olive); }
.card-log div small { display: block; color: var(--sand); font-size: 12px; }
#card footer { display: flex; align-items: center; gap: 8px; padding-top: 8px; background: linear-gradient(90deg, rgba(201, 180, 138, .35), transparent 75%) top / 100% 1px no-repeat; }
.pager { font: 700 15px var(--cond); color: var(--sand); letter-spacing: .06em; font-variant-numeric: tabular-nums; min-width: 44px; text-align: center; }
.pager[hidden] { display: none; }
#card-also { margin-left: auto; display: flex; }

/* zone reticles */
.ret { position: absolute; left: 0; top: 0; width: 30px; height: 30px; margin: -15px 0 0 -15px; pointer-events: auto;
  background:
    linear-gradient(var(--lv), var(--lv)) top left / 9px 2px no-repeat, linear-gradient(var(--lv), var(--lv)) top left / 2px 9px no-repeat,
    linear-gradient(var(--lv), var(--lv)) top right / 9px 2px no-repeat, linear-gradient(var(--lv), var(--lv)) top right / 2px 9px no-repeat,
    linear-gradient(var(--lv), var(--lv)) bottom left / 9px 2px no-repeat, linear-gradient(var(--lv), var(--lv)) bottom left / 2px 9px no-repeat,
    linear-gradient(var(--lv), var(--lv)) bottom right / 9px 2px no-repeat, linear-gradient(var(--lv), var(--lv)) bottom right / 2px 9px no-repeat; }
.ret::after { content: ''; position: absolute; left: 13px; top: 13px; width: 4px; height: 4px; background: var(--lv); }
.ret span { position: absolute; left: 34px; top: 6px; white-space: nowrap; font: 400 8px var(--wide); letter-spacing: .14em; text-transform: uppercase; color: var(--champagne); background: rgba(42, 46, 43, .9); padding: 3px 6px; border-left: 2px solid var(--lv); opacity: 0; transition: opacity .2s; }
.ret:hover span, .ret:focus span, body.labels-on .ret span { opacity: 1; }
@keyframes ret { 50% { scale: 1.18; } }  /* markers are positioned with the translate property; scale pulses in place */
body.xray .ret { display: none; }

/* scan-mode labels (worldkit labels) */
.wl { position: absolute; left: 0; top: 0; pointer-events: auto; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px; }
.wl::before { content: ''; width: 9px; height: 9px; transform: rotate(45deg); background: var(--lv, var(--sand)); border: 2px solid rgba(20, 22, 21, .85);
  box-shadow: 0 0 6px var(--lv, var(--sand)); transition: transform .15s; }
.wl:hover::before { transform: rotate(45deg) scale(1.25); }
.wl b, .wl span { display: none; }
.wl.open b, body.labels-on .wl b { display: block; animation: lblin .18s ease-out; }
@keyframes lblin { from { opacity: 0; transform: translateY(-3px); } }
.wl b { font: 700 13px/1 var(--cond); color: var(--champagne); background: rgba(42, 46, 43, .9); padding: 3px 6px; border-left: 2px solid var(--lv, var(--sand)); white-space: nowrap; }
.wl span { font: 400 7px var(--wide); letter-spacing: .14em; color: var(--sand); text-transform: uppercase; }

/* ---- Side bay ---- */
#bay { position: fixed; z-index: 20; top: max(8px, env(safe-area-inset-top)); bottom: max(8px, env(safe-area-inset-bottom)); right: max(8px, env(safe-area-inset-right));
  width: min(540px, calc(100vw - 16px)); display: flex; flex-direction: column; padding: 12px 16px; --ch: 20px; animation: bay .28s cubic-bezier(.2, .8, .2, 1); }
@keyframes bay { from { transform: translateX(40px); opacity: 0; } }
.bay-head { display: flex; align-items: center; gap: 10px; padding-bottom: 10px; background: linear-gradient(90deg, rgba(201, 180, 138, .35), transparent 75%) bottom / 100% 1px no-repeat; }
#bay-title { font: 400 15px var(--wide); letter-spacing: .24em; text-transform: uppercase; color: #fff; flex: 1; }
#zone-chip { display: flex; align-items: center; gap: 4px; border: 1px solid var(--amber); padding: 2px 2px 2px 8px; }
#zone-chip em { color: var(--amber); }
#zone-chip button { width: 26px; height: 26px; display: grid; place-items: center; color: var(--amber); }
#zone-chip .ic { width: 14px; height: 14px; }
.pane { flex: 1; overflow-y: auto; padding: 10px 2px 30px; }
.pane h3 { font: 400 10px var(--wide); letter-spacing: .22em; text-transform: uppercase; color: var(--sand); margin: 20px 0 8px; display: flex; align-items: center; gap: 10px; }
.pane h3::after { content: ''; flex: 1; height: 1px; background: var(--steel); }
.ent { display: grid; grid-template-columns: 6px 1fr auto; gap: 10px; padding: 9px 0; border-bottom: 1px solid rgba(77, 84, 80, .7); align-items: start; }
.ent > i { align-self: stretch; background: var(--lv, var(--steel)); }
.ent b { font: 700 17px/1.2 var(--cond); color: #fff; display: block; }
.ent p { margin: 3px 0 0; color: var(--champagne); font-size: 15px; line-height: 1.35; max-width: 64ch; }
.ent small { display: block; color: var(--sand); font-size: 13px; margin-top: 2px; }
.eh { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; }
.pill { font: 400 7.5px/1 var(--wide); letter-spacing: .12em; text-transform: uppercase; color: var(--lvt, var(--lv)); border: 1px solid currentColor; padding: 3px 5px; white-space: nowrap; }
.ent .acts { display: flex; gap: 6px; }
.ent input { margin-top: 6px; }
.life10 { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; height: 6px; margin-top: 6px; max-width: 220px; }
.life10 i { background: var(--steel); opacity: .5; }
.life10 i.on { background: var(--lv); opacity: 1; }
.btn { background: var(--champagne); color: var(--gunmetal); padding: 11px 16px; font: 400 10px var(--wide); letter-spacing: .16em; text-transform: uppercase; clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px); }
.btn.ghost { background: transparent; color: var(--champagne); box-shadow: inset 0 0 0 1px var(--sand); }
.btn.sm { padding: 7px 11px; }
.btn:disabled { opacity: .5; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.row-form { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.row-form [name=task], .row-form select, .row-form .btn { grid-column: span 2; }
input, select, textarea { width: 100%; background: rgba(20, 22, 21, .9); color: var(--champagne); border: 1px solid var(--steel); border-radius: 0; padding: 9px 10px; font: 500 16px var(--cond); }
input:focus, select:focus, textarea:focus { border-color: var(--amber); outline: none; }
.field { display: block; margin: 12px 0; font: 400 9px var(--wide); letter-spacing: .16em; text-transform: uppercase; color: var(--sand); }
.field input, .field select { margin-top: 5px; text-transform: none; letter-spacing: 0; }
.check { display: flex; gap: 10px; align-items: center; margin: 12px 0; color: var(--champagne); }
.check input { width: 18px; height: 18px; accent-color: var(--amber); }
.muted { color: var(--sand); font-size: 14px; }
.muted a { color: var(--amber); }
#adlog { font: 500 12px/1.4 var(--cond); color: var(--sand); background: rgba(20, 22, 21, .9); border: 1px solid var(--steel); padding: 8px; max-height: 180px; overflow: auto; white-space: pre-wrap; }
.ff { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
.ff span { border-left: 2px solid var(--olive); padding-left: 8px; color: var(--sand); font-size: 13px; }
.ff b { display: block; color: #fff; font-size: 18px; }

/* build sheet (parts) */
.sheet-head { display: flex; align-items: flex-end; gap: 14px; margin-bottom: 8px; }
.sheet-head b { font: 800 56px/.85 var(--cond); color: #fff; }
.sheet-head span { color: var(--champagne); font-size: 15px; }
.sheet-head span small { display: block; color: var(--sand); font-size: 13px; }
.goal { margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--edge); }
.goal > small { display: block; margin-top: 6px; }
.sheet { display: grid; grid-template-columns: repeat(25, 1fr); gap: 2px; margin-bottom: 6px; }
.sheet i { height: 22px; background: var(--steel); cursor: pointer; }
.sheet i[data-st="rep"] { background: var(--go); }
.sheet i[data-st="warn"] { background: var(--amber); }
.sheet i[data-st="bad"] { background: var(--red); }
.sheet i[data-st="cons"] { background: var(--olive); }
.sheet i:hover, .sheet i:focus { outline: 2px solid #fff; outline-offset: 1px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--sand); }
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: 5px; vertical-align: -1px; }
.spec { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 15px; margin: 8px 0; }
.spec dt { font: 400 8px/2 var(--wide); letter-spacing: .14em; color: var(--sand); text-transform: uppercase; }
.spec dd { margin: 0; color: var(--champagne); }
.search { position: sticky; top: -10px; z-index: 1; background: rgba(42, 46, 43, .96); padding: 8px 0; }
.figrow { display: grid; grid-template-columns: 112px minmax(0, 1fr) auto; gap: 10px; align-items: center; width: 100%; text-align: left; padding: 8px 0; border-bottom: 1px solid rgba(77, 84, 80, .7); }
.figrow em { color: var(--amber); letter-spacing: .08em; white-space: nowrap; }
.figrow small { white-space: nowrap; }
.figrow b { font: 600 16px var(--cond); color: var(--champagne); }
.figrow small { color: var(--sand); font-size: 13px; }
.hit { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 8px 0; border-bottom: 1px solid rgba(77, 84, 80, .7); width: 100%; text-align: left; }
.hit b { color: #fff; font-weight: 600; }
.hit code { font: 700 15px var(--cond); color: var(--amber); letter-spacing: .05em; }
.hit small { grid-column: 1 / 3; color: var(--sand); font-size: 13px; }

/* ---- Catalog drawing viewer ---- */
#dwg { position: fixed; z-index: 25; inset: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  display: grid; grid-template-rows: auto 1fr; padding: 12px 16px; --ch: 22px; }
#dwg .bay-head b { font: 400 13px/1.3 var(--wide); letter-spacing: .08em; color: #fff; flex: 1; min-width: 0; }
#dwg .bay-head em { color: var(--amber); }
.dwg-body { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 14px; min-height: 0; padding-top: 10px; }
.dwg-img { position: relative; overflow: auto; background: #e9e3d4; border: 1px solid var(--steel); touch-action: pan-x pan-y pinch-zoom; }
.dwg-img img { display: block; width: 100%; height: auto; mix-blend-mode: multiply; filter: contrast(1.1); }
.co { position: absolute; width: 30px; height: 30px; margin: -15px 0 0 -15px; border: 2px solid transparent; }
.co:hover, .co.on { border-color: var(--amber); background: rgba(255, 176, 0, .25); }
.dwg-tab { overflow-y: auto; min-height: 0; }
.crow2 { display: grid; grid-template-columns: 34px 1fr auto; gap: 2px 10px; padding: 7px 4px; border-bottom: 1px solid rgba(77, 84, 80, .7); width: 100%; text-align: left; }
.crow2 .n { font: 800 18px var(--cond); color: var(--sand); }
.crow2 b { color: #fff; font-weight: 600; font-size: 15px; }
.crow2 code { font: 700 15px var(--cond); color: var(--amber); letter-spacing: .04em; }
.crow2 small { grid-column: 2 / 4; color: var(--sand); font-size: 12px; }
.crow2.no { opacity: .45; }
.crow2.on { background: rgba(255, 176, 0, .14); box-shadow: inset 3px 0 var(--amber); }
.fits { font: 400 7px var(--wide); letter-spacing: .14em; text-transform: uppercase; padding: 2px 5px; border: 1px solid currentColor; }
.fits.yes { color: var(--go); } .fits.maybe { color: var(--amber); } .fits.no { color: var(--sand); }

/* ---- History ---- */
.chart { width: 100%; height: 120px; display: block; background: rgba(20, 22, 21, .7); border: 1px solid var(--steel); }
.chart.tall { height: 170px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; margin: 8px 0; }
.kv span { border-left: 2px solid var(--olive); padding: 2px 0 2px 8px; }
.kv b { display: block; font: 800 22px/1.05 var(--cond); color: #fff; }
.trip { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; width: 100%; text-align: left; padding: 9px 0; border-bottom: 1px solid rgba(77, 84, 80, .7); }
.trip b { font: 700 16px var(--cond); color: #fff; }
.trip small { color: var(--sand); font-size: 13px; }
.trip code { font: 800 18px var(--cond); color: var(--champagne); }
.tl { position: relative; margin-left: 8px; padding-left: 16px; border-left: 2px solid var(--steel); }
.tl .yr { font: 400 10px var(--wide); letter-spacing: .2em; color: var(--amber); margin: 14px 0 6px -24px; background: var(--gunmetal); display: inline-block; padding: 2px 6px; }
.tl .ev { position: relative; padding: 4px 0; font-size: 15px; color: var(--champagne); }
.tl .ev::before { content: ''; position: absolute; left: -21px; top: 10px; width: 8px; height: 8px; background: var(--lv, var(--sand)); }
.tl .ev small { color: var(--sand); margin-right: 8px; }

/* ---- Stale data ---- */
body.stale #drive b, body.stale .mod b { opacity: .4; }

/* ---- Boot: one orchestrated power-on ---- */
body.boot #hud > * { opacity: 0; }
body.booting #hud > * { animation: on .5s cubic-bezier(.2, .8, .2, 1) both; }
body.booting #top { animation-delay: .05s; } body.booting #drive { animation-delay: .2s; } body.booting #mods { animation-delay: .32s; }
body.booting #tape { animation-delay: .44s; } body.booting #cmd { animation-delay: .52s; }
@keyframes on { 0% { opacity: 0; clip-path: inset(0 0 100% 0); } 60% { opacity: 1; } 100% { opacity: 1; clip-path: inset(0 0 0 0); } }

/* ---- Phones and tablets ----------------------------------------------------------
   Grid tracks use minmax(0, ...) so long content can never push a column wider than the
   screen; every readout either truncates with an ellipsis or wraps inside its plate. */

/* Portrait (phones, tablets held upright): slim drive strip on top, 3D in the middle,
   4 x 2 module grid, alert tape, flat 7-button command bar. */
@media (max-aspect-ratio: 1/1) {
  #hud { gap: 6px; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
    grid-template-areas: "top" "drive" "mid" "mods" "tape" "cmd"; }
  #top { gap: 6px; }
  #top > .pl { min-height: 40px; padding: 4px 10px; gap: 8px; }
  .odo, .wx-mid, #nameplate span { display: none !important; }
  #nameplate { padding-right: 14px !important; }
  #nameplate b { font-size: 14px; letter-spacing: .22em; }
  .link b { font-size: 14px; max-width: 30vw; }
  .wx { flex: 0 1 auto; min-width: 0; }
  .wx-temp { font-size: 22px; }
  .wx-alert { max-width: 34vw; height: 26px; }
  .sq { width: 40px; }
  #btn-full { display: none; }   /* iPhone browsers have no page fullscreen; keeps the top bar inside the screen */

  #drive { align-self: stretch; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto auto; gap: 6px 16px; padding: 8px 12px 8px 14px; --ch: 10px; }
  .spd { grid-row: 1 / 3; grid-template-columns: 1fr; align-self: center; }
  .ladder { display: none; }
  .spd-read b { font-size: 54px; }
  .rpm { min-width: 0; }
  .rpm-head b { font-size: 20px; }
  .segs { height: 14px; gap: 1px; }
  .bars { gap: 12px; }
  .vbar b { font-size: 13px; }

  #mods { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
  .mod { padding: 4px 6px 4px 8px; --ch: 6px; }
  .mod em { font-size: 7.5px; letter-spacing: .05em; }
  .mod b { font-size: 19px; }
  .mod small, .mod canvas { display: none; }
  .mod.wide { grid-column: auto; }
  .mod.wide b { font-size: 12px; line-height: 1.6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  #tape { min-height: 28px; }
  #tape > i { width: 28px; }
  #tape > span { font-size: 14px; gap: 14px; padding: 0 10px; }

  #cmd { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)) 42px; gap: 3px; }
  #cmd > button { clip-path: none; min-width: 0; min-height: 44px; padding: 0 2px; gap: 3px; }
  #cmd > button span { font: 700 12px/1.3 var(--cond); letter-spacing: .03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #cmd .gear { flex: none; }
  #badge { position: absolute; top: 2px; right: 2px; min-width: 16px; height: 16px; font-size: 11px; line-height: 16px; padding: 0 3px; }
  .minisheet, #pct { display: none; }

  /* part card becomes a bottom sheet above the command bar */
  #card { position: fixed; left: 8px !important; right: 8px !important; width: auto; top: auto !important;
    bottom: calc(max(8px, env(safe-area-inset-bottom)) + 84px); max-height: 50vh; max-height: 50dvh; }
  #cutbar { bottom: calc(max(8px, env(safe-area-inset-bottom)) + 96px); width: calc(100% - 32px); }
  .dwg-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
}

/* Short landscape (phones on the dash mount): compact cluster so the command bar always fits. */
@media (orientation: landscape) and (max-height: 520px) {
  #hud { gap: 5px; grid-template-columns: minmax(150px, 23vw) minmax(0, 1fr) minmax(190px, 29vw); }
  #top { gap: 6px; }
  #top > .pl { min-height: 36px; padding: 3px 10px; }
  #nameplate b { font-size: 14px; }
  #nameplate span { font-size: 10px; }
  .link b { font-size: 14px; }
  .odo b { font-size: 16px; }
  .wx-temp { font-size: 20px; }
  .wx-sky { max-width: 14vw; }
  .sq { width: 38px; }
  #drive { padding: 8px 10px 8px 12px; gap: 6px; --ch: 10px; }
  .spd { grid-template-columns: 22px minmax(0, 1fr); gap: 6px; }
  .ladder { min-height: 64px; }
  .spd-read b { font-size: 48px; }
  .rpm-head b { font-size: 17px; }
  .segs { height: 11px; gap: 1px; }
  .vsegs { height: 8px; }
  .vbar b { font-size: 12px; }
  #mods { gap: 4px; }
  .mod { padding: 3px 7px 2px 9px; --ch: 6px; }
  .mod em { font-size: 7.5px; letter-spacing: .08em; }
  .mod b { font-size: 17px; }
  .mod small { font-size: 7px; }
  .mod canvas { height: 9px; }
  .mod.wide b { font-size: 13px; }
  #tape { min-height: 24px; }
  #tape > i { width: 30px; }
  #tape > span { font-size: 13px; }
  #cmd > button { min-height: 34px; padding: 0 6px; }
  #cmd > button span { font-size: 8px; letter-spacing: .1em; }
  .minisheet { display: none; }
  /* the card sits exactly in the centre column, between the drive cluster and the modules */
  #card { top: 46px; width: auto; left: calc(max(10px, env(safe-area-inset-left)) + max(150px, 23vw) + 6px) !important;
    right: calc(max(10px, env(safe-area-inset-right)) + max(190px, 29vw) + 6px) !important; max-height: calc(100vh - 104px); max-height: calc(100dvh - 104px); }
  #bay { padding: 8px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  body.boot #hud > * { opacity: 1; }
}
