:root {
  --ink: #16161b;
  --mute: #8a8378;
  --line: rgba(22, 22, 27, .14);
  --paper: rgba(250, 247, 241, .82);
  --orange: #ff5a1f;
  --ok: #2f9e6e;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Helvetica Neue", Helvetica, Inter, Arial, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: #efe8dc; color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased; touch-action: none; overscroll-behavior: none; user-select: none; -webkit-user-select: none; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
#scene:active { cursor: grabbing; }
#hud { position: fixed; inset: 0; pointer-events: none; display: grid; grid-template-columns: 228px 1fr 228px; grid-template-rows: auto 1fr auto; gap: 12px; padding: 0 12px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: none; }
kbd { font-family: var(--mono); }

.top { padding-top: env(safe-area-inset-top); grid-column: 1 / -1; display: flex; align-items: stretch; margin: 0 -12px; background: var(--paper); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); pointer-events: auto; }
.logo { background: var(--orange); color: #fff; display: flex; align-items: center; gap: 10px; padding: 0 22px; font: 700 12px var(--mono); letter-spacing: .08em; }
.title { padding: 9px 20px; display: flex; flex-direction: column; gap: 2px; }
.title small { font: 500 8.5px var(--mono); letter-spacing: .14em; color: var(--mute); }
.title h1 { font-size: 22px; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; }
.title h1 i { color: var(--orange); font-style: normal; font-weight: 400; }
.tele { display: flex; gap: 34px; margin-left: auto; padding: 0 22px; align-items: center; }
.tele dt { font: 500 8.5px var(--mono); letter-spacing: .12em; color: var(--mute); margin-bottom: 4px; white-space: nowrap; }
.tele dd { font: 600 12px var(--mono); white-space: nowrap; font-variant-numeric: tabular-nums; min-width: 66px; }
.tele .hot { color: var(--orange); }
#btn-fs { display: flex; align-items: center; justify-content: center; width: 58px; flex: none; border-left: 1px solid var(--line); pointer-events: auto; transition: background .12s, color .12s; }
#btn-fs[hidden] { display: none; }
#btn-fs:hover { background: rgba(22, 22, 27, .06); }
#btn-fs svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: square; }
#btn-fs .leave, #btn-fs.on .enter { display: none; }
#btn-fs.on .leave { display: block; }
#toast { position: fixed; top: 84px; left: 50%; transform: translate(-50%, -8px); width: max-content; max-width: min(420px, calc(100vw - 32px)); padding: 10px 14px; background: var(--ink); color: #fff; font: 500 12px/1.45 var(--sans); opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.col { display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow: hidden; }
.left { grid-column: 1; grid-row: 2; }
.right { grid-column: 3; grid-row: 2; }
.panel { background: var(--paper); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid var(--line); padding: 10px 12px; pointer-events: auto; }
.panel h3 { font: 600 9px var(--mono); letter-spacing: .14em; display: flex; justify-content: space-between; margin-bottom: 8px; }
.panel h3::before { content: ""; width: 6px; height: 6px; background: var(--orange); margin: 2px 6px 0 0; }
.panel h3 span { margin-left: auto; color: var(--mute); font-weight: 400; }
.metrics { display: flex; justify-content: space-between; align-items: flex-end; }
.metrics b { font-size: 26px; font-weight: 600; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.metrics small { font: 500 8px var(--mono); letter-spacing: .1em; color: var(--mute); margin-left: 4px; }
.metrics .r { text-align: right; }
#graph { width: 100%; height: 40px; display: block; margin: 6px 0; }
.mini { display: flex; justify-content: space-between; font: 500 8.5px var(--mono); letter-spacing: .08em; color: var(--mute); margin-top: 6px; }
.mini b { color: var(--ink); }
.cells { display: flex; gap: 2px; padding-bottom: 6px; }
.cells i { width: 8px; height: 14px; background: rgba(22, 22, 27, .1); }
.cells i.ok { background: var(--ok); }
.cells i.warn { background: var(--orange); }
.bar-row { display: grid; grid-template-columns: 18px 1fr 30px; align-items: center; gap: 6px; font: 500 8.5px var(--mono); height: 14px; }
.bar-row em { font-style: normal; text-align: right; color: var(--mute); }
.bar { height: 4px; background: rgba(22, 22, 27, .09); }
.bar i { display: block; height: 100%; background: var(--ink); transition: width .12s linear; }
.bar i.lift { background: var(--orange); }

.radar-wrap { display: grid; grid-template-columns: 88px 1fr; gap: 10px; align-items: center; }
#radar { width: 88px; height: 88px; display: block; }
.kv { list-style: none; font: 500 8px var(--mono); letter-spacing: .06em; color: var(--mute); display: grid; gap: 7px; }
.kv li { display: flex; justify-content: space-between; }
.kv b { color: var(--ink); font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chips button { font: 600 8.5px var(--mono); letter-spacing: .08em; border: 1px solid var(--line); padding: 6px 8px; background: rgba(255, 255, 255, .5); transition: background .12s, color .12s; }
.chips button:hover { border-color: var(--ink); }
.chips button.on { background: var(--orange); color: #fff; border-color: var(--orange); }
.subs { list-style: none; display: grid; gap: 7px; }
.subs li { display: flex; justify-content: space-between; align-items: center; font: 600 8.5px var(--mono); letter-spacing: .04em; }
.subs small { display: block; font-weight: 400; font-size: 7.5px; color: var(--mute); margin-top: 1px; }
.subs em { font-style: normal; color: #fff; background: var(--ok); padding: 2px 5px; font-size: 7.5px; white-space: nowrap; }
.subs em.alert { background: var(--orange); }

.state { grid-column: 2; grid-row: 2; align-self: end; padding: 0 0 2px 8px; pointer-events: none; }
.state small { font: 500 8.5px var(--mono); letter-spacing: .14em; color: var(--mute); }
#state-big { font-size: 44px; font-weight: 600; letter-spacing: -.03em; color: var(--orange); line-height: 1.05; }
#state-big.rev { color: var(--ink); }

.drive { grid-column: 1 / -1; grid-row: 3; justify-self: center; display: grid; grid-template-columns: auto minmax(220px, 400px) auto; gap: 18px; align-items: stretch; background: var(--paper); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border: 1px solid var(--line); padding: 10px; pointer-events: auto; }
.dpad { display: grid; grid-template-columns: repeat(3, 62px); grid-template-rows: 54px 54px; gap: 4px; }
.dpad button, .side-btns button { position: relative; background: #fff; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; gap: 5px; font: 700 9px var(--mono); letter-spacing: .08em; transition: background .08s, color .08s, transform .08s; }
.dpad svg { width: 15px; height: 15px; fill: currentColor; flex: none; }
.dpad .up { grid-column: 2; grid-row: 1; flex-direction: column; gap: 1px; }
.dpad .lf { grid-column: 1; grid-row: 2; }
.dpad .dn { grid-column: 2; grid-row: 2; flex-direction: column; gap: 1px; }
.dpad .rt { grid-column: 3; grid-row: 2; }
.dpad kbd, .side-btns kbd { position: absolute; top: 3px; right: 4px; font-size: 7.5px; font-weight: 500; color: var(--mute); }
.dpad button:hover, .side-btns button:hover { border-color: var(--ink); }
button.on[data-drive], .side-btns button.on { background: var(--orange); color: #fff; border-color: var(--orange); transform: translateY(1px); }
button.on[data-drive] kbd, .side-btns button.on kbd { color: #ffe1d4; }
.dpad .dn.on { background: var(--ink); border-color: var(--ink); }
.gear { display: flex; flex-direction: column; justify-content: space-between; min-width: 0; }
.gear-head { display: flex; justify-content: space-between; align-items: baseline; }
.gear-head small { font: 500 8.5px var(--mono); letter-spacing: .14em; color: var(--mute); }
.gear-head span { font: 500 9px var(--mono); color: var(--mute); }
.gear-head b { font-family: var(--sans); font-size: 24px; font-weight: 600; color: var(--ink); letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.gear-bar { position: relative; height: 8px; background: rgba(22, 22, 27, .09); margin-top: 2px; }
.gear-bar i { position: absolute; top: 0; bottom: 0; left: 50%; width: 0; background: var(--orange); }
.gear-bar i.rev { background: var(--ink); }
.gear-bar u { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--ink); }
.gear-scale { display: flex; justify-content: space-between; font: 500 7.5px var(--mono); letter-spacing: .1em; color: var(--mute); margin-top: 3px; }
.log { font: 500 8.5px var(--mono); letter-spacing: .06em; margin-top: 8px; border-top: 1px solid var(--line); padding-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { height: 2px; margin-top: 5px; background: rgba(22, 22, 27, .07); }
.progress i { display: block; height: 100%; width: 0; background: var(--orange); }
.side-btns { display: grid; grid-template-rows: repeat(3, 1fr); gap: 4px; width: 78px; }
.ai-chip kbd { opacity: .6; margin-left: 4px; }
.ai-on #state-hint { color: var(--orange); }

#labels { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity .25s; }
#labels.show { opacity: 1; }
.callout { position: absolute; left: 0; top: 0; width: 0; height: 0; transition: opacity .2s; will-change: transform; }
.callout .dot { position: absolute; width: 7px; height: 7px; margin: -3.5px; border-radius: 50%; border: 1.5px solid var(--orange); background: #fff; }
.callout svg { position: absolute; overflow: visible; width: 1px; height: 1px; }
.callout line { stroke: var(--orange); stroke-width: 1; }
.callout .txt { position: absolute; transform: translateY(-50%); padding-left: 5px; white-space: nowrap; font-family: var(--mono); }
.callout .txt.rev { transform: translate(-100%, -50%); padding: 0 5px 0 0; text-align: right; }
.callout .txt { background: rgba(250,247,241,.78); padding: 3px 6px !important; }
.callout b { display: block; font-size: 8.5px; letter-spacing: .08em; }
.callout span { font-size: 7.5px; color: #5f594f; }

@media (max-height: 800px) {
  .left .panel:nth-child(2) { display: none; }
  .right .panel:nth-child(3) { display: none; }
}
@media (max-height: 640px) {
  .left .panel:nth-child(3), .right .panel:nth-child(4) { display: none; }
}
@media (max-width: 1040px) {
  #hud { grid-template-columns: 1fr; }
  .col, .tele { display: none; }
  .state { grid-column: 1; }
  #state-big { font-size: 32px; }
  #labels { display: none; }
  .drive { width: 100%; grid-template-columns: auto 1fr auto; gap: 8px; padding: 8px; }
  .dpad { grid-template-columns: repeat(3, 52px); grid-template-rows: 52px 52px; }
  .side-btns { width: 58px; }
  .title { padding: 7px 12px; }
  .title small:last-child { display: none; }
  .logo { padding: 0 12px; }
}
@media (max-width: 480px) {
  .gear-scale, .log { display: none; }
  .gear { justify-content: center; gap: 6px; }
  .dpad { grid-template-columns: repeat(3, 44px); grid-template-rows: 46px 46px; gap: 3px; }
  .dpad span { display: none; }
  .logo b { display: none; }
  .title h1 { font-size: 19px; }
  .title small { display: none; }
}

/* Virtual gamepad: phones, tablets and narrow windows */
#gamepad, #pad-ai { display: none; }
@media (max-width: 1040px), (pointer: coarse) {
  #hud { grid-template-columns: 1fr; }
  .col, .tele, #labels { display: none; }
  .state { grid-column: 1; }
  #state-big { font-size: 30px; }
  .dpad, .side-btns { display: none; }
  .drive { grid-template-columns: 1fr; width: min(340px, 100%); padding: 8px 12px; justify-self: center; }
  .log { margin-top: 5px; padding-top: 4px; }
  #btn-fs { margin-left: auto; width: 52px; }
  #pad-ai { display: flex; align-items: center; gap: 7px; padding: 0 18px; min-width: 76px; justify-content: center; font: 700 13px var(--mono); letter-spacing: .08em; border-left: 1px solid var(--line); pointer-events: auto; }
  #pad-ai i { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid currentColor; }
  #pad-ai.on { background: var(--ink); color: #fff; }
  #pad-ai.on i { background: var(--orange); border-color: var(--orange); }

  #gamepad { display: flex; position: fixed; left: 0; right: 0; bottom: 0; justify-content: space-between; align-items: flex-end; pointer-events: none; padding: 0 max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  #stick { position: relative; width: 138px; height: 138px; flex: none; border-radius: 50%; background: var(--paper); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); pointer-events: auto; touch-action: none; }
  #stick .ring { position: absolute; inset: 24px; border-radius: 50%; border: 1px dashed rgba(22, 22, 27, .22); }
  #stick .tick { position: absolute; left: 0; right: 0; text-align: center; font: 600 7.5px var(--mono); letter-spacing: .1em; color: var(--mute); }
  #stick .tick.n { top: 7px; }
  #stick .tick.s { bottom: 7px; }
  #stick-knob { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px; border-radius: 50%; background: #fff; border: 1px solid rgba(22, 22, 27, .25); box-shadow: 0 3px 10px rgba(22, 22, 27, .22); transition: transform .14s ease-out, background .1s; }
  #stick-knob::after { content: ""; position: absolute; inset: 20px; border-radius: 50%; background: var(--ink); }
  #stick-knob.held { background: var(--orange); border-color: var(--orange); transition: background .1s; }
  #stick-knob.held::after { background: #fff; }

  .abxy { display: grid; grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(3, 56px); flex: none; margin: -2px; }
  .pad { position: relative; width: 62px; height: 62px; margin: -3px; border-radius: 50%; background: var(--paper); border: 1px solid rgba(22, 22, 27, .22); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; pointer-events: auto; transition: transform .06s, background .08s, color .08s; }
  .pad b { font: 700 20px var(--sans); }
  .pad small { font: 600 7px var(--mono); letter-spacing: .04em; margin-top: 2px; }
  .pad.y { grid-column: 2; grid-row: 1; }
  .pad.x { grid-column: 1; grid-row: 2; }
  .pad.b { grid-column: 3; grid-row: 2; }
  .pad.a { grid-column: 2; grid-row: 3; background: var(--orange); color: #fff; border-color: var(--orange); }
  .pad:active, .pad.on { background: var(--ink); color: #fff; border-color: var(--ink); transform: scale(.94); }
  .pad.a.on { background: #c8400f; border-color: #c8400f; }
}
@media (max-width: 1040px) and (orientation: portrait), (pointer: coarse) and (orientation: portrait) {
  #hud { padding-bottom: 196px; }
}
/* Phone held sideways: controls take the corners, the readout sits between them */
@media (orientation: landscape) and (max-height: 520px) {
  #hud { gap: 6px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .title { padding: 4px 12px; }
  .title small { display: none; }
  .title h1 { font-size: 16px; }
  .logo { padding: 0 12px; }
  .logo svg { width: 18px; height: 18px; }
  .state { align-self: start; padding: 2px 0 0 max(4px, env(safe-area-inset-left)); }
  #state-big { font-size: 22px; }
  .drive { width: min(280px, calc(100vw - 370px)); padding: 6px 10px; }
  .gear-scale, .log { display: none; }
  .gear-head b { font-size: 18px; }
  #stick { width: 124px; height: 124px; }
  #stick-knob { width: 52px; height: 52px; margin: -26px; }
  .abxy { grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(3, 50px); }
  .pad { width: 56px; height: 56px; }
  .pad b { font-size: 17px; }
}
