/* WingsLevel PWA. dp -> CSS px, sp -> CSS px (default font scale). */
:root {
  --primary: #66BB6A;
  --on-primary: #0B0C0F;
  --surface: #0B0C0F;
  --on-surface: #EDEDED;
  --night-text: #FF4444;
  --mono: 'Roboto Mono', 'Droid Sans Mono', 'DejaVu Sans Mono', Menlo, Consolas, monospace;
  --sans: Roboto, 'Segoe UI', system-ui, -apple-system, Helvetica, Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: #000; color: var(--on-surface);
  font-family: var(--sans); overflow: hidden; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
#app { position: fixed; inset: 0; background: #000; overflow: hidden; }
button { font: inherit; color: inherit; }
canvas { display: block; }

/* ---------------------------------------------------------------- Disclaimer */
.disclaimer { position: absolute; inset: 0; background: #121212; overflow-y: auto; }
.disclaimer-col {
  min-height: 100%; padding: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  max-width: 640px; margin: 0 auto;
}
.disclaimer-icon { width: 64px; height: 64px; flex: none; }
.disclaimer-title { font-size: 28px; line-height: 36px; font-weight: 700; color: #fff; text-align: center; }
.disclaimer-card { background: #222; border-radius: 8px; padding: 16px; align-self: stretch; }
.disclaimer-card-title { font-size: 16px; line-height: 24px; font-weight: 700; color: #FF5555; padding-bottom: 8px; letter-spacing: .15px; }
.disclaimer-card-body { font-size: 16px; line-height: 24px; color: #fff; letter-spacing: .5px; }
.disclaimer-bullets { align-self: stretch; color: #CCCCCC; font-size: 16px; line-height: 24px; letter-spacing: .5px; }
.disclaimer-bullets > div + div { margin-top: 4px; }
.disclaimer-check {
  align-self: stretch; display: flex; align-items: center; gap: 8px; padding: 8px; cursor: pointer;
  color: #fff; font-size: 16px; line-height: 24px; letter-spacing: .5px;
}
.m3-checkbox {
  flex: none; width: 18px; height: 18px; margin: 11px; border: 2px solid #C4C7C5; border-radius: 2px; position: relative;
}
.m3-checkbox.checked { background: var(--primary); border-color: var(--primary); }
.m3-checkbox.checked::after {
  content: ''; position: absolute; left: 4px; top: 0; width: 5px; height: 10px;
  border: solid var(--on-primary); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.disclaimer-accept { align-self: stretch; height: 56px; font-size: 18px !important; font-weight: 700 !important; }

/* ---------------------------------------------------------------- Material-style controls */
.m3-button {
  display: flex; align-items: center; justify-content: center; width: 100%; min-height: 40px; padding: 10px 24px;
  border: 0; border-radius: 20px; background: var(--primary); color: var(--on-primary);
  font-size: 14px; font-weight: 500; letter-spacing: .1px; line-height: 20px; cursor: pointer; text-align: center;
}
.m3-button:active { filter: brightness(1.12); }
.m3-button:disabled { background: rgba(237, 237, 237, .12); color: rgba(237, 237, 237, .38); cursor: default; filter: none; }
.m3-button.tall { height: 60px; }

.m3-field { position: relative; display: block; width: 100%; }
.m3-field-input {
  width: 100%; height: 56px; padding: 16px; border: 1px solid #8E918F; border-radius: 4px; background: transparent;
  color: var(--on-surface); font-size: 16px; letter-spacing: .5px; outline: none;
  -webkit-user-select: text; user-select: text;
}
.m3-field-input:focus { border: 2px solid var(--primary); padding: 15px; }
.m3-field-label {
  position: absolute; left: 12px; top: 16px; padding: 0 4px; color: #C4C7C5; font-size: 16px; line-height: 24px;
  pointer-events: none; transition: all .15s; background: #000;
}
.m3-field-input:focus + .m3-field-label,
.m3-field-input:not(:placeholder-shown) + .m3-field-label { top: -10px; font-size: 12px; line-height: 16px; }
.m3-field-input:focus + .m3-field-label { color: var(--primary); }

.m3-switch {
  flex: none; position: relative; width: 52px; height: 32px; border-radius: 16px; border: 2px solid #8E918F; background: #333537;
}
.m3-switch::after {
  content: ''; position: absolute; top: 6px; left: 6px; width: 16px; height: 16px; border-radius: 50%; background: #8E918F;
  transition: all .15s;
}
.m3-switch.checked { background: #1B5E20; border-color: #1B5E20; }
.m3-switch.checked::after { left: 22px; top: 2px; width: 24px; height: 24px; background: var(--primary); }
.sheet.night .m3-switch.checked { background: #330000; border-color: #330000; }
.sheet.night .m3-switch.checked::after { background: var(--night-text); }

/* ---------------------------------------------------------------- Main layout */
.main { position: absolute; inset: 0; display: flex; background: #000; overflow: hidden; }
.main.portrait { flex-direction: column; }
.main.landscape { flex-direction: row; }
.main > * { flex: 1 1 0; min-width: 0; min-height: 0; }

/* ---------------------------------------------------------------- Attitude pane */
.att-pane { position: relative; overflow: hidden; }
.att-row { position: absolute; inset: 0; display: flex; flex-direction: row; align-items: center; }
.tape-wrap { flex: none; height: 70%; padding: 8px 0; }
.tape-wrap > canvas { height: 100%; }
.tape-speed { width: 28px; }
.tape-alt { width: 36px; }
.tape-vsi { width: 24px; }
.att-center { position: relative; flex: 1 1 0; min-width: 0; height: 100%; padding: 8px 0; }
.att-center > .att-canvas, .att-center > .svt-canvas {
  position: absolute; left: 0; right: 0; top: 8px; bottom: 8px; width: 100%; height: calc(100% - 16px);
}
.svt-msg { position: absolute; left: 8px; bottom: 16px; font-size: 10px; line-height: 16px; color: #fff; letter-spacing: .5px; }
.turnslip { position: absolute; left: 50%; bottom: 18px; width: 150px; height: 64px; transform: translateX(-50%); pointer-events: none; }

.small-label { font-size: 10px; line-height: 16px; letter-spacing: .5px; color: #fff; font-weight: 500; white-space: pre; }
.att-topleft {
  position: absolute; left: 0; top: 0; padding: 12px; display: flex; flex-direction: column; gap: 8px; z-index: 2;
}
.status-row { display: flex; flex-direction: row; align-items: center; gap: 8px; }
.status-gps { width: 22px; height: 22px; }
.status-batt { width: 28px; height: 22px; }
.icon-btn {
  width: 36px; height: 36px; padding: 8px; border: 0; border-radius: 50%; background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: rgba(255, 255, 255, .12); }
.icon-btn svg { width: 20px; height: 20px; }

.att-overlay { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.att-overlay > * { pointer-events: auto; }
.debug-overlay { position: absolute; top: 0; right: 0; padding: 12px; text-align: left; pointer-events: none !important; }
.no-sensor { position: absolute; left: 0; bottom: 0; padding: 16px; font-size: 16px; line-height: 24px; color: var(--on-surface); }
.compass-wrap {
  position: absolute; top: 0; left: 50%; width: 65%; height: 32px; transform: translateX(-50%); overflow: hidden; pointer-events: none !important;
}
.compass-wrap > canvas { width: 100%; height: 100%; }
.hint {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, calc(-50% - 48px)); pointer-events: none !important;
}
.hint-box {
  background: rgba(0, 0, 0, .8); border-radius: 8px; padding: 16px 24px; display: flex; flex-direction: column; align-items: center;
}
.hint-text { color: #fff; font-size: 16px; line-height: 24px; font-weight: 500; text-align: center; letter-spacing: .15px; white-space: nowrap; }
.hint-progress { margin-top: 8px; width: 180px; height: 6px; border-radius: 3px; background: #444; overflow: hidden; }
.hint-progress-fill { height: 100%; width: 0; background: var(--primary); border-radius: 3px; }
.fs-btn {
  position: absolute; top: 4px; right: 4px; width: 48px; height: 48px; padding: 8px; border: 0; border-radius: 50%;
  background: transparent; cursor: pointer;
}
.fs-circle {
  display: flex; width: 100%; height: 100%; padding: 6px; border-radius: 50%; background: rgba(0, 0, 0, .5); border: 1px solid #fff;
}
.fs-circle svg { width: 100%; height: 100%; }

/* ---------------------------------------------------------------- HSI pane */
.hsi-pane { position: relative; background: #000; overflow: hidden; }
.hsi-view, .sub-screen { position: absolute; inset: 0; }
.hsi-canvas, .hsi-gesture { position: absolute; inset: 0; width: 100%; height: 100%; }
.hsi-gesture { touch-action: none; }
.hsi-hdg {
  position: absolute; left: 50%; transform: translateX(-50%); background: #000; border: 2px solid #fff; padding: 2px 10px;
  font-family: var(--mono); font-weight: 700; line-height: 1.2; white-space: nowrap; pointer-events: none;
}
.hsi-readouts { position: absolute; display: flex; flex-direction: column; gap: 0; font-family: var(--mono); font-weight: 700; }
.hsi-readout { padding: 0 6px; line-height: 1.17; margin-bottom: -3px; white-space: nowrap; pointer-events: none; }
.hsi-readout.clickable { pointer-events: auto; cursor: pointer; }
.dt-banner {
  position: absolute; top: 0; left: 0; right: 0; padding: 6px 120px 0 72px; color: #FF00FF; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.4; cursor: pointer; letter-spacing: .4px;
}
.dt-banner:empty { display: none; }
/* Direct-To keys: styled after avionics bezel softkeys (dark key, legend glyph + caption). */
.dt-btn {
  position: absolute; left: 12px; width: 60px; height: 60px; padding: 6px 0 5px; border-radius: 7px;
  background: linear-gradient(#2e2e2e, #151515); border: 1px solid #5a5a5a; cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.14), 0 2px 4px rgba(0,0,0,.6);
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  -webkit-tap-highlight-color: transparent;
}
.dt-btn:active { background: linear-gradient(#151515, #222); box-shadow: inset 0 2px 4px rgba(0,0,0,.7); }
.dt-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.dt-set { top: 12px; }
.dt-cancel { bottom: 12px; }
/* Annunciator bar: lit while a Direct-To is active, like a softkey whose function is engaged. */
.dt-set::after {
  content: ''; position: absolute; left: 14px; right: 14px; top: 3px; height: 3px; border-radius: 2px; background: #3a3a3a;
}
.dt-set.active::after { background: #FF00FF; box-shadow: 0 0 4px #FF00FF; }
.dt-svg { width: 38px; height: 28px; margin-top: 4px; }
.dt-set .dt-glyph { stroke: #FF00FF; }
.dt-set .dt-head { fill: #FF00FF; }
.dt-cancel .dt-glyph { stroke: #9a9a9a; }
.dt-cancel .dt-head { fill: #9a9a9a; }
.dt-knock { stroke: #202020; }
.dt-strike { stroke: #FF3B30; }
.dt-caption { font-family: var(--mono); font-weight: 700; font-size: 10px; letter-spacing: .8px; line-height: 1; color: #e6e6e6; }

.round-btn {
  position: absolute; top: 12px; left: 12px; width: 48px; height: 48px; border-radius: 50%; background: #000;
  border: 2px solid #fff; color: #fff; font-size: 16px; line-height: 24px; letter-spacing: .5px; padding: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center; z-index: 2;
}

/* ---------------------------------------------------------------- Direct-To screens */
.dt-menu { position: absolute; inset: 0; padding: 16px; display: flex; flex-direction: column; justify-content: center; align-items: center; }
.dt-search, .dt-nearest, .dt-info {
  position: absolute; inset: 0; padding: 56px 16px 16px; display: flex; flex-direction: column; overflow: hidden;
}
.dt-nearest, .dt-info { padding-top: 76px; }
.dt-info { overflow-y: auto; display: block; }
.dt-results { flex: 1 1 0; overflow-y: auto; min-height: 0; }
.dt-empty { text-align: center; padding-top: 24px; color: #fff; font-size: 16px; line-height: 24px; }
.dt-nogps { padding-top: 24px; color: #fff; font-size: 16px; line-height: 24px; }
.dt-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 8px; cursor: pointer; }
.dt-row:active { background: rgba(255, 255, 255, .08); }
.dt-row-main { flex: 1 1 0; min-width: 0; padding-right: 12px; }
.dt-row-code { color: #fff; font-size: 16px; line-height: 24px; letter-spacing: .5px; }
.dt-row-sub {
  color: rgba(255, 255, 255, .7); font-size: 16px; line-height: 24px; letter-spacing: .5px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.dt-row-dist { flex: none; width: 22%; text-align: right; white-space: nowrap; color: rgba(255, 255, 255, .85); font-size: 16px; line-height: 24px; }
.dt-info-title {
  color: #fff; font-size: 16px; line-height: 24px; font-weight: 500; letter-spacing: .15px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.dt-info-section { color: #fff; font-size: 14px; line-height: 20px; font-weight: 500; letter-spacing: .1px; }
.dt-info-row { color: #fff; font-size: 14px; line-height: 20px; letter-spacing: .25px; padding: 2px 0; -webkit-user-select: text; user-select: text; }

/* ---------------------------------------------------------------- Settings sheet */
.scrim { position: absolute; inset: 0; z-index: 10; background: rgba(0, 0, 0, 0); transition: background .2s; display: flex; align-items: flex-end; justify-content: center; }
.scrim.open { background: rgba(0, 0, 0, .32); }
.sheet {
  width: 100%; max-width: 640px; max-height: calc(100% - 56px); display: flex; flex-direction: column;
  background: var(--surface); border-radius: 28px 28px 0 0; transform: translateY(100%); transition: transform .2s ease-out;
}
.scrim.open .sheet { transform: translateY(0); }
.sheet.night { background: #111111; }
.sheet-handle-area { flex: none; padding: 22px 0; display: flex; justify-content: center; touch-action: none; cursor: grab; }
.sheet-handle { width: 32px; height: 4px; border-radius: 2px; background: rgba(196, 199, 197, .4); }
.sheet-content { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.sheet-title { font-size: 24px; line-height: 32px; color: var(--on-surface); }
.sheet.night .sheet-title, .sheet.night .sheet-row-label { color: var(--night-text); }
.sheet-row { display: flex; align-items: center; padding: 8px 0; cursor: pointer; }
.sheet-row-label { flex: 1; font-size: 16px; line-height: 24px; letter-spacing: .5px; color: var(--on-surface); }

/* Offline terrain tiles (settings sheet) */
.sheet-group { display: flex; flex-direction: column; gap: 8px; }
.sheet-progress { width: 100%; margin-top: 0; }
.sheet-status { font-size: 12px; line-height: 16px; letter-spacing: .4px; color: #C4C7C5; white-space: pre-line; }
.sheet-status:empty { display: none; }
.sheet.night .sheet-status { color: var(--night-text); }

/* Screen orientation (settings sheet): two-way segmented choice */
.seg { display: flex; border: 1px solid #8E918F; border-radius: 20px; overflow: hidden; }
.seg-btn {
  flex: 1; min-height: 40px; border: 0; background: transparent; color: var(--on-surface);
  font-size: 14px; font-weight: 500; letter-spacing: .1px; cursor: pointer;
}
.seg-btn + .seg-btn { border-left: 1px solid #8E918F; }
.seg-btn.selected { background: var(--primary); color: var(--on-primary); }
.sheet.night .seg { border-color: var(--night-text); }
.sheet.night .seg-btn { color: var(--night-text); }
.sheet.night .seg-btn.selected { background: #330000; }

/* Realign prompt after the screen orientation changed */
.scrim.realign { align-items: center; padding: 24px; z-index: 20; }
.dialog {
  width: 100%; max-width: 420px; padding: 24px; border-radius: 28px; background: #1E2022;
  display: flex; flex-direction: column; gap: 16px;
}
.dialog-title { font-size: 24px; line-height: 32px; color: var(--on-surface); }
.dialog-body { font-size: 14px; line-height: 20px; letter-spacing: .25px; color: #C4C7C5; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.dialog-actions .m3-button { width: auto; }
.text-btn { border: 0; background: transparent; color: var(--primary); font-size: 14px; font-weight: 500; padding: 10px 12px; cursor: pointer; }
.realign.night .dialog { background: #111111; }
.realign.night .dialog-title, .realign.night .dialog-body, .realign.night .text-btn { color: var(--night-text); }
.realign.night .m3-button { background: #330000; color: var(--night-text); }

/* Flight recorder indicator (status row) */
.rec-indicator {
  color: #FF3B30; font-size: 12px; font-weight: 700; letter-spacing: .5px; font-family: var(--mono);
  background: rgba(0, 0, 0, .55); border-radius: 4px; padding: 2px 6px; white-space: nowrap;
}

/* ---------------------------------------------------------------- Terrain manager */
.tm-overlay { position: absolute; inset: 0; z-index: 12; background: rgba(0, 0, 0, 0); transition: background .2s; display: flex; justify-content: center; }
.tm-overlay.open { background: rgba(0, 0, 0, .32); }
.tm {
  width: 100%; max-width: 640px; height: 100%; display: flex; flex-direction: column; background: var(--surface);
  transform: translateY(100%); transition: transform .2s ease-out;
}
.tm-overlay.open .tm { transform: translateY(0); }
.tm-head { flex: none; display: flex; align-items: center; gap: 12px; padding: 16px; border-bottom: 1px solid rgba(196, 199, 197, .16); }
.tm-title { flex: 1; font-size: 24px; line-height: 32px; color: var(--on-surface); }
.tm-close { width: auto; padding: 0 20px; height: 40px; }
.tm-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.tm-intro, .tm-storage, .tm-status, .tm-attrib { font-size: 13px; line-height: 18px; color: #C4C7C5; }
.tm-storage { color: var(--on-surface); font-size: 14px; }
.tm-status:empty { display: none; }
.tm-attrib { font-size: 11px; line-height: 15px; opacity: .8; padding: 8px 0 24px; }
.tm-list { display: flex; flex-direction: column; gap: 10px; }
.tm-group { margin-top: 8px; font-size: 14px; font-weight: 500; letter-spacing: .1px; color: var(--primary); text-transform: uppercase; }
.tm-area { background: rgba(255, 255, 255, .05); border-radius: 16px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.tm-area-name { font-size: 16px; line-height: 22px; font-weight: 500; color: var(--on-surface); }
.tm-layer { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tm-layer-text { flex: 1 1 160px; min-width: 0; }
.tm-layer-label { font-size: 14px; line-height: 20px; color: var(--on-surface); }
.tm-layer-info { font-size: 12px; line-height: 16px; color: #C4C7C5; }
.tm-layer.saved .tm-layer-info { color: var(--primary); }
.tm-actions { flex: none; display: flex; gap: 8px; margin-left: auto; }
.tm-btn { width: auto; height: 36px; padding: 0 16px; font-size: 14px; }
.tm-del { background: transparent; color: var(--on-surface); border: 1px solid rgba(196, 199, 197, .4); }
.tm-progress { flex: 1 1 100%; width: 100%; margin-top: 0; }
.tm.night { background: #111111; }
.tm.night .tm-title, .tm.night .tm-area-name, .tm.night .tm-layer-label, .tm.night .tm-storage,
.tm.night .tm-group, .tm.night .tm-layer-info, .tm.night .tm-intro, .tm.night .tm-attrib, .tm.night .tm-del { color: var(--night-text); }
.tm.night .tm-btn:not(.tm-del), .tm.night .tm-close { background: #330000; color: var(--night-text); }
.tm.night .tm-progress .hint-progress-fill { background: var(--night-text); }

/* ---------------------------------------------------------------- App update prompt (js/appUpdate.js) */
.update-scrim {
  position: absolute; inset: 0; z-index: 20; background: rgba(0, 0, 0, .6);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.update-dialog {
  width: 100%; max-width: 480px; max-height: 100%; overflow-y: auto; background: #1B1C1F; border-radius: 16px;
  padding: 24px; display: flex; flex-direction: column; gap: 12px; color: var(--on-surface);
}
.update-title { font-size: 24px; line-height: 32px; font-weight: 700; }
.update-body, .update-note { font-size: 14px; line-height: 20px; letter-spacing: .25px; color: #C4C7C5; }
.update-list { background: #222; border-radius: 8px; padding: 12px 16px; display: flex; flex-direction: column; gap: 12px; }
.update-version-title { font-size: 14px; line-height: 20px; font-weight: 700; color: var(--primary); }
.update-version ul { margin: 4px 0 0; padding-left: 20px; font-size: 14px; line-height: 20px; }
.update-version li + li { margin-top: 4px; }
.update-actions { display: flex; gap: 12px; margin-top: 4px; }
.m3-button.update-later { background: transparent; color: var(--primary); border: 1px solid #8E918F; }
