:root {
  color-scheme: dark;
  font-family: "Segoe UI", Arial, sans-serif;
  --ink: #f4f7f5;
  --muted: #bdc8c4;
  --panel: rgba(12, 20, 23, 0.92);
  --panel-strong: rgba(7, 13, 16, 0.97);
  --line: rgba(255, 255, 255, 0.2);
  --focus: #f0cf5a;
  --accent: #3dc79a;
}

* {
  box-sizing: border-box;
}

html,
body,
#map-app,
#map {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  min-width: 300px;
  overflow: hidden;
  background: #071a27;
  color: var(--ink);
}

body.finder-mode #map { cursor: crosshair; }

body.video-mode .app-header,
body.video-mode .language-switch,
body.video-mode .toolbar,
body.video-mode .readout,
body.video-mode .map-panel,
body.video-mode .info-panel,
body.video-mode .loading,
body.video-mode .error-message {
  display: none !important;
}

button,
a,
input {
  font: inherit;
}

a {
  color: #9dd7ff;
}

#map-app {
  position: relative;
  min-height: 440px;
  isolation: isolate;
}

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

.maplibregl-canvas {
  outline: none;
}

.app-header,
.language-switch,
.toolbar,
.readout,
.map-panel,
.info-panel,
.loading,
.error-message {
  position: absolute;
  z-index: 3;
}

.app-header {
  top: 18px;
  left: 18px;
  display: flex;
  max-width: min(560px, calc(100vw - 300px));
  align-items: center;
  gap: 11px;
  padding: 9px 13px 9px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  backdrop-filter: blur(8px);
}

.app-header img {
  flex: 0 0 auto;
}

.app-header h1,
.app-header p,
.info-panel h2,
.info-panel p {
  margin: 0;
}

.app-header h1 {
  font-size: 19px;
  line-height: 1.2;
}

.app-header p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.language-switch {
  top: 18px;
  right: 18px;
  display: flex;
  gap: 4px;
}

.language-switch a {
  display: grid;
  width: 35px;
  height: 28px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.language-switch a:hover,
.language-switch a:focus-visible,
.language-switch a[aria-current="page"] {
  border-color: var(--focus);
  color: var(--ink);
  outline: 0;
}

.toolbar {
  top: 54px;
  right: 18px;
  display: grid;
  grid-template-columns: repeat(2, 42px);
  gap: 6px;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  stroke-width: 2;
}

.icon-button:hover,
.icon-button:focus-visible,
.icon-button[aria-pressed="true"] {
  border-color: var(--focus);
  background: #26363a;
  outline: 0;
}

.icon-button.small {
  width: 34px;
  height: 34px;
}

.readout {
  bottom: 18px;
  left: 18px;
  display: grid;
  width: min(420px, calc(100vw - 36px));
  min-height: 116px;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 3px 14px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: 5px;
  background: var(--panel-strong);
}

.readout-location {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  grid-column: 1 / -1;
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
}

#station-code {
  align-self: end;
  color: var(--ink);
  font-family: Consolas, "Courier New", monospace;
  font-size: 29px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
}

#station-code[href="#"] {
  pointer-events: none;
}

#station-name {
  min-width: 0;
  align-self: start;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 13px;
}

#station-distance {
  grid-column: 2;
  grid-row: 2 / 4;
  align-self: center;
  color: var(--focus);
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
}

.map-panel {
  right: 18px;
  bottom: 18px;
  width: min(470px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel-strong);
}

.maplibregl-ctrl-bottom-right {
  right: 18px;
  bottom: 172px;
}

.panel-title,
.scale-row,
.legend-labels,
.info-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-title {
  font-size: 13px;
}

#zoom-value {
  color: #97e5bd;
  font-family: Consolas, "Courier New", monospace;
}

.fade-control {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 48px;
  align-items: center;
  gap: 10px;
  margin: 10px 0 8px;
}

.fade-control input {
  width: 100%;
  margin: 0;
  accent-color: var(--focus);
}

.fade-control output {
  font-family: Consolas, "Courier New", monospace;
  text-align: right;
}

.legend {
  height: 14px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: linear-gradient(90deg, #11b7a3 0%, #37be70 18%, #cbd144 42%, #f39b39 65%, #bd466d 82%, #4c54a4 100%);
}

.legend-labels {
  margin-top: 4px;
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
  font-size: 9px;
}

.scale-row {
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.info-panel {
  top: 152px;
  right: 18px;
  width: min(410px, calc(100vw - 36px));
  max-height: calc(100vh - 330px);
  overflow: auto;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel-strong);
}

.info-panel h2 {
  font-size: 18px;
}

.info-panel p {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.loading,
.error-message {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-strong);
}

.loading {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  font-weight: 600;
}

.loading[hidden],
.error-message[hidden] {
  display: none;
}

.error-message {
  width: min(520px, calc(100vw - 36px));
  padding: 18px;
  border-left: 5px solid #e05c5c;
  color: #ffdada;
  line-height: 1.5;
}

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

@media (max-width: 900px) {
  .app-header {
    max-width: calc(100vw - 126px);
  }

  .map-panel {
    bottom: 150px;
  }
}

@media (max-width: 620px) {
  .app-header {
    top: 10px;
    left: 10px;
    max-width: calc(100vw - 100px);
  }

  .app-header p {
    display: none;
  }

  .language-switch {
    top: 10px;
    right: 10px;
  }

  .toolbar {
    top: 46px;
    right: 10px;
    grid-template-columns: 40px;
  }

  .icon-button {
    width: 40px;
    height: 40px;
  }

  .readout {
    bottom: 10px;
    left: 10px;
    width: calc(100vw - 20px);
    min-height: 104px;
  }

  .map-panel {
    right: auto;
    bottom: 124px;
    left: 10px;
    width: calc(100vw - 20px);
  }

  .maplibregl-ctrl-bottom-right {
    right: 10px;
    bottom: 278px;
  }

  .info-panel {
    top: 98px;
    right: 58px;
    max-height: calc(100vh - 250px);
  }
}
