:root {
  --font-base: system-ui, -apple-system, "Segoe UI", sans-serif;

  --color-surface: rgba(32, 34, 40, 0.82);
  --color-surface-strong: rgba(36, 38, 44, 0.92);
  --color-surface-muted: rgba(40, 42, 50, 0.88);
  --color-surface-solid: #232731;
  --color-surface-active: rgba(255, 255, 255, 0.08);
  --color-surface-hover: rgba(255, 255, 255, 0.06);

  --color-border: rgba(255, 255, 255, 0.14);
  --color-border-strong: rgba(255, 255, 255, 0.22);
  --color-border-divider: rgba(255, 255, 255, 0.18);
  --color-border-input: rgba(255, 255, 255, 0.28);

  --color-overlay: rgba(4, 6, 10, 0.92);
  --color-overlay-strong: rgba(2, 3, 6, 0.95);

  --color-text: rgba(245, 247, 251, 0.92);
  --color-text-body: rgba(226, 229, 236, 0.9);
  --color-text-muted: rgba(198, 201, 210, 0.9);
  --color-text-weak: rgba(164, 168, 178, 0.9);
  --color-text-inverse: #fff;
  --color-text-shadow: #000;
  --color-link: #b8c8ff;
  --color-link-hover: #d6e1ff;

  --color-focus: rgba(255, 255, 255, 0.55);

  --shadow-elevated: 0 12px 28px rgba(0, 0, 0, 0.4);

  --radius-sm: 4px;
  --radius-md: 6px;
}

body {
  margin: 0;
  font-family: var(--font-base);
  color: var(--color-text);
}

html,
body {
  height: 100%;
}

main {
  min-height: 100vh;
  position: relative;
}

#globeViz {
  position: fixed;
  inset: 0;
  z-index: 0;
}

/* During loading */
#globe-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 600;
  background: var(--color-overlay-strong);
  color: var(--color-text-inverse);
  z-index: 50;
  pointer-events: none;
}

/* top-center slider */
#controls {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 800px;
  width: 90vw;
  display: none; /* Switch to grid after loading */
  grid-template-columns: 1fr;
  gap: 8px;
  z-index: 20;
  background: var(--color-surface);
  padding: 8px 12px;
  border-radius: var(--radius-md);
}
#controlsTitle {
  justify-self: center;
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
  font-weight: 700;
  text-align: center;
}
input[type="range"] {
  /* align with month labels */
  width: 93.5%; margin-left: 3.5%;
}
#monthRow {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  text-align: center;
  font-size: 12px;
  user-select: none;
}

.panelToggle {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface-strong);
  color: var(--color-text);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.panelToggle:hover,
.panelToggle:focus {
  background: var(--color-surface-solid);
  border-color: var(--color-border-strong);
}

.panelToggle[aria-expanded="true"] {
  background: var(--color-surface-active);
}

.panel-icon {
  font-size: 16px;
  line-height: 1;
}

#panelsSection {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  left: 50%;
  transform: translateX(-50%);
  max-width: 360px;
  width: 90vw;
  display: none; /* Switch to flex after loading */
  flex-direction: column;
  gap: 8px;
  z-index: 30;
  background: var(--color-surface);
  padding: 8px 12px;
  border-radius: var(--radius-md);
}

#togglesPanel {
  display: grid;
  grid-template-columns: 1fr 1.1fr 0.7fr auto;
  align-items: stretch;
  gap: 8px;
  width: 100%;
}

#togglesPanel.has-language {
  grid-template-columns: 1fr 1.1fr 0.7fr 0.6fr auto;
}

.settings-tile {
  display: grid;
  grid-template-rows: auto auto;
  gap: 4px;
}

.settings-tile .panelToggle {
  width: 100%;
  justify-content: center;
  white-space: nowrap;
}

.settings-value {
  display: inline-block;
  width: 100%;
  text-align: center;
  font-size: 12px;
  color: var(--color-text-muted);
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#infoToggle {
  justify-content: center;
  align-self: stretch;
}
.info-tile {
  display: grid;
  grid-template-rows: auto auto;
  gap: 4px;
}
.info-tile .panelToggle {
  padding-inline: 8px;
}

.language-tile {
  display: none;
  grid-template-rows: auto auto;
  gap: 4px;
}

.language-tile:not([hidden]) {
  display: grid;
}

.language-tile .panelToggle {
  justify-content: center;
  padding-inline: 8px;
}

.flag-icon {
  font-size: 18px;
  line-height: 1;
}

.panel-icon svg {
  width: 16px;
  height: 16px;
  display: block;
}

#panelDivider {
  width: 100%;
  border: 0;
  border-top: 1px solid var(--color-border-divider);
  margin: 4px 0;
}

#panelDivider[hidden] {
  display: none;
}

#settingsPanel,
#infoPanel {
  width: 100%;
}

#settingsPanel[hidden],
#infoPanel[hidden] {
  display: none;
}

#settingsPanel:not([hidden]) {
  display: block;
}

.settings-panel-section {
  display: none;
  gap: 8px;
}

.settings-panel-section:not([hidden]) {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#infoPanel:not([hidden]) {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#basemapSetting {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.setting-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.basemap-tiles {
  display: flex;
  align-items: stretch;
  gap: 6px;
  flex-wrap: nowrap;
  width: 100%;
  overflow-x: auto;
  padding: 2px 0 6px;
  max-width: 100%;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
}

.basemap-tiles::-webkit-scrollbar {
  height: 8px;
}

.basemap-tiles::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-sm);
}

.basemap-tile {
  flex: 0 0 78px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface-strong);
  color: var(--color-text);
  padding: 6px;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.basemap-tile:hover {
  transform: translateY(-1px);
  border-color: var(--color-border-strong);
}

.basemap-tile:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.basemap-tile.selected {
  border-color: var(--color-focus);
  box-shadow: 0 0 0 1px var(--color-focus);
}

.basemap-tile img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--color-surface-solid);
}

.basemap-title {
  display: inline-block;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  text-align: center;
}

#dataModeSetting,
#temperatureUnitSetting {
  margin: 0;
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#dataModeSetting legend,
#temperatureUnitSetting legend {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.dataModeOption {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}

.dataModeOption input:disabled {
  cursor: not-allowed;
}

.dataModeOption input:disabled + span {
  opacity: 0.55;
}

.dataModeLabel {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  position: relative;
}

.dataModeTitle {
  font-weight: 400;
}

.language-menu {
  display: grid;
  grid-template-columns: auto auto auto minmax(0, 1fr);
  column-gap: 6px;
  row-gap: 6px;
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface-strong);
}

.language-option {
  display: contents;
  font-size: 13px;
  color: var(--color-text-body);
}

.language-option > * {
  align-self: center;
}

.language-flag {
  font-size: 16px;
  line-height: 1;
}

.language-separator {
  color: var(--color-text-muted);
  justify-self: center;
}

.language-link {
  color: var(--color-link);
  text-decoration: underline;
  text-decoration-color: rgba(184, 200, 255, 0.7);
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

.language-link:hover,
.language-link:focus {
  color: var(--color-link-hover);
  text-decoration-color: var(--color-link-hover);
}

.language-url {
  color: var(--color-text-muted);
}

.language-link,
.language-url {
  justify-self: start;
  word-break: break-all;
}

/* Info button next to TravelScore */
.infoTrigger {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-surface-muted);
  color: var(--color-text-weak);
  font-size: 12px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.infoTrigger:hover,
.infoTrigger:focus-visible {
  background: var(--color-surface-hover);
  border-color: var(--color-border-strong);
  color: var(--color-text);
}

.infoTrigger:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 1px;
}

/* Tooltip for TravelScore */
.infoTooltip {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  display: none;
  padding: 8px 10px;
  min-width: 200px;
  max-width: 80vw;
  background: var(--color-overlay);
  color: var(--color-text-inverse);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-elevated);
  font-size: 12px;
  line-height: 1.4;
  z-index: 10;
}

.infoTooltip.visible {
  display: block;
}

#infoPanel h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
  text-align: center;
}

#infoPanelLogo {
  width: 64px;
  height: 64px;
  align-self: center;
}

#infoPanel a {
  color: var(--color-link);
  text-decoration: underline;
  text-decoration-color: rgba(184, 200, 255, 0.7);
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

#infoPanel a:hover,
#infoPanel a:focus {
  color: var(--color-link-hover);
  text-decoration-color: var(--color-link-hover);
}

#infoPanel p,
#infoPanel li,
#infoPanel summary {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--color-text-body);
}

#infoPanel summary {
  cursor: pointer;
}

#legalLinks {
  display: flex;
  align-items: center;
  gap: 4px;
  align-self: flex-end;
}

#legalLinks a {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-link);
  text-decoration: underline;
  text-decoration-color: rgba(184, 200, 255, 0.7);
  align-self: flex-start;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

#legalLinks a:hover,
#legalLinks a:focus {
  color: var(--color-link-hover);
  text-decoration-color: var(--color-link-hover);
}

@media (max-width: 720px) {
  #controls {
    top: auto;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  }
  #panelsSection {
    bottom: auto;
    top: calc(env(safe-area-inset-top, 0px) + 16px);
    flex-direction: column-reverse;
  }
}

/* simple score dot */
.score-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%; /* circle */
  display: grid;
  place-items: center;
  font-size: 11px;
  pointer-events: none;
}

.city-marker {
  position: relative;
  width: 0;
  height: 0;
  pointer-events: none;
}

.city-marker .score-dot {
  position: absolute;
  top: -11px;
  left: -11px;
}

.city-label {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-weight: 700;
  font-size: 12px;
  line-height: 1.1;
  text-align: center;
  color: var(--color-text-inverse);
  text-shadow:
    -1px -1px 0 var(--color-text-shadow),
    1px -1px 0 var(--color-text-shadow),
    -1px 1px 0 var(--color-text-shadow),
    1px 1px 0 var(--color-text-shadow),
    0 0 2px var(--color-text-shadow);
}
