*, *::before, *::after { box-sizing: border-box; }

html { height: 100%; }

/* The [hidden] attribute must win over component display rules (e.g. flex). */
[hidden] { display: none !important; }

:root {
  --bg: #f3f4f6;
  --panel: #fff;
  --border: #d4d8df;
  --text: #171a1f;
  --muted: #687281;
  --accent: #0f766e;              /* teal — matches the other tools */
  --accent-soft: rgba(15, 118, 110, .12);
  --speed: #6d28d9;              /* violet — expected airspeed cue */
  --speed-soft: rgba(109, 40, 217, .10);
  --info-blue: #2563eb;
  --warn-bg: #fef3c7;
  --warn-border: #f0c869;
  --warn-text: #92400e;
  --radius: 10px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}

/* --- Top bar ------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.title-block { display: grid; gap: 1px; }

.topbar h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
  white-space: nowrap;
}

.tail {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .02em;
  white-space: nowrap;
}

.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* --- Main layout -------------------------------------------------------- */
main {
  flex: 1;
  width: 100%;
  max-width: 30rem;
  margin: 0 auto;
  padding: 12px;
  display: grid;
  gap: 12px;
  align-content: start;
}

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

.card.inputs { display: grid; gap: 12px; }

/* --- Fields / steppers -------------------------------------------------- */
.field { display: grid; gap: 6px; }

.field > label {
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
}
.field .unit { font-weight: 500; opacity: .8; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stepper {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 46px;
  gap: 8px;
  align-items: stretch;
}

.step-btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--accent);
  font-size: 22px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  -webkit-user-select: none;
}
.step-btn:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.step-btn:active:not(:disabled) { background: var(--accent-soft); }
.step-btn:disabled { opacity: .4; cursor: default; }

.num-val {
  width: 100%;
  min-width: 0;               /* shrink inside the stepper grid track */
  height: 46px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 20px;
  font-weight: 650;
  text-align: center;
  font-variant-numeric: tabular-nums;
  cursor: pointer;                /* tap value = set standard */
}
.num-val:focus { outline: none; }
/* readonly number fields: hide spinners */
.num-val::-webkit-outer-spin-button,
.num-val::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.num-val[type="number"] { -moz-appearance: textfield; }

/* Value is at its standard setting (29.92 / ISA) */
.tap-std.is-standard {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  color: var(--accent);
}

/* --- Info line ---------------------------------------------------------- */
.info-line {
  margin: -2px 0 0;
  min-height: 1.1em;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* --- Power buttons ------------------------------------------------------ */
.power-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.power-btn {
  display: grid;
  gap: 2px;
  padding: 9px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  touch-action: manipulation;
}
.power-btn:hover { border-color: var(--accent); }
.power-btn.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}
.pb-title { font-size: 13px; font-weight: 650; }
.pb-sub { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.power-btn.active .pb-sub { color: rgba(255, 255, 255, .85); }
.pb-nowrap { white-space: nowrap; }

/* --- Results ------------------------------------------------------------ */
.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.result {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfbfc;
}
.result-label { font-size: 11px; font-weight: 650; color: var(--muted); }
.result-value {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.result-unit { font-size: 12px; font-weight: 500; color: var(--muted); }
.result-na { font-size: 15px; font-weight: 600; color: var(--muted); }

.result.speed { cursor: pointer; background: var(--speed-soft); border-color: rgba(109, 40, 217, .25); }
.result.speed .result-value { color: var(--speed); }
.result.speed.showing-ias .result-value { color: var(--info-blue); }
.result.speed.showing-ias { background: rgba(37, 99, 235, .08); border-color: rgba(37, 99, 235, .25); }

.warnings { display: grid; gap: 8px; }
.warnings:empty { display: none; }
.warning {
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid var(--warn-border);
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 12px;
}

/* --- Footer ------------------------------------------------------------- */
.disclaimer {
  padding: 10px 14px;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--panel);
}
.disclaimer .ver { opacity: .6; }

/* --- Dialogs ------------------------------------------------------------ */
.dialog {
  width: min(94vw, 26rem);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  color: var(--text);
  background: var(--panel);
}
.dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dialog-body { padding: 16px; }
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.dialog-head h2 { margin: 0; font-size: 17px; }
.dialog h3 { margin: 14px 0 6px; font-size: 13px; color: var(--accent); }
.dialog ul { margin: 0 0 4px; padding-left: 18px; }
.dialog li { font-size: 13px; margin-bottom: 5px; line-height: 1.35; }

.seg {
  display: inline-grid;
  grid-auto-flow: column;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.seg-btn {
  padding: 7px 14px;
  border: 0;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.seg-btn.active { background: var(--accent); color: #fff; }

.bias-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.bias-row input {
  width: 5.5rem;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.bias-row .unit { font-size: 13px; color: var(--muted); }
.hint { margin: 8px 0 0; font-size: 12px; color: var(--muted); line-height: 1.35; }

.dialog-actions { display: flex; gap: 8px; margin-top: 16px; }
.btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { color: var(--muted); }

.help-note {
  margin: 14px 0 0;
  padding: 10px;
  border-radius: 8px;
  background: var(--accent-soft);
  font-size: 12px;
  line-height: 1.4;
}
.help-ref { margin: 12px 0 0; font-size: 12px; color: var(--muted); }

/* Larger screens: give the calculator a touch more presence, stay centered */
@media (min-width: 32rem) {
  .topbar h1 { font-size: 18px; }
  .result-value { font-size: 26px; }
}
