/* ── Design 1b — "Brass marine rose: engraved, ceremonial, serif" ──
   Values are lifted from the handoff mock (390 × 790 card). Fixed pixel
   sizes become ratios of --face so the instrument scales on any phone,
   but every colour, weight and proportion is the mock's.
   ─────────────────────────────────────────────────────────────── */

:root {
  --ink: #2c2418;
  --ink-72: rgb(44 36 24 / 0.72);
  --ink-70: rgb(44 36 24 / 0.7);
  --ink-62: rgb(44 36 24 / 0.62);
  --ink-55: rgb(44 36 24 / 0.55);
  --ink-50: rgb(44 36 24 / 0.5);
  --ink-48: rgb(44 36 24 / 0.48);
  --ink-45: rgb(44 36 24 / 0.45);
  --ink-22: rgb(44 36 24 / 0.22);

  --rule: rgb(72 56 28 / 0.28);
  --paper: #f3ecd9;
  --green: #4a7c3f;
  --lacquer: #8f2f1e;

  --serif: "EB Garamond", "Iowan Old Style", Palatino, Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --tap: 44px;
}

/* ── Base ────────────────────────────────────────────────────── */

* {
  box-sizing: border-box;
}

/* Components below set `display`, which would otherwise beat the UA
   stylesheet's rule for [hidden]. */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: linear-gradient(170deg, #efe7d6, #ddd0b6) fixed;
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1,
h2,
p,
ul,
dl,
dd,
dt {
  margin: 0;
}
ul {
  padding: 0;
  list-style: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

:where(button, a, input, [tabindex]):focus-visible {
  outline: 1.5px solid var(--ink);
  outline-offset: 3px;
}

.app {
  max-width: 390px;
  height: 100dvh;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
}

/* ── Top bar ─────────────────────────────────────────────────── */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: max(16px, env(safe-area-inset-top)) 24px 0;
  font: 500 12px/1 var(--mono);
  color: var(--ink-45);
}

.topbar__origin {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.topbar__origin > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.topbar__pin {
  flex: none;
  width: 14px;
  height: 14px;
  fill: currentColor;
}
.topbar__pin .hole {
  fill: #efe7d6;
}

.topbar__actions {
  display: flex;
  flex: none;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
}

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

.icon-button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Compass ─────────────────────────────────────────────────── */

.main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Takes all the room the fixed blocks below leave; app.js reads this box's
   height to size --face, so the whole screen fits without scrolling. */
.compass-stage {
  flex: 1 1 0;
  min-height: 0;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

/* Mock: 330 outer, 15 padding, 300 face. --face is overwritten by app.js
   once the stage has been laid out; this is the pre-layout fallback. */
.compass {
  --face: min(76.9vw, 300px);
  flex: none;
  position: relative;
  width: calc(var(--face) * 1.1);
  height: calc(var(--face) * 1.1);
  padding: calc(var(--face) * 0.05);
  box-sizing: border-box;
  border-radius: 50%;
  background: conic-gradient(
    from 210deg,
    #8a6b34,
    #e4c98a 12%,
    #a8873f 30%,
    #6f5527 46%,
    #dcbf7d 62%,
    #95742f 80%,
    #8a6b34
  );
  box-shadow:
    0 16px 34px rgb(60 44 20 / 0.38),
    inset 0 2px 3px rgb(255 255 255 / 0.5);
}

.compass__face {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 46% 34%, #fbf5e6, #e3d7ba 72%, #cdbe99);
  box-shadow: inset 0 3px 10px rgb(90 70 36 / 0.45);
}

/* The rotating card. app.js turns this to -heading so N holds true north. */
.compass__rose {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

/* Minute ticks — one every 3.75°, confined to the outer 10% of the face. */
.compass__ticks,
.compass__rule {
  position: absolute;
  inset: calc(var(--face) * 0.02);
  border-radius: 50%;
}

.compass__ticks {
  background: repeating-conic-gradient(
    from 0deg,
    rgb(72 56 28 / 0.55) 0 0.5deg,
    transparent 0.5deg 3.75deg
  );
  -webkit-mask: radial-gradient(
    circle closest-side,
    transparent 0 90%,
    #000 91% 100%
  );
  mask: radial-gradient(circle closest-side, transparent 0 90%, #000 91% 100%);
}

.compass__rule {
  border: 1px solid rgb(72 56 28 / 0.35);
  -webkit-mask: radial-gradient(
    circle closest-side,
    transparent 0 78%,
    #000 78%
  );
  mask: radial-gradient(circle closest-side, transparent 0 78%, #000 78%);
}

/* The engraved rose: four long cardinal points, four faint intercardinals. */
.compass__star {
  position: absolute;
  border-radius: 50%;
}
.compass__star i {
  position: absolute;
  inset: 0;
  display: block;
}

.compass__star--inter {
  inset: calc(var(--face) * 0.12667);
  transform: rotate(45deg);
}

.compass__star--inter i {
  background: rgb(120 96 54 / 0.3);
}
.compass__star--inter i:first-child {
  clip-path: polygon(50% 0, 57% 50%, 50% 100%, 43% 50%);
}
.compass__star--inter i:last-child {
  clip-path: polygon(0 50%, 50% 43%, 100% 50%, 50% 57%);
}

.compass__star--cardinal {
  inset: calc(var(--face) * 0.06667);
}

.compass__star--cardinal i:first-child {
  background: linear-gradient(
    180deg,
    rgb(58 44 20 / 0.72) 50%,
    rgb(58 44 20 / 0.4) 50%
  );
  clip-path: polygon(50% 0, 56% 50%, 50% 100%, 44% 50%);
}

.compass__star--cardinal i:last-child {
  background: rgb(58 44 20 / 0.5);
  clip-path: polygon(0 50%, 50% 44%, 100% 50%, 50% 56%);
}

.compass__cardinal {
  position: absolute;
  transform: translate(-50%, -50%);
  font: 500 calc(var(--face) * 0.06) / 1 var(--serif);
  color: var(--ink-72);
}

.compass__cardinal--n {
  left: 50%;
  top: calc(50% - var(--face) * 0.37333);
  font-weight: 600;
  font-size: calc(var(--face) * 0.07);
  color: var(--ink);
}
.compass__cardinal--e {
  left: calc(50% + var(--face) * 0.37333);
  top: 50%;
}
.compass__cardinal--s {
  left: 50%;
  top: calc(50% + var(--face) * 0.37333);
}
.compass__cardinal--w {
  left: calc(50% - var(--face) * 0.37333);
  top: 50%;
}

/* Needle — the only part that moves. */
.compass__needle {
  position: absolute;
  inset: 0;
  transition: opacity 400ms ease;
}

.compass[data-mode="pending"] .compass__needle {
  opacity: 0.22;
}

/* Hunting for a fix — the dial is the progress indicator. A CSS animation
   outranks the inline transform app.js writes, so it takes over cleanly and
   hands back the moment the mode changes. */
.compass[data-mode="searching"] .compass__needle {
  opacity: 0.75;
  animation: hunt 2.8s cubic-bezier(0.5, 0, 0.4, 1) infinite;
}

@keyframes hunt {
  0% { transform: rotate(0deg); }
  30% { transform: rotate(215deg); }
  45% { transform: rotate(178deg); }
  70% { transform: rotate(348deg); }
  85% { transform: rotate(330deg); }
  100% { transform: rotate(360deg); }
}

.compass__needle i {
  position: absolute;
  left: 50%;
  display: block;
  width: calc(var(--face) * 0.08667);
  height: calc(var(--face) * 0.38667);
  margin-left: calc(var(--face) * -0.04333);
}

.compass__needle-n {
  top: calc(var(--face) * 0.11333);
  background: linear-gradient(180deg, #8f2f1e, #5f1d10);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  filter: drop-shadow(0 3px 5px rgb(80 60 30 / 0.5));
}

.compass__needle-s {
  bottom: calc(var(--face) * 0.11333);
  background: linear-gradient(0deg, #3a2c14, #6b5730);
  clip-path: polygon(50% 100%, 100% 0, 0 0);
}

.compass__hub {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--face) * 0.08667);
  height: calc(var(--face) * 0.08667);
  margin: calc(var(--face) * -0.04333) 0 0 calc(var(--face) * -0.04333);
  border-radius: 50%;
  background: radial-gradient(circle at 36% 30%, #f3e3b8, #8a6b34);
  box-shadow: 0 2px 5px rgb(60 44 20 / 0.6);
}

.compass__index {
  position: absolute;
  left: 50%;
  top: calc(var(--face) * 0.008);
  width: calc(var(--face) * 0.05);
  height: calc(var(--face) * 0.06);
  margin-left: calc(var(--face) * -0.025);
  background: var(--lacquer);
  clip-path: polygon(50% 100%, 100% 0, 0 0);
}

.compass__glass {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(
    circle at 28% 16%,
    rgb(255 255 255 / 0.5),
    rgb(255 255 255 / 0.06) 40%,
    transparent 60%
  );
}

.ghost-button {
  padding: 6px 14px;
  border: 1px solid var(--ink-22);
  border-radius: 3px;
  background: none;
  color: var(--ink-62);
  font: 500 10px/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
}

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

/* ── Nearest branch ──────────────────────────────────────────── */

.details {
  flex: none;
  padding: 4px 28px 0;
  text-align: center;
}

.details__head {
  font: italic 400 13px/1 var(--serif);
  letter-spacing: 0.06em;
  color: var(--ink-55);
}

.details__name {
  margin-top: 8px;
  font: 600 30px/1.1 var(--serif);
  letter-spacing: 0.01em;
  text-wrap: balance;
}

.rail {
  margin: 16px auto 0;
  max-width: 250px;
  padding: 12px 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  display: flex;
  justify-content: space-around;
  font: 500 11px/1.5 var(--mono);
  letter-spacing: 0.08em;
  color: var(--ink-70);
}

.rail__label {
  font-size: 9px;
  opacity: 0.55;
  text-transform: uppercase;
}

.rail__value {
  font-variant-numeric: tabular-nums;
}

.status {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: 500 10.5px/1 var(--mono);
  letter-spacing: 0.1em;
  color: var(--ink-62);
}

.status__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  display: block;
}

/* The mock prints the state word in caps and leaves the qualifier as-is. */
.status__state {
  text-transform: uppercase;
}
.status__detail:not(:empty)::before {
  content: "· ";
}

.status[data-state="closed"] .status__dot {
  background: var(--lacquer);
}
.status[data-state="unknown"] .status__dot {
  background: var(--ink-45);
}

.details__address {
  margin-top: 10px;
  font: italic 400 13px/1.45 var(--serif);
  color: var(--ink-50);
  text-wrap: balance;
}

/* ── Loading / error ─────────────────────────────────────────── */

.state {
  flex: none;
  padding: 8px 28px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

.state__message {
  font: 500 10.5px/1.4 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-62);
}

.state__detail {
  font: italic 400 14px/1.5 var(--serif);
  color: var(--ink-55);
  max-width: 22rem;
  text-wrap: balance;
}

.state__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 18px;
}

.link-button {
  padding: 3px 0;
  border: 0;
  border-bottom: 1px solid var(--ink-22);
  background: none;
  color: var(--ink-48);
  font: 500 10px/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
}

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

/* ── Footer actions ──────────────────────────────────────────── */

.actions {
  flex: none;
  padding: 18px 26px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.actions__primary {
  width: 100%;
  padding: 17px;
  border: 0;
  border-radius: 4px;
  background: var(--ink);
  color: var(--paper);
  font: 600 14px/1 var(--serif);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.actions__primary:hover {
  background: #3b3122;
}

.actions__primary[aria-disabled="true"] {
  opacity: 0.35;
  pointer-events: none;
}

.actions__primary--inline {
  width: auto;
  padding: 15px 20px;
}

.actions__nearby {
  padding: 0 0 3px;
  border: 0;
  /* border-bottom: 1px solid var(--ink-22); */
  background: none;
  color: var(--ink-48);
  font: 500 10px/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
}

.actions__nearby:hover {
  color: var(--ink);
  border-bottom-color: var(--ink);
}
.actions__nearby[disabled] {
  opacity: 0.4;
  cursor: default;
}

/* ── Sheets ──────────────────────────────────────────────────── */

.sheet {
  width: min(390px, calc(100vw - 24px));
  max-height: min(78dvh, 640px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: linear-gradient(170deg, #efe7d6, #e4d8c0);
  color: var(--ink);
  box-shadow: 0 -10px 40px rgb(60 44 20 / 0.35);
  overflow: hidden;
}

.sheet::backdrop {
  background: rgb(44 36 24 / 0.5);
}

.sheet__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-45);
}

.sheet__title {
  font: 500 10px/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-62);
}

.sheet__head .icon-button {
  margin-inline-start: auto;
}

.sheet__body {
  display: flex;
  flex-direction: column;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
.sheet__row {
  display: flex;
  gap: 8px;
  padding: 16px 20px 0;
}

.sheet__input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: rgb(255 255 255 / 0.45);
  color: var(--ink);
  font: 400 16px/1 var(--serif); /* 16px keeps iOS from zooming on focus */
}

.sheet__body > .link-button {
  align-self: center;
  margin: 16px 0 0;
}

.sheet__message {
  padding: 16px 20px 20px;
  font: italic 400 13px/1.5 var(--serif);
  color: var(--ink-55);
  text-align: center;
}

/* ── Branch list ─────────────────────────────────────────────── */

.branches {
  overflow-y: auto;
  padding: 0 20px;
}

.branches:empty {
  display: none;
}

.branches li + li {
  border-top: 1px solid var(--rule);
}

.branch {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: var(--tap);
  padding: 14px 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.branch:hover .branch__name {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.branch__arrow {
  flex: none;
  width: 15px;
  height: 15px;
  fill: var(--ink-45);
  transition: transform 300ms cubic-bezier(0.3, 1.3, 0.5, 1);
}

.branch[aria-current="true"] .branch__arrow {
  fill: var(--lacquer);
}

.branch__text {
  flex: 1;
  min-width: 0;
}

.branch__name {
  display: block;
  font: 400 17px/1.25 var(--serif);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.branch[aria-current="true"] .branch__name {
  font-weight: 600;
}

.branch__meta {
  display: block;
  margin-top: 3px;
  font: 500 9.5px/1.4 var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-45);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.branch__meta [data-state="open"] {
  color: var(--green);
}
.branch__meta [data-state="closed"] {
  color: var(--lacquer);
}

.branch__distance {
  flex: none;
  font: 500 11px/1 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink-70);
}

/* Nominatim results reuse the same row, minus the compass parts. */
.branch--place {
  align-items: baseline;
}
.branch--place .branch__meta {
  text-transform: none;
  font-family: var(--serif);
  font-size: 12px;
  letter-spacing: 0;
}

/* ── Toast ───────────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  translate: -50% 0;
  max-width: min(340px, calc(100vw - 32px));
  padding: 11px 18px;
  border-radius: 4px;
  background: var(--ink);
  color: var(--paper);
  font: 500 10px/1.4 var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
  z-index: 10;
  animation: toast-in 240ms ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    translate: -50% 10px;
  }
}

/* ── Motion ──────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
