/* Palette tokens for the existing CORA layout. */
:root {
  color-scheme: light;
  --page: #f2f5f9;
  --surface: #ffffff;
  --stripe: #f3f6fa;
  --heading: #e2eaf3;
  --ink: #17283c;
  --line: #aebed1;
  --link: #174f91;
  --accent: #235f9f;
  --on-accent: #ffffff;
  --error: #a32535;
  --ui-font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --data-font: ui-monospace, "SFMono-Regular", Consolas, monospace;
}

:root[data-palette="teal"] {
  --page: #eff6f4;
  --surface: #ffffff;
  --stripe: #edf6f3;
  --heading: #d9ece7;
  --ink: #132e2b;
  --line: #a7c4bd;
  --link: #075b50;
  --accent: #076b5e;
}

:root[data-palette="sand"] {
  --page: #f7f3eb;
  --surface: #fffdf8;
  --stripe: #f6efe3;
  --heading: #ece1ce;
  --ink: #38291d;
  --line: #c6b59b;
  --link: #774921;
  --accent: #845324;
}

/* Neutral alternatives. Links stay underlined in both variants. */
:root[data-palette="gray"] {
  --page: #efefef;
  --surface: #ffffff;
  --stripe: #f4f4f4;
  --heading: #e1e1e1;
  --ink: #272727;
  --line: #adadad;
  --link: #353535;
  --accent: #454545;
}

:root[data-palette="night-gray"] {
  --page: #e6e6e6;
  --surface: #f4f4f4;
  --stripe: #ebebeb;
  --heading: #d7d7d7;
  --ink: #262626;
  --line: #a3a3a3;
  --link: #303030;
  --accent: #424242;
}

:root[data-appearance="dark"] {
  color-scheme: dark;
  --page: #101722;
  --surface: #192333;
  --stripe: #1e2a3b;
  --heading: #28394f;
  --ink: #edf3fa;
  --line: #526781;
  --link: #a7d2ff;
  --accent: #a4cbf1;
  --on-accent: #101722;
  --error: #ffadb8;
}

:root[data-palette="teal"][data-appearance="dark"] {
  --page: #0c1a19;
  --surface: #142625;
  --stripe: #19302d;
  --heading: #23433d;
  --ink: #e5f5ef;
  --line: #4e766e;
  --link: #8ce3cf;
  --accent: #8ce3cf;
  --on-accent: #0c1a19;
}

:root[data-palette="sand"][data-appearance="dark"] {
  --page: #1c1713;
  --surface: #29211a;
  --stripe: #322820;
  --heading: #46382b;
  --ink: #f7ede0;
  --line: #806c57;
  --link: #f4ca95;
  --accent: #f4ca95;
  --on-accent: #1c1713;
}

:root[data-palette="default"][data-appearance="dark"] {
  --page: #191717;
  --surface: #222020;
  --stripe: #272424;
  --heading: #332f2f;
  --ink: #e1dddd;
  --line: #686060;
  --link: #e4abab;
  --accent: #d9a3a3;
  --on-accent: #191717;
}

:root[data-palette="gray"][data-appearance="dark"] {
  --page: #171717;
  --surface: #222222;
  --stripe: #292929;
  --heading: #343434;
  --ink: #dcdcdc;
  --line: #666666;
  --link: #dadada;
  --accent: #d0d0d0;
  --on-accent: #171717;
  --error: #e9bbbb;
}

:root[data-palette="night-gray"][data-appearance="dark"] {
  --page: #0e0e0e;
  --surface: #171717;
  --stripe: #1d1d1d;
  --heading: #272727;
  --ink: #bfbfbf;
  --line: #535353;
  --link: #c6c6c6;
  --accent: #b5b5b5;
  --on-accent: #0e0e0e;
  --error: #d6a4a4;
}

/* Keep the scientific plots and map tiles in their original colours. */
:where(:root:not([data-original-colors])) body {
  background: var(--page);
  color: var(--ink);
  font-family: var(--ui-font);
  line-height: 1.45;
}

:where(:root:not([data-original-colors])) :is(.cora-title, h1, h2, h3, h4, h5, h6) {
  color: var(--ink);
  font-family: var(--ui-font);
  font-weight: 650;
  line-height: 1.25;
}

:where(:root:not([data-original-colors])) .cora-title {
  letter-spacing: -0.025em;
}

:root[data-appearance="dark"] body > table img[src$="/cora_logo.png"] {
  filter: invert(1);
}

:where(:root:not([data-original-colors])) :is(p, table, th, td) {
  font-family: var(--ui-font);
}

:where(:root:not([data-original-colors])) a:is(:link, :visited, :active) {
  color: var(--link);
  text-underline-offset: 0.16em;
}

:where(:root:not([data-original-colors])) #content a[style*="color:black"] {
  color: var(--link) !important;
}

:where(:root:not([data-original-colors])) a:hover {
  color: var(--link);
  font-weight: inherit;
  text-decoration-thickness: 2px;
}

:where(:root:not([data-original-colors])) hr {
  background: var(--line);
  border: 0;
}

:where(:root:not([data-original-colors])) #hormenu {
  line-height: 1.9;
}

.theme-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.7rem 1rem;
  margin: 0.5rem auto;
}

.theme-controls[hidden] {
  display: none;
}

.theme-controls label {
  white-space: nowrap;
}

.theme-controls select {
  margin-inline-start: 0.25rem;
}

:where(:root:not([data-original-colors])) button,
:where(:root:not([data-original-colors])) select,
:where(:root:not([data-original-colors])) textarea,
:where(:root:not([data-original-colors])) input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]) {
  background-color: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  padding: 0.32em 0.6em;
  font-family: inherit;
  line-height: 1.3;
}

:where(:root:not([data-original-colors])) button:hover:not(:disabled),
:where(:root:not([data-original-colors])) input:is([type="submit"], [type="button"]):hover:not(:disabled) {
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
}

:where(:root:not([data-original-colors])) input[type="checkbox"],
:where(:root:not([data-original-colors])) input[type="radio"] {
  accent-color: var(--accent);
  filter: none;
}

:where(:root:not([data-original-colors])) :focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

:where(:root:not([data-original-colors])) #content table[border="1"] {
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

:where(:root:not([data-original-colors])) #content table[border="1"],
:where(:root:not([data-original-colors])) #content table[border="1"] :is(th, td) {
  border-color: var(--line);
}

:where(:root:not([data-original-colors])) #content table[border="1"] :is(th, td) {
  padding: 0.35em 0.55em;
}

:where(:root:not([data-original-colors])) #content th {
  background: var(--heading);
  font-weight: 650;
}

:where(:root:not([data-original-colors])) #content [bgcolor="white"],
:where(:root:not([data-original-colors])) #content table[border="1"] tr {
  background-color: var(--surface);
}

:where(:root:not([data-original-colors])) #content table[border="1"] tr:nth-child(even),
:where(:root:not([data-original-colors])) #content table.occ tr:nth-child(even) {
  background-color: var(--stripe);
}

:where(:root:not([data-original-colors])) #content table.occ tr:nth-child(odd) {
  background-color: var(--surface);
}

:where(:root:not([data-original-colors])) #content :is(table.occ, table[border="1"]) tr:has(> td > a):is(:hover, :focus-within) {
  background-color: var(--heading);
}

:where(:root:not([data-original-colors])) #content :is(pre, pre-wrap, tt) {
  background: var(--surface);
  color: var(--ink);
  font-family: var(--data-font);
  line-height: 1.5;
}

:where(:root:not([data-original-colors])) #content font[color="red"],
:where(:root:not([data-original-colors])) #content .errorlist {
  color: var(--error);
}

:where(:root:not([data-original-colors])) #navlist li a:link,
:where(:root:not([data-original-colors])) #navlist li a:visited {
  background: var(--surface);
  border-color: var(--line);
  color: var(--link);
}

:where(:root:not([data-original-colors])) #navlist li a:hover,
:where(:root:not([data-original-colors])) #navlist li a#current {
  background: var(--heading);
  border-color: var(--line);
  color: var(--ink);
}

:where(:root:not([data-original-colors])) .leaflet-container {
  color-scheme: light;
  color: #17283c;
}

:where(:root:not([data-original-colors])) .leaflet-container a:link,
:where(:root:not([data-original-colors])) .leaflet-container a:visited {
  color: #174f91;
}

/* Widen the prediction, call, favorites and observed-event tables when space permits. */
#content table:is([width="875px"], [width="850"][border="1"]) {
  width: min(100%, 72rem);
  margin-inline: auto;
}

@media (max-width: 60rem) {
  #content table:is([width="875px"], [width="850"][border="1"]),
  #content > table[border="1"]:not([width]) {
    display: block;
    width: max-content;
    max-width: 100%;
    overflow-x: auto;
    margin-inline: auto;
  }

  #content table:is([width="875px"], [width="850"][border="1"]) :is(th, td),
  #content > table[border="1"]:not([width]) :is(th, td) {
    white-space: nowrap;
  }

  #content table[width="800px"] {
    width: 100%;
  }

  #map_rep {
    max-width: 100%;
  }

  #content p {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }
}

.globe-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.6em;
  /* Center the controls over the 800 px globe, not the wider content area. */
  width: min(100%, 800px);
  margin-block: 0.5rem;
}

.globe-dimming {
  display: flex;
  align-items: center;
  gap: 0.3em;
}

#globe-export-status {
  min-width: 6em;
  font-size: 0.9em;
}

.globe-toolbar:has(#globe-dim:checked) + #svg1 {
  filter: brightness(0.6);
}

/* Prediction details use the existing 800 px globe and single-cell details table. */
#content:has(> #svg1) {
  overflow-x: auto;
}

#content:has(> #svg1) > table[width="800px"],
#content:has(> #svg1) > table:has(> caption) {
  width: min(100%, 50rem);
  margin-inline: auto;
}

#content:has(> #svg1) > table[width="800px"][border="1"],
#content:has(> #svg1) > table:has(> caption) {
  table-layout: fixed;
}

#content:has(> #svg1) > table[width="800px"][border="1"] pre {
  margin: 0;
  padding: clamp(0.4rem, 2vw, 1rem);
  text-align: start;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#content:has(> #svg1) > table:has(> caption) :is(th, td) {
  overflow-wrap: anywhere;
  padding: 0.35em 0.55em;
  text-align: center;
}

#content:has(> #svg1) > table:has(> caption) th:first-child {
  width: 38%;
}

#content:has(> #svg1) > table:has(> caption) th:nth-child(2) {
  width: 22%;
}

#content:has(> #svg1) > table:has(> caption) th:nth-child(3) {
  width: 23%;
}

#content:has(> #svg1) > table:has(> caption) :is(th, td):nth-child(n+3) {
  white-space: nowrap;
}

@media (max-width: 40rem) {
  #content:has(> #svg1) > table:has(> caption) {
    display: block;
    table-layout: auto;
    overflow-x: auto;
  }

  #content:has(> #svg1) > table:has(> caption) th:nth-child(-n+3) {
    width: auto;
  }
}

#content:has(> #svg1) #GTtable {
  max-width: 100%;
  overflow-x: auto;
}

#content:has(> #svg1) #map_pred {
  width: min(100%, 50rem);
  height: clamp(24rem, 85vw, 50rem);
  margin-inline: auto;
}

#content:has(> #svg1) #aladin-lite-div,
#content:has(> #svg1) #aladin-lite-div img {
  max-width: 100%;
}

@supports (zoom: calc(1px / 1px)) {
  /* Scale the drawing without changing the 800×800 coordinate system used by D3. */
  #content > #svg1 {
    zoom: min(1, calc((100vw - 40px) / 800px));
  }
}

:root[data-appearance="dark"] #map_pred :is(
  .leaflet-bar a,
  .leaflet-control-layers,
  .leaflet-control-attribution,
  .leaflet-control-mouseposition,
  .leaflet-popup-content-wrapper,
  .leaflet-popup-tip,
  .info
) {
  background-color: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}

:root[data-appearance="dark"] #map_pred :is(.leaflet-control-attribution, .leaflet-popup-content) a {
  color: var(--link);
}

:root[data-appearance="dark"] #map_pred :is(.leaflet-bar a:hover, .leaflet-bar a:focus-visible) {
  background-color: var(--heading);
}
