/* Layout from the commute-compute Atlas design (experiments/ui-directions/atlas.html in that repo):
   full-viewport map, floating card, result stamp, bottom drawer. */
:root {
  color-scheme: light;
  --ink: #141414;
  --paper: #ffffff;
  --soft: #f4f1e8;
  --line: #d6d1c2;
  --muted: #5e5a50;
  --yellow: #ffd21f;
  --warn: #b3261e;
  --font: "Libre Franklin", "Segoe UI", sans-serif;
  --drawer-peek: 3.1rem;
}

* { box-sizing: border-box; border-radius: 0; }

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

body {
  color: var(--ink);
  font: 14px/1.45 var(--font);
  background: var(--soft);
}

.map { position: fixed; inset: 0; background: var(--soft); }
.map .leaflet-container, .leaflet-container { font: inherit; }
.map .leaflet-top.leaflet-left { left: 27rem; }
.map .leaflet-top.leaflet-right { top: 8rem; }

.card {
  position: fixed;
  z-index: 1000;
  top: 1rem;
  left: 1rem;
  width: 25rem;
  max-height: calc(100vh - 2rem - var(--drawer-peek));
  overflow-y: auto;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 6px 6px 0 rgba(20, 20, 20, 0.85);
}

.tab {
  padding: 0.55rem 0.9rem;
  background: var(--yellow);
  border-bottom: 2px solid var(--ink);
}

.tab h1 {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.card section { padding: 0.9rem; }
.card section + section { border-top: 1px solid var(--line); }

.card h2, .drawer-body h3 {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.hint { margin: 0.6rem 0 0; font-size: 0.85rem; color: var(--muted); }

#people {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

/* Each person is a small table: number column, then NAME / ADDRESS / AFTER rows with the
   caption on the left and the input filling the rest. */
.person {
  border: 2px solid var(--ink);
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) 2rem;
}

.person > * { grid-column: 2 / -1; }
.person > .field:first-of-type { grid-column: 2; }
.person > .remove { grid-column: 3; grid-row: 1; }

.person-num, .mp-pin {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.8rem;
  background: var(--yellow);
  color: var(--ink);
  border: 2px solid var(--ink);
}

.mp-pin { box-shadow: 2px 2px 0 rgba(20, 20, 20, 0.8); }
.mp-pin.back { background: var(--paper); border-style: dashed; }

.person > .person-num {
  grid-column: 1;
  grid-row: 1 / span 5;
  width: auto;
  height: auto;
  place-items: start center;
  padding-top: 0.45rem;
  border: 0;
  border-right: 2px solid var(--ink);
}

.field {
  display: grid;
  grid-template-columns: 4.4rem minmax(0, 1fr) auto;
  align-items: center;
  border-top: 1px solid var(--line);
}

.person > .field:first-of-type { border-top: 0; }

.field-caption {
  padding-left: 0.5rem;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.field input {
  border: 0;
  border-left: 1px solid var(--line);
  padding: 0.4rem 0.45rem;
  font-size: 0.88rem;
}

.field input:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--ink); background: #fffbe6; }

input {
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  padding: 0.35rem 0.45rem;
}

button {
  font: inherit;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 2px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  min-height: 2.4rem;
  padding: 0 0.7rem;
  cursor: pointer;
}

button:focus-visible, input:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

input:focus-visible { outline-color: var(--yellow); outline-offset: 0; box-shadow: 0 0 0 5px var(--ink); }

button.ghost { margin-top: 0.6rem; width: 100%; }
button.remove {
  min-height: 0;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--line);
  font-size: 0.8rem;
}

button.remove:hover:not(:disabled) { background: var(--ink); color: var(--yellow); }

button.primary {
  width: 100%;
  background: var(--ink);
  color: var(--yellow);
}

button:disabled { opacity: 0.45; cursor: default; }

.suggestions {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 rgba(20, 20, 20, 0.8);
}

.suggestions button {
  width: 100%;
  min-height: 2.2rem;
  padding: 0.35rem 0.5rem;
  text-align: left;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  font-size: 0.85rem;
  border-width: 0 0 1px;
  border-color: var(--line);
}

.suggestions button:hover { background: var(--soft); }
.suggestions li:last-child button { border-bottom: 0; }

.suggest-wait { display: grid; place-items: center; padding: 0.55rem; }

.wheel {
  width: 16px;
  height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.verdict {
  padding: 0 0.45rem;
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  white-space: nowrap;
  color: #1f6b3a;
}

.person > .suggestions { margin: 0.25rem 0.4rem 0.4rem; }
.verdict.bad { color: var(--warn); }

.stamp {
  position: fixed;
  z-index: 1000;
  top: 1rem;
  right: 1rem;
  text-align: right;
  padding: 0.7rem 1rem 0.6rem;
  background: var(--ink);
  color: var(--yellow);
  border: 2px solid var(--ink);
  box-shadow: 6px 6px 0 rgba(255, 210, 31, 0.9);
}

.stamp span { display: block; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: #fff; }
.stamp strong { display: block; font-size: 2.3rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stamp small { display: block; margin-top: 0.3rem; font-size: 0.75rem; color: #ddd; }

.drawer {
  --h: min(30rem, 62vh);
  position: fixed;
  z-index: 1001;
  left: 27rem;
  right: 1rem;
  bottom: 0;
  height: var(--h);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-bottom: 0;
  box-shadow: 0 -4px 0 rgba(20, 20, 20, 0.12);
  transform: translateY(calc(var(--h) - var(--drawer-peek)));
  transition: transform 0.25s ease;
  display: grid;
  grid-template-rows: auto 1fr;
}

.drawer[data-open="true"] { transform: none; }
/* With results, the open drawer takes most of the screen so many pubs fit. */
.drawer[data-full="true"] { --h: calc(100vh - 5rem); }

.drawer-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  height: calc(var(--drawer-peek) - 2px);
  padding: 0 0.6rem 0 0.4rem;
  border-bottom: 1px solid var(--line);
}

.drawer-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  background: var(--yellow);
}

.drawer-toggle::after { content: '▲'; font-size: 0.65rem; transition: transform 0.2s; }
.drawer[data-open="true"] .drawer-toggle::after { transform: rotate(180deg); }

.drawer-sum { font-size: 0.85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-sum b { color: var(--ink); }

.drawer-status {
  margin: 0 0 0 auto;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 45%;
}

.drawer-body { overflow: auto; padding: 0.8rem 1rem 1rem; }

/* Ranked table, best first, one line per pub: # | pub | each person | avg | longest.
   --people is set from the script to the number of person columns. */
.pub-table {
  --people: 0;
  --grid: 2.4rem minmax(0, 1fr) repeat(var(--people), 6.2rem) 4.8rem 4.8rem;
  /* Every row shares one width, so a long street name cannot push its own row's columns. */
  --min: calc(27rem + var(--people) * 6.8rem);
  margin-top: 0.5rem;
  border: 2px solid var(--ink);
  overflow-x: auto;
}

.pub-table.untimed { --grid: 2.4rem minmax(0, 1fr); --min: 0; }

.pub-head, #pub-list { min-width: var(--min); }

.pub-head, .pub-select {
  display: grid;
  grid-template-columns: var(--grid);
  align-items: center;
  column-gap: 0.6rem;
  padding-right: 0.6rem;
  width: 100%;
}

.pub-head {
  position: sticky;
  top: 0;
  z-index: 1;
  padding-block: 0.3rem;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pub-head .pub-rank { border-right: 0; }

#pub-list { list-style: none; margin: 0; padding: 0; }

.pub + .pub { border-top: 1px solid var(--line); }

.pub-select {
  min-height: 0;
  padding-block: 0;
  border: 0;
  text-align: left;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  font-size: 0.85rem;
}

.pub-select:hover { background: var(--soft); }
.pub-select[aria-pressed="true"] { background: var(--yellow); }
.pub-select:focus-visible { outline: 3px solid var(--ink); outline-offset: -3px; }

.pub-rank {
  align-self: stretch;
  display: grid;
  place-items: center;
  padding-block: 0.4rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  border-right: 2px solid var(--ink);
}

.pub-select[aria-pressed="true"] .pub-rank { background: var(--ink); color: var(--yellow); }

.pub-main { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pub-name { font-weight: 800; }
.pub-where { margin-left: 0.5rem; font-size: 0.75rem; color: var(--muted); }
.pub-cell { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pub-head .pub-cell { overflow: hidden; text-overflow: ellipsis; }
.pub-cell-note { display: block; font-size: 0.55rem; color: var(--line); }
.pub-leg { font-size: 0.8rem; }
.pub-avg { font-weight: 800; }
.pub-worst { color: var(--muted); }

/* Collapsed bar: the selected pub. */
.drawer-pick {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  min-height: 2.2rem;
  padding: 0 0.6rem 0 0;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  font-size: 0.85rem;
  background: var(--yellow);
}

.drawer-pick[hidden] { display: none; }
.pick-rank { align-self: stretch; display: grid; place-items: center; min-width: 2rem; background: var(--ink); color: var(--yellow); font-weight: 800; }
.pick-name { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-times { font-size: 0.72rem; font-weight: 800; white-space: nowrap; }

.pub-pin {
  width: 14px;
  height: 14px;
  background: var(--ink);
  border: 2px solid var(--yellow);
  box-shadow: 0 0 0 1.5px var(--ink);
}

.pub-pin.selected { width: 20px; height: 20px; background: var(--yellow); border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }

@media (prefers-reduced-motion: reduce) {
  .drawer, .drawer-toggle::after { transition: none; }
  .wheel { animation: none; }
}

@media (max-width: 860px) {
  html, body { overflow: auto; height: auto; }
  .map { position: relative; height: 62vh; }
  .stamp { position: absolute; top: 0.6rem; right: 0.6rem; padding: 0.45rem 0.7rem; }
  .stamp strong { font-size: 1.5rem; }
  .stamp small { display: none; }
  .card { position: relative; top: auto; left: auto; width: auto; max-height: none; margin: 0.8rem; box-shadow: 4px 4px 0 rgba(20, 20, 20, 0.85); }
  .drawer { position: relative; left: auto; right: auto; height: auto; margin: 0 0.8rem 0.8rem; transform: none; border-bottom: 2px solid var(--ink); }
  .drawer-bar { height: auto; min-height: calc(var(--drawer-peek) - 2px); flex-wrap: wrap; gap: 0.3rem 1rem; padding: 0.4rem; }
  .drawer-toggle { pointer-events: none; }
  .drawer-toggle::after { display: none; }
  .drawer-status { margin: 0; max-width: none; white-space: normal; flex-basis: 100%; }
  .map .leaflet-top.leaflet-left { left: 0; }
  .map .leaflet-top.leaflet-right { top: 0; }
  .pub-table { --grid: 2.2rem minmax(0, 1fr) repeat(var(--people), 5.6rem) 4.4rem 4.4rem; --min: calc(22rem + var(--people) * 6.2rem); }
}
