/* Field Meter — concept demo
   Dark instrument theme, one accent (amber). Mobile first. */

:root {
  --bg: #0a0c0f;
  --panel: #12161b;
  --panel-2: #171d24;
  --line: #232c36;
  --line-soft: #1a2129;
  --ink: #e9eff6;
  --ink-dim: #9aa8b6;
  --ink-faint: #6d7b89;
  --accent: #ffb020;
  --accent-dim: rgba(255, 176, 32, 0.14);
  --pass: #4ec07a;
  --fail: #ff5f57;
  --warn: #ffb020;
  --radius: 14px;
  --radius-sm: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --pad: 14px;
  --tab-h: 62px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

/* measurements read left-to-right even in Arabic: 12.42 V, never V 12.42 */
.reading-num, .stat-val, .test-meas, .range-label, .ctl-head .mono, #trimVal {
  direction: ltr;
  unicode-bidi: isolate;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.small { font-size: 12px; }
.muted { color: var(--ink-dim); }

.app {
  padding-top: env(safe-area-inset-top, 0);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 540px;
  margin: 0 auto;
  background: var(--bg);
  border-inline: 1px solid transparent;
}

@media (min-width: 720px) {
  body { background: #06080a; }
  .app {
    border-inline-color: var(--line);
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.6);
  }
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px var(--pad) 8px;
  border-bottom: 1px solid var(--line-soft);
  flex: 0 0 auto;
}

.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }

.brand-mark {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(255, 176, 32, 0.55);
  flex: 0 0 auto;
}

.brand-name {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.02em;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  background: var(--panel);
  white-space: nowrap;
}

.chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-faint);
}

.chip[data-state="on"] { color: var(--ink); border-color: rgba(255, 176, 32, 0.45); }
.chip[data-state="on"] .chip-dot { background: var(--accent); box-shadow: 0 0 8px rgba(255, 176, 32, 0.8); }

.chip-hold {
  color: #0a0c0f;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

.lang {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: var(--panel);
}

.lang-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 9px;
  cursor: pointer;
  line-height: 1.4;
}

.lang-btn.is-on { background: var(--accent); color: #0a0c0f; }

.demo-banner {
  margin: 0;
  padding: 7px var(--pad);
  font-size: 11.5px;
  line-height: 1.35;
  color: #ffd591;
  background: rgba(255, 176, 32, 0.1);
  border-bottom: 1px solid rgba(255, 176, 32, 0.22);
  flex: 0 0 auto;
}

/* ---------- layout ---------- */

#main {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: var(--pad);
  padding-bottom: 22px;
  min-height: 0;
}

.screen { display: flex; flex-direction: column; gap: 12px; }
.screen[hidden] { display: none; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.card-quiet { background: var(--panel-2); }

.card-title {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.hint {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-dim);
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* ---------- buttons ---------- */

.btn {
  appearance: none;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  padding: 11px 14px;
  cursor: pointer;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0a0c0f;
}

.btn-lg { width: 100%; padding: 15px; font-size: 16px; }

.btn-ghost[aria-pressed="true"],
.btn-ghost.is-on {
  border-color: rgba(255, 176, 32, 0.55);
  background: var(--accent-dim);
  color: var(--accent);
}

.btn-danger { border-color: rgba(255, 95, 87, 0.5); color: #ff8b85; }

/* ---------- connect ---------- */

.pod-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.pod-art { flex: 0 0 132px; width: 132px; }
.pod-art svg { width: 100%; height: auto; display: block; }

.pod-id { min-width: 0; }
.pod-name { font-size: 20px; font-weight: 700; letter-spacing: 0.02em; }
.pod-status { font-size: 13px; color: var(--ink-dim); margin-top: 3px; }
.pod-status.is-on { color: var(--accent); }

.plain-list {
  margin: 0;
  padding-inline-start: 18px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-dim);
}

.plain-list li { margin-bottom: 6px; }
.plain-list li:last-child { margin-bottom: 0; }

/* ---------- form ---------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }

.field label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

select {
  appearance: none;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 34px 11px 12px;
  min-height: 44px;
  width: 100%;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-dim) 50%), linear-gradient(135deg, var(--ink-dim) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

[dir="rtl"] select {
  padding: 11px 12px 11px 34px;
  background-position: 18px 50%, 13px 50%;
}

input[type="range"] {
  appearance: none;
  width: 100%;
  height: 30px;
  background: transparent;
  margin: 0;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--line);
  border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -9px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0a0c0f;
}

input[type="range"]::-moz-range-track {
  height: 4px;
  background: var(--line);
  border-radius: 2px;
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0a0c0f;
}

/* ---------- meter ---------- */

.meter { padding: 12px 12px 8px; }

.meter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-dim);
  min-height: 20px;
}

.reading {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 0 2px;
  min-height: 84px;
}

.reading-num {
  font-size: clamp(44px, 17vw, 76px);
  line-height: 0.98;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.reading-unit {
  font-size: clamp(18px, 6vw, 26px);
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}

.reading.is-overload .reading-num { color: var(--accent); }

.meter-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
  color: var(--ink-dim);
  letter-spacing: 0.03em;
  padding-bottom: 4px;
  min-height: 18px;
}

.trend {
  display: block;
  width: 100%;
  height: 56px;
  margin-top: 4px;
  border-top: 1px solid var(--line-soft);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 10px;
}

.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.stat-lbl {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
}

.stat-val {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.funcgrid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.func {
  appearance: none;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  min-height: 48px;
  padding: 6px 2px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-dim);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  line-height: 1.15;
  -webkit-tap-highlight-color: transparent;
}

.func .func-sym { font-size: 14px; font-family: var(--mono); }
.func.is-on {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}

.ctl-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.ctl-row .btn { flex: 1 1 0; }
.ctl-row .range-ctl { flex: 1.4 1 0; }

.range-ctl {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  overflow: hidden;
}

.range-ctl .btn {
  border: 0;
  border-radius: 0;
  background: transparent;
  flex: 0 0 44px;
  font-size: 18px;
  padding: 0;
}

.range-label {
  flex: 1 1 auto;
  text-align: center;
  font-size: 13px;
  color: var(--ink);
  white-space: nowrap;
}

.rec .card-title { margin: 0; }
.rec-meta { margin: 6px 0 10px; }

/* ---------- scope / spectrum ---------- */

.scope-card { padding: 8px; }

.scope {
  display: block;
  width: 100%;
  height: 300px;
  border-radius: 8px;
  background: #06080b;
  touch-action: manipulation;
}

.scope-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
  color: var(--ink-dim);
  padding: 6px 4px 0;
  min-height: 18px;
}

.scope-foot .mono { white-space: nowrap; }

.ctl-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.ctl {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}

.ctl-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 8px;
}

.ctl-head .mono {
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  color: var(--accent);
}

.ctl-btns { display: flex; gap: 8px; }
.ctl-btns .btn { flex: 1 1 0; font-size: 18px; padding: 8px; min-height: 40px; }

.peaks { width: 100%; border-collapse: collapse; font-size: 12.5px; }

.peaks th {
  text-align: start;
  font-size: 10px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 600;
  padding: 0 6px 6px 0;
  border-bottom: 1px solid var(--line-soft);
}

.peaks td {
  padding: 7px 6px 7px 0;
  border-bottom: 1px solid var(--line-soft);
  color: var(--ink);
  white-space: nowrap;
}

.peaks td:last-child { white-space: normal; color: var(--ink-dim); }
.peaks tr:last-child td { border-bottom: 0; }
.peaks .freq { color: var(--accent); font-weight: 600; }

/* ---------- car diagnostics ---------- */

.test {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}

.test-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.test-name { font-size: 15px; font-weight: 650; margin: 0 0 2px; }
.test-sub { font-size: 12px; color: var(--ink-dim); margin: 0; line-height: 1.4; }

.test-body { margin-top: 10px; }

.test-meas {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--mono);
  direction: ltr;
  unicode-bidi: isolate;
}

[dir="rtl"] .test-meas { justify-content: flex-end; }

.test-meas .val { font-size: 26px; font-weight: 600; }
.test-meas .unit { font-size: 13px; color: var(--ink-dim); }

.test-verdict {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  line-height: 1.45;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel-2);
  margin-top: 8px;
}

.test-verdict .badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 3px 7px;
  border-radius: 4px;
  flex: 0 0 auto;
}

.test-verdict[data-v="pass"] { border-color: rgba(78, 192, 122, 0.4); }
.test-verdict[data-v="pass"] .badge { background: rgba(78, 192, 122, 0.16); color: var(--pass); }
.test-verdict[data-v="fail"] { border-color: rgba(255, 95, 87, 0.4); }
.test-verdict[data-v="fail"] .badge { background: rgba(255, 95, 87, 0.16); color: var(--fail); }
.test-verdict[data-v="warn"] { border-color: rgba(255, 176, 32, 0.4); }
.test-verdict[data-v="warn"] .badge { background: rgba(255, 176, 32, 0.16); color: var(--warn); }
.test-verdict[data-v="idle"] .badge { background: var(--line); color: var(--ink-dim); }
.test-verdict[data-v="run"] .badge { background: var(--accent); color: #0a0c0f; }

.test-bar {
  height: 3px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 10px;
}

.test-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.1s linear;
}

.test-thresh { font-size: 11px; color: var(--ink-faint); margin-top: 7px; line-height: 1.4; }

.test .btn { width: 100%; margin-top: 10px; }

#carSummary { white-space: nowrap; flex: 0 0 auto; }

.btn-run {
  background: transparent;
  border-color: rgba(255, 176, 32, 0.45);
  color: var(--accent);
  font-weight: 600;
}

.btn-run:active { background: var(--accent-dim); }

/* ---------- tab bar ---------- */

.tabbar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border-top: 1px solid var(--line);
  background: #0c1014;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-faint);
  font: inherit;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 8px 2px 9px;
  min-height: var(--tab-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  border-top: 2px solid transparent;
  margin-top: -1px;
  -webkit-tap-highlight-color: transparent;
}

.tab-ico { font-size: 15px; line-height: 1; font-family: var(--mono); }
.tab.is-on { color: var(--accent); border-top-color: var(--accent); }

/* ---------- narrow screens ---------- */

@media (max-width: 359px) {
  :root { --pad: 10px; }
  .reading-num { font-size: clamp(38px, 16vw, 60px); }
  .func { font-size: 11px; min-height: 46px; }
  .brand-name { font-size: 14px; }
  .pod-art { flex-basis: 104px; width: 104px; }
  .tab { font-size: 10px; }
}

@media (max-width: 320px) {
  .funcgrid { grid-template-columns: repeat(2, 1fr); }
  .stats { grid-template-columns: 1fr 1fr; }
}

/* ---------- rtl ---------- */

[dir="rtl"] .plain-list { padding-inline-start: 20px; }
[dir="rtl"] .reading { flex-direction: row-reverse; justify-content: flex-end; }
[dir="rtl"] .test-head { flex-direction: row-reverse; }
[dir="rtl"] .ctl-row { flex-direction: row-reverse; }
[dir="rtl"] .tabbar { direction: rtl; }
[dir="rtl"] .peaks th, [dir="rtl"] .peaks td { text-align: right; padding: 0 0 6px 6px; }
[dir="rtl"] .peaks td { padding: 7px 0 7px 6px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
