:root {
  color-scheme: dark;
  color: #f2f6fc;
  background: #111720;
  font: 100%/1.45 system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(16px, 4vw, 48px);
}

main { width: min(100%, 56rem); }
section { margin: auto; }
h1 {
  margin: 0 0 .45rem;
  font-size: clamp(1.9rem, 3.8vw, 3.4rem);
  line-height: 1.08;
  letter-spacing: -.035em;
}

.instruction { margin: 0 0 1.35rem; color: #b7c8da; max-width: 29rem; }
#pairing { width: min(100%, 27rem); }
form { display: grid; gap: .55rem; }
label { font-weight: 650; color: #dce8f7; }

input, button {
  min-height: 48px;
  min-width: 44px;
  border: 1px solid #3c516a;
  border-radius: .65rem;
  font: inherit;
}

input {
  width: 100%;
  color: inherit;
  background: #0c1118;
  text-align: center;
  letter-spacing: .22em;
  font-size: 1.5rem;
}

button {
  background: #202c3b;
  color: inherit;
  font-size: 1.3rem;
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover { background: #2b3f56; }
button:focus-visible, input:focus-visible { outline: 3px solid #87c2ff; outline-offset: 3px; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .45rem; }
.keypad [data-key="clear"] { font-size: .95rem; }
.primary { color: #101923; background: #94c8ff; border-color: #94c8ff; }
.primary:hover { background: #bcddff; }
.primary:disabled { background: #263445; color: #adbed1; border-color: #3c516a; cursor: default; }
#pair-message { color: #ffd498; min-height: 1.4em; margin: 0; }

#screen { max-width: 36rem; }
.connection { margin: 0 0 1.2rem; color: #ffd498; font-weight: 650; }
.connection[data-online="true"] { color: #a4e7c6; }

@media (min-width: 820px) and (min-height: 430px) {
  #pairing { display: grid; width: auto; grid-template-columns: 1fr minmax(305px, .75fr); column-gap: 3rem; }
  #pairing-title { align-self: end; }
  #pairing .instruction { grid-column: 1; align-self: start; font-size: 1.12rem; }
  form { grid-column: 2; grid-row: 1 / span 2; }
  button, input { min-height: 56px; }
}

body[data-mode="screen"] {
  align-items: start;
  padding: clamp(14px, 2.4vw, 36px);
}
body[data-mode="screen"] main, #screen { width: 100%; max-width: 100rem; }
.screen-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  column-gap: 2rem;
  margin-bottom: 1rem;
}
.screen-header h1 { margin: 0; font-size: clamp(1.45rem, 3vw, 2.5rem); }
.screen-header .connection { margin: 0; }
.screen-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.map-frame.base-map { grid-template-columns: minmax(0, 1fr); }
.location-controls { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin-top: .8rem; }
.location-controls p { margin: 0; color: #b7c8da; }
.map-frame {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(17rem, 1fr);
  min-height: 65vh;
  border: 1px solid #3c516a;
  border-radius: .8rem;
  overflow: hidden;
  background: #192331;
}
#map { min-height: 55vh; background: #1b2838; }
.stations-panel { padding: .9rem; max-height: 72vh; overflow-y: auto; }
.stations-panel h2 { margin: 0; font-size: 1.25rem; }
#data-age, .diagnostics { color: #b7c8da; }
#data-age { font-size: .85rem; }
.map-legend { display: flex; flex-wrap: wrap; gap: .35rem .9rem; font-size: .83rem; }
.map-legend span { display: inline-flex; gap: .4rem; align-items: center; }
.map-legend span::before { content: ''; width: 1.4rem; border-top: 3px solid #78c6ff; }
.map-legend .alternative-line::before { border-top: 3px dashed #ffd596; }
#stations { list-style: none; padding: 0; display: grid; gap: .55rem; }
#stations li { display: flex; padding: .7rem; gap: .65rem; border-radius: .55rem; background: #202d3f; }
#stations li.station-selected { outline: 2px solid #8cc9ff; }
#stations p { margin: .15rem 0 0; font-size: .88rem; }
.station-details { min-width: 0; }
.station-heading { display: flex; flex-wrap: wrap; column-gap: .55rem; overflow-wrap: anywhere; }
.station-distance { color: #b9dfff; white-space: nowrap; }
.station-number {
  display: inline-grid;
  place-items: center;
  min-width: 1.85rem;
  height: 1.85rem;
  flex: 0 0 auto;
  padding: 0 .25rem;
  border-radius: 50%;
  color: #102238;
  background: #98d0ff;
  font: 750 1rem/1 system-ui, sans-serif;
}
.station-marker .station-number { position: relative; z-index: 1; width: 36px; height: 36px; border: 2px solid #0a233b; }
.station-marker-label {
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  width: max-content;
  max-width: 11rem;
  padding: .23rem .55rem;
  overflow: hidden;
  border: 1px solid #56748d;
  border-radius: 0 1rem 1rem 0;
  background: #192331;
  color: #f2f6fc;
  font: 700 .85rem/1.3 system-ui, sans-serif;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.station-marker-label-left .station-marker-label { left: auto; right: 100%; border-radius: 1rem 0 0 1rem; }
.station-marker-selected .station-number { background: #ffd596; }
.station-marker-selected .station-marker-label { border-color: #ffd596; }
.display-card { padding: 1.5rem; border-radius: .8rem; background: #202d3f; font-size: clamp(1.25rem, 3vw, 2.1rem); }
.display-card p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.display-card img { display: block; max-width: 100%; max-height: 66vh; }
.diagnostics { margin-top: 1.1rem; }
.diagnostics summary { cursor: pointer; width: max-content; }
#location-button { padding: .45rem .8rem; font-size: 1rem; }
@media (max-width: 760px) {
  .map-frame { grid-template-columns: 1fr; }
  .stations-panel { max-height: 35vh; }
}
