/* Pit page. Colours are the dash's (DT-1 rev AO §5.1.2); tile states as
   §5.1.3: COLD cyan number and bar; OK white number, green bar; WARNING
   whole tile amber, black text; CRITICAL whole tile red, white text,
   flashing 2 Hz; NO DATA grey "--", bar empty. Black background for
   sunlight, like the dash. */
:root {
  --black: #000000;
  --outline: #444444;
  --label: #9A9A9A;
  --scale: #8A8A8A;
  --green: #2EE05A;
  --amber: #FFB000;
  --red: #FF2A2A;
  --cyan: #3CC8FF;
  --nodata: #5A5A5A;
  --unlit: #262626;
  --white: #FFFFFF;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--black); color: var(--white); }
body {
  font-family: "Liberation Sans", Arial, Helvetica, sans-serif;
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right))
           env(safe-area-inset-bottom) max(8px, env(safe-area-inset-left));
  -webkit-text-size-adjust: 100%;
}

/* ---- status strip ---- */
.strip {
  display: grid; gap: 6px 10px; padding: 8px 0; border-bottom: 2px solid var(--outline);
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-areas: "d s a" "f g g";        /* phone: two rows */
}
.strip .driver { grid-area: d; } .strip .stint { grid-area: s; } .strip .age { grid-area: a; }
.strip .fuel { grid-area: f; } .strip .gps { grid-area: g; }
@media (min-width: 640px) {
  .strip { grid-template-columns: repeat(5, minmax(0, 1fr)); grid-template-areas: "d s f g a"; }
}
.cell { display: flex; flex-direction: column; min-width: 0; }
.cell .k { color: var(--scale); font-size: 11px; font-weight: bold; letter-spacing: .05em; }
.cell .v { font-size: clamp(18px, 5vw, 30px); font-weight: bold; white-space: nowrap;
           overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.v.amber { color: var(--amber); }
.v.red { color: var(--red); }
.v.green { color: var(--green); }
.v.cyan { color: var(--cyan); }
.v.grey { color: var(--nodata); }

.banner { margin: 8px 0 0; padding: 10px; border-radius: 6px; font-weight: bold;
          font-size: clamp(16px, 4.5vw, 28px); text-align: center; }
.banner.amber { background: var(--amber); color: var(--black); }
.banner.red { background: var(--red); color: var(--white); }

/* ---- race layout: phone = speed on top, two tile columns below ---- */
.race {
  display: grid; gap: 8px; margin-top: 8px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas: "c c" "l r";
}
.left { grid-area: l; } .right { grid-area: r; } .center { grid-area: c; }
.col { display: grid; gap: 8px; grid-auto-rows: 1fr; }

.center { display: grid; grid-template-columns: 1fr 1fr; align-items: end; gap: 0 12px;
          padding: 4px 4px 8px; border: 2px solid var(--outline); border-radius: 6px; }
.speed { grid-column: 1; display: flex; align-items: baseline; gap: 6px; }
.speed-ecu { grid-column: 1; color: var(--label); font-size: 14px; font-weight: bold; }
.rpm { grid-column: 2; grid-row: 1; display: flex; align-items: baseline; gap: 6px; justify-content: flex-end; }
.rpmbar { grid-column: 2; grid-row: 2; height: 10px; background: var(--unlit); border-radius: 3px; overflow: hidden; }
.rpmbar i { display: block; height: 100%; width: 0; background: var(--green); }
.big { font-size: clamp(56px, 18vw, 150px); font-weight: bold; line-height: .95; font-variant-numeric: tabular-nums; }
.mid { font-size: clamp(30px, 9vw, 64px); font-weight: bold; font-variant-numeric: tabular-nums; }
.unit { color: var(--label); font-size: 14px; font-weight: bold; }

/* ---- tiles ---- */
.tile {
  position: relative; border: 2px solid var(--outline); border-radius: 6px;
  background: var(--black); min-height: 92px; padding: 6px 8px 6px 30px;
  display: flex; flex-direction: column; justify-content: space-between;
}
.right .tile { padding: 6px 30px 6px 8px; }
.tile .val { font-size: clamp(34px, 11vw, 64px); font-weight: bold; text-align: right;
             line-height: 1; font-variant-numeric: tabular-nums; }
.tile .lbl { font-size: clamp(13px, 3.6vw, 20px); font-weight: bold; }
.tile .lbl .unit { font-size: .8em; margin-left: 4px; }
.tile .ack { position: absolute; top: 6px; font-size: 11px; font-weight: bold; padding: 1px 4px;
             border: 1px solid currentColor; border-radius: 3px; }
.left .tile .ack { right: 8px; } .right .tile .ack { left: 8px; }
.bar { position: absolute; top: 8px; bottom: 8px; width: 14px;
       display: flex; flex-direction: column-reverse; gap: 3px; }
.left .bar { left: 8px; } .right .bar { right: 8px; }
.bar i { flex: 1; background: var(--unlit); border-radius: 1px; }
.bar i.on { background: var(--green); }

.tile[data-state="OK"] .val { color: var(--white); }
.tile[data-state="COLD"] .val { color: var(--cyan); }
.tile[data-state="COLD"] .bar i.on { background: var(--cyan); }
.tile[data-state="WARNING"] { background: var(--amber); border-color: var(--amber); color: var(--black); }
.tile[data-state="WARNING"] .unit { color: var(--black); }
.tile[data-state="WARNING"] .bar i { background: rgba(0, 0, 0, .18); }
.tile[data-state="WARNING"] .bar i.on { background: var(--black); }
.tile[data-state="CRITICAL"] { background: var(--red); border-color: var(--red); color: var(--white);
                               animation: flash 0.5s steps(1) infinite; }
.tile[data-state="CRITICAL"] .unit { color: var(--white); }
.tile[data-state="CRITICAL"] .bar i { background: rgba(255, 255, 255, .22); }
.tile[data-state="CRITICAL"] .bar i.on { background: var(--white); }
.tile[data-state="NO_DATA"] .val, .tile[data-state="NO_DATA"] .lbl { color: var(--nodata); }
@keyframes flash { 50% { background: var(--black); color: var(--red); } }
@media (prefers-reduced-motion: reduce) { .tile[data-state="CRITICAL"] { animation: none; } }

/* old data: dim everything the car sent */
body.stale .race, body.stale .strip .driver, body.stale .strip .stint,
body.stale .strip .fuel, body.stale .strip .gps { opacity: .4; }

/* ---- alarms ---- */
.alarms h2 { font-size: 13px; color: var(--scale); margin: 14px 0 6px; letter-spacing: .05em; }
.alarms ol { list-style: none; margin: 0; padding: 0; }
.alarms li { display: grid; grid-template-columns: 5.2em 1fr auto; gap: 8px; align-items: baseline;
             padding: 7px 8px; border-left: 6px solid var(--outline); border-bottom: 1px solid #1a1a1a;
             font-size: 16px; }
.alarms li.none { display: block; color: var(--nodata); border-left-color: transparent; }
.alarms li .t { color: var(--label); font-variant-numeric: tabular-nums; font-size: 14px; }
.alarms li .what { font-weight: bold; }
.alarms li .dur { color: var(--label); font-size: 14px; text-align: right; font-variant-numeric: tabular-nums; }
.alarms li.WARNING { border-left-color: var(--amber); }
.alarms li.CRITICAL { border-left-color: var(--red); }
.alarms li.active.WARNING .what { color: var(--amber); }
.alarms li.active.CRITICAL .what { color: var(--red); }
.alarms li:not(.active) { opacity: .65; }
.tag { font-size: 11px; border: 1px solid currentColor; border-radius: 3px; padding: 0 4px; margin-left: 6px; }

/* ---- footer ---- */
.health { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 14px 0 20px;
          font-size: 13px; font-weight: bold; color: var(--label); }
.dot::before { content: "\25CF"; margin-right: 4px; color: var(--nodata); }
.dot.ok::before { color: var(--green); }
.dot.warn::before { color: var(--amber); }
.dot.bad::before { color: var(--red); }
.dim { color: var(--scale); font-weight: normal; }
.health a { color: var(--scale); }

/* ---- tablet / laptop landscape: the dash's own layout ---- */
@media (min-width: 900px) and (min-aspect-ratio: 1/1) {
  .race { grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr) minmax(0, 1fr);
          grid-template-areas: "l c r"; }
  .center { grid-template-columns: 1fr; align-content: center; justify-items: center; gap: 14px; }
  .speed, .speed-ecu, .rpm, .rpmbar { grid-column: 1; grid-row: auto; }
  .rpmbar { width: 80%; height: 14px; }
  .big { font-size: clamp(90px, 11vw, 200px); }
  .tile { min-height: 130px; }
  .tile .val { font-size: clamp(54px, 6vw, 96px); }
  .tile .lbl { font-size: clamp(18px, 1.8vw, 28px); }
  .bar { width: 20px; }
  .left .tile { padding-left: 38px; } .right .tile { padding-right: 38px; }
  .cell .v { font-size: clamp(22px, 2.4vw, 36px); }
  .alarms li { font-size: 18px; }
}

/* ---- login ---- */
/* an overlay on the live page, so the login tap can unlock the alarm sound */
.login { position: fixed; inset: 0; z-index: 30; background: var(--black);
         display: grid; place-items: center; }
.login[hidden] { display: none; }
.login-box { display: grid; gap: 10px; width: min(340px, 90vw); }
.login-box h1 { margin: 0 0 10px; font-size: 34px; letter-spacing: .06em; }
.login-box label { color: var(--label); font-weight: bold; }
.login-box input { font-size: 20px; padding: 12px; background: #111; color: var(--white);
                   border: 2px solid var(--outline); border-radius: 6px; }
.login-box button { font-size: 20px; font-weight: bold; padding: 12px; border: 0; border-radius: 6px;
                    background: var(--green); color: var(--black); }
.login-msg { color: var(--amber); min-height: 1.2em; margin: 0; }

/* ---- critical alarm: 3 s full-screen red flash (iOS has no vibration) ---- */
.alert { position: fixed; inset: 0; z-index: 20; pointer-events: none;
         display: grid; place-items: center; background: var(--red); color: var(--white);
         font-weight: bold; font-size: clamp(36px, 10vw, 120px); text-align: center; padding: 20px;
         animation: alertflash 0.5s steps(1) infinite; }
.alert[hidden] { display: none; }
@keyframes alertflash { 50% { background: var(--black); color: var(--red); } }
@media (prefers-reduced-motion: reduce) { .alert { animation: none; } }

/* sound still locked (page opened with a saved login): one tap unlocks it */
.sound { position: fixed; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 10;
         font: bold 14px "Liberation Sans", Arial, sans-serif; padding: 10px 14px; border-radius: 6px;
         border: 2px solid var(--amber); background: var(--black); color: var(--amber); }
.sound[hidden] { display: none; }
