/* The Loop - a city journal. Transit-map editorial reader. */

@font-face {
  font-family: "DM Serif Display";
  src: url("assets/dm-serif.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Work Sans";
  src: url("assets/work-sans.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("assets/ibm-plex-mono.ttf") format("truetype");
  font-weight: 100 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Paper palette: cool off-white, near-black ink, no beige/brass. */
  --paper: #eceee9;
  --paper-2: #e3e6df;
  --ink: #1b1d1a;
  --ink-2: #3a3f39;
  --muted: #62665f;
  --rule: #c8ccc2;

  /* Transit line colours (muted, distinct). */
  --c-culture: #b06a2c;
  --c-food: #a4392b;
  --c-movement: #2c6396;
  --c-people: #5d7a3a;
  --c-places: #2a7a6a;

  --track: #2b2f2a;
  --radius: 4px;

  --serif: "DM Serif Display", Georgia, "Times New Roman", serif;
  --sans: "Work Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* very faint paper texture, fixed, non-interactive */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(0,0,0,0.035), transparent 60%),
    radial-gradient(100% 60% at 50% 110%, rgba(0,0,0,0.04), transparent 60%);
}

body > * { position: relative; z-index: 1; }

a.skip {
  position: fixed;
  left: 12px;
  top: -60px;
  background: var(--ink);
  color: var(--paper);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 13px;
  z-index: 200;
  transition: top 0.18s ease;
}
a.skip:focus { top: 12px; }

:focus-visible {
  outline: 3px solid var(--c-movement);
  outline-offset: 2px;
  border-radius: var(--radius);
}

/* ---------- Masthead ---------- */
.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 26px clamp(16px, 4vw, 56px) 18px;
  border-bottom: 1px solid var(--rule);
}
.masthead__brand { display: flex; align-items: center; gap: 14px; }
.mark { color: var(--ink); display: flex; }
.masthead__words { display: flex; flex-direction: column; line-height: 1; }
.wordmark {
  font-family: var(--serif);
  font-size: 34px;
  letter-spacing: -0.01em;
}
.tagline {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 7px;
}
.issue {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.issue__no { color: var(--ink); }

/* ---------- Planner (search / filter / saved) ---------- */
.planner {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
  padding: 16px clamp(16px, 4vw, 56px);
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(180deg, var(--paper), rgba(255,255,255,0));
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field--search { flex: 1 1 320px; min-width: 220px; }
.field--line { flex: 0 0 auto; }
.field__label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.field__control {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--paper-2);
  border: 1.5px solid var(--rule);
  border-radius: var(--radius);
  padding: 0 12px;
  height: 44px;
}
.field__icon { color: var(--muted); flex: 0 0 auto; }
.field__control input {
  border: 0;
  background: transparent;
  outline: none;
  width: 100%;
  font: inherit;
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  padding: 0 0 0 10px;
  height: 100%;
}
.field__control input::placeholder { color: #5f6359; }
.field__control:focus-within { border-color: var(--ink); }

select#filter {
  height: 44px;
  border: 1.5px solid var(--rule);
  background: var(--paper-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2362665f' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 14px center;
  -webkit-appearance: none;
  appearance: none;
  padding: 0 36px 0 12px;
  font: inherit;
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  border-radius: var(--radius);
  cursor: pointer;
}
select#filter:focus { border-color: var(--ink); }

.saved-toggle {
  height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 0 16px;
  border: 1.5px solid var(--rule);
  background: var(--paper-2);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}
.saved-toggle__dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  border: 2px solid var(--ink-2);
  background: transparent;
  transition: background 0.16s ease, border-color 0.16s ease;
}
.saved-toggle:hover { border-color: var(--ink); }
.saved-toggle[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.saved-toggle[aria-pressed="true"] .saved-toggle__dot {
  background: var(--paper);
  border-color: var(--paper);
}

/* ---------- Board / Loop ---------- */
.board {
  padding: 22px clamp(16px, 4vw, 56px) 8px;
  overflow: visible;
}
.board__hint {
  margin: 0 0 14px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
  min-height: 16px;
}

.loop {
  position: relative;
  width: 100%;
  max-width: 980px;
  margin: 6px auto 0;
  aspect-ratio: 1000 / 560;
  overflow: visible;
}

.loop__track, .loop__train {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}
.loop__train { z-index: 1; }
.loop__track { z-index: 0; }

.track {
  fill: none;
  stroke: var(--track);
  stroke-width: 7;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 3400;
  stroke-dashoffset: 3400;
  animation: draw 1.5s cubic-bezier(0.16, 1, 0.3, 1) 0.1s forwards;
}
@keyframes draw { to { stroke-dashoffset: 0; } }

.train {
  fill: var(--ink);
  filter: drop-shadow(0 0 0 var(--paper));
}

/* Stops */
.stops {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  z-index: 2;
}

.station {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  transform: scale(0.5);
  animation: pop 0.5s cubic-bezier(0.34, 1.4, 0.64, 1) forwards;
}
@keyframes pop {
  to { opacity: 1; transform: scale(1); }
}

.station__btn {
  position: absolute;
  left: 0; top: 0;
  transform: translate(-50%, -50%);
  width: 34px; height: 34px;
  padding: 0; margin: 0; border: 0;
  background: none;
  cursor: pointer;
  display: block;
}
.station__node {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--line);
  color: #fff;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.02em;
  border: 3px solid var(--paper);
  box-shadow: 0 0 0 1.5px var(--line), 0 1px 2px rgba(0,0,0,0.18);
  transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.18s ease;
}
.station__label {
  position: absolute;
  width: 158px;
  font-family: var(--sans);
  pointer-events: auto;
}
.station__title {
  display: block;
  font-size: 13px;
  line-height: 1.22;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.005em;
}
.station__meta {
  display: block;
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.station__meta .pip {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--line);
  margin-right: 6px;
  vertical-align: -1px;
}
.station--saved .station__node::after {
  content: "";
  position: absolute;
  top: -5px; right: -5px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 0 0 0 1px var(--paper);
}

/* label placement per side */
.station--top .station__label {
  left: 17px; bottom: 40px;
  transform: translateX(-50%);
  text-align: center;
}
.station--bottom .station__label {
  left: 17px; top: 40px;
  transform: translateX(-50%);
  text-align: center;
}
.station--left .station__label {
  right: 40px; top: 17px;
  transform: translateY(-50%);
  text-align: right;
}
.station--right .station__label {
  left: 40px; top: 17px;
  transform: translateY(-50%);
  text-align: left;
}

.station__btn:hover .station__node,
.station__btn:focus-visible .station__node {
  transform: scale(1.16);
  box-shadow: 0 0 0 1.5px var(--line), 0 3px 10px rgba(0,0,0,0.22);
}
.station__btn:hover .station__title { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1.5px; }

/* ---------- Legend ---------- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  justify-content: center;
  margin: 28px auto 8px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.legend__item { display: inline-flex; align-items: center; gap: 7px; }
.legend__swatch {
  width: 14px; height: 4px;
  border-radius: 2px;
  background: var(--line);
}

/* ---------- Empty state ---------- */
.empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 5;
}
.empty[hidden] { display: none; }
.empty__card {
  max-width: 380px;
  text-align: center;
  background: var(--paper);
  border: 1.5px dashed var(--rule);
  border-radius: 8px;
  padding: 24px 22px;
}
.empty__mark { color: var(--ink-2); display: inline-flex; }
.empty__title {
  font-family: var(--serif);
  font-size: 24px;
  margin: 12px 0 6px;
  letter-spacing: -0.01em;
}
.empty__body { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.empty__action {
  border: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 11px 18px;
  border-radius: var(--radius);
  cursor: pointer;
}
.empty__action:hover { background: #000; }

/* ---------- Detail ---------- */
.detail {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: block;
}
.detail[hidden] { display: none; }
.detail__scrim {
  position: absolute;
  inset: 0;
  background: rgba(20, 22, 19, 0.42);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: fade 0.22s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.detail__sheet {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(560px, 100%);
  background: var(--paper);
  border-left: 1px solid var(--rule);
  box-shadow: -20px 0 60px rgba(0,0,0,0.18);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px clamp(22px, 5vw, 40px) 40px;
  animation: slide 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slide { from { transform: translateX(40px); opacity: 0.4; } to { transform: translateX(0); opacity: 1; } }

.detail__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px dashed var(--rule);
  margin-bottom: 16px;
}
.detail__line {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 6px 12px;
  border-radius: 999px;
  color: #fff;
  background: var(--line);
}
.detail__close {
  border: 1.5px solid var(--rule);
  background: var(--paper-2);
  color: var(--ink);
  width: 40px; height: 40px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
}
.detail__close:hover { border-color: var(--ink); }

.detail__meta {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0 8px;
  margin-bottom: 14px;
}
.detail__no { color: var(--ink); }
.detail__sep { color: var(--rule); }

.detail__title {
  font-family: var(--serif);
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1.08;
  letter-spacing: -0.015em;
  margin: 0 0 12px;
  color: var(--ink);
}
.detail__summary {
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink-2);
  margin: 0 0 22px;
  font-style: italic;
  border-left: 3px solid var(--line);
  padding-left: 14px;
}

.detail__photo { margin: 0 0 22px; }
.detail__img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius);
  filter: saturate(0.92) contrast(1.02);
}
.detail__caption {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 8px 0 0;
}

.detail__body { font-size: 17px; line-height: 1.7; color: var(--ink); }
.detail__body p { margin: 0 0 1.1em; }
.detail__body p:first-child::first-letter {
  font-family: var(--serif);
  font-size: 3.2em;
  float: left;
  line-height: 0.86;
  padding: 4px 8px 0 0;
  color: var(--line);
}

.detail__actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px dashed var(--rule);
}
.save {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border: 1.5px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 11px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease;
}
.save:hover { background: var(--paper-2); }
.save[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}
.save[aria-pressed="true"] .save__icon svg path { fill: var(--paper); }
.detail__done {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
  padding: 11px 6px;
}
.detail__done:hover { color: var(--ink); }

/* ---------- Colophon ---------- */
.colophon {
  margin-top: 26px;
  padding: 26px clamp(16px, 4vw, 56px) 36px;
  border-top: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.colophon__brand {
  font-family: var(--serif);
  font-size: 22px;
  color: var(--ink);
  margin-bottom: 6px;
}
.colophon p { margin: 0 0 4px; max-width: 70ch; line-height: 1.6; }

/* ---------- Mobile / vertical route ---------- */
@media (max-width: 1279px) {
  .loop {
    position: relative;
    aspect-ratio: auto;
    max-width: 760px;
    padding: 10px 0 0;
  }
  .loop__track, .loop__train { display: none; }
  .empty { position: relative; }
  .empty__card { width: 100%; max-width: 460px; }

  .stops {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 4px 0 6px 48px;
  }
  .stops::before {
    content: "";
    position: absolute;
    left: 47px;
    top: 6px;
    bottom: 6px;
    width: 2px;
    background: var(--track);
  }

  .station {
    position: static;
    width: auto;
    height: auto;
    animation: pop 0.4s ease forwards;
  }
  .station__btn {
    position: static;
    transform: none;
    width: auto;
    height: auto;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    text-align: left;
  }
  .station__node { flex: 0 0 auto; margin-left: -17px; }
  .station__label {
    position: static;
    transform: none;
    width: auto;
    text-align: left;
    padding-top: 4px;
  }
  .station__title { font-size: 16px; line-height: 1.25; }
  .station__meta { font-size: 11px; margin-top: 5px; }

  .legend { margin-top: 6px; justify-content: flex-start; }
}

@media (max-width: 560px) {
  .masthead { padding: 18px 16px 14px; flex-direction: column; align-items: flex-start; gap: 8px; }
  .issue { align-items: flex-start; }
  .wordmark { font-size: 30px; }
  .planner { padding: 14px 16px; gap: 10px; }
  .field--search { flex: 1 1 100%; }
  .saved-toggle { flex: 1 1 100%; justify-content: center; }
  .board { padding: 18px 16px 8px; }
  .stops { padding-left: 38px; gap: 16px; }
  .stops::before { left: 37px; }
  .station__node { margin-left: -17px; }
  .detail__sheet { padding: 18px 18px 34px; width: 100%; }
  .detail__title { font-size: 26px; }
  .detail__body { font-size: 16px; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .track { animation: none; stroke-dashoffset: 0; }
  .station { animation: none; opacity: 1; transform: none; }
  .detail__sheet { animation: none; }
  .detail__scrim { animation: none; }
  .loop__train { display: none; }
  * { transition: none !important; }
}

@media (prefers-reduced-transparency: reduce) {
  .detail__scrim { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(20,22,19,0.6); }
}
