/* EngineHoursLog — Field-Use UI
   Governing rule: legible in bright sun, usable in an engine bay, one-handed,
   in gloves, on a phone, offline. Type is heavy. Targets are huge.
   Color is supplementary — pattern + position + text carries meaning. */

:root {
  /* geometry */
  --tap: 72px;          /* minimum tap target — gloved thumb */
  --pad: 20px;
  --hair: 2px;          /* rules are heavy */
  --hair-thick: 4px;

  /* type scale — bumped two steps above "desk" norm */
  --t-body: 20px;
  --t-label: 14px;
  --t-h: 28px;
  --t-big: 48px;
  --t-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --t-display: 'IBM Plex Serif', Georgia, serif;
  --t-text: 'Source Serif 4', Georgia, serif;
}

/* ============ SUNLIGHT THEME (default) ============ */
/* Pure white / pure black. Brutal contrast. Designed for a cockpit at noon. */
:root, [data-theme='sun'] {
  --bg: #ffffff;
  --bg-alt: #f2ece0;
  --fg: #000000;
  --fg-soft: #2a2a2a;
  --fg-faint: #666666;
  --rule: #000000;
  --accent: #a1371e;
  --accent-fg: #ffffff;
  --chip: #000000;
  --chip-fg: #ffffff;
  --ok: #000000;
  --overdue: #a1371e;
}

/* ============ ENGINE-BAY THEME ============ */
/* Amber on near-black — preserves dark adaptation. No blue, no green. */
[data-theme='bay'] {
  --bg: #000000;
  --bg-alt: #0d0906;
  --fg: #ff8d3a;
  --fg-soft: #c8641f;
  --fg-faint: #6b3611;
  --rule: #ff8d3a;
  --accent: #ff5a1e;
  --accent-fg: #000000;
  --chip: #ff8d3a;
  --chip-fg: #000000;
  --ok: #ff8d3a;
  --overdue: #ffb300;
}

/* ============ base ============ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--fg);
  font-family: var(--t-text);
  font-size: var(--t-body);
  line-height: 1.4;
  font-weight: 600;                 /* body weight is bumped — no thin strokes in sun */
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
}
button { font-family: inherit; font-size: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea { font-family: inherit; font-size: inherit; color: inherit; background: none; border: 0; outline: none; }
textarea { user-select: text; }

/* ============ layout ============ */
.app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-width: 640px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ============ header ============ */
.hdr {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 14px var(--pad) 10px;
  border-bottom: var(--hair) solid var(--rule);
  position: sticky; top: 0;
  background: var(--bg);
  z-index: 20;
}
.hdr .mark {
  font-family: var(--t-display);
  font-weight: 900;
  font-size: 22px;
  letter-spacing: -0.01em;
  text-transform: uppercase;
}
.hdr .mark em { font-style: italic; color: var(--accent); font-weight: 400; }
.hdr .net {
  font-family: var(--t-mono);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--fg-soft);
  padding: 6px 10px;
  border: var(--hair) solid var(--rule);
}
.hdr .net[data-state='offline'] { color: var(--fg); background: var(--bg-alt); }
.hdr .net[data-state='pending'] { color: var(--fg); background: var(--bg-alt); }

/* big theme toggle — always visible, never buried */
.theme-btn {
  width: 52px; height: 44px;
  border: var(--hair) solid var(--rule);
  font-family: var(--t-mono);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: var(--fg);
}
.theme-btn:active { background: var(--fg); color: var(--bg); }

/* ============ main ============ */
.main { padding: 16px var(--pad) 140px; }

/* ============ dashboard ============ */
.upcoming {
  border: var(--hair-thick) solid var(--rule);
  margin-bottom: 24px;
}
.upcoming h2 {
  margin: 0;
  padding: 12px 16px;
  font-family: var(--t-mono);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  border-bottom: var(--hair) solid var(--rule);
}
.up-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: baseline;
  padding: 14px 16px;
  border-bottom: var(--hair) solid var(--rule);
}
.up-row:last-child { border-bottom: 0; }
.up-row .what { font-size: 20px; font-weight: 700; }
.up-row .when {
  font-family: var(--t-mono);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-soft);
}
.up-row.overdue { background: var(--bg-alt); }
.up-row.overdue::before {
  content: "OVERDUE ";
  display: inline-block;
  margin-right: 8px;
  padding: 2px 8px;
  background: var(--overdue);
  color: var(--accent-fg);
  font-family: var(--t-mono);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.14em;
  vertical-align: 2px;
}
[data-theme='bay'] .up-row.overdue { background: #1a0f00; }
[data-theme='bay'] .up-row.overdue::before { background: var(--overdue); color: #000; }

/* ============ engine list ============ */
.section-label {
  font-family: var(--t-mono);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--fg-soft);
  margin: 0 0 10px;
  padding: 0 2px;
}
.engine-card {
  display: block;
  width: 100%;
  text-align: left;
  border: var(--hair-thick) solid var(--rule);
  padding: 16px;
  margin-bottom: 12px;
  background: var(--bg);
}
.engine-card:active { background: var(--bg-alt); }
.engine-card .name {
  font-family: var(--t-display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: -0.01em;
  line-height: 1.1;
  margin-bottom: 4px;
}
.engine-card .meta {
  font-family: var(--t-mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-soft);
  margin-bottom: 12px;
}
.engine-card .hours {
  font-family: var(--t-mono);
  font-weight: 900;
  font-size: 44px;
  line-height: 1;
  letter-spacing: -0.02em;
}
.engine-card .hours small {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.12em;
  margin-left: 8px;
  color: var(--fg-soft);
  text-transform: uppercase;
}

.add-engine {
  display: block; width: 100%;
  min-height: 64px;
  border: var(--hair-thick) dashed var(--rule);
  font-family: var(--t-mono);
  font-weight: 900;
  font-size: 15px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--fg);
  margin-top: 8px;
}
.add-engine:active { background: var(--bg-alt); }

.secondary-action {
  display: block; width: 100%;
  min-height: 64px;
  border: var(--hair-thick) solid var(--rule);
  background: var(--bg);
  font-family: var(--t-mono);
  font-weight: 900;
  font-size: 15px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--fg);
  margin-top: 8px;
}
.secondary-action:active { background: var(--fg); color: var(--bg); }
.account-entry[data-state='ready'] {
  border-style: solid;
}
.account-entry[data-state='ready']::after {
  content: "PASSKEY READY";
  display: block;
  margin-top: 4px;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--fg-soft);
}

/* ============ floating primary action — the 90% button ============ */
.fab {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  width: min(560px, calc(100% - 32px));
  min-height: var(--tap);
  background: var(--fg);
  color: var(--bg);
  border: var(--hair-thick) solid var(--fg);
  font-family: var(--t-mono);
  font-weight: 900;
  font-size: 22px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  display: flex; align-items: center; justify-content: center;
  gap: 14px;
  box-shadow: 0 -24px 32px -12px var(--bg);
  z-index: 30;
}
.fab:active { transform: translate(-50%, 2px); }
[data-theme='bay'] .fab { background: var(--accent); color: #000; border-color: var(--accent); }

/* ============ modal screens ============ */
.sheet {
  position: fixed; inset: 0;
  background: var(--bg);
  display: grid;
  grid-template-rows: auto 1fr auto;
  z-index: 40;
}
.sheet[hidden] { display: none; }
.sheet-hdr {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  padding: 14px var(--pad);
  border-bottom: var(--hair) solid var(--rule);
  gap: 12px;
}
.sheet-hdr .back {
  min-width: var(--tap); min-height: var(--tap);
  font-family: var(--t-mono); font-weight: 900; font-size: 28px;
  display: flex; align-items: center; justify-content: center;
}
.sheet-hdr h1 {
  margin: 0;
  font-family: var(--t-display);
  font-weight: 700;
  font-size: 24px;
  letter-spacing: -0.01em;
}
.sheet-hdr .sub {
  font-family: var(--t-mono); font-size: 12px; font-weight: 700;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--fg-soft);
}
.sheet-body { padding: var(--pad); overflow-y: auto; }
.sheet-foot {
  padding: 14px var(--pad) calc(env(safe-area-inset-bottom, 0px) + 14px);
  border-top: var(--hair) solid var(--rule);
  background: var(--bg);
}

/* ============ hours entry screen ============ */
.hours-display {
  font-family: var(--t-mono);
  font-weight: 900;
  font-size: clamp(84px, 22vw, 140px);
  line-height: 1;
  letter-spacing: -0.04em;
  text-align: center;
  padding: 32px 0 12px;
}
.hours-display.empty { color: var(--fg-faint); }
.hours-display .unit {
  display: block;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.22em;
  color: var(--fg-soft);
  margin-top: 8px;
}
.hours-current {
  text-align: center;
  font-family: var(--t-mono);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-soft);
  padding-bottom: 20px;
  border-bottom: var(--hair) solid var(--rule);
  margin-bottom: 24px;
}

/* custom numeric keypad — full width, keys size of a pack of gum */
.pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.key {
  min-height: 84px;
  border: var(--hair-thick) solid var(--rule);
  font-family: var(--t-mono);
  font-weight: 900;
  font-size: 40px;
  background: var(--bg);
  color: var(--fg);
}
.key:active { background: var(--fg); color: var(--bg); }
.key.wide { font-size: 22px; letter-spacing: 0.14em; }

.submit {
  width: 100%;
  min-height: var(--tap);
  background: var(--fg);
  color: var(--bg);
  border: var(--hair-thick) solid var(--fg);
  font-family: var(--t-mono);
  font-weight: 900;
  font-size: 22px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.submit:active { transform: translateY(2px); }
.submit[disabled] { opacity: 0.35; }
[data-theme='bay'] .submit { background: var(--accent); color: #000; border-color: var(--accent); }
.account-passkey {
  margin-top: 28px;
}
.account-status {
  border: var(--hair-thick) solid var(--rule);
  background: var(--bg-alt);
  padding: 16px;
  margin-bottom: 20px;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.35;
}
.account-status[data-state='error'] {
  background: var(--accent);
  color: var(--accent-fg);
}
.account-status[data-state='success'] {
  background: var(--fg);
  color: var(--bg);
}

/* ============ confirmations — persistent, not toast ============ */
.confirm {
  padding: 20px;
  border: var(--hair-thick) solid var(--rule);
  background: var(--bg-alt);
  margin-bottom: 20px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: start;
}
.confirm .tick {
  font-family: var(--t-mono);
  font-size: 32px;
  font-weight: 900;
  line-height: 1;
}
.confirm .msg {
  font-family: var(--t-display);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: -0.01em;
  line-height: 1.15;
}
.confirm .msg small {
  display: block;
  margin-top: 4px;
  font-family: var(--t-mono);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-soft);
}

/* ============ engine detail hero + stats ============ */
.eng-hero {
  border: var(--hair-thick) solid var(--rule);
  padding: 20px;
  margin-bottom: 12px;
  text-align: center;
}
.eng-hero-hours .n {
  display: block;
  font-family: var(--t-mono);
  font-weight: 900;
  font-size: 72px;
  line-height: 1;
  letter-spacing: -0.03em;
}
.eng-hero-hours .u {
  display: block;
  font-family: var(--t-mono);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.22em;
  color: var(--fg-soft);
  margin-top: 6px;
}
.eng-hero-meta {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  font-family: var(--t-mono);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-soft);
}
.eng-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0;
  border: var(--hair) solid var(--rule);
}
.eng-stat {
  padding: 12px 10px;
  border-right: 1px solid var(--rule);
  text-align: center;
}
.eng-stat:last-child { border-right: 0; }
.eng-stat .l {
  font-family: var(--t-mono);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--fg-soft);
  margin-bottom: 4px;
}
.eng-stat .v {
  font-family: var(--t-display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.01em;
  line-height: 1;
}

/* ============ history list ============ */
.hist {
  border: var(--hair-thick) solid var(--rule);
}
.hist-row {
  display: grid;
  grid-template-columns: 90px 1fr auto;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: var(--hair) solid var(--rule);
  align-items: baseline;
}
.hist-row:last-child { border-bottom: 0; }
.hist-row .h {
  font-family: var(--t-mono);
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 0.02em;
}
.hist-row .e { font-size: 18px; font-weight: 700; }
.hist-row .t {
  font-family: var(--t-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-soft);
}

/* ============ category picker (add engine) ============ */
.cat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.cat {
  min-height: 112px;
  border: var(--hair-thick) solid var(--rule);
  padding: 14px;
  text-align: left;
  display: flex; flex-direction: column; justify-content: space-between;
  font-family: var(--t-display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.01em;
  line-height: 1.1;
  color: var(--fg);
  background: var(--bg);
}
.cat small {
  font-family: var(--t-mono);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-soft);
  margin-top: 10px;
}
.cat:active { background: var(--bg-alt); }
.cat.selected { background: var(--fg); color: var(--bg); }
.cat.selected small { color: var(--bg); }

.field {
  width: 100%;
  min-height: var(--tap);
  padding: 0 16px;
  border: var(--hair-thick) solid var(--rule);
  font-family: var(--t-mono);
  font-weight: 700;
  font-size: 22px;
  background: var(--bg);
  color: var(--fg);
  margin-bottom: 12px;
  display: block;
}
.field-multi {
  padding: 14px 16px;
  font-family: var(--t-text);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.4;
  min-height: 140px;
  resize: vertical;
}

/* ============ inline dictation (Web Speech API) ============ */
.section-label .hint {
  font-family: var(--t-mono);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--fg-soft);
  text-transform: none;
  margin-left: 4px;
}
.mic-wrap {
  position: relative;
  margin-bottom: 12px;
}
.mic-wrap .field {
  margin-bottom: 0;
  padding-right: 72px;
}
.mic-wrap .field.field-multi {
  padding-right: 76px;
}
.mic-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 56px;
  height: 56px;
  border: var(--hair-thick) solid var(--rule);
  background: var(--bg);
  color: var(--fg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.mic-btn svg { width: 26px; height: 26px; display: block; }
.mic-btn:active { background: var(--fg); color: var(--bg); }
.mic-btn.listening {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  animation: mic-pulse 1.1s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent); }
  50%      { box-shadow: 0 0 0 8px transparent; }
}
[data-theme='bay'] .mic-btn.listening { color: #000; }

/* ============ empty state ============ */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  border: var(--hair-thick) dashed var(--rule);
  margin: 30px 0;
}
.empty-state h3 {
  font-family: var(--t-display);
  font-weight: 700;
  font-size: 32px;
  letter-spacing: -0.01em;
  margin: 0 0 10px;
}
.empty-state p {
  color: var(--fg-soft);
  margin: 0 0 0;
  max-width: 36ch;
  margin-left: auto; margin-right: auto;
}

/* ============ welcome (first-run) ============ */
/* display:block + overflow-y:auto (not flex) — flex centering + overflow
   clips content above the scroll origin on desktop and doesn't scroll. */
.welcome {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 100;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 32px 20px;
  padding-top: max(32px, env(safe-area-inset-top));
  padding-bottom: max(32px, env(safe-area-inset-bottom));
}
.welcome-card {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  border: var(--hair-thick) solid var(--rule);
  padding: 28px 24px 20px;
  background: var(--bg);
}
.welcome-kicker {
  font-family: var(--t-mono);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;
}
.welcome-h {
  font-family: var(--t-display);
  font-weight: 700;
  font-size: clamp(36px, 8vw, 48px);
  line-height: 1.04;
  letter-spacing: -0.02em;
  margin: 0 0 24px;
}
.welcome-h em { font-style: italic; color: var(--accent); font-weight: 400; }
.welcome-steps {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
}
/* absolute-positioned number keeps the text flowing as normal paragraph
   text — avoids grid-track width collapse when content is long. */
.welcome-steps li {
  font-size: 18px;
  line-height: 1.45;
  font-weight: 600;
  padding: 14px 0 14px 48px;
  border-top: 1px solid var(--rule);
  position: relative;
}
.welcome-steps li:last-child { border-bottom: 1px solid var(--rule); }
.welcome-steps .n {
  position: absolute;
  left: 0;
  top: 14px;
  font-family: var(--t-display);
  font-style: italic;
  font-weight: 400;
  font-size: 26px;
  line-height: 1.1;
  color: var(--accent);
}
.welcome-steps b { font-weight: 700; }
.welcome-note {
  font-size: 15px;
  color: var(--fg-soft);
  font-weight: 600;
  margin: 0 0 22px;
  line-height: 1.5;
}
.welcome-x {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 44px;
  height: 44px;
  font-family: var(--t-mono);
  font-weight: 900;
  font-size: 18px;
  color: var(--fg-soft);
  background: transparent;
  border: 0;
}
.welcome-x:active { color: var(--fg); }
.welcome-card { position: relative; }

/* ============ banners (install, nudge) ============ */
.banner {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 14px 14px 14px 16px;
  border: var(--hair-thick) solid var(--rule);
  background: var(--bg-alt);
  margin-bottom: 18px;
}
.banner-body { display: flex; flex-direction: column; gap: 2px; line-height: 1.3; }
.banner-body b { font-size: 17px; font-weight: 700; }
.banner-body span { font-size: 14px; color: var(--fg-soft); font-weight: 600; }
.banner-action {
  text-decoration: none;
  font-family: var(--t-mono);
  font-weight: 900;
  font-size: 12px;
  letter-spacing: 0.18em;
  padding: 10px 14px;
  border: var(--hair-thick) solid var(--fg);
  color: var(--fg);
  background: var(--bg);
}
.banner-action:active { background: var(--fg); color: var(--bg); }
.banner-x {
  width: 44px;
  height: 44px;
  font-family: var(--t-mono);
  font-size: 18px;
  font-weight: 900;
  color: var(--fg-soft);
  border: 0;
  background: transparent;
}
.banner.nudge { border-color: var(--accent); }
.banner.nudge b { color: var(--accent); }
[data-theme='bay'] .banner.nudge { background: #1a0f00; }

/* ============ theme button icon ============ */
.theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: auto;
  min-width: 66px;
  padding: 0 10px;
}
.theme-btn #themeIcon { width: 18px; height: 18px; flex: 0 0 18px; }

/* ============ utility ============ */
[hidden] { display: none !important; }
