/* «Ночная приборка»: тёмная тема намеренно одна — страница для салона машины,
   цвета как у симулятора дисплея (firmware/tools/display-sim.html). */
:root {
  --bg: #100f0e;
  --panel: #1a1816;
  --panel-2: #23201d;
  --line: #2f2a25;
  --fg: #ebe5dc;
  --muted: #9d958a;
  --red: #ff4a2e;
  --red-soft: #ff8a70;
  --red-deep: #4a1710;
  --ok: #7fc48a;
  --warn: #e6b450;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.45 var(--font); -webkit-tap-highlight-color: transparent; }
.wrap { max-width: 560px; margin: 0 auto; display: grid; gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
main { display: grid; gap: 12px; }
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0; letter-spacing: .01em; }
h2 { font-size: 17px; margin: 0 0 10px; font-weight: 600; }
p { margin: 0; }
.sub { color: var(--muted); font-size: 13px; }
.mono { font-family: var(--mono); }
.hint { color: var(--muted); font-size: 13.5px; margin-top: 8px; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; }
.top { align-items: flex-start; }
.brand { min-width: 0; }
.top-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex: none; }
.langs { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.langs button { min-height: 34px; padding: 4px 9px; border: 0; border-radius: 0; background: transparent; color: var(--muted);
  font-size: 13px; font-weight: 600; letter-spacing: .04em; }
.langs button + button { border-left: 1px solid var(--line); }
.langs button[aria-pressed=true] { background: var(--red-deep); color: var(--red-soft); }
.pill { font-size: 13px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.on { border-color: var(--ok); color: var(--ok); }
.pill.demo { border-color: var(--warn); color: var(--warn); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; min-width: 0; }
.card.warn { border-color: var(--warn); }
.card.warn h2 { color: var(--warn); }
.card.warn p + p { margin-top: 8px; }
#connectCard { display: grid; gap: 10px; }

button { font: inherit; color: var(--fg); background: var(--panel-2); border: 1px solid #3a342e; border-radius: 10px;
  padding: 10px 16px; min-height: 48px; cursor: pointer; touch-action: manipulation; }
button:active { transform: scale(.98); }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.primary { background: var(--red); border-color: var(--red); color: #1a0703; font-weight: 600; }
.primary.big { min-height: 64px; font-size: 19px; display: flex; align-items: center; justify-content: center; gap: 10px; }
.primary.big svg { width: 26px; height: 26px; }
.ghost { background: transparent; }
.ghost.small { min-height: 36px; padding: 4px 12px; font-size: 14px; }
.ghost.wide { width: 100%; }
.danger { border-color: #7a2a1e; color: var(--red-soft); }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btns.end { justify-content: flex-end; }
.btns > * { flex: 1 1 auto; }
a.button { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 10px 16px;
  border-radius: 10px; background: var(--red); color: #1a0703; font-weight: 600; text-decoration: none; }

input[type=text], input[type=password] { width: 100%; min-width: 0; font: inherit; font-size: 18px; color: var(--fg);
  background: #0e0d0c; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 48px; }
.pin-row, .text-row { display: flex; gap: 8px; }
.pin-row input { font-family: var(--mono); letter-spacing: .3em; font-size: 22px; }
.pin-row button, .text-row button { flex: none; }
.car-row { margin-top: 14px; align-items: center; }
.car-row label { color: var(--muted); font-size: 14px; flex: none; }
.car-row input { font-family: var(--mono); text-transform: uppercase; letter-spacing: .15em; }
.check { display: flex; gap: 8px; align-items: center; margin-top: 12px; color: var(--muted); font-size: 14px; }
.check input { width: 20px; height: 20px; accent-color: var(--red); }
.msg { margin-top: 10px; min-height: 1.4em; font-size: 14.5px; }
.msg.err { color: var(--red-soft); }

/* Превью дисплея */
.preview { padding: 12px; }
.bezel { background: #050403; border-radius: 10px; padding: 8px; box-shadow: inset 0 2px 8px #000; }
canvas#lcd { display: block; width: 100%; height: auto; border-radius: 4px; }
.pv-info { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-top: 10px; font-size: 13px; color: var(--muted); }
.pv-info b { color: var(--red-soft); font-weight: 500; white-space: pre; }
.track { margin-top: 4px; font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Режимы */
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.modes button { min-height: 72px; display: grid; align-content: center; gap: 2px; text-align: left; padding: 10px 14px; }
.modes b { font-size: 16.5px; font-weight: 600; }
.modes small { color: var(--muted); font-size: 12.5px; }
.modes button[aria-checked=true] { background: var(--red-deep); border-color: var(--red); box-shadow: inset 0 0 0 1px var(--red); }
.modes button[aria-checked=true] small { color: var(--red-soft); }
.modes button.busy { opacity: .7; }

/* Переключатель */
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.switch-row h2 { margin: 0; }
.switch-row .hint { margin-top: 2px; }
.switch { flex: none; width: 64px; min-height: 36px; height: 36px; padding: 3px; border-radius: 999px; background: #2b2723; position: relative; }
.switch span { position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%; background: #8a8178; transition: left .15s; }
.switch[aria-checked=true] { background: var(--red-deep); border-color: var(--red); }
.switch[aria-checked=true] span { left: 31px; background: var(--red); }

/* Ползунок */
.scroll-row { display: flex; align-items: center; gap: 14px; }
input[type=range] { flex: 1; min-width: 0; height: 40px; accent-color: var(--red); }
output { min-width: 5.5em; text-align: right; font-size: 16px; color: var(--red-soft); }
.scale { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-right: calc(5.5em + 14px); }

.player { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.player button { min-height: 56px; font-size: 22px; }

.row-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.row-head h2 { margin: 0; }
.stat { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 14.5px; }
.stat dt { color: var(--muted); }
.stat dd { margin: 0; overflow-wrap: anywhere; }
.badge { display: inline-block; font-size: 12.5px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); }
.badge.ok { border-color: var(--ok); color: var(--ok); }
.badge.warn { border-color: var(--warn); color: var(--warn); }

.pin-change { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pin-change input { font-family: var(--mono); letter-spacing: .2em; }
.pin-change button { grid-column: 1 / -1; }

/* Как подключиться */
.tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.tabs button { min-height: 44px; padding: 6px 4px; font-size: 14px; background: transparent; line-height: 1.2; }
.tabs button[aria-selected=true] { background: var(--red-deep); border-color: var(--red); color: var(--red-soft); }
.steps { margin: 14px 0 0; padding-left: 1.5em; display: grid; gap: 8px; font-size: 15px; }
.steps li { padding-left: 4px; }
.steps li::marker { color: var(--red-soft); font-weight: 600; font-variant-numeric: tabular-nums; }
.howto a { color: var(--red-soft); }
.howto code { font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; color: var(--fg); }
.trouble { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.trouble summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.trouble ul { margin: 10px 0 0; padding-left: 1.2em; display: grid; gap: 8px; color: var(--muted); font-size: 14.5px; }
.trouble b { color: var(--fg); }

.log summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.log pre { margin: 10px 0 0; max-height: 260px; overflow: auto; font: 12.5px/1.45 var(--mono); color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }

.foot { text-align: center; color: #5f584f; font-size: 12px; padding-top: 4px; }

dialog { background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: 14px; padding: 18px; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog p { color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0;
  background: #2a2622; border: 1px solid var(--line); color: var(--fg); padding: 10px 16px; border-radius: 10px; font-size: 15px;
  max-width: calc(100vw - 32px); transition: opacity .2s, transform .2s; pointer-events: none; z-index: 10; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: var(--red); color: var(--red-soft); }

@media (min-width: 520px) { .modes { grid-template-columns: repeat(3, 1fr); } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
