:root {
  color-scheme: light;
  --brand-mark: #1f3928;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  color: #172019;
  background: #f2efe5;
}

* {
  box-sizing: border-box;
}

a {
  color: #215d2d;
}

body {
  margin: 0;
  min-height: 100vh;
  padding-top: env(safe-area-inset-top);

  >header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem clamp(1rem, 5vw, 4rem);
    border-bottom: 1px solid #ced2c4;

    a {
      display: inline-flex;
      align-items: center;
      gap: .4rem;
      color: inherit;
      font-family: Georgia, serif;
      font-size: 1.5rem;
      text-decoration: none;

      svg { width: 1.5em; height: auto; fill: var(--brand-mark); }
    }

    >span {
      color: #5d685e;
      font-size: .875rem;
    }
  }
}

.offline-banner {
  display: none;
  padding: .75rem 1rem;
  background: #fff0d7;
  color: #58330d;
  font-size: .875rem;
  font-weight: 650;
  line-height: 1.45;
  text-align: center;
}

body[data-cached-offline][data-connection-failed] .offline-banner {
  display: block;
}

body.active-trip-body[data-cached-offline] .offline-banner {
  padding-top: calc(.75rem + env(safe-area-inset-top));
}

.offline-banner button {
  display: block;
  min-height: 2.75rem;
  margin: .5rem auto 0;
  padding: .4rem .8rem;
  border: 1px solid currentColor;
  border-radius: .4rem;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.offline-banner button:disabled { opacity: .65; }

.offline-banner [role="status"] { font-size: .8125rem; font-weight: 400; }
.offline-banner [role="status"]:not(:empty) { display: block; margin-top: .4rem; }

main {
  padding: clamp(2rem, 8vw, 6rem) 1rem;

  > :is(section, .stopped-trip) {
    max-width: 40rem;
    margin: 0 auto;
    padding: clamp(1.5rem, 5vw, 3rem);
    background: #faf8f1;
    border: 1px solid #d9d9cc;
    border-radius: 1rem;
  }
}

main>.auth-panel {
  max-width: 30rem;
}

.eyebrow {
  margin: 0 0 .5rem;
  color: #52654e;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font: 400 clamp(2.25rem, 8vw, 4rem)/1 Georgia, serif;
}

.lede {
  color: #4f5a51;
  line-height: 1.6;
}

.hint {
  color: #5d685e;
  font-size: .875rem;
  font-weight: 400;
}

.required-mark {
  color: #a93625;
}

form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  margin-top: 2rem;
}

label {
  display: grid;
  min-width: 0;
  gap: .4rem;
  font-weight: 650;
}

.contact-fields {
  display: grid;
  gap: .6rem;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.contact-fields legend {
  padding: 0;
  font-weight: 650;
}

.contact-fields > .hint {
  margin: .4rem 0 0;
}

.contact-rows {
  display: grid;
  gap: .6rem;
}

.contact-row {
  display: flex;
  gap: .5rem;
}

.contact-row input {
  min-width: 0;
  flex: 1;
}

.contact-remove,
.contact-add {
  background: transparent;
  color: inherit;
  border-color: #aeb7aa;

  &:hover {
    background: #80bd7a22;
  }
}

.contact-add {
  justify-self: start;
}

input[type="datetime-local"] {
  min-width: 0;
}

input,
textarea,
select,
:where(button) {
  min-height: 3rem;
  border: 1px solid #aeb7aa;
  border-radius: .5rem;
  font: inherit;
}

input,
textarea,
select {
  width: 100%;
  padding: .75rem;
  background: white;
  color: inherit;
}

textarea[name="emergencyPlan"] {
  field-sizing: content;
  min-height: 12rem;
}

input::placeholder,
textarea::placeholder {
  color: #a3aaa1;
  opacity: 1;
}

:where(button) {
  padding: .75rem 1rem;
  border-color: #1f3928;
  background: #1f3928;
  color: white;
  font-weight: 700;
  cursor: pointer;

  &:hover {
    background: #15291c;
  }

  &:disabled {
    cursor: not-allowed;
  }
}

:is(a, button, summary, input, textarea, select):focus-visible {
  outline: 3px solid #80bd7a;
  outline-offset: 3px;
}

.error {
  padding: .75rem 1rem;
  border: 1px solid #a33b31;
  border-radius: .5rem;
  color: #7e211a;
  background: #fff1ef;

  &[hidden] {
    display: none;
  }
}

.status {
  display: grid;
  gap: .25rem;
  margin: 2rem 0;
  padding: 1rem;
  border-radius: .65rem;
  background: #e6eadf;

  span {
    color: #4f5a51;
  }
}

dl {
  display: grid;
  gap: 0;
  margin: 0;

  >div {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: .85rem 0;
    border-bottom: 1px solid #deded4;

    &:last-child {
      border: none;
    }
  }

  dt {
    color: #5d685e;
  }

  dd {
    margin: 0;
    font-weight: 650;
  }
}

.edit-link,
.cancel-link,
.delete-link {
  display: block;
  margin-top: 1.25rem;
  color: #1f3928;
  font-weight: 700;
  text-align: center;
}

.delete-link {
  color: #953527;
}

.new-tab-icon {
  width: 1.3em;
  height: 1.3em;
  margin-left: .2em;
  vertical-align: -.3em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

form > button + .cancel-link {
  margin-top: 0;
}

.trip-new-button {
  display: block;
  margin-top: 2rem;
  padding: .9rem 1rem;
  border-radius: .5rem;
  background: #1f3928;
  color: white;
  font-weight: 700;
  text-align: center;
  text-decoration: none;

  &:hover {
    background: #15291c;
  }
}

.trip-active-notice {
  margin: 2rem 0 0;
  padding: 1rem;
  border: 1px solid #a33b31;
  border-radius: .65rem;
  background: #fff1ef;
  color: #7e211a;
  font-weight: 400;

  a {
    color: inherit;
  }
}

.trip-list {
  display: grid;
  gap: .75rem;
  margin: 2rem 0 0;
  padding: 0;
  list-style: none;

  li {
    position: relative;
    padding: 1rem;
    border: 1px solid #ced2c4;
    border-radius: .65rem;

    &:hover {
      border-color: #67836c;
      background: #edf2e9;
    }
  }

  a {
    display: block;
    color: inherit;
    text-decoration: none;
  }

  li > a:first-child {
    padding-right: 3rem;

    &::after {
      content: "";
      position: absolute;
      inset: 0;
      border-radius: .65rem;
    }

    &:focus-visible::after {
      outline: 3px solid currentColor;
      outline-offset: 2px;
    }
  }
}

.trip-list-title {
  font-weight: 700;
}

.trip-list-details {
  margin-top: .35rem;
}

.trip-list trip-copy {
  position: absolute;
  z-index: 1;
  top: .5rem;
  right: .5rem;
  display: block;
}

.trip-list .trip-share-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  min-height: 2.25rem;
  padding: 0;
  border: 0;
  border-radius: .4rem;
  background: transparent;
  color: #1f3928;

  &:hover {
    background: #dce8d9;
  }

  svg {
    width: 1.25rem;
    height: 1.25rem;
  }

  .trip-share-status:not(:empty) {
    position: absolute;
    z-index: 2;
    top: calc(100% + .25rem);
    right: 0;
    padding: .35rem .55rem;
    border-radius: .35rem;
    background: #1f3928;
    color: white;
    font-size: .75rem;
    white-space: nowrap;
    pointer-events: none;
  }

  .trip-share-status.copy-error {
    background: #a33b31;
  }
}

.trip-list .trip-list-active,
.trip-list .trip-list-active:hover {
  border-color: #2c6d3e;
  background: #e6f1e4;
  box-shadow: inset .25rem 0 #2c6d3e;
}

.trip-list-meta {
  color: #5d685e;
  font-size: .875rem;
}

.trip-options {
  display: grid;
  justify-items: center;
  gap: .75rem;
  margin-top: 1.25rem;

  :is(.edit-link, .cancel-link, .delete-link) {
    margin-top: 0;
  }
}

form > .trip-options {
  gap: 1rem;
  margin-top: 0;
}

.trip-settings {
  padding: 1rem;
  border: 1px solid #ced2c4;
  border-radius: .65rem;

  summary {
    cursor: pointer;
    font-weight: 700;
  }

  &[open]>summary {
    margin-bottom: 1rem;
  }

  >label+label {
    margin-top: 1rem;
  }

  >.hint {
    margin: 1rem 0 0;
    line-height: 1.5;
  }

  dd {
    white-space: pre-line;
  }
}

.stop-button,
.delete-button {
  background: #9e3323;
  border-color: #9e3323;

  &:hover {
    background: #7e291d;
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.active-trip-body {
  padding-top: 0;
  background: #111b18;

  main {
    padding: 0;
  }
}

trip-actions {
  display: block;
}

.active-trip {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f5f3ed;
}

.trip-map {
  display: block;
  position: relative;
  isolation: isolate;
  height: min(54vh, 31rem);
  min-height: min(22rem, calc(100svh - 5rem));
  overflow: hidden;
  color: #fff;
  background:
    repeating-linear-gradient(0deg, #b5d0aa44 0 1px, transparent 1px 48px),
    repeating-linear-gradient(90deg, #b5d0aa44 0 1px, transparent 1px 48px),
    radial-gradient(ellipse at 25% 58%, #4c6151 0, transparent 36%),
    radial-gradient(ellipse at 84% 28%, #29483d 0, transparent 36%),
    linear-gradient(135deg, #10251f, #3a5241 52%, #142d29);

  >.trip-map-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
  }

  >header {
    position: absolute;
    z-index: 2;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .75rem;
    padding: calc(1rem + env(safe-area-inset-top)) 1.25rem 1rem;
    pointer-events: none;
  }

  .map-sos-badge {
    padding: .55rem .8rem;
    border: 2px solid #fff;
    border-radius: .65rem;
    background: #9f251d;
    box-shadow: 0 2px 12px #0008;
    font-size: .95rem;
    line-height: 1.1;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
  }

  .trip-map-shade {
    position: absolute;
    inset: 0;
    background: linear-gradient(#06110dcc 0%, transparent 35%, transparent 65%, #06110dd6 100%);
  }

  &.map-loaded {
    .trip-map-shade {
      pointer-events: none;
    }

  }
}

.map-controls {
  position: absolute;
  top: calc(1rem + env(safe-area-inset-top));
  right: 1.25rem;
  display: grid;
  justify-items: end;
  gap: .4rem;
  pointer-events: auto;
}

.map-compass {
  min-height: 2.2rem;
  padding: .35rem .6rem;
  border: 1px solid #ffffff66;
  border-radius: .5rem;
  background: #06110de6;
  color: white;
  font-size: .72rem;
  backdrop-filter: blur(8px);
}

.map-compass-status {
  max-width: calc(100vw - 2.5rem);
  padding: .4rem .55rem;
  border-radius: .4rem;
  background: #06110de6;
  color: white;
  font-size: .7rem;
  line-height: 1.3;
  text-align: right;
  white-space: nowrap;
}

.map-center {
  display: grid;
  place-items: center;
  position: relative;
  width: 3.5rem;
  height: 3.5rem;
  min-height: 3.5rem;
  padding: 0;
  border: 1px solid #ffffff66;
  border-radius: 50%;
  background: #06110dcc;
  color: white;
  cursor: pointer;
  backdrop-filter: blur(8px);

  &:hover {
    background: #173c31;
  }

  svg {
    width: 1.5rem;
    height: 1.5rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
  }

  span {
    position: absolute;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: .6rem;
    font-weight: 800;
    line-height: 1;
  }

  .map-cardinal-north { top: .22rem; left: 50%; color: #ff6b5e; transform: translateX(-50%); }
  .map-cardinal-east { top: 50%; right: .35rem; transform: translateY(-50%); }
  .map-cardinal-south { bottom: .2rem; left: 50%; transform: translateX(-50%); }
  .map-cardinal-west { top: 50%; left: .35rem; transform: translateY(-50%); }
}

.map-center:disabled {
  opacity: .55;
  cursor: default;
}

.map-caption {
  position: absolute;
  z-index: 2;
  left: 1.25rem;
  right: 1.25rem;
  bottom: 1.65rem;
  padding: .5rem .75rem;
  border-radius: .65rem;
  color: #fff;
  background: #06110dcc;
  backdrop-filter: blur(8px);

  >button {
    display: grid;
    gap: .15rem;
    width: 100%;
    min-height: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    text-align: left;
    font-weight: 400;
    cursor: pointer;

    &:is(:hover, :disabled) {
      background: transparent;
    }

    &:not(:disabled):hover .map-caption-coordinates {
      text-decoration: underline;
    }
  }

  .map-caption-title {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: .5rem;
  }

  .map-caption-title>span:first-child {
    font-weight: 700;
  }

  .map-caption-location {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: .5rem;
  }

  .map-caption-coordinates {
    font-size: .82rem;
  }

  .map-copy-feedback {
    color: #b9ddff;
    font-size: .75rem;
    white-space: nowrap;

    &:empty {
      display: none;
    }
  }
}

.trip-dashboard {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  flex: 1;
  margin-top: -1.1rem;
  padding: 1rem 1rem max(1.5rem, env(safe-area-inset-bottom));
  border-radius: 1.1rem 1.1rem 0 0;
  background: #f5f3ed;

  >.map-credit {
    margin: auto .15rem 0;
    padding-top: 1.5rem;
    color: #5d685e;
    font-size: .72rem;
    text-align: center;

    a {
      color: inherit;
    }
  }

  >.trip-metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .6rem;

    >div {
      min-width: 0;
      min-height: 5rem;
      display: flex;
      flex-direction: column;
      justify-content: center;
      gap: .3rem;
      padding: .8rem .9rem;
      border: 0;
      border-radius: .85rem;
      background: #ebece6;
    }

    dt {
      color: #49534c;
      font-size: .77rem;
    }

    dd {
      text-align: left;
      font-size: clamp(1rem, 4vw, 1.3rem);
      line-height: 1.15;
      overflow-wrap: anywhere;
    }
  }

  >.trip-reminder {
    display: block;
    margin: .8rem .15rem 0;
    padding: .65rem .75rem;
    border: 1px solid #a33b31;
    border-radius: .65rem;
    background: #fff1ef;
    color: #7e211a;
    font-size: .85rem;
    line-height: 1.4;

    a { color: inherit; font-weight: 700; }
  }

  >trip-actions>.trip-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .65rem;
    margin-top: .9rem;

    >button {
      min-height: 3.5rem;
      border: 0;
      border-radius: .95rem;
      font-size: 1.1rem;
    }

    .checkin-button {
      background: #2e793c;

      &:hover {
        background: #215d2d;
      }

      &:disabled {
        opacity: .65;
      }
    }

    .sos-button {
      background: #a93625;

      &:hover {
        background: #872519;
      }

      &:disabled {
        opacity: .7;
      }
    }
  }

  >trip-actions>.trip-connection {
    margin: .8rem .15rem 0;
    color: #435349;
    font-size: .79rem;
    line-height: 1.4;
  }

  >trip-actions>.trip-offline-status {
    margin: .8rem .15rem 0;
    padding: .65rem .75rem;
    border: 1px solid #a33b31;
    border-radius: .65rem;
    background: #fff1ef;
    color: #7e211a;
    font-size: .85rem;
    line-height: 1.4;
  }

  >trip-actions>.trip-offline-status[hidden] {
    display: none;
  }

  >.trip-details {
    margin-top: 1rem;
    border-top: 1px solid #d6dbd1;
    color: #26382d;

    h2 {
      margin: 0;
      padding: .8rem .15rem;
      font-size: 1rem;
    }

    dl {
      margin: 0 .15rem;
      font-size: .88rem;
    }

    .trip-detail-actions {
      display: flex;
      flex-direction: column;
      flex-wrap: wrap;
      align-items: center;
      gap: .5rem;
      margin: .85rem .15rem;
      font-size: .88rem;
      font-weight: 700;

      a {
        margin: 0;
      }

      .stop-link {
        color: #953527;
      }
    }
  }
}

@media (max-width: 34rem) {
  body>header>span {
    display: none;
  }

  dl>div {
    display: grid;
    gap: .2rem;
  }

  dd {
    text-align: left;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --brand-mark: #a5d5a6;
    color: #e7eee7;
    background: #101713;
  }

  a {
    color: #a9dfab;
  }

  body>header {
    border-color: #34483b;

    >span {
      color: #a9bcad;
    }
  }

  .offline-banner {
    background: #49361f;
    color: #ffe5b6;
  }

  main> :is(section, .stopped-trip) {
    background: #1b2920;
    border-color: #3b5041;
  }

  .eyebrow {
    color: #a5d5a6;
  }

  .lede,
  .status span {
    color: #c3d0c3;
  }

  .hint,
  dl dt {
    color: #a9bcad;
  }

  .required-mark {
    color: #ff9b90;
  }

  input,
  textarea,
  select {
    background: #152219;
    border-color: #5b735f;
    color: #e7eee7;
  }

  input::placeholder,
  textarea::placeholder {
    color: #607260;
  }

  :where(button) {
    background: #2c6d3e;
    border-color: #2c6d3e;
  }

  :where(button):hover {
    background: #36864b;
  }

  .error {
    background: #3c201e;
    border-color: #d7796e;
    color: #ffd6d0;
  }

  .status {
    background: #263b2b;
  }

  dl>div {
    border-color: #3b5041;
  }

  .trip-settings {
    border-color: #3b5041;
  }

  .edit-link,
  .cancel-link {
    color: #a9dfab;
  }

  .delete-link {
    color: #ffb4a3;
  }

  .trip-new-button {
    background: #2c6d3e;

    &:hover {
      background: #36864b;
    }
  }

  .trip-active-notice {
    background: #3c201e;
    border-color: #d7796e;
    color: #ffd6d0;
  }

  .trip-list .trip-list-active,
  .trip-list .trip-list-active:hover {
    border-color: #78a982;
    background: #263b2b;
    box-shadow: inset .25rem 0 #78a982;
  }

  .trip-list li {
    border-color: #3b5041;

    &:hover {
      border-color: #78a982;
      background: #263b2b;
    }
  }

  .trip-list-meta {
    color: #a9bcad;
  }

  .trip-list .trip-share-link {
    color: #a9d8b2;

    &:hover {
      background: #36533c;
    }
  }

  .stop-button,
  .delete-button {
    background: #b94736;
    border-color: #b94736;
  }

  .stop-button:hover,
  .delete-button:hover {
    background: #ce5948;
  }

  .active-trip,
  .trip-dashboard {
    background: #19251d;
  }

  .trip-dashboard>.trip-metrics>div {
    background: #26362b;
  }

  .trip-dashboard>.trip-metrics dt {
    color: #b7c9b8;
  }

  .trip-dashboard>.trip-reminder {
    border-color: #d7796e;
    background: #3c201e;
    color: #ffd6d0;
  }

  .trip-dashboard>.map-credit {
    color: #a9bcad;
  }

  .trip-dashboard>trip-actions>.trip-connection {
    color: #bbccbd;
  }

  .trip-dashboard>trip-actions>.trip-offline-status {
    background: #3c201e;
    border-color: #d7796e;
    color: #ffd6d0;
  }

  .trip-dashboard>.trip-details {
    border-color: #3b5041;
    color: #e7eee7;
  }

  .trip-dashboard>.trip-details .trip-detail-actions .stop-link {
    color: #ffb4a3;
  }
}
