:root {
  color-scheme: dark;
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  --ink: #f5f7f4;
  --muted: #b8c1ba;
  --panel: rgba(22, 25, 23, 0.9);
  --panel-strong: rgba(14, 16, 15, 0.96);
  --line: rgba(255, 255, 255, 0.18);
  --focus: #f4d35e;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  background: #080a09;
  color: var(--ink);
}

button,
a {
  font: inherit;
}

a {
  color: #9bc9ef;
}

#globe-app {
  position: relative;
  isolation: isolate;
  min-width: 280px;
  min-height: 420px;
}

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

#scene canvas {
  display: block;
  touch-action: none;
}

.app-header,
.toolbar,
.readout,
.scale-panel,
.info-panel,
.loading,
.error-message {
  position: absolute;
  z-index: 2;
}

.app-header {
  top: 18px;
  left: 18px;
  display: flex;
  align-items: center;
  gap: 11px;
  max-width: min(520px, calc(100vw - 150px));
  padding: 9px 12px 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;
  letter-spacing: 0;
}

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

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

.language-switch {
  display: flex;
  grid-column: 1 / -1;
  justify-content: flex-end;
  gap: 4px;
}

.language-switch a {
  display: grid;
  min-width: 34px;
  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;
  line-height: 1;
  text-decoration: none;
  backdrop-filter: blur(8px);
}

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

.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;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  backdrop-filter: blur(8px);
}

.icon-button:last-child {
  font-family: Georgia, serif;
  font-size: 20px;
}

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

.readout {
  bottom: 18px;
  left: 18px;
  display: grid;
  width: min(410px, 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 #2bb673;
  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;
  font-family: Consolas, "Courier New", monospace;
  font-size: 29px;
  line-height: 1;
}

#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: #f4d35e;
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
}

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

.scale-title,
.zoom-readout,
.legend-labels {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.scale-title {
  margin-bottom: 8px;
  font-size: 13px;
}

#render-mode {
  color: #89d6a8;
  font-size: 12px;
}

.legend-gradient {
  width: 100%;
  height: 14px;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

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

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

.fade-control {
  display: grid;
  grid-template-columns: auto minmax(110px, 1fr) 44px;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.fade-control input {
  width: 100%;
  margin: 0;
  accent-color: #f4d35e;
  cursor: pointer;
}

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

#pixel-scale {
  color: var(--ink);
  font-family: Consolas, "Courier New", monospace;
}

.info-panel {
  top: 112px;
  right: 18px;
  width: min(390px, calc(100vw - 36px));
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel-strong);
  font-size: 13px;
  line-height: 1.5;
}

.info-panel h2 {
  margin-bottom: 8px;
  font-size: 16px;
}

.info-panel p + p {
  margin-top: 9px;
}

.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: 13px;
  padding: 13px 17px;
  font-weight: 600;
}

.error-message {
  width: min(560px, calc(100vw - 36px));
  padding: 18px;
  border-left: 5px solid #d1495b;
  color: #ffd7dc;
}

[hidden] {
  display: none !important;
}

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

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

  .app-header img {
    width: 36px;
    height: 36px;
  }

  .app-header h1 {
    font-size: 15px;
  }

  .app-header p {
    display: none;
  }

  .toolbar {
    top: 10px;
    right: 10px;
    grid-template-columns: repeat(4, 36px);
    gap: 4px;
  }

  .language-switch a {
    min-width: 32px;
    height: 25px;
    font-size: 11px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
    font-size: 19px;
  }

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

  #station-code {
    font-size: 24px;
  }

  #station-distance {
    font-size: 17px;
  }

  .scale-panel {
    right: 10px;
    bottom: 10px;
    width: calc(100vw - 20px);
    padding: 10px 12px;
  }

  .fade-control {
    margin-top: 8px;
  }

  .info-panel {
    top: 94px;
    right: 10px;
    width: calc(100vw - 20px);
    max-height: calc(100vh - 210px);
    overflow: auto;
  }
}

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

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

  .toolbar {
    grid-template-columns: repeat(4, 34px);
  }

  .readout-location {
    gap: 7px;
    font-size: 11px;
  }

  .legend-labels span:nth-child(even) {
    display: none;
  }
}
