/*
 * The shared UI. Flavors theme it through the --hm-* variables set from their
 * Theme, and nothing here names a flavor. Mobile first: phones get bottom sheets
 * and a thumb bar, and wide screens only move the sheet aside.
 */
:root {
  --hm-bg: #14171c;
  --hm-fg: #e8e6df;
  --hm-muted: #a3a7ad;
  --hm-accent: #7cc4ff;
  --hm-panel: #20252d;
  --hm-line: #3b424d;
  --hm-font: ui-rounded, "Avenir Next", Verdana, sans-serif;
  --hm-numeric: ui-monospace, Menlo, Consolas, monospace;
  --hm-radius: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bar-height: 56px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--hm-bg);
  color: var(--hm-fg);
  font: 15px/1.35 var(--hm-font);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

#scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--hm-muted);
  padding: 24px;
  text-align: center;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

/*
 * The readout is permanent, and the MTA's terms require the notice it carries, so
 * nothing in the UI may cover it. A phone's sheet fills the width and is as tall as
 * what is in it, so no fixed place is safe: the readout and the sheet share one
 * column, and the readout rides on the sheet's top edge.
 */
.dock {
  position: fixed;
  z-index: 5;
  left: 0;
  right: 0;
  bottom: calc(var(--bar-height) + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

.age {
  align-self: flex-start;
  max-width: calc(100vw - 20px);
  margin: 0 10px 8px;
  padding: 5px 9px;
  border-radius: var(--hm-radius);
  background: var(--hm-panel);
  background: color-mix(in srgb, var(--hm-panel) 86%, transparent);
  font-size: 12px;
  line-height: 1.3;
  pointer-events: none;
}

.age b {
  font-family: var(--hm-numeric);
  font-weight: 600;
}

.age span {
  color: var(--hm-muted);
}

.age.stale b {
  color: var(--hm-accent);
}

.age .status {
  display: inline;
}

/*
 * The margins take back the padding, which is there only for a thumb to hit. A dot
 * like the readout's others would be left dangling whenever this wraps.
 */
.sources {
  margin: -9px -7px -9px -3px;
  padding: 9px 7px;
  color: var(--hm-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  pointer-events: auto;
}

.sources[aria-expanded="true"] {
  color: var(--hm-accent);
}

:root[data-age="bottom-right"] .age {
  align-self: flex-end;
  text-align: right;
}

/* A phone's sheet never reaches the top, so a readout there can stay put. */
:root[data-age^="top"] .age {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  margin: 0;
}

:root[data-age="top-left"] .age {
  left: 10px;
}

:root[data-age="top-right"] .age {
  right: 10px;
  text-align: right;
}

.bar {
  position: fixed;
  z-index: 4;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--bar-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: var(--hm-panel);
  border-top: 1px solid var(--hm-line);
}

.bar button {
  flex: 1 1 0;
  min-width: 0;
  height: var(--bar-height);
  font-size: 12.5px;
  color: var(--hm-muted);
}

.bar button[aria-pressed="true"],
.bar button[aria-expanded="true"] {
  color: var(--hm-accent);
}

.toast {
  position: fixed;
  z-index: 7;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  transform: translateX(-50%);
  max-width: calc(100vw - 24px);
  padding: 8px 12px;
  border-radius: var(--hm-radius);
  background: var(--hm-panel);
  border: 1px solid var(--hm-line);
  font-size: 13px;
}

/* A toast keeps to the far end from the readout, whichever end that is. */
:root[data-age^="top"] .toast {
  top: auto;
  bottom: calc(var(--bar-height) + var(--safe-bottom) + 12px);
}

/* On a short screen, the room above a sheet is the readout's and a toast's. */
.sheet {
  max-height: min(
    58vh,
    calc(100vh - var(--bar-height) - var(--safe-bottom) - env(safe-area-inset-top, 0px) - 120px)
  );
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  background: var(--hm-panel);
  border-top: 1px solid var(--hm-line);
  border-radius: var(--hm-radius) var(--hm-radius) 0 0;
  transform: translateY(0);
  transition: transform 180ms ease-out;
}

.sheet[hidden] {
  display: none;
}

.sheet header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px 8px 16px;
  border-bottom: 1px solid var(--hm-line);
}

.sheet header h2 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

.sheet .close {
  width: 44px;
  height: 36px;
  color: var(--hm-muted);
  font-size: 13px;
}

.sheet .body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 16px calc(14px + 44px);
}

.sheet p {
  margin: 6px 0;
}

.muted {
  color: var(--hm-muted);
}

.num {
  font-family: var(--hm-numeric);
}

.small {
  font-size: 12.5px;
}

.mark {
  display: inline-block;
  min-width: 1.2em;
  margin-right: 6px;
  font-weight: 800;
  text-align: center;
  border-bottom: 3px solid var(--route, var(--hm-line));
}

.rows {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}

.rows li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--hm-line);
}

.rows li:last-child {
  border-bottom: 0;
}

.rows .grow {
  flex: 1;
  min-width: 0;
}

.rows button {
  flex: 1;
  min-height: 40px;
  text-align: left;
}

.group {
  margin: 14px 0 0;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--hm-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--hm-line);
  border-radius: var(--hm-radius);
  background: var(--hm-bg);
}

.field:focus {
  outline: 2px solid var(--hm-accent);
  outline-offset: 1px;
}

.slider {
  width: 100%;
  height: 44px;
  accent-color: var(--hm-accent);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.chip {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--hm-line);
  border-radius: var(--hm-radius);
  background: var(--hm-bg);
  font-size: 13.5px;
}

.chip[aria-pressed="true"] {
  border-color: var(--hm-accent);
  color: var(--hm-accent);
}

.credit {
  font-size: 11.5px;
  color: var(--hm-muted);
}

/* The right-hand column is the sheet's and the bar's, at any height. */
@media (min-width: 720px) {
  .dock {
    display: contents;
  }

  .sheet {
    position: fixed;
    z-index: 5;
    right: 12px;
    width: 400px;
    bottom: calc(var(--bar-height) + var(--safe-bottom) + 12px);
    max-height: calc(100vh - var(--bar-height) - 24px);
    border: 1px solid var(--hm-line);
    border-radius: var(--hm-radius);
  }

  .sheet .body {
    padding-bottom: 16px;
  }

  .bar {
    left: auto;
    right: 12px;
    bottom: 8px;
    width: 400px;
    border: 1px solid var(--hm-line);
    border-radius: var(--hm-radius);
    overflow: hidden;
  }

  .age {
    position: fixed;
    z-index: 3;
    left: 10px;
    bottom: 12px;
    max-width: min(44vw, calc(100vw - 446px));
    margin: 0;
  }

  :root[data-age$="right"] .age {
    left: auto;
    right: 424px;
  }

  :root[data-age^="top"] .age {
    bottom: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sheet {
    transition: none;
  }
}
