/* Garage control — styled after the Tesla in-car Controls screen: pure black
   ground, dark raised cards, generous touch targets, system font only (no
   webfont, because the car's connection is unreliable and the CSP is self). */

/* Dark is the base, so a browser too old to support prefers-color-scheme gets
   dark rather than a guess. Otherwise the device decides, with no in-page
   override.

   Modern browsers dropped `no-preference` and report `light` when nothing is
   set, so a car that never forwards its theme reads as light. Accepted. */

:root {
  color-scheme: dark;
  --bg: #000;
  --card: #1b1c1e;
  --card-press: #2a2c2f;
  --line: #2e3034;
  --notice-bg: #16181b;
  --text: #f5f5f7;
  --muted: #8e8e93;
  --accent: #3e6ae1;
  --ok: #30d158;
  --bad: #e31937;
  --radius: 18px;
}

/* Light is not an inversion: the accent, green and red are all darkened,
   because the dark palette's versions fall below 4.5:1 on a white card. */
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f2f2f4;
    --card: #ffffff;
    --card-press: #e9e9ee;
    --line: #d7d7de;
    --notice-bg: #ffffff;
    --text: #15161a;
    --muted: #62636a;
    --accent: #2f55c4;
    --ok: #1a7f37;
    --bad: #c01128;
  }
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-text-size-adjust: 100%;
}

.sr {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* --- shell --------------------------------------------------------------- */
.wrap { max-width: 1040px; margin: 0 auto; padding: 22px 20px 28px; }

.bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 18px;
}

h1 { margin: 0; font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }


.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 13px; border: 1px solid var(--line); border-radius: 999px;
  font-size: 13px; color: var(--muted); white-space: nowrap;
}
.pill::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
}
.pill[data-state="up"]   { color: var(--ok); }
.pill[data-state="down"] { color: var(--bad); }

.notice {
  margin: 0 0 16px; padding: 11px 14px;
  background: var(--notice-bg); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: 10px;
  font-size: 14px; color: var(--muted);
}
.notice--warn { border-left-color: var(--bad); }

/* --- tiles --------------------------------------------------------------- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

.tile {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 9px; min-height: 176px; padding: 24px 14px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  font: inherit; text-align: center; cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background .12s ease, transform .12s ease, border-color .12s ease;
}
.tile:active { background: var(--card-press); transform: scale(.985); }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile[disabled] { cursor: default; }
.tile[disabled]:active { transform: none; background: var(--card); }

.glyph { width: 46px; height: 42px; color: var(--text); }
.glyph--wide { width: 56px; }

.name { font-size: 17px; font-weight: 600; }
.meta { font-size: 13px; color: var(--muted); min-height: 1.2em; }

.tile[data-state="sending"] .glyph { opacity: .45; }
.tile[data-state="sent"]    { border-color: var(--ok); }
.tile[data-state="sent"] .meta  { color: var(--ok); }
.tile[data-state="error"]   { border-color: var(--bad); }
.tile[data-state="error"] .meta { color: var(--bad); }

/* Drains across the bottom of the tile for the debounce window, so a second
   tap that would stop the door mid-travel is visibly unavailable. */
.cool {
  position: absolute; left: 0; bottom: 0; height: 3px; width: 100%;
  background: var(--ok); transform: scaleX(0); transform-origin: left;
}
.tile[data-state="sent"] .cool { animation: drain 3s linear forwards; }
@keyframes drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }

@media (prefers-reduced-motion: reduce) {
  .tile, .cool { transition: none; animation: none; }
}

/* --- foot ---------------------------------------------------------------- */
.foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-top: 22px; padding-top: 16px;
  border-top: 1px solid var(--line);
}
.hint { font-size: 12.5px; color: var(--muted); max-width: 62ch; }

/* --- login --------------------------------------------------------------- */
.centred { min-height: 100vh; display: grid; place-items: center; }
.gate { width: min(360px, calc(100vw - 40px)); padding: 24px; text-align: center; }
.glyph--lead { width: 64px; height: 58px; margin-bottom: 10px; color: var(--muted); }
.gate h1 { margin: 0 0 20px; }
.gate__form { display: grid; gap: 12px; }

input[type="password"] {
  width: 100%; padding: 14px 16px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  font: inherit; font-size: 16px; /* 16px keeps iOS from zooming on focus */
}
input[type="password"]:focus {
  outline: none; border-color: var(--accent);
}

.primary {
  padding: 14px 16px; background: var(--accent); color: #fff;
  border: 0; border-radius: 12px;
  font: inherit; font-size: 16px; font-weight: 600;
  cursor: pointer; touch-action: manipulation;
}
.primary:active { filter: brightness(.9); }
.gate .hint { display: block; margin-top: 16px; }

/* On a landscape display with room to spare — the car screen above all — the
   stack sits in the middle rather than clinging to the top edge. */
@media (min-width: 701px) and (min-height: 620px) {
  .wrap {
    min-height: 100vh;
    display: flex; flex-direction: column; justify-content: center;
  }
}

/* --- narrow ------------------------------------------------------------- */
@media (max-width: 700px) {
  .wrap { padding: 16px 14px 22px; }
  h1 { font-size: 22px; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .tile { min-height: 148px; padding: 18px 10px; }
  .tile--both { grid-column: 1 / -1; min-height: 112px; }
  .glyph { width: 40px; height: 36px; }
  .foot { flex-direction: column; align-items: flex-start; }
}
