:root {
  --ink: #0e1b2e;
  --ground: #ffffff;
  --surface: #f2f4f7;
  --surface-hover: #f7f9fc;
  --line: #e3e6eb;
  --line-strong: #d5dae2;
  --muted: #55607a;
  --accent: #ffcb05;
  --on-accent: #0e1b2e;
  /* Filled controls: the active day, active pills, the Filters button. */
  --strong: #0e1b2e;
  --on-strong: #ffffff;
  --logo: #0e1b2e;
  --tag-plain: #eef1f5;
  --map-ground: #e9edf2;
  --shadow: 0 8px 28px rgba(14, 27, 46, 0.18);
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --body: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --ink: #eef2f8;
  --ground: #0d1522;
  --surface: #182231;
  --surface-hover: #131d2b;
  --line: #233042;
  --line-strong: #364660;
  --muted: #9ba8bc;
  --strong: #eef2f8;
  --on-strong: #0d1522;
  --logo: #1f2b3d;
  --tag-plain: #1f2b3d;
  --map-ground: #0b111b;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

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

body {
  display: grid;
  grid-template-columns: minmax(360px, 440px) 1fr;
  font: 14px/1.45 var(--body);
  color: var(--ink);
  background: var(--ground);
}

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

button {
  cursor: pointer;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

/* --- panel ------------------------------------------------------------- */

#panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--ground);
  z-index: 1;
}

header {
  padding: 24px 24px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 9px;
}

/* The mark is black; give it an edge against the dark panel. */
[data-theme="dark"] .logo {
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.22);
}

/* Maize and blue: "Eats" sits on a maize tab, which reads on either theme. */
.eats {
  margin-left: 4px;
  padding: 0 6px 1px;
  border-radius: 7px;
  background: #ffcb05;
  color: #00274c;
}

.theme {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-left: auto;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
}

.theme:hover {
  background: var(--surface);
  color: var(--ink);
}

.theme .sun,
[data-theme="dark"] .theme .moon {
  display: none;
}

[data-theme="dark"] .theme .sun {
  display: block;
}

h1 {
  margin: 0;
  font: 800 26px/1 var(--display);
  letter-spacing: -0.02em;
}

.summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.summary strong {
  font: 800 40px/1 var(--display);
  letter-spacing: -0.03em;
  color: var(--ink);
}

.filters {
  display: grid;
  gap: 12px;
  padding: 0 24px 16px;
  border-bottom: 1px solid var(--line);
}

.days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: var(--surface);
}

/* Only as tall as the label needs. */
.days button {
  padding: 5px 0;
  border: 0;
  border-radius: 7px;
  line-height: 1.2;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 12.5px;
}

.days button:hover {
  color: var(--ink);
}

.days button.active {
  background: var(--strong);
  color: var(--on-strong);
  font-weight: 700;
}

.pills,
.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pills button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border: 1.5px solid var(--line-strong);
  border-radius: 999px;
  background: var(--ground);
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}

.pills button:hover {
  border-color: var(--ink);
}

.pills button.active {
  border-color: var(--strong);
  background: var(--strong);
  color: var(--on-strong);
}

.fab,
.done,
.handle {
  display: none;
}

/* The row above the search bar: a label, and Clear when there is something to clear. */
.filters-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 32px;
}

.filters-head h2 {
  margin: 0;
  color: var(--muted);
  font: 600 12px/1 var(--body);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.clear {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  text-decoration: underline;
}

.clear:hover {
  color: var(--ink);
}

/* Kept in the layout while idle, so the row does not jump when it appears. */
.clear.idle {
  visibility: hidden;
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 46px;
  padding: 0 14px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
}

.search:focus-within {
  outline: 2px solid var(--ink);
}

.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 500;
  outline: none;
}

/* --- list -------------------------------------------------------------- */

#list {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.card {
  display: grid;
  gap: 12px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.card:hover,
.card.selected {
  background: var(--surface-hover);
}

.card.selected {
  box-shadow: inset 4px 0 0 var(--accent);
}

.place {
  display: grid;
  gap: 2px;
}

.place-name {
  display: flex;
  align-items: center;
  gap: 8px 10px;
}

.place h2 {
  min-width: 0;
}

.place h2 {
  margin: 0;
  font: 600 18px/1.25 var(--display);
  letter-spacing: -0.01em;
}

.badge {
  padding: 2px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge.closed {
  border-color: transparent;
  background: var(--tag-plain);
  color: var(--ink);
}

.meta,
.when {
  color: var(--muted);
  font-size: 13px;
}

.deal {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 12px;
  align-items: start;
}

.price {
  padding: 6px 6px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  font-size: 14px;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
}

.price.none {
  background: var(--tag-plain);
  color: var(--ink);
  font-size: 13px;
}

.deal-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.deal-title {
  font-weight: 600;
}

.more {
  justify-self: start;
  min-height: 36px;
  padding: 0 14px;
  border: 1.5px solid var(--line-strong);
  border-radius: 999px;
  background: var(--ground);
  font-weight: 600;
  font-size: 13px;
}

.more:hover {
  border-color: var(--ink);
}

.checked {
  color: var(--muted);
  font-size: 12.5px;
}

/* On the name's row, pushed to the right edge, sized to be easy to hit. */
.source {
  flex: none;
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  margin-left: auto;
  padding: 0 12px;
  border: 1.5px solid var(--line-strong);
  border-radius: 999px;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.source:hover {
  border-color: var(--ink);
}

.outside {
  padding: 16px 24px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.outside button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font-weight: 600;
  text-decoration: underline;
}

.empty {
  padding: 48px 24px;
  color: var(--muted);
  text-align: center;
}

footer {
  padding: 10px 24px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

/* --- map --------------------------------------------------------------- */

main {
  position: relative;
  min-height: 0;
  background: var(--map-ground);
}

#map {
  position: absolute;
  inset: 0;
}

.status {
  position: absolute;
  right: 12px;
  bottom: 36px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--ground);
  box-shadow: 0 2px 10px rgba(14, 27, 46, 0.12);
  color: var(--muted);
  font-size: 12.5px;
}

.status:empty {
  display: none;
}

.maplibregl-popup-content {
  background: var(--ground);
  display: grid;
  gap: 2px;
  min-width: 200px;
  padding: 12px 14px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  font: 13px/1.4 var(--body);
  color: var(--ink);
}

.maplibregl-popup-content h2 {
  margin: 0;
  padding-right: 16px;
  font: 600 15px/1.25 var(--display);
}

.maplibregl-popup-content p {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

.maplibregl-popup-content ul {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
}

.maplibregl-popup-content li {
  display: flex;
  gap: 8px;
  padding: 3px 0;
}

.maplibregl-popup-content li b {
  flex: none;
  min-width: 52px;
}

.maplibregl-popup-anchor-bottom .maplibregl-popup-tip,
.maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip,
.maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip {
  border-top-color: var(--ground);
}

.maplibregl-popup-anchor-top .maplibregl-popup-tip,
.maplibregl-popup-anchor-top-left .maplibregl-popup-tip,
.maplibregl-popup-anchor-top-right .maplibregl-popup-tip {
  border-bottom-color: var(--ground);
}

.maplibregl-popup-anchor-left .maplibregl-popup-tip {
  border-right-color: var(--ground);
}

.maplibregl-popup-anchor-right .maplibregl-popup-tip {
  border-left-color: var(--ground);
}

.maplibregl-popup-close-button {
  width: 28px;
  height: 28px;
  font-size: 18px;
  color: var(--muted);
}

.maplibregl-ctrl-group {
  border-radius: 10px !important;
  box-shadow: 0 2px 10px rgba(14, 27, 46, 0.12) !important;
}

/* --- desktop: a compact top, so more of the panel is deals -------------- */

@media (min-width: 761px) {
  header {
    padding: 14px 24px 10px;
  }

  .logo {
    width: 28px;
    height: 28px;
    border-radius: 9px;
  }

  h1 {
    font-size: 22px;
  }

  .theme {
    width: 36px;
    height: 36px;
  }

  .summary {
    margin-top: 6px;
    font-size: 13.5px;
  }

  .summary strong {
    font-size: 24px;
  }

  .filters {
    gap: 8px;
    padding: 0 24px 12px;
  }

  /* No label row: Clear rides up beside the count instead. */
  .filters-head {
    position: relative;
    min-height: 0;
    height: 0;
  }

  .filters-head h2 {
    display: none;
  }

  .clear {
    position: absolute;
    right: 0;
    bottom: 8px;
  }

  .search {
    height: 40px;
  }

  .pills,
  .pill-group {
    gap: 6px;
  }

  .pills button {
    min-height: 32px;
    padding: 0 12px;
    font-size: 12.5px;
  }
}

/* --- phone: map on the top half, list on the bottom half, filters behind a
   button that opens them as a sheet over the list ----------------------- */

@media (max-width: 760px) {
  body {
    grid-template-columns: 1fr;
    /* The list is a drawer: 40% of the screen until dragged. */
    /* Top bar, map, then the list drawer. The drawer's row is 16px short of
       its height because it overlaps the map by its rounded corners. */
    --top: 56px;
    grid-template-rows: var(--top) minmax(0, 1fr) calc(var(--drawer, 40dvh) - 16px);
    height: 100dvh;
    /* No "overflow: hidden" here: with it the browser treats the page as
       unscrollable and turns off its pull-down-to-refresh gesture. The layout
       fits the screen exactly, so nothing scrolls anyway. */
  }

  main {
    grid-row: 2;
  }

  /* Above the map's own controls, so the filter sheet covers them. */
  #panel {
    grid-row: 3;
    position: relative;
    z-index: 3;
    border-radius: 16px 16px 0 0;
    margin-top: -16px;
    box-shadow: 0 -4px 18px rgba(14, 27, 46, 0.12);
    border-right: 0;
    border-top: 1px solid var(--line);
    overflow: hidden;
  }

  .handle {
    display: grid;
    place-items: center;
    flex: none;
    height: 28px;
    border-bottom: 1px solid var(--line);
    cursor: ns-resize;
    touch-action: none;
  }

  .handle::before {
    content: "";
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--line-strong);
  }

  /* Scrolling the list past its top should not reload the page; pulling
     down on the top bar should. */
  #list {
    overscroll-behavior: contain;
  }

  /* The top bar: fixed above the map, with the name on the left, the count
     in the middle and the theme switch on the right. */
  header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    height: var(--top);
    padding: 0 8px 0 16px;
    border-bottom: 1px solid var(--line);
    background: var(--ground);
    touch-action: pan-y;
  }

  .brand {
    display: contents;
  }

  .logo {
    width: 26px;
    height: 26px;
    border-radius: 7px;
  }

  h1 {
    font-size: 19px;
  }

  .summary {
    flex: 1;
    order: 1;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0 5px;
    margin: 0;
    font-size: 12.5px;
    line-height: 1.25;
    text-align: center;
  }

  .summary strong {
    font-size: 17px;
  }

  .theme {
    order: 2;
    width: 44px;
    height: 44px;
    margin-left: 0;
  }

  .source {
    min-height: 40px;
  }

  .card {
    padding: 16px;
  }

  /* Room for the Filters button at the end of the list. */
  #list {
    padding-bottom: 72px;
  }

  footer {
    display: none;
  }

  .status {
    display: none;
  }

  .fab {
    position: absolute;
    right: 16px;
    bottom: 16px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 48px;
    padding: 0 18px;
    border: 0;
    border-radius: 999px;
    background: var(--strong);
    color: var(--on-strong);
    font-weight: 700;
    box-shadow: var(--shadow);
  }

  .fab-count:not(:empty) {
    display: grid;
    place-items: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--accent);
    color: var(--on-accent);
    font-size: 12.5px;
  }

  /* The list only has a third of the screen, so the sheet rises from the
     bottom edge to its own height, over the list and part of the map. */
  .filters {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 3;
    display: none;
    align-content: start;
    max-height: 90dvh;
    padding: 12px 16px 20px;
    border-bottom: 0;
    border-radius: 20px 20px 0 0;
    background: var(--ground);
    box-shadow: 0 -6px 24px rgba(14, 27, 46, 0.18);
    overflow-y: auto;
  }

  .filters-open .filters {
    display: grid;
  }

  .filters-open .fab {
    display: none;
  }

  .filters-head h2 {
    color: var(--ink);
    font: 800 19px/1 var(--display);
    letter-spacing: 0;
    text-transform: none;
  }

  .sheet-actions {
    display: flex;
    gap: 8px;
  }

  .clear {
    min-height: 44px;
    padding: 0 18px;
    border: 1.5px solid var(--line-strong);
    border-radius: 999px;
    background: var(--ground);
    color: var(--ink);
    font-weight: 700;
    font-size: inherit;
    text-decoration: none;
  }

  .done {
    display: inline-block;
    min-height: 44px;
    padding: 0 18px;
    border: 0;
    border-radius: 999px;
    background: var(--strong);
    color: var(--on-strong);
    font-weight: 700;
  }

  /* Full-size touch targets on a phone, lined up on the right. */
  .pills button {
    min-height: 44px;
  }

  .pills,
  .pill-group {
    justify-content: flex-end;
  }

  .pill-group {
    flex-basis: 100%;
  }

  .outside button {
    min-height: 44px;
  }

}

@media (prefers-reduced-motion: no-preference) {
  .pills button,
  .days button,
  .card {
    transition:
      background-color 120ms,
      border-color 120ms,
      color 120ms;
  }
}
