* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: system-ui, sans-serif;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

#panel {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1;
  width: 280px;
  max-height: calc(100% - 24px);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
  font-size: 13px;
}

#panel.hidden {
  display: none;
}

.panel-min {
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  background: none;
  font-size: 18px;
  line-height: 1;
  color: #888;
  cursor: pointer;
}

.panel-min:hover {
  color: #000;
}

.panel-open {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 2;
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  font-size: 18px;
  cursor: pointer;
}

.panel-open.hidden {
  display: none;
}

/* Mini time control: just the clock + a play button. */
.tb-mini-only {
  display: none;
}

.tb-min {
  margin-left: auto;
  border: none;
  background: none;
  color: #888;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

.tb-min:hover {
  color: #000;
}

#time-box.mini #scrub,
#time-box.mini .tb-controls,
#time-box.mini .date-nav {
  display: none;
}

#time-box.mini .tb-mini-only {
  display: inline-flex;
}

/* Minimised: shrink to fit the header (clock + play), don't keep the full
   600px width. Anchored bottom-right, so it collapses toward the corner. */
#time-box.mini {
  width: auto;
}

#panel h1 {
  font-size: 15px;
  margin: 0 0 12px;
}

#mode-badge {
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: #1f77b4;
  padding: 2px 6px;
  border-radius: 6px;
  vertical-align: middle;
}

fieldset {
  border: 1px solid #ddd;
  border-radius: 8px;
  margin: 0 0 12px;
  padding: 8px 10px;
}

legend {
  font-weight: 600;
  padding: 0 4px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 4px 0;
}

.row > span:first-child {
  color: #555;
}

input[type="text"],
input:not([type]),
select {
  flex: 1;
  min-width: 0;
  padding: 3px 6px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font: inherit;
}

input[type="range"] {
  width: 100%;
  margin: 2px 0;
}

.classes {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 6px;
}

.classes label {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.count {
  font-weight: 600;
  margin: 4px 0 12px;
}

.legend {
  border-top: 1px solid #eee;
  padding-top: 10px;
  margin-top: 10px;
}

.legend h2 {
  font-size: 13px;
  margin: 0 0 8px;
}

/* Selected-aircraft panel (bottom-left, draggable) */
#flight-panel {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 2;
  width: min(600px, 96vw);
  box-sizing: border-box;
  padding: 8px 10px 10px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid #ccc;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  font-size: 13px;
}

#flight-panel.hidden {
  display: none;
}

#flight-panel.dragging {
  user-select: none;
  cursor: grabbing;
}

.fp-head {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: grab;
  touch-action: none;
}

.fp-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #7f7f7f;
  flex: 0 0 auto;
}

.fp-title {
  flex: 1;
  font-weight: 600;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

#fp-close {
  border: none;
  background: none;
  color: #888;
  font-size: 14px;
  cursor: pointer;
  padding: 0 2px;
}

#fp-close:hover {
  color: #000;
}

#flight-panel dl {
  grid-template-columns: auto 1fr auto 1fr;
  column-gap: 16px;
  row-gap: 2px;
  margin: 8px 0;
}

#flight-panel dd {
  text-align: right;
}

.fp-chart-wrap {
  border-top: 1px solid #eee;
  padding-top: 6px;
}

#fp-chart {
  width: 100%;
  height: 120px;
  display: block;
  cursor: crosshair;
}

.fp-alt {
  fill: none;
  stroke: #1f77b4;
  stroke-width: 1.5;
}

.fp-gs {
  fill: none;
  stroke: #ff7f0e;
  stroke-width: 1;
  opacity: 0.85;
}

.fp-cursor {
  stroke: #333;
  stroke-width: 1;
}

.fp-axis {
  fill: #999;
  font-size: 9px;
  font-variant-numeric: tabular-nums;
}

.fp-axis-alt {
  fill: #1f77b4;
}

.fp-axis-gs {
  fill: #ff7f0e;
}

/* Map-overlays settings (gear button + panel, top-right under the nav control) */
#settings-btn {
  position: fixed;
  top: 68px;
  right: 10px;
  z-index: 3;
  width: 29px;
  height: 29px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  font-size: 15px;
  line-height: 29px;
  cursor: pointer;
}

#settings-btn:hover {
  background: #f0f0f0;
}

/* Copy-link button, directly under the settings gear. */
#share-btn {
  position: fixed;
  top: 101px;
  right: 10px;
  z-index: 3;
  width: 29px;
  height: 29px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  font-size: 14px;
  line-height: 29px;
  cursor: pointer;
}

#share-btn:hover {
  background: #f0f0f0;
}

#settings-panel {
  position: fixed;
  top: 68px;
  right: 48px;
  z-index: 3;
  width: 210px;
  box-sizing: border-box;
  padding: 8px 10px 10px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid #ccc;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  font-size: 13px;
}

.sp-sub {
  margin: 8px 0 2px;
  font-weight: 600;
  font-size: 12px;
  color: #555;
}

.sp-airports {
  display: grid;
  grid-template-columns: repeat(2, max-content);
  gap: 2px 18px;
}

.sp-airports label {
  font-size: 12px;
  padding: 1px 0;
}

#settings-panel.hidden {
  display: none;
}

.sp-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  margin-bottom: 6px;
}

#sp-close {
  border: none;
  background: none;
  color: #888;
  font-size: 13px;
  cursor: pointer;
}

#sp-close:hover {
  color: #000;
}

#settings-panel label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  cursor: pointer;
}

.sp-indent {
  margin-left: 14px;
  font-size: 12px;
  color: #555;
}

.sp-airac {
  margin: 8px 0 0;
  color: #666;
  font-variant-numeric: tabular-nums;
}

dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
}

dt {
  color: #777;
}

dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Mode toggle */
.modes {
  display: flex;
  gap: 6px;
  margin: 0 0 12px;
}

.modes button {
  flex: 1;
  padding: 5px 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #f4f4f4;
  font: inherit;
  cursor: pointer;
}

.modes button.active {
  background: #1f77b4;
  border-color: #1f77b4;
  color: #fff;
  font-weight: 600;
}

/* Detached, draggable time-control box (bottom-right by default) */
#time-box {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 2;
  width: min(600px, 94vw);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px 10px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid #ccc;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  font-size: 13px;
}

#time-box.dragging {
  user-select: none;
  cursor: grabbing;
}

.tb-head {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: grab;
  touch-action: none;
}

.tb-grip {
  color: #aaa;
  font-size: 15px;
  line-height: 1;
}

.tb-head .date-nav {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.tb-head .date-nav select {
  flex: 1;
}

.tb-head .clock {
  margin: 0;
  font-size: 14px;
}

#time-box #scrub {
  width: 100%;
  margin: 0;
}

.tb-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

/* Playback-speed segmented control */
.speed {
  display: inline-flex;
}

.speed button {
  padding: 4px 8px;
  border: 1px solid #ccc;
  background: #fff;
  font: inherit;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.speed button:first-child {
  border-radius: 6px 0 0 6px;
}

.speed button:last-child {
  border-radius: 0 6px 6px 0;
}

.speed button:not(:first-child) {
  border-left: none;
}

.speed button.active {
  background: #1f77b4;
  border-color: #1f77b4;
  color: #fff;
}

/* Replay transport: symmetric step buttons flanking a central play/pause */
.transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 3px;
  margin: 0;
}

.transport button {
  flex: 0 0 auto;
  padding: 4px 6px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  font: inherit;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.transport button:hover {
  background: #f0f0f0;
}

.transport .play {
  margin: 0 6px;
  padding: 4px 12px;
  border-color: #1f77b4;
  color: #1f77b4;
  font-size: 14px;
  font-weight: 600;
}

.clock {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 15px;
  text-align: center;
  margin: 2px 0 6px;
}

/* Date navigation arrows */
.date-nav {
  align-items: center;
  gap: 6px;
}

.date-nav select {
  flex: 1;
}

.date-nav button {
  padding: 2px 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  font: inherit;
  cursor: pointer;
}

.date-nav button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Legend */
.legend ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 3px 0;
}

.swatch {
  width: 14px;
  height: 4px;
  border-radius: 2px;
}

.error {
  color: #b00020;
  font-weight: 600;
}

.hidden {
  display: none;
}
