/* Flight Finder — built for comfortable reading and big, obvious targets. */

:root {
  --base: 18px;
  --navy: #10365f;
  --navy-dark: #0a2444;
  --ink: #16202c;
  --ink-soft: #4a5565;
  --line: #d2d9e2;
  --paper: #ffffff;
  --shell: #eef1f5;
  --accent: #c2410c;      /* selected plane / primary action */
  --accent-dark: #9a330a;
  --good: #157347;
  --focus: #0b5ed7;
  --tap: 3.1rem;          /* minimum touch target */
  --tap-slim: 2.6rem;     /* the same, where a row of them would eat the map */
}

html[data-size="large"]   { --base: 22px; }
html[data-size="largest"] { --base: 26px; }

* { box-sizing: border-box; }

/* Several panels are shown and hidden with the `hidden` attribute; make sure
   that always wins over a component's own display rule. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-size: var(--base);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--shell);
  -webkit-text-size-adjust: 100%;
}

body {
  display: grid;
  grid-template-rows: auto 1fr;
  /* minmax(0, …) rather than 1fr: a grid column refuses to go below its
     content's minimum width, and one long word in the header or a banner is
     enough to push the whole page — the settings button with it — off the
     side of a narrow phone. */
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
}

.topbar, main { min-width: 0; }

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

:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.8rem;
  padding-top: max(0.4rem, env(safe-area-inset-top));
  background: var(--navy);
  color: #fff;
  flex-wrap: wrap;
  z-index: 1200;
}

.brand { font-size: 1.6rem; line-height: 1; }

.topbar h1 {
  font-size: 1.25rem;
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.search {
  display: flex;
  gap: 0.45rem;
  flex: 1 1 16rem;
  min-width: 12rem;
}

.search input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: var(--tap);
  font-size: 1.05rem;
  padding: 0 0.85rem;
  border: 3px solid transparent;
  border-radius: 0.6rem;
  background: #fff;
  color: var(--ink);
}
.search input::placeholder { color: #6b7280; }
.search input:focus { border-color: #ffd166; outline: none; }

/* ------------------------------------------------------------------ buttons */

.btn {
  min-height: var(--tap);
  font-size: 1.02rem;
  font-weight: 700;
  font-family: inherit;
  padding: 0 1.1rem;
  border-radius: 0.6rem;
  border: 2px solid var(--line);
  cursor: pointer;
  background: #fff;
  color: var(--ink);
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }

.btn-plain {
  background: transparent;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.55);
  display: flex; align-items: center; gap: 0.3rem;
  padding: 0 0.8rem;
}
.btn-plain .gear { font-size: 1.5em; line-height: 1; }
.btn-plain .btn-label { font-size: 0.78rem; font-weight: 600; }

.btn-small { min-height: 2.4rem; font-size: 0.92rem; padding: 0 0.8rem; border: 2px solid var(--line); }
.btn-wide { width: 100%; margin-top: 1rem; }
.btn-back { background: var(--shell); border-color: var(--line); margin-bottom: 0.9rem; }

/* --------------------------------------------------------------------- map */

main {
  position: relative;
  min-height: 0;
  min-width: 0;
}

#map {
  position: absolute;
  inset: 0;
  background: #dfe6ee;
}

.leaflet-container { font-size: 0.85rem; }
.leaflet-control-attribution { font-size: 11px; }

.map-buttons {
  position: absolute;
  right: 0.85rem;
  top: 0.85rem;
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.round-btn {
  width: 3.4rem; height: 3.4rem;
  border-radius: 50%;
  border: 3px solid var(--navy);
  background: #fff;
  color: var(--navy);
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
  display: flex; align-items: center; justify-content: center;
}
.round-btn:hover { background: var(--navy); color: #fff; }
.round-btn.locate.on { background: var(--navy); color: #fff; }

.banner {
  position: absolute;
  top: 0.85rem; left: 0.85rem;
  max-width: min(26rem, calc(100% - 6rem));
  z-index: 900;
  margin: 0;
  padding: 0.7rem 0.95rem;
  background: #fff8e1;
  border: 3px solid #d9a441;
  border-radius: 0.6rem;
  font-size: 0.98rem;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

/* ------------------------------------------------------------ plane markers */

/* Each aircraft is one absolutely positioned node inside its own map pane,
   moved only with a transform so the browser never has to lay the page out
   again for a plane that has shifted a few pixels. */
.plane-marker {
  position: absolute;
  left: 0;
  top: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;   /* the pane itself is transparent to the mouse */
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.plane-marker:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.plane-marker .rot {
  display: block;
  transform-origin: 50% 50%;
  line-height: 0;
}
.plane-marker svg { display: block; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.45)); }
.plane-body { fill: #10365f; stroke: #fff; stroke-width: 1.6; }
.plane-marker.ground .plane-body { fill: #6b7280; }
.plane-marker.selected .plane-body { fill: var(--accent); stroke: #fff; stroke-width: 2.2; }

/* The chosen plane has to be findable at a glance among a hundred others. */
.plane-marker.selected::before {
  content: "";
  position: absolute;
  inset: -12px;
  border: 4px solid var(--accent);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.65);
  box-shadow: 0 0 0 2px #fff;
}
.plane-marker.selected .rot { position: relative; }
.plane-marker.selected .plane-label {
  margin-top: 14px;
  border-color: var(--accent);
  border-width: 2px;
  color: var(--accent-dark);
}

/* On a photograph or a busy street map, navy on navy-ish ground disappears.
   A heavier white outline and a deeper shadow cut the plane back out of it. */
body[data-map="dark"] .plane-body { stroke-width: 2.4; }
body[data-map="dark"] .plane-marker svg { filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.9)); }
body[data-map="dark"] .plane-marker.ground .plane-body { fill: #cbd5e1; }
body[data-map="dark"] .me-marker { box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.55); }

.plane-label {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  margin-top: 2px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  padding: 1px 5px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  pointer-events: none;
}

.airport-marker {
  background: var(--navy);
  color: #fff;
  border: 3px solid #fff;
  border-radius: 0.45rem;
  padding: 0.2rem 0.5rem;
  font-weight: 800;
  font-size: 0.9rem;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.airport-marker small { display: block; font-weight: 600; font-size: 0.72em; opacity: 0.9; }

.airport-pin {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  background: #fff;
  color: var(--navy);
  border: 3px solid var(--navy);
  border-radius: 0.5rem;
  padding: 0.22rem 0.45rem;
  font-weight: 800;
  font-size: 0.92rem;
  line-height: 1.1;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
.airport-pin::before { content: "\2691"; font-size: 1em; }
.airport-pin:hover, .airport-pin.selected { background: var(--navy); color: #fff; }

.board-title {
  font-size: 1.1rem;
  margin: 1.2rem 0 0.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 3px solid var(--line);
}
.board-note { margin-top: 1rem; }
.board[hidden] { display: none !important; }

/* The peek summary only exists for the quarter-height sheet on a phone. */
.peek-summary { display: none; }
.peek-name { margin: 0 0 0.35rem; font-size: 1.2rem; font-weight: 800; line-height: 1.2; }
.peek-route { margin: 0 0 0.35rem; font-size: 1.02rem; font-weight: 600; line-height: 1.3; }
.peek-route b { color: var(--navy); font-size: 1.12em; }
.peek-facts { margin: 0; font-size: 0.95rem; font-weight: 600; color: var(--ink-soft); line-height: 1.3; }

/* Tracking is a mode, so the button has to look different while it is on. */
.btn.tracking { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.tracking:hover { background: var(--navy-dark); }

.track-note {
  margin: 1rem 0 0.5rem;
  padding: 0.6rem 0.8rem;
  background: #eef4ff;
  border: 2px solid var(--navy);
  border-radius: 0.6rem;
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.35;
}
.fl-when { grid-column: 2; grid-row: 1; text-align: right; font-weight: 800; font-size: 0.95rem; color: var(--accent); white-space: nowrap; }

.me-marker {
  width: 1.15rem; height: 1.15rem;
  background: var(--focus);
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(11, 94, 215, 0.3);
}

/* ------------------------------------------------------------------- panel */

.panel {
  background: var(--paper);
  border-top: 3px solid var(--navy);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 1000;
}

.panel-handle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  min-height: var(--tap);
  padding: 0.6rem 1rem;
  font: inherit;
  font-weight: 700;
  font-size: 1.02rem;
  color: #fff;
  background: var(--navy);
  border: 0;
  cursor: pointer;
  text-align: left;
}
.panel-handle .chev { transition: transform 0.18s ease; }
.panel.open .panel-handle .chev { transform: rotate(180deg); }

.panel-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem 1rem 1.4rem;
  padding-bottom: max(1.4rem, env(safe-area-inset-bottom));
  flex: 1 1 auto;
}

.view h2 { font-size: 1.3rem; margin: 0 0 0.3rem; line-height: 1.25; }
.hint { margin: 0 0 0.9rem; color: var(--ink-soft); font-size: 0.95rem; }
.sub { margin: 0 0 1rem; color: var(--ink-soft); font-size: 1rem; font-weight: 600; }

/* list of flights */

.flight-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.55rem; }

.flight-list button {
  width: 100%;
  min-height: var(--tap);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.25rem 0.8rem;
  text-align: left;
  font: inherit;
  padding: 0.7rem 0.85rem;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 0.7rem;
  cursor: pointer;
}
.flight-list button:hover { border-color: var(--navy); background: #f6f9ff; }
.flight-list button[aria-current="true"] { border-color: var(--accent); background: #fff4ed; }

.fl-name { grid-column: 1; grid-row: 1; font-weight: 800; font-size: 1.05rem; }
.fl-alt { grid-column: 2; grid-row: 1; color: var(--ink-soft); font-size: 0.9rem; font-weight: 700; text-align: right; white-space: nowrap; }
.fl-route { grid-column: 1 / -1; grid-row: 2; color: var(--ink-soft); font-size: 0.95rem; font-weight: 600; }

.empty { padding: 1.1rem; border: 2px dashed var(--line); border-radius: 0.7rem; color: var(--ink-soft); font-weight: 600; }

/* route strip */

.route {
  display: grid;
  grid-template-columns: 1fr 3.2rem 1fr;
  align-items: center;
  gap: 0.4rem;
  background: var(--shell);
  border-radius: 0.8rem;
  padding: 0.9rem 0.7rem;
}
.route-end { text-align: center; min-width: 0; }
.route-label { margin: 0 0 0.15rem; font-size: 0.82rem; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }
.route-code { margin: 0; font-size: 1.9rem; font-weight: 800; line-height: 1.05; color: var(--navy); }
.route-city { margin: 0.15rem 0 0; font-size: 0.95rem; font-weight: 600; line-height: 1.25; }

.route-mid { position: relative; height: 2.6rem; }
.route-line { position: absolute; top: 50%; left: 0; right: 0; height: 3px; background: var(--navy); }
.route-plane { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -52%); font-size: 1.4rem; color: var(--accent); background: var(--shell); padding: 0 0.15rem; }

.progress-wrap { margin-top: 0.9rem; }
.progress { height: 1rem; background: var(--shell); border: 2px solid var(--line); border-radius: 1rem; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: 1rem; transition: width 0.4s ease; }
.progress-text { margin: 0.45rem 0 0; font-weight: 700; font-size: 1rem; }

/* facts */

.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.55rem; margin: 1rem 0 0; }
.fact { background: #fff; border: 2px solid var(--line); border-radius: 0.7rem; padding: 0.7rem 0.8rem; }
.fact dt { font-size: 0.82rem; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }
.fact dd { margin: 0.2rem 0 0; font-size: 1.15rem; font-weight: 800; line-height: 1.2; }

.photo-wrap { margin-top: 1rem; }
.photo-wrap img { width: 100%; border-radius: 0.7rem; border: 2px solid var(--line); display: block; }
.photo-credit { margin: 0.3rem 0 0; font-size: 0.8rem; color: var(--ink-soft); }

/* -------------------------------------------------------------- bottom nav */

/* Phones get a permanent set of four big destinations; on a wide screen the
   side panel already shows everything, so the bar would only take up room. */
.bottom-nav { display: none; }

@media (max-width: 799px) {
  .bottom-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 1400;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: var(--paper);
    border-top: 2px solid var(--navy);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.05rem;
    min-height: 2.9rem;
    padding: 0.2rem 0.15rem;
    font: inherit;
    background: none;
    border: 0;
    border-top: 3px solid transparent;
    color: var(--ink-soft);
    cursor: pointer;
  }
  .nav-icon { font-size: 1.15rem; line-height: 1.05; }
  .nav-label { font-size: 0.68rem; font-weight: 700; text-align: center; line-height: 1.1; }

  .nav-btn[aria-current="true"] {
    color: var(--navy);
    border-top-color: var(--accent);
    background: #f3f6fb;
  }
}

/* ----------------------------------------------------------------- overlay */

.overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(8, 20, 35, 0.72);
  display: flex; align-items: center; justify-content: center;
  padding: 1.2rem;
}
.overlay-card {
  background: #fff;
  border-radius: 1rem;
  padding: 1.4rem;
  max-width: 30rem;
  width: 100%;
}
.overlay-card h2 { margin: 0 0 0.8rem; font-size: 1.5rem; }
.help-list { margin: 0; padding-left: 1.2rem; display: grid; gap: 0.65rem; font-size: 1.05rem; line-height: 1.45; }

.overlay-card { max-height: 90vh; overflow-y: auto; }

.setting { border: 2px solid var(--line); border-radius: 0.7rem; padding: 0.7rem 0.9rem 0.9rem; margin: 0 0 0.9rem; }
.setting legend { font-weight: 800; font-size: 0.95rem; padding: 0 0.35rem; }
.setting-note { margin: 0 0 0.7rem; font-weight: 600; color: var(--ink-soft); line-height: 1.35; }
.setting .btn-wide { margin-top: 0; }

.choices { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.choice {
  flex: 1 1 6rem;
  min-height: var(--tap);
  font: inherit;
  font-weight: 700;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 0.6rem;
  cursor: pointer;
}
.choice[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }

/* The welcome and settings cards are the only places the map is covered. */
.overlay-card .btn-wide + .btn-wide { margin-top: 0.6rem; }

/* -------------------------------------------------------------- responsive */

/* Phones: the panel is a sheet that slides up from the bottom. */
@media (max-width: 799px) {
  /* Brand, search and settings share one row: the second row of header was
     costing a strip of sky. The words "Flight Finder" are the part that gives
     way — the ✈ says it, and the title is still read out by a screen reader. */
  .topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "brand search size";
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.6rem;
    padding-top: max(0.3rem, env(safe-area-inset-top));
  }
  .brand { grid-area: brand; font-size: 1.5rem; }
  .search { grid-area: search; min-width: 0; gap: 0.35rem; }
  .btn-plain { grid-area: size; }
  .btn-plain .btn-label { display: none; }

  html:not([data-size="largest"]) .topbar h1 {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }

  /* At the largest text size sharing a row would leave a letterbox to type
     into, so the search takes a row of its own — and the title comes back to
     keep the first row company. */
  html[data-size="largest"] .topbar {
    grid-template-areas: "brand title size" "search search search";
  }
  html[data-size="largest"] .topbar h1 { grid-area: title; font-size: 1.1rem; }

  .search input { min-height: var(--tap-slim); font-size: 1rem; padding: 0 0.7rem; }
  .search .btn { min-height: var(--tap-slim); padding: 0 0.8rem; }
  .btn-plain { min-height: var(--tap-slim); padding: 0 0.6rem; }
  .panel {
    position: fixed;
    left: 0; right: 0;
    bottom: var(--nav-h, 3.6rem);
    /* Never taller than the gap between the header and the nav bar, or the
       sheet's own handle disappears behind the search box. */
    max-height: calc(100vh - var(--nav-h, 3.6rem) - var(--header-h, 9rem));
    max-height: calc(100dvh - var(--nav-h, 3.6rem) - var(--header-h, 9rem));
    border-radius: 1rem 1rem 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    transition: transform 0.25s ease;
    /* --handle-h is measured in JS so this works at every text size. */
    transform: translateY(calc(100% - var(--handle-h, 3.4rem)));
  }

  /* Picking a plane off the map lifts the sheet just far enough to read the
     headline, leaving the map — and the plane you tapped — still in view. */
  .panel.peek { transform: translateY(calc(100% - var(--peek-h, 25vh))); }
  .panel.peek .panel-body { overflow-y: hidden; }
  .panel.peek .peek-summary { display: block; }
  .panel.peek .detail-full { display: none; }

  .panel.open { transform: translateY(0); }
  .panel-handle { border-radius: 1rem 1rem 0 0; }
  .panel-body {
    max-height: calc(100vh - var(--nav-h, 3.6rem) - var(--header-h, 9rem) - var(--handle-h, 3.4rem));
    max-height: calc(100dvh - var(--nav-h, 3.6rem) - var(--header-h, 9rem) - var(--handle-h, 3.4rem));
  }
  .facts { grid-template-columns: 1fr 1fr; }
}

/* Tablets and computers: the panel is a column beside the map. */
@media (min-width: 800px) {
  body { grid-template-columns: 1fr minmax(23rem, 27rem); }
  .panel { border-top: 0; border-left: 3px solid var(--navy); }
  .panel-handle { display: none; }
  .route-code { font-size: 2.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
