/* Wind Aloft — Low & Slow. Aviator's Toolkit dark tokens. */

:root {
  --bg: #141418;
  --cream: #FDF6E3;
  --ink: #e7e3d6;
  --muted: #8d8a7e;
  --red: #C0392B;
  --grass: #2e7d32;
  --amber: #d98324;
  --line: #2c2c33;
  --panel: #1c1c22;
  --radius: 10px;
  --tap: 44px;
}

/* B612 — bundled locally (no CDN). */
@font-face {
  font-family: "B612";
  src: url("fonts/B612-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "B612";
  src: url("fonts/B612-Bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "B612 Mono";
  src: url("fonts/B612Mono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

* { box-sizing: border-box; }

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

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}

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

/* ---- Header ---- */
.hdr h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--cream);
  margin: 0;
  letter-spacing: -0.01em;
}
.hdr-sub { color: var(--muted); font-weight: 400; }
.subhead { color: var(--muted); margin: 4px 0 0; font-size: 0.95rem; }

/* ---- Controls ---- */
.controls {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.field-row { display: flex; gap: 8px; align-items: stretch; }
.select-wrap { flex: 1; position: relative; }
.field-select {
  width: 100%;
  min-height: var(--tap);
  background: var(--panel);
  color: var(--cream);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 36px 0 12px;
  font: inherit;
  font-size: 1.05rem;
  appearance: none;
  -webkit-appearance: none;
}
.select-wrap::after {
  content: "▾";
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.icon-btn {
  min-width: var(--tap);
  min-height: var(--tap);
  background: var(--red);
  color: var(--cream);
  border: none;
  border-radius: var(--radius);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.icon-btn--ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 1.1rem;
}

.ceiling-row { display: flex; align-items: center; gap: 10px; }
.ceiling-row label { color: var(--ink); min-width: 56px; }
.ceiling-row input {
  width: 100px;
  min-height: var(--tap);
  background: var(--panel);
  color: var(--cream);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  font: inherit;
  font-size: 1.05rem;
}
.unit { color: var(--muted); font-size: 0.9rem; }

.when-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.when-row label { color: var(--ink); min-width: 56px; }
.when-row input[type="date"],
.when-row input[type="time"] {
  min-height: var(--tap);
  background: var(--panel);
  color: var(--cream);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 10px;
  font: inherit;
  font-size: 0.95rem;
}
.when-row input[type="date"] { flex: 1.3; min-width: 0; }
.when-row input[type="time"] { flex: 1; min-width: 0; }
.when-hint {
  width: 100%;
  color: var(--muted);
  font-size: 0.8rem;
  font-family: "B612 Mono", monospace;
}

/* ---- Meta ---- */
.meta {
  margin: 18px 0 10px;
  color: var(--muted);
  font-family: "B612 Mono", monospace;
  font-size: 0.9rem;
  min-height: 1.2em;
}
.meta--offline { color: var(--red); }
.decl-note {
  margin: -6px 0 8px;
  color: var(--amber);
  font-family: "B612 Mono", monospace;
  font-size: 0.78rem;
}

/* ---- Weather grid (4-column forecast table) ---- */
.stack-area { display: flex; flex-direction: column; }

/*
 * Grid layout: alt-label col + 4 equal time cols.
 * Rows are rendered low→high in the DOM; flex-direction:column-reverse
 * flips them so ground (Surface) is at the bottom of the screen.
 */
.wx-grid {
  display: flex;
  flex-direction: column-reverse; /* ground at bottom */
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

/* Header row is not reversed — it sits above the data visually. We pull it
   out of the reverse flow by making it order:1 (data rows default to order:0). */
.wx-hdr {
  display: grid;
  grid-template-columns: 60px repeat(4, 1fr);
  border-top: 1px solid var(--line);
  background: #1a1a21;
  order: 1; /* always on top regardless of column-reverse */
}
.wx-hdr__alt { /* empty corner */ }
.wx-hdr__time {
  padding: 6px 4px;
  text-align: center;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.hdr-label {
  color: var(--cream);
  font-weight: 700;
  font-size: 0.8rem;
}
.hdr-sub {
  color: var(--muted);
  font-size: 0.68rem;
  font-family: "B612 Mono", monospace;
}

/* Each AGL row */
.wx-row {
  display: grid;
  grid-template-columns: 60px repeat(4, 1fr);
  border-top: 1px solid var(--line);
  min-height: 64px;
}
.wx-row--surface {
  background: #1a1a20;
  border-top: 2px solid var(--line);
}

/* Alt label */
.wx-row__alt {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-end;
  padding: 4px 8px 4px 4px;
  border-right: 1px solid var(--line);
  background: #181820;
}
.wx-row__alt .agl {
  font-weight: 700;
  color: var(--cream);
  font-size: 0.82rem;
  font-family: "B612 Mono", monospace;
  white-space: nowrap;
}
.wx-row__alt .msl {
  color: var(--muted);
  font-size: 0.62rem;
  font-family: "B612 Mono", monospace;
  white-space: nowrap;
}

/* Data cell */
.wx-cell {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 4px 3px;
  border-left: 1px solid var(--line);
  gap: 3px;
}
.wx-cell--empty {
  color: var(--muted);
  font-size: 0.8rem;
  justify-content: center;
  align-items: center;
}

/* Speed bar inside each cell */
.cell-bar {
  width: 100%;
  height: 6px;
  background: #26262d;
  border-radius: 3px;
  overflow: hidden;
}
.cell-fill {
  height: 100%;
  border-radius: 3px;
  /* color set inline by cellEl based on absolute speed */
}

/* Arrow + speed text row */
.cell-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}
.cell-arrow {
  width: 18px;
  height: 24px;
  color: var(--cream);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cell-arrow svg { display: block; width: 100%; height: 100%; }
.cell-spd {
  font-weight: 700;
  color: var(--cream);
  font-family: "B612 Mono", monospace;
  font-size: 0.82rem;
  white-space: nowrap;
}
.cell-unit { color: var(--muted); font-weight: 400; font-size: 0.68rem; }
.cell-dir {
  color: var(--muted);
  font-family: "B612 Mono", monospace;
  font-size: 0.65rem;
  line-height: 1;
}

/* ---- Skeleton (loading) ---- */
.wx-grid--loading .wx-row {
  min-height: 52px;
}
.sk { background: #22222a; border-radius: 4px; }
.sk--hdr { height: 28px; margin: 8px 6px; }
.sk--label { height: 28px; margin: 10px 6px; }
.sk--cell { height: 34px; margin: 8px 4px; }
@media (prefers-reduced-motion: no-preference) {
  .sk { animation: pulse 1.2s ease-in-out infinite; }
  @keyframes pulse { 0%,100% { opacity: .4; } 50% { opacity: .9; } }
}

/* ---- Empty / message states ---- */
.state {
  text-align: center;
  padding: 40px 16px;
  color: var(--ink);
}
.state h2 { color: var(--cream); font-size: 1.15rem; margin: 0 0 8px; }
.state p { color: var(--muted); margin: 0 0 18px; }
.state--error h2 { color: var(--red); }

/* ---- Buttons ---- */
.btn {
  width: 100%;
  min-height: var(--tap);
  border-radius: var(--radius);
  border: none;
  font: inherit;
  font-size: 1.05rem;
  cursor: pointer;
}
.btn--primary { background: var(--red); color: var(--cream); }
.btn--ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn--inline { width: auto; padding: 0 18px; }

.banner {
  margin: 8px 0;
  padding: 8px 12px;
  border: 1px solid var(--red);
  border-radius: var(--radius);
  color: var(--red);
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.banner--update {
  border-color: var(--grass);
  color: var(--grass);
  margin-top: 14px;
}
.banner--update .btn--ghost { border-color: var(--grass); color: var(--grass); }

/* ---- Honesty + footer ---- */
.honesty {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
.ftr {
  margin-top: 24px;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}
.ftr a { color: var(--muted); }

/* ---- Picker overlay ---- */
.picker {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.picker-hdr {
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--line);
}
.link-btn {
  background: none;
  border: none;
  color: var(--cream);
  font: inherit;
  font-size: 1.05rem;
  cursor: pointer;
  min-height: var(--tap);
  padding: 0;
}
.picker-body { padding: 16px; max-width: 560px; margin: 0 auto; width: 100%; }

.map {
  width: 100%;
  height: 300px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.map-offline {
  color: var(--red);
  font-size: 0.9rem;
  margin: 12px 0;
}

.picker-form { margin-top: 16px; display: flex; flex-direction: column; gap: 14px; }
.picker-form label {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 4px;
}
.picker-form input {
  width: 100%;
  min-height: var(--tap);
  background: var(--panel);
  color: var(--cream);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  font: inherit;
}
.coord-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.elev-row { display: grid; grid-template-columns: auto 120px auto; align-items: end; gap: 10px; }
.elev-row label { margin-bottom: 8px; }
.elev-row .unit { padding-bottom: 12px; }
.elev-hint { color: var(--muted); font-size: 0.82rem; margin: -8px 0 0; min-height: 1em; }
.picker-err { color: var(--red); font-size: 0.85rem; margin: 0; }
.or { text-align: center; color: var(--muted); font-size: 0.85rem; }
.fallback-row { display: flex; gap: 10px; }

/* ---- Settings ---- */
.settings {
  margin-top: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.settings-summary {
  list-style: none;
  padding: 12px 16px;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
}
.settings-summary::-webkit-details-marker { display: none; }
.settings-summary::before {
  content: "▸";
  transition: transform 0.15s;
  display: inline-block;
}
.settings[open] .settings-summary::before { transform: rotate(90deg); }
.settings-body {
  padding: 0 16px 16px;
  border-top: 1px solid var(--line);
}
.setting-group {
  border: none;
  margin: 12px 0 0;
  padding: 0;
}
.setting-group legend {
  color: var(--ink);
  font-size: 0.9rem;
  margin-bottom: 10px;
  padding: 0;
}
.radio-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
  min-height: var(--tap);
}
.radio-row:last-child { border-bottom: none; }
.radio-row input[type="radio"] {
  margin-top: 3px;
  accent-color: var(--red);
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  cursor: pointer;
}
.radio-row strong { color: var(--cream); }
.radio-sub {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 2px;
}

/* Sub-setting row (indented, under a radio option) */
.sub-setting {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 0 8px 28px;
  border-bottom: 1px solid var(--line);
}
.sub-setting-label {
  color: var(--muted);
  font-size: 0.82rem;
  flex: 0 0 auto;
}
.sub-radio-row {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  min-height: var(--tap);
  font-size: 0.88rem;
  color: var(--ink);
}
.sub-radio-row input[type="radio"] {
  accent-color: var(--red);
  width: 16px;
  height: 16px;
  cursor: pointer;
}
.sub-setting--disabled {
  opacity: 0.38;
  pointer-events: none;
}

/* ---- Wind threshold dual-range slider ---- */
.thresh-slider {
  position: relative;
  padding: 8px 0 0;
  user-select: none;
}

.thresh-track {
  position: absolute;
  top: 20px;
  left: 0;
  right: 0;
  height: 6px;
  border-radius: 3px;
  pointer-events: none;
  /* background painted by JS */
}

.thresh-input {
  position: absolute;
  top: 8px;
  left: 0;
  width: 100%;
  height: 20px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  pointer-events: none;
}

.thresh-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--cream);
  border: 2px solid var(--line);
  cursor: pointer;
  pointer-events: all;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  transition: border-color 0.15s;
}
.thresh-input::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--cream);
  border: 2px solid var(--line);
  cursor: pointer;
  pointer-events: all;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
.thresh-input:focus::-webkit-slider-thumb { border-color: var(--cream); outline: 2px solid var(--cream); }
.thresh-input:focus { outline: none; }

/* space below the track for labels */
.thresh-labels {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 32px;
  font-family: "B612 Mono", monospace;
  font-size: 0.72rem;
}
.thresh-label--green { color: var(--grass); }
.thresh-label--amber { color: var(--amber); }
.thresh-label--red   { color: var(--red); }
.thresh-label--lo,
.thresh-label--hi {
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  white-space: nowrap;
}

/* Toggle switch */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  cursor: pointer;
  min-height: var(--tap);
}
.toggle-row input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0; height: 0;
}
.toggle-track {
  flex: 0 0 auto;
  width: 42px; height: 24px;
  background: var(--line);
  border-radius: 12px;
  position: relative;
  transition: background 0.2s;
}
.toggle-row input:checked ~ .toggle-track { background: var(--red); }
.toggle-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  background: var(--cream);
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle-row input:checked ~ .toggle-track .toggle-thumb { transform: translateX(18px); }
.toggle-row strong { color: var(--cream); }
.setting-note {
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.5;
  margin: 4px 0 0;
  padding: 0;
}

/* ---- Weather History panel ---- */
.hist-body {
  padding-bottom: 16px;
}
.hist-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.hist-empty {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 8px 0 0;
  line-height: 1.5;
}
.hist-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--panel);
}
.hist-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.hist-field {
  font-weight: 700;
  color: var(--cream);
  font-size: 0.9rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hist-view,
.hist-del {
  min-width: 32px;
  min-height: 32px;
  font-size: 0.8rem;
  flex: 0 0 auto;
}
.hist-times {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.hist-req {
  font-family: "B612 Mono", monospace;
  font-size: 0.78rem;
  color: var(--ink);
}
.hist-valid {
  font-family: "B612 Mono", monospace;
  font-size: 0.72rem;
  color: var(--muted);
}
.hist-clear {
  margin-top: 14px;
  display: block;
}

/* Focus visibility everywhere */
:focus-visible {
  outline: 2px solid var(--cream);
  outline-offset: 2px;
}

[hidden] { display: none !important; }
