/* Catchment Explorer (code name rainroute). The tool fills the whole window, over the site's own header.
 * The frame (panel, search, card) matches Will It Flood and School Scout, so the map tools feel like one family. */

body.iit-tool-rainroute,
body.iit-tool {
  overflow: hidden !important;
}

#iit-rainroute {
  --rrt-brand: #73182c;
  --rrt-blue: #12a7ff;
  --rrt-ink: #111827;
  --rrt-soft: #4b5563;
  --rrt-grey: #eaecf0;
  position: fixed;
  inset: 0;
  z-index: 999999;
  background: #2a3324;
  color: var(--rrt-ink);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.35;
  text-align: left;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body.admin-bar #iit-rainroute { top: 32px; }
@media (max-width: 782px) {
  body.admin-bar #iit-rainroute { top: 46px; }
}

#iit-rainroute,
#iit-rainroute *,
#iit-rainroute *::before,
#iit-rainroute *::after {
  box-sizing: border-box;
}

/* The theme styles plain buttons loudly. None of it inside the tool. */
#iit-rainroute button {
  letter-spacing: 0;
  text-transform: none;
  outline: 0; /* the theme rings every button; here only a keyboard gets a ring */
}
#iit-rainroute button:focus-visible {
  outline: 2px solid var(--rrt-brand);
  outline-offset: 2px;
}

#iit-rainroute .rrt-map {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #2a3324;
  font-family: inherit;
}

#iit-rainroute .rrt-hide {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* The column on the left: the panel, then the answer. */
#iit-rainroute .rrt-side {
  position: absolute;
  top: 10px;
  left: 10px;
  bottom: 10px;
  z-index: 1100;
  width: 400px;
  max-width: calc(100% - 20px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
#iit-rainroute .rrt-side > * {
  pointer-events: auto;
}

#iit-rainroute .rrt-panel,
#iit-rainroute .rrt-card {
  flex: 0 0 auto;
  margin: 0;
  padding: 14px;
  border: 1px solid rgba(17, 24, 39, 0.1);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 10px 28px rgba(17, 24, 39, 0.18);
}
#iit-rainroute .rrt-panel {
  flex: 0 0 auto;
  max-height: 62%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
#iit-rainroute .rrt-card {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
#iit-rainroute .rrt-card[hidden] {
  display: none;
}

/* The panel */
#iit-rainroute .rrt-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--rrt-soft);
}
#iit-rainroute .rrt-top a {
  color: var(--rrt-brand);
  font-weight: 700;
  text-decoration: none;
}
#iit-rainroute .rrt-top a:hover,
#iit-rainroute .rrt-top a:focus-visible {
  text-decoration: underline;
}
/* Every heading on the site is Anton in capitals. */
#iit-rainroute .rrt-title,
#iit-rainroute .rrt-card-title,
#iit-rainroute .rrt-listhead {
  margin: 0;
  padding: 0;
  border: 0;
  font-family: Anton, Impact, "Arial Narrow", sans-serif;
  font-weight: 400;
  letter-spacing: 0.01em;
  text-align: left;
  text-transform: uppercase;
  color: var(--rrt-ink);
}
#iit-rainroute .rrt-title {
  font-size: 34px;
  line-height: 1;
  color: var(--rrt-brand);
}
/* The logo, as the card has it: black capitals, the A a blue drop. */
#iit-rainroute .rrt-title img {
  display: block;
  width: auto;
  max-width: 100%;
  height: 25px;
  margin: 2px 0 0;
}
#iit-rainroute .rrt-sub {
  margin: 6px 0 10px;
  padding: 0;
  text-align: left;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--rrt-soft);
}

/* A long label for a computer, a short one for a phone. */
#iit-rainroute .rrt-short {
  display: none;
}

#iit-rainroute .rrt-msg {
  margin: 6px 0 0;
  padding: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--rrt-brand);
  overflow-wrap: anywhere;
}
#iit-rainroute .rrt-msg:empty {
  display: none;
}

/* Waterways and Catchments: two buttons. The words turn all of that kind on or off; the arrow opens the strip. */
#iit-rainroute .rrt-masters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0 0;
}
#iit-rainroute .rrt-master {
  display: flex;
  min-width: 0;
  border: 2px solid var(--rrt-brand);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}
#iit-rainroute .rrt-all,
#iit-rainroute .rrt-open {
  appearance: none;
  min-height: 44px;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: #fff;
  box-shadow: none;
  color: var(--rrt-brand);
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}
#iit-rainroute .rrt-all {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  padding: 0 8px;
  white-space: nowrap;
}
#iit-rainroute .rrt-all.is-on {
  background: var(--rrt-brand);
  color: #fff;
}
#iit-rainroute .rrt-open {
  flex: 0 0 40px;
  width: 40px;
  padding: 0;
  border-left: 2px solid var(--rrt-brand);
}
#iit-rainroute .rrt-open span {
  display: block;
  width: 9px;
  height: 9px;
  margin: -4px auto 0;
  border-right: 2.5px solid currentColor;
  border-bottom: 2.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s;
}
#iit-rainroute .rrt-open[aria-expanded="true"] {
  background: #fbeef1;
}
#iit-rainroute .rrt-open[aria-expanded="true"] span {
  margin-top: 4px;
  transform: rotate(225deg);
}

/* The little marks: a line for a waterway, a patch for a catchment. */
#iit-rainroute .rrt-key {
  flex: 0 0 auto;
  display: block;
  background: currentColor;
}
#iit-rainroute .rrt-key--line {
  width: 18px;
  height: 4px;
  border-radius: 2px;
  transform: rotate(-20deg);
}
#iit-rainroute .rrt-key--area {
  width: 15px;
  height: 12px;
  border: 2px solid currentColor;
  border-radius: 4px;
  background: transparent;
}
#iit-rainroute .rrt-key--border {
  width: 18px;
  height: 0;
  border-top: 3px dashed #6b7280;
  background: transparent;
}
#iit-rainroute .rrt-key--labels {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: transparent;
}
#iit-rainroute .rrt-key--labels::before {
  content: "Aa";
  display: block;
  font-size: 11px;
  font-weight: 800;
  line-height: 14px;
}

/* The strip: a chip for each waterway or catchment, in its own colour. On a computer they wrap; on a phone
   they sit in one row you swipe. */
#iit-rainroute .rrt-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 0;
}
#iit-rainroute .rrt-strip[hidden] {
  display: none;
}
#iit-rainroute .rrt-item {
  appearance: none;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  margin: 0;
  padding: 0 12px;
  border: 2px solid #d3d8e0;
  border-radius: 999px;
  background: #fff;
  box-shadow: none;
  color: #8a929e;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
}
#iit-rainroute .rrt-item .rrt-key {
  color: #c5cad3;
}
#iit-rainroute .rrt-item.is-on {
  border-color: var(--rrt-c, var(--rrt-ink));
  color: var(--rrt-ink);
}
#iit-rainroute .rrt-item.is-on .rrt-key {
  color: var(--rrt-c, var(--rrt-ink));
}
#iit-rainroute .rrt-item--area.is-on .rrt-key {
  background: color-mix(in srgb, var(--rrt-c) 45%, transparent);
}

/* The border and the names: two switches of their own, under Waterways and Catchments. */
#iit-rainroute .rrt-extras {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 8px 0 0;
}
#iit-rainroute .rrt-extra {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  min-height: 40px;
  margin: 0;
  padding: 0 8px;
  border: 2px solid #d3d8e0;
  border-radius: 10px;
  background: #fff;
  box-shadow: none;
  color: #8a929e;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
}
#iit-rainroute .rrt-extra .rrt-key {
  color: #c5cad3;
}
#iit-rainroute .rrt-extra .rrt-key--border {
  border-top-color: #c5cad3;
}
#iit-rainroute .rrt-extra.is-on {
  border-color: var(--rrt-ink);
  color: var(--rrt-ink);
}
#iit-rainroute .rrt-extra.is-on .rrt-key {
  color: var(--rrt-ink);
}
#iit-rainroute .rrt-extra.is-on .rrt-key--border {
  border-top-color: var(--rrt-ink);
}

/* The map's own buttons, over the zoom: use my location, and the other map style. */
#iit-rainroute .rrt-mapbtns {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 10px;
}
#iit-rainroute .leaflet-control-container .rrt-mapbtns {
  pointer-events: auto;
}
#iit-rainroute .rrt-mapbtn {
  appearance: none;
  min-width: 44px;
  height: 44px;
  margin: 0;
  padding: 0 10px;
  border: 0;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 2px 10px rgba(17, 24, 39, 0.28);
  color: var(--rrt-ink);
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}
#iit-rainroute #rrt-locate {
  font-size: 20px;
}
#iit-rainroute .rrt-mapbtn:disabled {
  opacity: 0.5;
  cursor: progress;
}
#iit-rainroute .rrt-mapbtn[hidden] {
  display: none;
}
/* Before the map takes them, they wait out of sight. */
#iit-rainroute > .rrt-mapbtns {
  display: none;
}

#iit-rainroute .rrt-small {
  margin: 10px 0 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--rrt-soft);
}
#iit-rainroute .rrt-small a,
#iit-rainroute .rrt-more-link a {
  color: var(--rrt-brand);
  font-weight: 700;
}

/* The card: the catchments a spot sits inside, smallest first, down to the bay. */
#iit-rainroute .rrt-card-head {
  position: relative;
  padding-right: 40px;
}
/* This catchment's own switches, under its name. */
#iit-rainroute .rrt-card-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 8px 0 2px;
}
#iit-rainroute .rrt-card-show {
  margin-right: 2px;
  font-size: 12px;
  font-weight: 800;
  color: var(--rrt-soft);
}
#iit-rainroute .rrt-card-tools .rrt-item {
  min-height: 36px;
}
#iit-rainroute .rrt-kicker {
  margin: 0 0 2px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--rrt-brand);
}
#iit-rainroute .rrt-card-title {
  font-size: 24px;
  line-height: 1.1;
}
#iit-rainroute .rrt-close {
  appearance: none;
  position: absolute;
  top: -6px;
  right: -6px;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--rrt-soft);
  font-family: inherit;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}
#iit-rainroute .rrt-close:hover,
#iit-rainroute .rrt-close:focus-visible {
  background: var(--rrt-grey);
  color: var(--rrt-ink);
}
#iit-rainroute .rrt-routehead {
  margin: 12px 0 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--rrt-soft);
}
#iit-rainroute .rrt-route {
  margin: 0 0 0 6px;
  padding: 0 0 0 18px;
  border-left: 2px solid #9cc9ea;
  list-style: none;
}
#iit-rainroute .rrt-route li {
  position: relative;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  font-size: 15px;
}
#iit-rainroute .rrt-route li::before {
  content: none;
}
#iit-rainroute .rrt-dot {
  position: absolute;
  top: 9px;
  left: -26px;
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #8a94a0;
}
#iit-rainroute .rrt-route b {
  font-weight: 700;
}
#iit-rainroute .rrt-route em {
  font-style: normal;
  font-weight: 600;
  color: var(--rrt-soft);
}
#iit-rainroute .rrt-route small {
  display: block;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--rrt-soft);
}
#iit-rainroute .rrt-nest,
#iit-rainroute .rrt-note,
#iit-rainroute .rrt-more-link {
  margin: 10px 0 0;
  font-size: 14px;
  line-height: 1.45;
  color: #374151;
}
#iit-rainroute .rrt-nest {
  font-size: 13px;
  font-weight: 600;
  color: var(--rrt-soft);
}

/* Names on the map. */
#iit-rainroute .rrt-label {
  background: none;
  border: 0;
}
#iit-rainroute .rrt-label span {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.1;
  color: #fff;
  text-shadow: 0 1px 2px #000, 0 0 6px rgba(0, 0, 0, 0.85);
  letter-spacing: 0.02em;
  pointer-events: none;
}
#iit-rainroute .rrt-label--big span {
  font-size: 13px;
}

/* A hint over the map until the first answer. */
#iit-rainroute .rrt-hint {
  position: absolute;
  left: 50%;
  bottom: 24px;
  z-index: 1000;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.82);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  pointer-events: none;
  white-space: nowrap;
}
#iit-rainroute .rrt-hint[hidden] {
  display: none;
}
#iit-rainroute .rrt-noscript {
  position: absolute;
  inset: auto 16px 16px;
  z-index: 2000;
  padding: 14px;
  border-radius: 14px;
  background: #fff;
}

/* Leaflet's own bits, kept clear of the panel. */
#iit-rainroute .leaflet-bottom.leaflet-right {
  margin-bottom: 0;
}
#iit-rainroute .leaflet-control-zoom a {
  width: 40px;
  height: 40px;
  line-height: 40px;
  font-size: 20px;
}
#iit-rainroute .leaflet-control-attribution {
  font-size: 11px;
}

@media (prefers-reduced-motion: reduce) {
  #iit-rainroute * {
    transition: none !important;
    animation: none !important;
  }
}

/* Phones first: the panel sits across the top, kept short so the map shows, and the answer slides up from
   the foot. With an answer on screen the panel shrinks to its title and search. */
@media (max-width: 720px) {
  #iit-rainroute .rrt-side {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-width: none;
    justify-content: space-between;
    gap: 0;
  }
  /* Two short rows: the name with All tools beside it, then Waterways and Catchments. A strip opens under
   * them when an arrow is pressed. Jamey, 26 November: "The toolbar takes up half the screen on mobile". */
  #iit-rainroute .rrt-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 8px;
    align-items: center;
    max-height: 62%;
    padding: 10px 12px 10px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    border-width: 0 0 1px;
    border-radius: 0 0 16px 16px;
  }
  #iit-rainroute .rrt-top {
    display: contents;
  }
  #iit-rainroute .rrt-by,
  #iit-rainroute .rrt-sub,
  #iit-rainroute .rrt-small,
  #iit-rainroute .rrt-long {
    display: none;
  }
  #iit-rainroute .rrt-short {
    display: inline;
  }
  #iit-rainroute .rrt-back {
    grid-row: 1;
    grid-column: 2;
    justify-self: end;
    margin: -8px 0;
    padding: 8px 0;
  }
  #iit-rainroute .rrt-title {
    grid-row: 1;
    grid-column: 1;
    font-size: 26px;
  }
  #iit-rainroute .rrt-title img {
    height: 19px;
  }
  #iit-rainroute .rrt-msg {
    grid-row: 5;
    grid-column: 1 / -1;
  }
  #iit-rainroute .rrt-extras {
    grid-row: 4;
    grid-column: 1 / -1;
  }
  #iit-rainroute .rrt-extra {
    min-height: 36px;
  }
  /* With an answer open, the card has that catchment's own switches, so the row folds away and the
   * map keeps room for its buttons. */
  #iit-rainroute.has-answer .rrt-extras {
    display: none;
  }
  #iit-rainroute .rrt-masters {
    grid-row: 2;
    grid-column: 1 / -1;
    margin-top: 8px;
  }
  #iit-rainroute .rrt-strip {
    grid-row: 3;
    grid-column: 1 / -1;
    flex-wrap: nowrap;
    margin: 8px calc(-1 * max(12px, env(safe-area-inset-right))) 0 calc(-1 * max(12px, env(safe-area-inset-left)));
    padding: 0 12px 2px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  #iit-rainroute .rrt-strip::-webkit-scrollbar {
    display: none;
  }
  /* The credits on one line, cut short, until tapped. */
  #iit-rainroute .leaflet-control-attribution {
    max-width: calc(100vw - 64px);
    overflow: hidden;
    font-size: 10px;
    white-space: nowrap;
    text-overflow: ellipsis;
    cursor: pointer;
  }
  #iit-rainroute .leaflet-control-attribution.is-open {
    max-width: calc(100vw - 12px);
    white-space: normal;
  }
  #iit-rainroute .rrt-card {
    max-height: 50%;
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    border-width: 1px 0 0;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 24px rgba(17, 24, 39, 0.2);
  }
  #iit-rainroute .rrt-card-title {
    font-size: 21px;
  }
  /* Kept clear of the map's buttons on the right. */
  #iit-rainroute .rrt-hint {
    left: 12px;
    right: 76px;
    bottom: calc(36px + env(safe-area-inset-bottom));
    transform: none;
    text-align: center;
    white-space: normal;
    border-radius: 14px;
  }
  #iit-rainroute .leaflet-bottom.leaflet-right {
    bottom: 16px;
  }
  #iit-rainroute.has-answer .leaflet-bottom.leaflet-right {
    bottom: 50%;
  }
}
