/*
 * airband-map: the frequency list first, the traffic behind it second, nothing else.
 *
 * Dark and monospaced where numbers are, because this is read the way the terminal interface
 * is read — a frequency scanned off a screen while a radio is in the other hand. Every colour
 * stands for one fact: an emergency squawk, an aircraft going quiet, stale aviation data.
 */

:root {
  --bg: #0d1117;
  --raised: #12171f;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #4fc3f7;
  --warn: #f0883e;
  --danger: #f85149;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* -------------------------------------------------------------------- header */

#bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

#title {
  font-weight: 600;
  letter-spacing: 0.02em;
  flex: 0 0 auto;
}

#status {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#status.warn {
  color: var(--warn);
}

#status.stale {
  color: #fff;
  background: #7d2a2a;
  padding: 1px 6px;
  border-radius: 4px;
}

#bar-actions {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

button {
  font: inherit;
  color: var(--text);
  background: #21262d;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

/* --------------------------------------------------------------------- shell */

/*
 * One column on a phone, two from a tablet up. The frequency list leads in both, and it comes
 * first in the document so it is what a narrow screen shows without scrolling.
 *
 * `minmax(0, …)` rather than a bare `1fr`: a grid track sized `1fr` refuses to go below its
 * content's min-content width, and the aircraft table has one — ten columns that must not
 * wrap. Without the zero floor the track grew past the viewport and the whole page scrolled
 * sideways on a phone.
 */
main {
  display: grid;
  gap: 0 24px;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  padding: 16px;
  max-width: 1400px;
  margin: 0 auto;
}

@media (min-width: 900px) {
  main {
    grid-template-columns: minmax(320px, 1fr) minmax(0, 1.15fr);
  }
}

section {
  margin-bottom: 20px;
  min-width: 0;
}

/* Where something genuinely too wide is allowed to scroll on its own. */
.scroll {
  overflow-x: auto;
}

h2 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.hint,
.disclaimer {
  color: var(--muted);
  font-size: 11px;
  margin: 6px 0 0;
}

.disclaimer {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 12px;
}

.notice {
  margin: 0 0 8px;
  padding: 6px 8px;
  border: 1px solid var(--warn);
  border-radius: 6px;
  color: var(--warn);
  font-size: 11px;
  line-height: 1.4;
}

/*
 * Attribution for a network traffic source. Informational, not a warning: it says where the
 * traffic came from, which the orange .notice styling would overstate.
 */
.source-notice {
  margin: 0 0 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.source-notice a {
  color: var(--accent);
}

/* --------------------------------------------------------------- frequencies */

/* A frequency entry has to be readable while holding a radio in the other hand. */
.freq {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  gap: 4px 12px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  margin-bottom: 6px;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.freq:hover {
  border-color: var(--accent);
}

.freq .mhz {
  font-family: var(--mono);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.freq .meta {
  min-width: 0;
}

.freq .name {
  display: block;
  font-size: 13px;
  /* A long callsign like "MORIA RADAR (SOUTH)" must not be cut mid-word. */
  overflow-wrap: break-word;
}

.freq .tag {
  display: block;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  overflow-wrap: break-word;
}

/*
 * The evidence, on the face of the button rather than in a tooltip: it is what makes a
 * suggestion judgeable, and a tooltip is unreachable on a touch device.
 */
.freq .why {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: break-word;
}

/* The score bar sits under the number it belongs to, in the first column. */
.score {
  grid-column: 1;
  grid-row: 2;
  display: block;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: #21262d;
  overflow: hidden;
}

.score i {
  display: block;
  height: 100%;
  background: var(--muted);
}

/* Only the leader is highlighted: a runner-up can round to a near-full bar as well, and
   colouring those too would claim a tie the ranking did not find. */
.list li:first-child .score i {
  background: var(--accent);
}

/* ------------------------------------------------------------------- aircraft */

/*
 * Sized to its content, not to the column it sits in. Stretched to full width the ten values
 * of one aircraft end up spread over a thousand pixels, and reading a row then means crossing
 * the screen — the terminal keeps them a few characters apart for exactly that reason. Too
 * wide to fit, it scrolls inside its own container instead of widening the page.
 */
#aircraft {
  width: auto;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

#aircraft th {
  text-align: left;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  padding: 2px 8px 4px 0;
  white-space: nowrap;
}

#aircraft td {
  padding: 3px 8px 3px 0;
  white-space: nowrap;
}

#aircraft .num {
  text-align: right;
}

#aircraft tr.quiet {
  color: var(--muted);
}

#aircraft tr.emergency {
  color: var(--danger);
  font-weight: 600;
}

/*
 * The address links out to a lookup. `color: inherit` on purpose: a row that is red for an
 * emergency squawk or dimmed for going quiet says something, and a blue link in the middle of
 * it would overrule that with something merely clickable.
 */
#aircraft a {
  color: inherit;
  text-decoration: none;
}

#aircraft a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* --------------------------------------------------------- airports and area */

/*
 * Capped rather than stretched: a name on the left and its distance pinned to the far edge of
 * a 600 px column is two readings, not one line.
 */
#airports,
#areas {
  max-width: 32rem;
}

.airport,
.area {
  display: flex;
  gap: 8px;
  align-items: baseline;
  width: 100%;
  text-align: left;
  padding: 5px 8px;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
}

.airport:hover {
  border-color: var(--border);
}

.airport .icao,
.area .ident {
  font-family: var(--mono);
}

.airport .icao {
  color: var(--accent);
  flex: 0 0 4.2em;
}

.airport .name,
.area .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.airport .km {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.airport-frequencies {
  margin: 2px 0 8px 8px;
  padding-left: 8px;
  border-left: 1px solid var(--border);
}

.area .ident {
  color: var(--muted);
  font-size: 10px;
}

.area .mhz-small {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ clipboard */

#copied {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 20;
  padding: 6px 12px;
  border-radius: 6px;
  background: #1f6feb;
  color: #fff;
  font-family: var(--mono);
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}

#copied.show {
  opacity: 1;
}

/* ----------------------------------------------------------------- adaptions */

/* Touch devices: the list is worked through with a finger, not a trackpad. */
@media (pointer: coarse) {
  .airport,
  .freq {
    padding: 10px;
  }

  button {
    padding: 7px 12px;
  }
}

/* Narrow screens: the columns the answer does not depend on give way first. */
@media (max-width: 560px) {
  #title {
    display: none;
  }

  #aircraft .optional {
    display: none;
  }

  .freq .mhz {
    font-size: 22px;
  }
}
