/* 023 Rush Hour — opaque, high-contrast HUD: ink on paper, hard borders, solid offset shadows. No gradients, no blur.
   v0.6 layout: one 8px grid (--u), one edge margin (--m) on top of the safe-area insets, four zones:
   top-left status (+ fines under it) · top-right group #tr (bill, car, mute, author mark) · bottom-left stick · bottom-right thumb cluster
   with the instrument strip (speed + propellant) sitting on the jet buttons. Floating things: 3px ink border + 4px hard shadow;
   inner gauges 2px. Purple only for the throttle, gauge fills, the stick knob and airborne jets. */
@font-face { font-family: "JetBrains Mono"; src: url("fonts/JetBrainsMonoNL-Bold.ttf") format("truetype"); font-weight: 400 700; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("fonts/JetBrainsMonoNL-ExtraBold.ttf") format("truetype"); font-weight: 800 900; font-display: swap; }
:root {
  --ink: #17130f; --paper: #ffffff; --mustard: #e9b13a; --red: #d93a25; --green: #23864a; --amber: #f0b429; --accent: #6b3cf0; --accent-lt: #b9a2ff; --mute: #786f6c;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --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: 8px; --m: 16px; --g: 8px; --gp: 16px; --sh: 4px;
  --top: 80px; --stw: 280px; --bw: 240px;                 /* top-row box height, status width, bill width */
  --kT: 96px; --kB: 72px; --kJ: 64px; --cw: calc(var(--kB) + var(--gp) + var(--kT));   /* thumb cluster: 184 wide */
  --capT: calc(var(--top) + 2 * var(--u));                /* caption / fines offset under the top row */
}
@media (max-width: 600px), (max-height: 500px) { :root { --m: 8px; --top: 64px; --capT: calc(var(--top) + var(--u)); } }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #eceae6; color: var(--ink); font-family: -apple-system, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif; -webkit-user-select: none; user-select: none; touch-action: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
#view { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; image-rendering: pixelated; }

.panel { position: fixed; background: var(--paper); border: 3px solid var(--ink); box-shadow: var(--sh) var(--sh) 0 var(--ink); pointer-events: none; }
.tag { display: inline-block; background: var(--ink); color: var(--paper); font-size: 11px; font-weight: 800; line-height: 15px; padding: 1px 6px; letter-spacing: 1px; white-space: nowrap; }
.tag.red { background: var(--red); color: #fff; }

/* top-left: status */
#clockbox { top: calc(var(--sat) + var(--m)); left: calc(var(--sal) + var(--m)); width: var(--stw); height: var(--top); padding: 6px 10px; display: flex; flex-direction: column; justify-content: space-between; }
#clockbox .row1, #billbox .row1 { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
#clock { font: 700 12px/1.4 var(--mono); }
#left { display: inline-flex; align-items: baseline; gap: 3px; padding: 0 4px; white-space: nowrap; }
#left-label { font-size: 11px; font-weight: 800; }
#left-number { font: 800 38px/1 var(--mono); }
#left small { font: 700 12px/1 var(--mono); }
#left.urgent { color: var(--red); }
#clockbox .row2, #billbox .row2 { display: flex; justify-content: space-between; gap: 8px; font: 700 12px/1.4 var(--mono); }
#left.warn, #left.late { color: #fff; background: var(--red); }
.route { position: relative; height: 10px; background: #e4e4e2; border: 2px solid var(--ink); margin-right: 36px; }
.route i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--accent); }
.route b { position: absolute; top: -5px; width: 8px; height: 16px; margin-left: -4px; background: var(--ink); left: 0; }
.route em { position: absolute; right: -38px; top: -5px; font: normal 800 11px/16px -apple-system, "PingFang SC", sans-serif; background: var(--ink); color: var(--paper); padding: 0 4px; }

/* top-right group: one grid, so bill / car / mute / author mark share the same edge and gaps in every layout */
#tr { position: fixed; z-index: 1; top: calc(var(--sat) + var(--m)); right: calc(var(--sar) + var(--m)); display: grid; gap: var(--g);
  grid-template-areas: "bill bill" "mute car" "wm wm"; grid-template-columns: 1fr auto; justify-items: end; align-items: start; pointer-events: none; }
#tr .panel { position: static; }
#billbox { grid-area: bill; width: var(--bw); height: var(--top); padding: 6px 10px; display: flex; flex-direction: column; justify-content: space-between; }
#bill { font: 800 26px/1 var(--mono); color: var(--red); }
#bal { font-family: var(--mono); }
#bal.neg { color: #fff; background: var(--red); padding: 0 4px; }
#carbox { grid-area: car; padding: 5px 6px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.diagram { position: relative; width: 62px; height: 104px; }
.diagram i { position: absolute; display: block; }
.diagram .shell { left: 9px; right: 9px; top: 4px; bottom: 4px; background: var(--mustard); border: 2px solid var(--ink); }
.diagram .glassp { left: 15px; right: 15px; top: 34px; height: 30px; background: #26303f; border: 2px solid var(--ink); }
.diagram .glassp.damaged { background: #8d9bb3; } .diagram .glassp.broken { background: #fff; outline: 2px dashed var(--red); outline-offset: -6px; }
.diagram .p { background: var(--green); border: 2px solid var(--ink); }
.diagram .p.damaged { background: var(--amber); }
.diagram .p.broken { background: var(--red); }
.diagram .p.gone { background: var(--paper); border-style: dashed; border-color: var(--red); }
.diagram .bumpF { left: 7px; right: 7px; top: 0; height: 7px; } .diagram .bumpR { left: 7px; right: 7px; bottom: 0; height: 7px; }
.diagram .w { width: 10px; height: 20px; } .diagram .wFL { left: 0; top: 14px; } .diagram .wFR { right: 0; top: 14px; } .diagram .wRL { left: 0; bottom: 14px; } .diagram .wRR { right: 0; bottom: 14px; }
.diagram .j { width: 8px; height: 8px; }
.diagram .mainL { left: 20px; bottom: 9px; } .diagram .mainR { right: 20px; bottom: 9px; }
.diagram .lift { left: 27px; top: 68px; width: 8px; height: 8px; }
.diagram .sideL { left: 10px; top: 46px; } .diagram .sideR { right: 10px; top: 46px; }
.diagram .attF { left: 27px; top: 10px; } .diagram .attR { left: 27px; bottom: 20px; }
/* sound switch: a quiet paper utility (not the accent); off = dashed + grey */
#audio-toggle { grid-area: mute; pointer-events: auto; min-width: 64px; height: 44px; padding: 0 8px; font-size: 12px; line-height: 1; white-space: nowrap; }
#audio-toggle[aria-pressed="false"] { border-style: dashed; color: var(--mute); }
/* author mark (anti-repost): always on screen, quiet, tucked under the top-right group */
#wm { grid-area: wm; pointer-events: none; font: 900 13px/1 "PingFang SC", -apple-system, sans-serif; color: var(--ink); opacity: .8; letter-spacing: 1px; white-space: nowrap;
  text-shadow: 1px 0 0 #fff, -1px 0 0 #fff, 0 1px 0 #fff, 0 -1px 0 #fff, 1px 1px 0 #fff, -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff; }
#wm b { font-family: var(--mono); font-weight: 900; margin-left: 3px; }

/* instrument strip: speed + propellant. Desktop: bottom-right corner; touch: sits on the jet buttons, same width */
#fuelbox { right: calc(var(--sar) + var(--m)); bottom: calc(var(--sab) + var(--m)); width: var(--bw); padding: 5px 8px; display: flex; flex-direction: column; gap: 4px; }
#fuelbox .row { display: flex; align-items: center; gap: 6px; height: 18px; }
.meter { flex: 1; min-width: 0; height: 12px; background: #e4e4e2; border: 2px solid var(--ink); overflow: hidden; }
.meter i { display: block; height: 100%; width: 100%; background: var(--accent); }
.meter i.low { background: var(--red); }
.meter i.burn { background: var(--accent-lt); }
#fuel-txt { font: 800 12px var(--mono); min-width: 34px; text-align: right; }
#speed { margin-left: auto; font: 800 16px/1 var(--mono); }
#speed small { font-size: 10px; margin-left: 2px; }
body.touch #fuelbox { width: var(--cw); bottom: calc(var(--sab) + var(--m) + var(--kT) + var(--gp) + var(--kJ) + var(--g)); }

#caption { position: fixed; top: calc(var(--sat) + var(--m) + var(--capT)); left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; border: 3px solid var(--ink); box-shadow: var(--sh) var(--sh) 0 var(--accent);
  padding: 8px 16px; text-align: center; display: flex; flex-direction: column; gap: 4px; pointer-events: none; width: max-content;
  max-width: min(640px, calc(100vw - 2 * max(var(--sal), var(--sar)) - 2 * (var(--m) + 216px))); }
#caption.hide { display: none; }
#caption b { font-size: 21px; letter-spacing: 1px; line-height: 1.25; text-wrap: balance; }
#caption span { font-size: 13px; font-weight: 700; color: #ececea; }
#caption span:empty { display: none; }
#caption.big b { font-size: 30px; }
#caption.red { background: var(--red); box-shadow: var(--sh) var(--sh) 0 var(--ink); } #caption.red span { color: #fff; }
#caption.green { background: var(--accent); box-shadow: var(--sh) var(--sh) 0 var(--ink); } #caption.green span { color: #fff; }
#caption.pop { animation: pop .3s steps(4) both; }
@keyframes pop { from { transform: translateX(-50%) scale(1.3); } to { transform: translateX(-50%) scale(1); } }

/* fines: always stacked under the status box */
#fines { position: fixed; top: calc(var(--sat) + var(--m) + var(--capT)); left: calc(var(--sal) + var(--m)); max-width: 200px; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; pointer-events: none; }
#fines div { background: var(--paper); border: 3px solid var(--ink); box-shadow: var(--sh) var(--sh) 0 var(--ink); font: 800 12px/1.3 var(--mono); padding: 2px 6px; color: var(--red); animation: fine 2.4s steps(6) forwards; }
@keyframes fine { 0% { transform: translateX(-12px); } 10%, 85% { transform: none; opacity: 1; } 100% { opacity: 0; } }

/* windscreen cracks */
#cracks { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; display: none; }
#cracks polyline, #cracks circle { fill: none; stroke-linejoin: miter; vector-effect: non-scaling-stroke; }
#cracks.lv1, #cracks.lv2 { display: block; }
#cracks .c1 polyline { stroke: #ffffff; stroke-width: 3; filter: drop-shadow(1px 1px 0 #17130f); }
#cracks .c2 { display: none; }
#cracks.lv2 .c2 { display: block; }
#cracks .c2 polyline, #cracks .c2 circle { stroke: #ffffff; stroke-width: 3; filter: drop-shadow(1px 1px 0 #17130f); }

/* receipt */
#result { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; padding: calc(var(--sat) + 10px) calc(var(--sar) + 10px) calc(var(--sab) + 10px) calc(var(--sal) + 10px); background: rgba(23, 19, 15, 0.55); }
#result.show { display: flex; }
#result .card { position: relative; background: var(--paper); border: 3px solid var(--ink); box-shadow: 8px 8px 0 var(--ink); width: min(600px, 100%); max-height: 100%; overflow: auto; padding: 14px 18px 16px; animation: slip .35s steps(5) both; }
@keyframes slip { from { transform: translateY(30px); } to { transform: none; } }
.head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 3px solid var(--ink); padding-bottom: 6px; gap: 10px; }
.head b { font-size: 19px; letter-spacing: 1px; } .head span { font: 700 12px var(--mono); }
.cols { display: grid; grid-template-columns: 1fr 1.25fr; gap: 16px; margin-top: 10px; }
.lines { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 0; font-size: 14px; }
.lines dt { font-weight: 700; } .lines dd { margin: 0; text-align: right; font: 800 14px var(--mono); }
.items-h { font-size: 12px; font-weight: 800; background: var(--ink); color: var(--paper); padding: 2px 6px; }
#r-items { list-style: none; margin: 4px 0; padding: 0; font: 700 12.5px/1.65 var(--mono); max-height: 170px; overflow: auto; }
#r-items li { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px dashed #b9ad92; }
#r-items li b { color: var(--red); white-space: nowrap; }
#r-items li.none { color: var(--green); }
.sum { display: flex; justify-content: space-between; font-weight: 800; padding-top: 4px; }
.sum b { font-family: var(--mono); color: var(--red); }
.final { margin-top: 10px; border-top: 3px double var(--ink); padding-top: 8px; display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.final span { font-weight: 800; font-size: 14px; }
.final b { font: 900 36px/1 var(--mono); }
.final b.neg { color: var(--red); }
.stamp { display: inline-block; margin: 14px 0 0 18px; transform: rotate(-8deg); border: 4px solid var(--red); color: var(--red); background: var(--paper); font-size: 24px; font-weight: 900; padding: 4px 12px; letter-spacing: 3px; pointer-events: none; }
.stamp.good { border-color: var(--green); color: var(--green); }
.rating { margin-top: 8px; background: var(--ink); color: #fff; padding: 7px 10px; font-weight: 800; font-size: 15px; text-align: center; }
.rating small { display: block; font-size: 12px; color: #ececea; font-weight: 700; margin-top: 2px; }
.btns { display: flex; gap: 8px; margin-top: 12px; }
button { appearance: none; border: 3px solid var(--ink); background: var(--paper); color: var(--ink); padding: 10px 14px; font: 800 16px -apple-system, "PingFang SC", sans-serif; cursor: pointer; border-radius: 0; touch-action: none; box-shadow: var(--sh) var(--sh) 0 var(--ink); }
button.primary { background: var(--accent); color: #fff; flex: 1; }
button small { font: 700 11px var(--mono); margin-left: 6px; opacity: .8; }

/* Touch: bottom-left floating stick only; bottom-right thumb cluster (jets row on top of brake + throttle, one 184px column). */
#pad { display: none; position: fixed; inset: 0; pointer-events: none; }
body.touch #pad { display: block; }
#stick-zone { position: absolute; left: var(--sal); bottom: var(--sab); width: calc(45% - var(--sal)); height: 60%; pointer-events: auto; touch-action: none; }
#stick { position: fixed; left: calc(var(--sal) + var(--m) + 60px); bottom: calc(var(--sab) + var(--m)); width: 120px; height: 120px; margin-left: -60px; border: 3px solid var(--ink); border-radius: 50%; background: var(--paper); box-shadow: var(--sh) var(--sh) 0 var(--ink); opacity: .45; pointer-events: none; }
#stick.active { margin-top: -60px; opacity: .9; }
#stick-knob { position: absolute; width: 48px; height: 48px; left: 33px; top: 33px; border: 3px solid var(--ink); border-radius: 50%; background: var(--accent-lt); box-shadow: 3px 3px 0 var(--ink); }
#stick small { position: absolute; top: 85px; width: 100%; text-align: center; font-size: 11px; font-weight: 800; }
#cluster { position: absolute; right: calc(var(--sar) + var(--m)); bottom: calc(var(--sab) + var(--m)); width: var(--cw); display: flex; flex-wrap: wrap; gap: var(--gp); }
.k { pointer-events: auto; padding: 0; font-size: 18px; line-height: 1; letter-spacing: 1px; background: var(--paper); display: flex; align-items: center; justify-content: center; flex-direction: column; touch-action: none; }
.k small { margin: 4px 0 0; font-size: 11px; letter-spacing: 0; }
.k.jet { width: calc((var(--cw) - var(--gp)) / 2); height: var(--kJ); }
.k.brake { width: var(--kB); height: var(--kT); color: var(--red); }
.k.throttle { width: var(--kT); height: var(--kT); background: var(--accent); color: #fff; font-size: 20px; }
body.air .k.jet { background: var(--accent-lt); border-width: 4px; }
body.air .k.throttle, body.air .k.brake { background: var(--paper); color: var(--mute); }
.k.on { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); background: var(--accent-lt); }
#keys { position: fixed; left: calc(var(--sal) + var(--m)); bottom: calc(var(--sab) + var(--m)); max-width: calc(100vw - var(--sal) - var(--sar) - 3 * var(--m) - var(--bw) - var(--sh)); background: var(--ink); color: var(--paper); font-size: 12px; font-weight: 600; line-height: 1.5; padding: 4px 10px; pointer-events: none; }
#keys b { color: var(--accent-lt); }
body.touch #keys { display: none; }

body.touch .panel, body.touch #caption, body.touch #fines { z-index: 1; }
#result { z-index: 2; }
/* receipt up: the HUD steps back; mute (bottom-left) and the author mark (bottom-right) sit in the strip the card leaves free */
body.done #pad, body.done #caption, body.done #fines, body.done #keys { display: none !important; }
body.done .panel { visibility: hidden; }
body.done #tr { z-index: 3; }
body.done #audio-toggle { position: fixed; left: calc(var(--sal) + var(--m)); bottom: calc(var(--sab) + var(--u)); }
body.done #wm { position: fixed; right: calc(var(--sar) + var(--m)); bottom: calc(var(--sab) + var(--u) + 16px); }
body.done #result { padding-bottom: calc(var(--sab) + 2 * var(--u) + 44px + var(--sh)); }

/* phones portrait: status and bill split the top row */
@media (max-width: 600px) {
  :root { --stw: calc((100vw - var(--sal) - var(--sar) - 2 * var(--m) - 2 * var(--u)) / 2); --bw: var(--stw); }
  #clockbox, #billbox { padding: 4px 8px; }
  #clock { font-size: 10.5px; }
  #left-number { font-size: 28px; }
  #clockbox .route { height: 8px; flex-shrink: 0; }
  #bill { font-size: 19px; }
  #clockbox .row2, #billbox .row2 { font-size: 10.5px; }
  .tag { font-size: 10px; padding: 0 4px; }
  .diagram { zoom: .62; }
  /* caption below the whole top-right group (bill 64 + car ~96 + mark), full width */
  #caption { top: calc(var(--sat) + var(--m) + var(--top) + 26 * var(--u)); max-width: calc(100vw - var(--sal) - var(--sar) - 2 * var(--m) - var(--sh)); padding: 6px 10px; }
  #caption b { font-size: 16px; } #caption.big b { font-size: 21px; } #caption span { font-size: 11.5px; }
  .cols { grid-template-columns: 1fr; gap: 8px; }
  .final b { font-size: 28px; }
  .stamp { font-size: 18px; display: block; width: max-content; margin: 8px 6px 2px auto; }
  #r-items { max-height: min(30vh, 250px); }
  #keys { display: none; }
}
/* short portrait phones (375x667): the camera puts the car ~60% down, so the cluster gets one notch shorter to stay below it */
@media (max-aspect-ratio: 1/1) and (max-height: 720px) { :root { --kT: 88px; --kJ: 56px; } }
/* phones landscape: everything in the top-right group goes into one row of equal height: mute · car · bill (bill = cluster width) */
@media (max-height: 500px) {
  :root { --stw: 216px; --bw: var(--cw); }
  #clockbox, #billbox { padding: 4px 8px; }
  #clock { font-size: 10.5px; }
  #left-number { font-size: 28px; }
  #clockbox .route { height: 8px; flex-shrink: 0; }
  #bill { font-size: 19px; }
  #clockbox .row2, #billbox .row2 { font-size: 11px; }
  #caption { padding: 6px 12px; }
  #caption b { font-size: 16px; } #caption.big b { font-size: 20px; } #caption span { font-size: 11px; }
  #result .card { padding: 10px 14px 12px; }
  .lines { font-size: 12.5px; gap: 2px 8px; } .lines dd { font-size: 12.5px; }
  #r-items { max-height: 96px; font-size: 11.5px; }
  .final { margin-top: 6px; padding-top: 4px; } .final b { font-size: 26px; }
  .rating { margin-top: 6px; padding: 4px 8px; font-size: 13px; }
  .btns { margin-top: 8px; } button { padding: 6px 12px; }
  .stamp { font-size: 17px; margin-top: 6px; }
  #keys { display: none; }
}
@media (max-height: 500px) and (min-aspect-ratio: 1/1) {
  #tr { grid-template-areas: "mute car bill" "wm wm wm"; grid-template-columns: auto auto auto; }
  #carbox { height: var(--top); padding: 3px 6px; gap: 2px; }
  #carbox .tag { font-size: 10px; line-height: 13px; padding: 0 4px; }
  .diagram { zoom: .38; }
  #wm { font-size: 12px; }
  /* receipt: height is the scarce axis, so mute + author mark move into side gutters and the card gets the full height */
  body.done #result { padding: calc(var(--sat) + var(--u)) calc(var(--sar) + 2 * var(--m) + 72px + var(--sh)) calc(var(--sab) + var(--u)) calc(var(--sal) + 2 * var(--m) + 72px + var(--sh)); }
  body.done #wm { bottom: calc(var(--sab) + var(--m)); }
}
