/* evsound - cockpit styling.
   Dark, high contrast, touch first (nothing interactive below 44 px).
   Scales from a phone held sideways to a 15" dash screen. No external assets. */

:root {
  --bg: #07090c;
  --bg-raise: #11151b;
  --bg-sunken: #04060a;
  --line: #26303c;
  --line-strong: #3b4857;
  --fg: #eef3f8;
  --fg-dim: #8e9daa;
  --fg-faint: #5d6b78;

  --ok: #38e07b;
  --warn: #ffc23d;
  --hot: #ff4d3d;
  --cool: #35b8ff;
  --brake: #ff5f4a;

  --touch: 44px;
  --radius: 12px;
  --gap: clamp(8px, 1.4vh, 18px);
  --pad: clamp(10px, 2vw, 22px);

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  overscroll-behavior: none;
}

body { -webkit-text-size-adjust: 100%; }

.noscript {
  display: block;
  padding: 16px;
  background: var(--hot);
  color: #14060a;
  font-weight: 700;
}

#app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: var(--gap);
  padding: var(--pad);
  padding-bottom: max(var(--pad), env(safe-area-inset-bottom));
}

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

#topbar {
  display: flex;
  align-items: center;
  gap: var(--gap);
  min-height: var(--touch);
}

.brand {
  font-weight: 800;
  letter-spacing: 0.18em;
  font-size: clamp(0.8rem, 1.6vw, 1.05rem);
  color: var(--fg-dim);
  white-space: nowrap;
}

.status {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}

.chip {
  font-family: var(--mono);
  font-size: clamp(0.62rem, 1.15vw, 0.8rem);
  line-height: 1;
  padding: 7px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-raise);
  color: var(--fg-dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.chip.is-live { color: var(--ok); border-color: rgba(56, 224, 123, 0.45); }
.chip.is-connecting { color: var(--warn); border-color: rgba(255, 194, 61, 0.45); }
.chip.is-error { color: var(--hot); border-color: rgba(255, 77, 61, 0.5); }
.chip.is-warn { color: var(--warn); border-color: rgba(255, 194, 61, 0.5); }

/* -------------------------------------------------------------------- HUD */

#hud {
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: center;
  gap: var(--gap);
  min-height: 0;
}

.tach-wrap { position: relative; }

#tach {
  display: block;
  width: 100%;
  height: clamp(84px, 17vh, 190px);
}

.tach-foot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
}

.rpm-read {
  font-family: var(--mono);
  font-size: clamp(1rem, 2.6vw, 1.7rem);
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}

.rpm-read .unit { color: var(--fg-faint); margin-left: 6px; font-size: 0.62em; }

.light-note {
  font-family: var(--mono);
  font-size: clamp(0.7rem, 1.4vw, 0.95rem);
  letter-spacing: 0.22em;
  color: var(--hot);
  animation: pulse 0.25s steps(2, end) infinite;
}

@keyframes pulse { 50% { opacity: 0.25; } }

.readouts {
  display: grid;
  grid-template-columns: minmax(120px, 0.32fr) 1fr;
  align-items: end;
  gap: var(--gap);
  min-height: 0;
}

.gear-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--bg-raise), var(--bg-sunken));
  padding: clamp(6px, 1.2vh, 14px) clamp(10px, 2vw, 22px);
  text-align: center;
}

.label,
.field-label,
.bar-label {
  font-size: clamp(0.58rem, 1.05vw, 0.72rem);
  letter-spacing: 0.16em;
  color: var(--fg-faint);
}

.gear {
  font-size: clamp(3.2rem, 13vh, 8rem);
  line-height: 0.95;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}

.gear.is-shifting { color: var(--warn); }

.speed-box { text-align: right; }

.speed {
  font-size: clamp(4rem, 19vh, 12rem);
  line-height: 0.86;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  color: var(--fg);
}

.speed-unit {
  font-size: clamp(0.75rem, 2.4vw, 1.5rem);
  letter-spacing: 0.14em;
  color: var(--fg-dim);
}

.pedals { display: grid; gap: 6px; }

.bar-row {
  display: grid;
  grid-template-columns: 3.2em 1fr 3.6em;
  align-items: center;
  gap: 10px;
}

.bar {
  height: clamp(12px, 2.4vh, 20px);
  border-radius: 999px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  overflow: hidden;
}

.fill {
  height: 100%;
  width: 0%;
  transform-origin: left center;
  transition: width 60ms linear;
}

.fill-pedal { background: linear-gradient(90deg, #1f8f4e, var(--ok)); }
.fill-brake { background: linear-gradient(90deg, #8f2b1f, var(--brake)); }

.bar-val {
  font-family: var(--mono);
  font-size: clamp(0.66rem, 1.2vw, 0.85rem);
  color: var(--fg-dim);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------- controls */

#controls {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: var(--gap);
}

.btn {
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--bg-raise);
  color: var(--fg);
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.1em;
  font-size: clamp(0.75rem, 1.35vw, 0.95rem);
  cursor: pointer;
  touch-action: manipulation;
}

.btn:hover { border-color: var(--fg-faint); }
.btn:focus-visible { outline: 2px solid var(--cool); outline-offset: 2px; }

.btn-ghost { background: transparent; color: var(--fg-dim); }

.btn-start {
  flex: 0 0 auto;
  min-width: clamp(140px, 22vw, 260px);
  font-size: clamp(1rem, 2.4vw, 1.6rem);
  letter-spacing: 0.2em;
  background: linear-gradient(180deg, #16351f, #0d2216);
  border-color: rgba(56, 224, 123, 0.5);
  color: var(--ok);
}

.btn-start[aria-pressed="true"] {
  background: linear-gradient(180deg, #3a1512, #240b0a);
  border-color: rgba(255, 77, 61, 0.55);
  color: var(--hot);
}

.quick {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: var(--gap);
  flex: 1 1 auto;
  min-width: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field-wide { grid-column: 1 / -1; }

.field-label { display: flex; justify-content: space-between; gap: 8px; }

select,
input[type="text"],
input[type="password"],
input[type="number"] {
  min-height: var(--touch);
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-sunken);
  color: var(--fg);
  font: inherit;
  font-size: clamp(0.8rem, 1.3vw, 0.95rem);
  min-width: 0;
}

select { padding-right: 6px; }

input[type="range"] {
  min-height: var(--touch);
  width: 100%;
  accent-color: var(--ok);
  background: transparent;
}

input:focus-visible,
select:focus-visible { outline: 2px solid var(--cool); outline-offset: 1px; }

.shortcuts {
  flex: 1 1 100%;
  margin: 0;
  font-size: clamp(0.6rem, 1.05vw, 0.74rem);
  letter-spacing: 0.06em;
  color: var(--fg-faint);
}

/* ----------------------------------------------------------------- drawer */

.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(420px, 94vw);
  display: flex;
  flex-direction: column;
  background: var(--bg-raise);
  border-left: 1px solid var(--line-strong);
  box-shadow: -24px 0 60px rgba(0, 0, 0, 0.6);
  transform: translateX(102%);
  transition: transform 220ms ease, visibility 0s linear 220ms;
  visibility: hidden;
  z-index: 20;
  padding: var(--pad);
  padding-bottom: max(var(--pad), env(safe-area-inset-bottom));
  overflow-y: auto;
}

.drawer.open {
  transform: none;
  visibility: visible;
  transition: transform 220ms ease, visibility 0s;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: var(--gap);
}

.drawer-head h2 { margin: 0; font-size: 1.1rem; letter-spacing: 0.12em; }

.drawer-body { display: grid; gap: var(--gap); }

fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--gap);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  margin: 0;
  min-width: 0;
}

legend {
  padding: 0 6px;
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  color: var(--fg-faint);
}

.drawer-note {
  margin: 0;
  font-size: 0.72rem;
  color: var(--fg-faint);
  line-height: 1.5;
}

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--pad) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--bg-raise);
  border: 1px solid var(--line-strong);
  color: var(--fg);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  z-index: 30;
  pointer-events: none;
}

/* ------------------------------------------------------------ responsive */

/* Phone portrait: stack the readouts, keep the digits huge. */
@media (max-width: 560px) {
  .readouts { grid-template-columns: 1fr; }
  .speed-box { text-align: left; }
  .gear-box { display: flex; align-items: baseline; gap: 12px; text-align: left; }
  .gear { font-size: clamp(2.4rem, 14vh, 5rem); }
  .brand { display: none; }
  fieldset { grid-template-columns: 1fr; }
}

/* Short landscape (phone on a mount, or a wide dash strip): everything must fit
   in ~390 px of height, so the rows are sized to their content with margin. */
@media (max-height: 520px) {
  #app { gap: 6px; padding: 8px; }
  .brand { display: none; }
  .shortcuts { display: none; }
  #hud { gap: 6px; }
  #tach { height: clamp(48px, 15vh, 92px); }
  .tach-foot { margin-top: 0; }
  .rpm-read { font-size: clamp(0.8rem, 3.6vh, 1.1rem); }
  .readouts { grid-template-columns: minmax(84px, 0.28fr) 1fr; gap: 6px; }
  .gear-box { padding: 2px 10px; }
  .gear { font-size: clamp(1.5rem, 9vh, 3rem); }
  .speed { font-size: clamp(2rem, 17vh, 5rem); }
  .speed-unit { font-size: clamp(0.6rem, 3vh, 1rem); }
  .pedals { gap: 4px; }
  .bar-row { grid-template-columns: 2.6em 1fr 2.8em; gap: 6px; }
  #controls { gap: 6px; }
  .field-label { display: none; } /* the <label> still names the control for a11y */
}

/* Wide dash screen: readouts share one row with the tach. */
@media (min-width: 1100px) {
  #hud {
    grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
    grid-template-rows: auto auto;
    grid-template-areas:
      "tach readouts"
      "pedals pedals";
    align-content: center;
  }
  #tach { height: clamp(120px, 30vh, 300px); }
  .tach-wrap { grid-area: tach; }
  .readouts { grid-area: readouts; align-items: center; }
  .pedals { grid-area: pedals; margin-top: clamp(8px, 3vh, 40px); }
}

@media (prefers-reduced-motion: reduce) {
  .drawer { transition: none; }
  .light-note { animation: none; }
  .fill { transition: none; }
}
