/* Pneu TPMS – night-garage instrument look.
   Asphalt-blue base, one light action colour, state colours reserved for tyres only. */
:root {
  --bg: #0d1621;
  --bg2: #101c29;
  --panel: #142231;
  --line: #22364a;
  --text: #e8eef4;
  --muted: #8496a8;
  --ok: #5fe0c1;
  --low: #ff5468;
  --crit: #ff2d4b;
  --none: #4b5a6b;
  --num: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif;
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.45 var(--ui);
  color: var(--text);
  background:
    radial-gradient(120% 60% at 50% 38%, #18293a 0%, var(--bg) 62%) fixed,
    var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  overflow-x: hidden;
}
button, input { font: inherit; color: inherit; }
input { font-size: 16px; } /* no iOS zoom */
code { font-family: ui-monospace, Menlo, monospace; font-size: .92em; }
[hidden] { display: none !important; }

.app {
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 10px) 18px calc(var(--safe-b) + 28px);
}

/* ---------- header ---------- */
.top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; height: 48px; }
.brand { font-weight: 650; letter-spacing: .01em; color: var(--muted); font-size: 15px; }
.pill {
  justify-self: start; display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px 7px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: rgba(20, 34, 49, .7); font-size: 13px; font-weight: 600; cursor: pointer;
  max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--none); flex: none; }
.pill[data-s="on"] .dot { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.pill[data-s="busy"] .dot { background: var(--ok); animation: blink 1s infinite; }
.pill[data-s="err"] .dot { background: var(--low); }
.pill[data-s="demo"] .dot { background: #b9a4ff; }
.icon-btn {
  justify-self: end; width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--line);
  background: rgba(20, 34, 49, .7); display: grid; place-items: center; cursor: pointer;
}

.banner {
  margin: 8px 0 4px; padding: 12px 14px; border-radius: 14px;
  background: #1b2433; border: 1px solid #33405a; font-size: 14px; color: #c9d3de;
}
.banner p { margin: 0 0 8px; }

/* ---------- verdict headline ---------- */
.verdict {
  margin: 18px 0 6px; text-align: center; font-weight: 700; font-size: 22px; line-height: 1.2;
  letter-spacing: -.01em; text-wrap: balance; min-height: 2.4em; display: grid; place-items: center;
}
.verdict[data-state="ok"] { color: var(--ok); }
.verdict[data-state="low"] { color: var(--low); }
.verdict[data-state="crit"] { color: var(--crit); }
.verdict[data-state="none"] { color: var(--muted); font-weight: 600; font-size: 18px; }

/* ---------- stage: car + readouts ---------- */
.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(96px, 124px) minmax(0, 1fr);
  grid-template-rows: auto auto;
  grid-template-areas: "fl car fr" "rl car rr";
  align-items: center; column-gap: 6px; row-gap: 0;
  margin: 4px 0 0;
}
.car { width: 100%; height: auto; max-height: 52dvh; display: block; overflow: visible; }
.car .shell { stroke: #3a5068; stroke-width: 1.2; }
.car .crease, .car .roofline { fill: none; stroke: #33475c; stroke-width: 1.1; stroke-linecap: round; }
.car .roof { fill: #182634; stroke: #304559; }
.car .side-glass { fill: #172636; }
.car .mirror { fill: #22334a; stroke: #3a5068; }
.car .lamp { fill: none; stroke-width: 3; stroke-linecap: round; }
.car .lamp.front { stroke: #cfe6ff; opacity: .8; }
.car .lamp.rear { stroke: #ff5a5a; opacity: .55; }

.wheel { fill: #0a1119; stroke: var(--none); stroke-width: 2; transition: stroke .4s, fill .4s; }
.halo { fill: var(--none); opacity: .0; transition: opacity .5s, fill .5s; }
.wheel[data-s="ok"] { stroke: var(--ok); }
.halo[data-s="ok"] { fill: var(--ok); opacity: .32; }
.wheel[data-s="low"] { stroke: var(--low); fill: #2a0f16; }
.halo[data-s="low"] { fill: var(--low); opacity: .55; }
.wheel[data-s="crit"] { stroke: var(--crit); fill: #3a0d16; }
.halo[data-s="crit"] { fill: var(--crit); opacity: .8; animation: halo 1.1s ease-in-out infinite; }

.readout {
  position: relative; min-width: 0; overflow: hidden; padding: 12px 11px; border-radius: 18px;
  background: rgba(20, 34, 49, .78); border: 1px solid var(--line);
  min-height: 112px; display: flex; flex-direction: column; justify-content: center;
  transition: background .4s, border-color .4s;
}
.readout[data-w="0"], .readout[data-w="2"] { text-align: right; }
.readout[data-w="0"], .readout[data-w="1"] { align-self: start; margin-top: 8%; }
.readout[data-w="2"], .readout[data-w="3"] { align-self: end; margin-bottom: 8%; }
.readout .pos { font-size: 12px; color: var(--muted); }
.readout .p {
  font-family: var(--num); font-weight: 800; font-size: clamp(27px, 8.4vw, 38px); line-height: 1.05;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em; margin: 2px 0 2px; color: var(--text);
}
.readout .p small { font-size: 12px; font-weight: 700; color: var(--muted); margin-left: 3px; letter-spacing: 0; }
.readout .t { font-family: var(--num); font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.readout[data-s="none"] .p { color: var(--none); }
.readout[data-s="ok"] .p { color: var(--ok); }
.readout[data-s="low"] { background: rgba(70, 18, 30, .82); border-color: #6c2333; }
.readout[data-s="low"] .p { color: var(--low); }
.readout[data-s="crit"] { background: rgba(110, 14, 32, .9); border-color: var(--crit); animation: critbox 1.1s ease-in-out infinite; }
.readout[data-s="crit"] .p { color: #fff; }
.readout[data-s="crit"] .p small, .readout[data-s="crit"] .t, .readout[data-s="crit"] .pos { color: #ffd2d8; }

/* ---------- actions ---------- */
.actions { margin-top: 18px; }
.primary {
  width: 100%; min-height: 58px; border-radius: 18px; border: 0; cursor: pointer;
  background: var(--text); color: #0d1621; font-weight: 750; font-size: 18px; letter-spacing: -.005em;
  box-shadow: 0 10px 30px -12px rgba(232, 238, 244, .45);
  transition: transform .12s, background .2s;
}
.primary:active { transform: scale(.985); }
.primary[data-mode="stop"] { background: #2a3a4c; color: var(--text); box-shadow: none; }
.primary:disabled { opacity: .5; }
.sub-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.updated { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hint { margin: 12px 0 0; font-size: 13.5px; color: var(--muted); }

.switch { display: inline-flex; align-items: center; gap: 10px; font-size: 14.5px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 46px; height: 28px; border-radius: 999px; background: #22364a; position: relative; flex: none; transition: background .2s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #e8eef4; transition: transform .2s; }
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--text); outline-offset: 2px; }

/* ---------- sensors ---------- */
.sensors { margin-top: 30px; padding-top: 20px; border-top: 1px solid var(--line); }
.sec-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sec-head h2 { margin: 0; font-size: 17px; font-weight: 650; }
.idlist { list-style: none; padding: 0; margin: 12px 0 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.idlist li { padding: 10px 12px; border-radius: 12px; background: var(--bg2); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.idlist span { font-size: 12px; color: var(--muted); }
.idlist code { font-size: 15px; letter-spacing: .04em; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; min-width: 0; }
.inline button { flex: none; }
.fine { font-size: 12.5px; color: var(--muted); margin: 10px 0 0; }

input[type="text"], input:not([type]), input[type="number"] {
  width: 100%; padding: 12px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: #0b131d; color: var(--text); outline: none; letter-spacing: .02em;
}
input:focus-visible { border-color: #5d7a96; box-shadow: 0 0 0 3px rgba(93, 122, 150, .3); }

button { min-height: 44px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-weight: 600; cursor: pointer; }
button:disabled { opacity: .42; cursor: default; }
button:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.ghost { background: transparent; }
.small { min-height: 38px; padding: 7px 12px; font-size: 14px; }
.wide { width: 100%; margin-top: 10px; }
.danger-outline { border-color: #7a2a3a; color: #ff9aa8; background: transparent; }
.danger { background: var(--crit); border-color: var(--crit); color: #fff; font-weight: 750; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; margin-top: 12px; color: #c4cfda; }
.check input { width: 20px; height: 20px; accent-color: var(--ok); }

/* ---------- sheet ---------- */
.scrim { position: fixed; inset: 0; background: rgba(3, 7, 12, .6); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-width: 620px; margin: 0 auto;
  height: calc(100dvh - var(--safe-t) - 28px); display: flex; flex-direction: column;
  background: #111d2a; border: 1px solid var(--line); border-bottom: 0; border-radius: 24px 24px 0 0;
  transform: translateY(105%); transition: transform .32s cubic-bezier(.2, .8, .2, 1);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, .5);
}
.sheet.open { transform: none; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: #33485e; margin: 8px auto 0; flex: none; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 16px 4px 20px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 6px 16px 10px; scrollbar-width: none; flex: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; min-height: 36px; padding: 6px 14px; border-radius: 999px; font-size: 14px; background: transparent; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--text); color: #0d1621; border-color: var(--text); }
.sheet-body { flex: 1; overflow-y: auto; padding: 4px 18px 20px; -webkit-overflow-scrolling: touch; }
.sheet-body h3 { font-size: 15px; margin: 24px 0 4px; }
.sheet-foot { padding: 10px 18px calc(var(--safe-b) + 12px); border-top: 1px solid var(--line); flex: none; }
.stop { width: 100%; }
.stop:not(:disabled) { background: var(--low); border-color: var(--low); color: #fff; }
.stat { font-size: 14px; color: var(--muted); }
#status { color: var(--text); font-weight: 600; }
#status.ok { color: var(--ok); } #status.bad { color: var(--low); }
.log {
  margin: 12px 0 0; padding: 12px; border-radius: 12px; background: #08101a; border: 1px solid var(--line);
  font: 11.5px/1.45 ui-monospace, Menlo, monospace; white-space: pre-wrap; word-break: break-all;
  min-height: 40vh; max-height: 60vh; overflow: auto; color: #b8c6d4;
}
.log.mini { min-height: 120px; max-height: 30vh; }
.log .hit { color: var(--ok); font-weight: 700; }
.log .bad { color: var(--low); font-weight: 700; }
.rawtires { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.rawtires .tire { padding: 8px; border-radius: 10px; background: #0b131d; border: 1px solid var(--line); text-align: center; font-size: 13px; }
.rawtires .p { font-weight: 700; font-size: 17px; }
.rawtires .raw, .rawtires .pos { color: var(--muted); font-size: 11px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; min-width: 72px; background: transparent; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--text); color: #0d1621; }
.version { margin-top: 28px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: end center; background: rgba(3, 7, 12, .7); padding: 12px; padding-bottom: calc(var(--safe-b) + 12px); }
.modal-card { width: 100%; max-width: 480px; background: #132030; border: 1px solid var(--line); border-radius: 22px; padding: 20px; }
.modal-card h2 { margin: 0 0 4px; font-size: 21px; }
.cmp { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 14px; }
.cmp th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 0 0 6px; }
.cmp td { padding: 8px 0; border-top: 1px solid var(--line); }
.cmp td code { font-size: 14px; }
.cmp tr.changed td:last-child code { color: #ffb3bd; font-weight: 700; }
.warnline { font-size: 13px; color: #ffb3bd; margin: 14px 0 4px; }

/* ---------- alarm ---------- */
.alarm { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: radial-gradient(circle at 50% 40%, #b0122e, #4a0612 75%); color: #fff; text-align: center; padding: 24px; animation: alarmbg 1.2s ease-in-out infinite; }
.alarm-inner { max-width: 380px; }
.alarm h2 { font-size: 34px; margin: 10px 0 4px; letter-spacing: -.02em; }
.al-wheel { font-size: 18px; margin: 0; opacity: .9; }
.al-value { font-family: var(--num); font-weight: 800; font-size: 76px; line-height: 1; margin: 10px 0 14px; font-variant-numeric: tabular-nums; }
.alarm button { margin-top: 18px; width: 100%; min-height: 56px; border-radius: 16px; border: 0; background: #fff; color: #7a0a1e; font-weight: 800; font-size: 18px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 20px); transform: translateX(-50%); z-index: 60; background: #e8eef4; color: #0d1621; padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; max-width: 90vw; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); }

@keyframes blink { 50% { opacity: .25; } }
@keyframes halo { 50% { opacity: .35; } }
@keyframes critbox { 50% { background: rgba(60, 10, 22, .9); } }
@keyframes alarmbg { 50% { filter: brightness(.82); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-width: 360px) {
  .readout { padding: 10px 9px; }
  .readout .p { font-size: 25px; }
}
#nobt.demo-on { display: none; }
