* {
  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 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;
}

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

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

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;
}
