/* Search from the next town over (site/snippets/blocks/nexttown.php, the
   Single Location tier page's signature demo; public/assets/js/nexttown.js).
   The head and the short lines beside a sample metro (a map with the office
   in the middle and a button for each town) and a sample page of search
   results, with the "With city pages" switch. The search look is the doula
   page's example searches (ind-p06b.css, p06x-searches): the query pill
   with its glass, the result title in Trirong, underlined, the found result
   in mint. Linked by the block itself (peanut_page_css), once per page.
   Every selector names a nexttown class. Tokens only. The shared hint,
   progress bar and sample controls are industry.css's. */

@layer blocks {
  /* ---------- the section: the words beside the demo (from 64rem) ---------- */
  .nexttown {
    display: grid;
    gap: var(--space-5);
    align-items: start;
  }

  @media (min-width: 64rem) {
    .nexttown {
      grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
      gap: var(--space-5);
    }
  }

  .nexttown__head {
    max-width: 36rem;
  }

  .nexttown__title {
    margin: 0;
  }

  .nexttown__intro {
    margin: var(--space-3) 0 0;
  }

  /* the short lines that replace a written problem section */
  .nexttown__lines {
    display: grid;
    max-width: 36rem;
    margin: var(--space-4) 0 0;
    padding: 0;
    list-style: none;
    counter-reset: nexttown-line;
  }

  .nexttown__lines li {
    display: grid;
    grid-template-columns: 2.25rem minmax(0, 1fr);
    padding-block: var(--space-2);
    border-block-start: 1px solid var(--color-ink-line-faint);
    font-family: var(--font-body);
    font-size: var(--text-body);
    font-weight: 400;
    line-height: 1.7;
    counter-increment: nexttown-line;
  }

  .nexttown__lines li:last-child {
    border-block-end: 1px solid var(--color-ink-line-faint);
  }

  .nexttown__lines li::before {
    content: counter(nexttown-line, decimal-leading-zero);
    padding-block-start: 0.25rem;
    font-family: var(--font-body);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: var(--tracking-caps);
  }

  /* ---------- the demo ---------- */
  .nexttown__demo {
    display: grid;
    gap: var(--space-2);
    min-width: 0;
  }

  .nexttown__progress {
    max-width: 24rem;
  }

  .nexttown__frame {
    container-type: inline-size;
    overflow: hidden;
    background: var(--color-white);
    border: var(--border);
    border-radius: var(--radius-sm);
    color: var(--color-ink);
    font-size: var(--step--1);
    line-height: 1.45;
  }

  .nexttown__bar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem var(--space-2);
    background: var(--color-paper);
    border-block-end: var(--border);
  }

  .nexttown__maptitle,
  .nexttown__statelabel {
    margin: 0;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: var(--tracking-caps);
    line-height: 1.6;
    text-transform: uppercase;
  }

  /* "Sample": the demo standard's label, in the bar, in every state */
  .nexttown__sample {
    flex: none;
    padding: 0.0625rem 0.5rem;
    background: var(--color-butter);
    border: var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: var(--tracking-caps);
    line-height: 1.6;
    text-transform: uppercase;
  }

  /* the map, then the search; side by side when the frame is 40rem wide */
  .nexttown__body {
    display: grid;
  }

  @container (min-width: 40rem) {
    .nexttown__body {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .nexttown__where {
      border-inline-end: var(--border);
    }
  }

  @container (max-width: 39.99rem) {
    .nexttown__where {
      border-block-end: var(--border);
    }
  }

  .nexttown__where {
    display: grid;
    gap: var(--space-2);
    align-content: start;
    padding: var(--space-2);
    background: var(--color-paper);
  }

  .nexttown__search {
    display: grid;
    gap: var(--space-2);
    align-content: start;
    padding: var(--space-2);
  }

  /* ---------- the sample metro ---------- */
  .nexttown__map {
    position: relative;
    width: 100%;
    max-width: 30rem;
    margin-inline: auto;
    aspect-ratio: 4 / 3;
  }

  .nexttown__drawing {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }

  .nexttown__metro {
    fill: var(--color-brand);
    opacity: 0.35;
  }

  .nexttown__river {
    fill: none;
    stroke: var(--color-white);
    stroke-width: 7;
    stroke-linecap: round;
  }

  /* the roads out to the towns: dashed while the site names one city, solid
     once each town has a page; the chosen town's road in ink */
  .nexttown__road {
    stroke: var(--color-ink-track);
    stroke-width: 1.5;
    stroke-dasharray: 5 5;
    vector-effect: non-scaling-stroke;
  }

  .nexttown__demo[data-on] .nexttown__road {
    stroke-dasharray: none;
  }

  .nexttown__road.is-current {
    stroke: var(--color-ink);
    stroke-width: 2;
  }

  /* the one city the site names, around the office */
  .nexttown__named {
    fill: var(--color-brand);
    stroke: var(--color-ink);
    stroke-width: 1;
    vector-effect: non-scaling-stroke;
  }

  .nexttown__office {
    position: absolute;
    top: 58%;
    left: 50%;
    display: inline-flex;
    gap: 0.375rem;
    align-items: center;
    margin: 0;
    padding: 0.25rem 0.625rem;
    background: var(--color-white);
    border: var(--border);
    border-radius: var(--radius-pill);
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    translate: -50% -50%;
  }

  .nexttown__pin {
    flex: none;
  }

  .nexttown__places,
  .nexttown__towns {
    position: absolute;
    inset: 0;
  }

  .nexttown__towns[hidden] {
    display: none;
  }

  .nexttown__demo.is-live .nexttown__places {
    display: none;
  }

  /* a town on the map: a plain name without the script, a button with it */
  .nexttown__spot {
    position: absolute;
    top: var(--y);
    left: var(--x);
    display: inline-flex;
    gap: 0.375rem;
    align-items: center;
    padding: 0.25rem 0.75rem;
    background: var(--color-white);
    border: var(--border);
    border-radius: var(--radius-pill);
    color: var(--color-ink);
    font-size: var(--step--1);
    font-weight: 500;
    line-height: 1.3;
    white-space: nowrap;
    translate: -50% -50%;
  }

  .nexttown__town {
    min-height: 2.75rem;
    margin: 0;
    font-family: inherit;
    cursor: pointer;
    transition: background-color 300ms var(--ease-out);
  }

  .nexttown__town:hover {
    background: var(--color-brand);
  }

  .nexttown__town[aria-pressed="true"] {
    background: var(--color-ink);
    color: var(--color-white);
  }

  .nexttown__town:focus-visible,
  .nexttown__switch:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
  }

  /* the town's page: a dashed outline while it has none, a mint page once
     the site has city pages; it keeps its size, so the button never moves */
  .nexttown__page {
    flex: none;
    width: 0.625rem;
    height: 0.8125rem;
    border: 1px dashed currentColor;
    border-radius: 0.125rem;
  }

  .nexttown__demo[data-on] .nexttown__page {
    background: var(--color-brand);
    border-style: solid;
  }

  .nexttown__legend {
    display: flex;
    gap: 0.5rem;
    align-items: baseline;
    margin: 0;
  }

  .nexttown__legendmark {
    flex: none;
    width: 0.75rem;
    height: 0.5rem;
    background: var(--color-brand);
    border: var(--border);
    border-radius: 50%;
    translate: 0 0.0625rem;
  }

  /* ---------- the switch (role switch): coral, knob at the start, when the
     site names one city; mint, knob at the end, with city pages ---------- */
  .nexttown__switchrow {
    display: flex;
    margin-block-start: var(--space-1);
    padding-block-start: var(--space-2);
    border-block-start: 1px solid var(--color-ink-line-faint);
    flex-wrap: wrap;
    gap: 0.5rem var(--space-2);
    align-items: center;
  }

  .nexttown__switchrow[hidden] {
    display: none;
  }

  .nexttown__switch {
    display: inline-flex;
    gap: 0.75rem;
    align-items: center;
    min-height: 2.75rem;
    margin: 0;
    padding: 0.375rem 1rem 0.375rem 0.5rem;
    background: var(--color-white);
    border: var(--border);
    border-radius: var(--radius-pill);
    color: var(--color-ink);
    font: inherit;
    font-weight: 600;
    text-align: start;
    cursor: pointer;
  }

  .nexttown__track {
    position: relative;
    flex: none;
    width: 2.75rem;
    height: 1.5rem;
    background: var(--color-accent-2);
    border: var(--border);
    border-radius: var(--radius-pill);
  }

  .nexttown__switch[aria-checked="true"] .nexttown__track {
    background: var(--color-brand);
  }

  .nexttown__knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: calc(1.5rem - 6px);
    height: calc(1.5rem - 6px);
    background: var(--color-white);
    border: var(--border);
    border-radius: 50%;
  }

  .nexttown__switch[aria-checked="true"] .nexttown__knob {
    translate: 1.25rem 0;
  }

  /* ---------- the sample search ---------- */
  .nexttown__set + .nexttown__set {
    margin-block-start: var(--space-3);
    padding-block-start: var(--space-3);
    border-block-start: var(--border);
  }

  .nexttown__ask {
    display: grid;
    gap: 0.375rem;
    justify-items: start;
    margin-block-end: 0.75rem;
  }

  .nexttown__query {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin: 0;
    padding: 0.375rem 0.875rem;
    background: var(--color-white);
    border: var(--border);
    border-radius: var(--radius-pill);
    font-weight: 500;
  }

  .nexttown__glass {
    position: relative;
    flex: none;
    width: 0.75rem;
    height: 0.75rem;
    margin-inline-end: 0.125rem;
    border: 1.5px solid currentColor;
    border-radius: 50%;
  }

  .nexttown__glass::after {
    content: "";
    position: absolute;
    right: -0.25rem;
    bottom: -0.25rem;
    width: 0.3125rem;
    height: 1.5px;
    background: currentColor;
    transform: rotate(45deg);
  }

  .nexttown__from {
    display: flex;
    gap: 0.375rem;
    align-items: center;
    margin: 0;
    font-size: 0.75rem;
    font-weight: 500;
  }

  .nexttown__state + .nexttown__state {
    margin-block-start: var(--space-2);
  }

  .nexttown__state {
    display: grid;
    gap: 0.5rem;
    align-content: start;
  }

  .nexttown__statelabel {
    justify-self: start;
    padding: 0 0.5rem;
    background: var(--color-accent-2);
    border: var(--border);
    border-radius: var(--radius-pill);
  }

  .nexttown__state--on .nexttown__statelabel {
    background: var(--color-brand);
  }

  .nexttown__results {
    display: grid;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .nexttown__result {
    display: grid;
    gap: 0.25rem;
    padding: 0.625rem 0.75rem;
    background: var(--color-white);
    border: var(--border);
    border-radius: var(--radius-sm);
  }

  .nexttown__result--ours {
    background: var(--color-brand);
  }

  .nexttown__url,
  .nexttown__rline {
    margin: 0;
  }

  .nexttown__url {
    font-size: 0.75rem;
    font-weight: 500;
    overflow-wrap: anywhere;
  }

  .nexttown__rtitle {
    margin: 0;
    font-family: var(--font-heading);
    font-size: 1.125rem;
    font-weight: var(--weight-heading);
    line-height: 1.25;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
  }

  /* the other results: their words, and grey lines for the rest */
  .nexttown__ghosturl,
  .nexttown__bars span {
    display: block;
    height: 0.375rem;
    background: var(--color-ink-track);
    border-radius: var(--radius-pill);
  }

  .nexttown__ghosturl {
    width: 40%;
  }

  .nexttown__bars {
    display: grid;
    gap: 0.3125rem;
    margin-block-start: 0.125rem;
  }

  .nexttown__bars span:last-child {
    width: 70%;
  }

  /* the note under the results: why the business is missing, or that its
     town's page came up */
  .nexttown__note {
    display: flex;
    gap: 0.625rem;
    align-items: flex-start;
    margin: 0;
    padding: 0.625rem 0.75rem;
    background: var(--color-paper);
    border: 1px dashed var(--color-ink);
    border-radius: var(--radius-sm);
    font-weight: 500;
  }

  .nexttown__note--found {
    border-style: solid;
  }

  /* the small line under the results with city pages on */
  .nexttown__posnote {
    margin: var(--space-1) 0 0;
    font-size: 0.75rem;
    line-height: 1.5;
  }

  .nexttown__mark {
    display: grid;
    flex: none;
    place-items: center;
    width: 1.25rem;
    height: 1.25rem;
    background: var(--color-accent-2);
    border: var(--border);
    border-radius: 50%;
  }

  .nexttown__note--found .nexttown__mark {
    background: var(--color-brand);
  }

  .nexttown__mark svg {
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  /* with the script: the towns share one cell, and so do each town's two
     states (the tallest sets the height, so nothing moves) */
  .nexttown__demo.is-live :is(.nexttown__sets, .nexttown__states) {
    display: grid;
  }

  .nexttown__demo.is-live :is(.nexttown__set, .nexttown__state) {
    grid-area: 1 / 1;
  }

  .nexttown__demo.is-live .nexttown__set + .nexttown__set,
  .nexttown__demo.is-live .nexttown__state + .nexttown__state {
    margin: 0;
    padding: 0;
    border: 0;
  }

  .nexttown__demo.is-live :is(.nexttown__set, .nexttown__state)[data-off] {
    visibility: hidden;
  }

  @media print {
    /* every town and both states print (as specific as the screen rule that hides them) */
    .nexttown__demo.is-live :is(.nexttown__set, .nexttown__state)[data-off],
    .nexttown__demo :is(.nexttown__set, .nexttown__state)[data-off] {
      visibility: visible;
    }

    .nexttown__demo.is-live :is(.nexttown__sets, .nexttown__states) {
      display: block;
    }

    .nexttown__demo.is-live .nexttown__places {
      display: block;
    }

    .nexttown__towns,
    .nexttown__switchrow {
      display: none;
    }
  }
}

@layer motion {
  @media screen and (prefers-reduced-motion: no-preference) {
    .nexttown__knob {
      transition: translate 250ms var(--ease-out);
    }

    .nexttown__track {
      transition: background-color 250ms var(--ease-out);
    }

    html[data-fx~="diagrams"] .nexttown__demo.is-live :is(.nexttown__set, .nexttown__state):not([data-off]) {
      animation: nexttown-in 400ms var(--ease-out) both;
    }

    html[data-fx~="diagrams"] .nexttown__demo.is-live .nexttown__state--on:not([data-off]) .nexttown__result--ours {
      animation: nexttown-up 500ms 150ms var(--ease-out) both;
    }
  }

  @keyframes nexttown-in {
    from {
      opacity: 0;
    }

    to {
      opacity: 1;
    }
  }

  @keyframes nexttown-up {
    from {
      opacity: 0;
      translate: 0 0.5rem;
    }

    to {
      opacity: 1;
      translate: 0 0;
    }
  }
}
