:root {
  /* Both themes are supported: the browser picks one, and draws its own widgets to match. */
  color-scheme: light dark;

  /* Light theme, the default. The dark one below replaces these four. */
  --ui-background: oklch(98.4% 0.003 247.858);
  --ui-foreground: #fff;
  --ui-text: oklch(27.9% 0.041 260.031);
  --ui-selected: oklch(96.8% 0.007 247.896);

  /* Derived from the text colour, so they follow the theme on their own. */
  --ui-line: color-mix(in oklch, var(--ui-text) 14%, transparent);
  --ui-text-dim: color-mix(in oklch, var(--ui-text) 72%, transparent);
  --ui-font: "Helvetica Neue", Helvetica, Arial, sans-serif;

  /* Sunset gradient, the same in both themes. */
  --accent-stops:
    oklch(49.1% 0.27 292.581), oklch(66.7% 0.295 322.15), oklch(71.8% 0.202 349.761),
    oklch(82.8% 0.189 84.429);
  --accent: linear-gradient(180deg, var(--accent-stops));
  --pin-cards: #e0528c;
  --pin-meditation: #6f4fc4;
  --pin-magazines: #dc6b22;
  --pin-underwater: #2a9d5c;
  --pin-treasures: #2a62c9;
  --pin-animals: #8a5a2c;
  --pin-ramps: #d23b30;
}

/* Dark theme: follows the browser's setting, which follows the device's unless changed. */
@media (prefers-color-scheme: dark) {
  :root {
    --ui-background: #000;
    --ui-foreground: oklch(20.8% 0.042 265.755);
    --ui-text: #fff;
    --ui-selected: oklch(37.2% 0.044 257.287);
  }
}

html,
body {
  height: 100%;
  margin: 0;
}

/* What the hidden attribute asks for, also on the elements given a display of their own below. */
[hidden] {
  display: none !important;
}

/* The page is a column: the map, or the page shown in its place, takes the height the navbar leaves. */
body {
  display: flex;
  flex-direction: column;
  background: var(--ui-background);
  color: var(--ui-text);
}

#map {
  flex: 1 1 0;
  min-height: 0;
}

/* Read by screen readers and search engines, not drawn: the page title sits here. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Shown in place of the map when scripts are off. */
.noscript {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 24px;
  background: var(--ui-background);
  color: var(--ui-text);
  font: 600 16px/1.5 var(--ui-font);
  text-align: center;
}

/* Same colour as the open ocean in the tiles, so the map edge is invisible. */
.leaflet-container {
  background: #2f90b0;
}

/* Toolbar: a vertical strip of square icon cells in the foreground colour. */
.toolbar {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 1100; /* above every Leaflet pane and control */
  display: flex;
  flex-direction: column;
  background: var(--ui-foreground);
  border-left: 2px solid var(--ui-line);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

.toolbar__button {
  position: relative;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ui-text-dim);
  font-size: 24px;
  cursor: pointer;
  transition:
    background-color 0.12s,
    color 0.12s;
}

.toolbar__button:focus-visible,
.navbar__button:focus-visible {
  background: var(--ui-selected);
  color: var(--ui-text);
  outline: 2px solid var(--ui-text);
  outline-offset: -2px;
}

/* Hover only where there is a real pointer: on touch it would stick after a tap. */
@media (hover: hover) {
  .toolbar__button:hover:not(:disabled),
  .navbar__button:hover {
    background: var(--ui-selected);
    color: var(--ui-text);
  }

  .toolbar__button:hover::after {
    opacity: 1;
  }
}

.toolbar__button:disabled {
  cursor: default;
}

/* Dim only the icon, so a disabled button's tooltip stays readable. */
.toolbar__button:disabled i {
  opacity: 0.35;
}

/* A selected cell keeps the hover look for good: its accent line is what sets it apart. */
.toolbar__button[aria-pressed="true"],
.navbar__button[aria-current="page"] {
  background: var(--ui-selected);
  color: var(--ui-text);
}

/* Accent line beside a selected cell, covering the toolbar's left border. */
.toolbar__button[aria-pressed="true"]::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -2px;
  width: 2px;
  background: var(--accent);
}

.toolbar__divider {
  height: 1px;
  margin: 0 12px;
  background: var(--ui-line);
}

/* The layer cells: past this height they scroll, so the toolbar stops growing with each new layer. */
.toolbar__layers {
  /* One cell wide whatever happens: where a scrollbar takes up room, it lies over the cells'
     right edge instead of widening the toolbar. */
  width: 52px;
  max-height: 256px;
  /* Reaches over the toolbar's left border, where a selected cell draws its accent line. */
  margin-left: -2px;
  padding-left: 2px;
  overflow: hidden auto;
  overscroll-behavior: contain;
}

/* The scrollbar of what scrolls, this list and the pages: a slim bar in the text
   colour over a clear track, so a selected cell's background shows through. Styled this way it
   stays on show, and a list reads as scrollable even at rest. */
.toolbar__layers,
.page {
  --scrollbar-thumb: color-mix(in oklch, var(--ui-text) 36%, transparent);
}

@supports selector(::-webkit-scrollbar) {
  .toolbar__layers::-webkit-scrollbar,
  .page::-webkit-scrollbar {
    width: 6px;
  }

  .toolbar__layers::-webkit-scrollbar-track,
  .page::-webkit-scrollbar-track {
    background: transparent;
  }

  .toolbar__layers::-webkit-scrollbar-thumb,
  .page::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
  }

  .toolbar__layers::-webkit-scrollbar-thumb:hover,
  .toolbar__layers::-webkit-scrollbar-thumb:active,
  .page::-webkit-scrollbar-thumb:hover,
  .page::-webkit-scrollbar-thumb:active {
    background: var(--ui-text-dim);
  }
}

/* Firefox has only the standard properties, which choose the width themselves. */
@supports not selector(::-webkit-scrollbar) {
  .toolbar__layers,
  .page {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
  }
}

/* A hint that the list goes on below: script.js sets data-more while cells are hidden there. */
.toolbar[data-more]::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 32px;
  background: linear-gradient(transparent, var(--ui-foreground));
  pointer-events: none;
}

/* Tooltips: the toolbar's own and the Leaflet ones on the pins share one look. */
.toolbar__button::after,
.leaflet-tooltip.pin-tooltip {
  padding: 6px 10px;
  border: 0;
  border-radius: 0;
  background: var(--ui-foreground);
  box-shadow: none;
  color: var(--ui-text);
  font: 600 11px/1 var(--ui-font);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.toolbar__button::after {
  content: attr(data-tooltip);
  position: absolute;
  top: 50%;
  left: calc(100% + 12px);
  transform: translateY(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}

.toolbar__button:focus-visible::after {
  opacity: 1;
}

/* The scrolling list would clip a tooltip at its edge, so a layer's tooltip is pinned to the
   window instead, beside the spot where script.js last found its cell. */
.toolbar__layers .toolbar__button::after {
  position: fixed;
  top: var(--tooltip-top);
  left: calc(var(--tooltip-left) + 12px);
}

.leaflet-tooltip.pin-tooltip::before {
  border-top-color: var(--ui-foreground);
}

/* Navbar: a strip below the map, not over it, in the foreground colour. */
.navbar {
  display: flex;
  flex: none;
  background: var(--ui-foreground);
  border-top: 2px solid var(--ui-line);
}

.navbar__button {
  position: relative;
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  height: 56px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ui-text-dim);
  font: 600 10px/1 var(--ui-font);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition:
    background-color 0.12s,
    color 0.12s;
}

.navbar__button i {
  font-size: 22px;
}

/* On a phone the cells share the whole strip. On a wider screen they stop growing and gather in the middle. */
@media (min-width: 768px) {
  .navbar {
    justify-content: center;
  }

  .navbar__button {
    max-width: 128px;
  }
}

/* Four cells leave a narrow phone little room, so there the labels are set tighter: the longest,
   Compartilhar, would otherwise run into its neighbours. */
@media (max-width: 380px) {
  .navbar__button {
    letter-spacing: 0.02em;
  }
}

/* Accent line above the current cell, covering the navbar's top border. */
.navbar__button[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: -2px;
  right: 0;
  left: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent-stops));
}

/* Pins: round blips coloured by layer. */
.pin {
  display: grid;
  place-items: center;
  box-sizing: border-box;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--pin);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}

.pin--cards {
  --pin: var(--pin-cards);
}

.pin--meditation {
  --pin: var(--pin-meditation);
}

.pin--magazines {
  --pin: var(--pin-magazines);
}

.pin--underwater {
  --pin: var(--pin-underwater);
}

.pin--treasures {
  --pin: var(--pin-treasures);
}

.pin--animals {
  --pin: var(--pin-animals);
}

.pin--ramps {
  --pin: var(--pin-ramps);
}

/* A found pin goes dark and keeps its layer colour only as a ring. */
.pin--found {
  border-color: var(--pin);
  background: #14171c;
  opacity: 0.85;
}

/* Pages, for the trophies and the profile: shown in place of the map. On a phone a page is flat,
   the foreground colour from edge to edge with no frame. */
.page {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  background: var(--ui-foreground);
  color: var(--ui-text);
  font-family: var(--ui-font);
}

/* On a wider screen the content becomes a framed panel down the middle, over the background colour. */
@media (min-width: 768px) {
  .page {
    padding: 16px;
    background: var(--ui-background);
  }

  .page__panel {
    max-width: 640px;
    margin: 0 auto;
    border: solid;
    border-width: 2px 0 0;
    border-image: linear-gradient(90deg, var(--accent-stops)) 1;
    background: var(--ui-foreground);
    box-shadow: 0 0 0 1px var(--ui-line);
  }
}

.page__title {
  margin: 0;
  padding: 18px 20px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.page__hint {
  margin: 0;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--ui-line);
  color: var(--ui-text-dim);
  font-size: 12px;
  line-height: 1.5;
}

/* Progress rows: icon, name and count on one line, the bar underneath. */
.progress-list {
  margin: 0;
  padding: 0 20px;
  list-style: none;
}

.progress {
  display: grid;
  grid-template-columns: auto 1fr auto 4ch;
  align-items: center;
  gap: 10px;
  padding: 14px 0;
  border-top: 1px solid var(--ui-line);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.progress > i {
  color: var(--ui-text-dim);
  font-size: 20px;
}

.progress__label {
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.progress__count {
  color: var(--ui-text-dim);
}

.progress__percent {
  text-align: right;
}

.progress__track {
  grid-column: 1 / -1;
  height: 6px;
  background: var(--ui-line);
}

.progress__fill {
  display: block;
  height: 100%;
  background: var(--bar);
}

.progress--total {
  padding-bottom: 18px;
}

.progress--total .progress__percent {
  font-size: 16px;
}

.progress--total .progress__track {
  height: 8px;
}

/* Trophies: how many there are of each grade, then one row for each trophy. */
.trophy-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: 0;
  padding: 14px 20px;
  border-top: 1px solid var(--ui-line);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.trophy-summary span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.trophy-summary i,
.trophy > i {
  color: var(--grade);
}

.trophy-summary i {
  font-size: 16px;
}

.trophy-list {
  margin: 0;
  padding: 0 20px;
  border-top: 1px solid var(--ui-line);
  list-style: none;
}

/* Icon on the left, name and grade on one line, the description under them. */
.trophy {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 4px 12px;
  padding: 12px 0;
  border-top: 1px solid var(--ui-line);
}

.trophy:first-child {
  border-top: 0;
}

.trophy > i {
  grid-row: 1 / 3;
  font-size: 24px;
}

.trophy__name {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
}

/* Marks a trophy the console keeps secret until it is earned. */
.trophy__tag {
  margin-left: 8px;
  padding: 2px 6px;
  background: var(--ui-selected);
  color: var(--ui-text-dim);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  vertical-align: 1px;
}

.trophy__grade {
  color: var(--ui-text-dim);
  font-size: 10px;
  font-weight: 600;
  line-height: 1.8;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.trophy__description {
  grid-column: 2 / 4;
  margin: 0;
  color: var(--ui-text-dim);
  font-size: 12px;
  line-height: 1.5;
}

.trophy--platinum {
  --grade: #7c9cc0;
}

.trophy--gold {
  --grade: #d4a017;
}

.trophy--silver {
  --grade: #939ba6;
}

.trophy--bronze {
  --grade: #b56b3a;
}
