/* ============================================================
   THE CROSSTOWN — a magazine organised as a transit line.
   One line colour per category; every story is a stop.
   ============================================================ */

@font-face {
  font-family: "Space Grotesk";
  src: url("assets/space-grotesk.ttf") format("truetype");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Literata";
  src: url("assets/literata.ttf") format("truetype");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("assets/ibm-plex-mono.ttf") format("truetype");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f5f1e6;
  --card: #fffdf6;
  --ink: #181510;
  --ink-soft: #5c5648;
  --board: #141210;
  --amber: #ffb000;
  --line-culture: #6d28d9;
  --line-food: #c2410c;
  --line-movement: #047857;
  --line-people: #be185d;
  --line-places: #1d4ed8;
  --rail-w: 64px;
  --gap: 16px;
  --border: 2px solid var(--ink);
  --font-display: "Space Grotesk", "Helvetica Neue", Arial, sans-serif;
  --font-body: "Literata", Georgia, "Times New Roman", serif;
  --font-mono: "IBM Plex Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
html.is-locked, html.is-locked body { overflow: hidden; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
}

.wrap { max-width: 900px; margin: 0 auto; padding: 0 20px; }

/* Focus ------------------------------------------------------ */
:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
  border-radius: 2px;
}
.board :focus-visible,
.detail-topbar :focus-visible { outline-color: var(--amber); }

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 200;
  background: var(--ink);
  color: var(--amber);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 12px 18px;
  border: 2px solid var(--amber);
  transition: top 0.2s ease;
}
.skip-link:focus { top: 12px; }

button { cursor: pointer; }
.btn {
  background: var(--ink);
  color: var(--paper);
  border: var(--border);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 12px 18px;
  min-height: 44px;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.btn:hover { background: var(--amber); color: var(--ink); }
.btn:active { transform: translateY(1px); }

/* Masthead --------------------------------------------------- */
.masthead-top {
  text-align: center;
  padding-top: 40px;
  padding-bottom: 26px;
}
.roundel-wrap { color: var(--ink); }
.roundel { display: inline-block; }
.masthead-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.6rem, 7.5vw, 4.6rem);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin: 10px 0 6px;
  line-height: 1;
}
.masthead-tag { color: var(--ink-soft); margin: 0; }

/* Departure board --------------------------------------------- */
.board {
  background: var(--board);
  color: var(--amber);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  overflow: hidden;
  -webkit-mask-image: radial-gradient(circle, #000 52%, transparent 62%);
  mask-image: radial-gradient(circle, #000 52%, transparent 62%);
  -webkit-mask-size: 4px 4px;
  mask-size: 4px 4px;
}
.board-msg { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-clock { margin: 0; flex-shrink: 0; font-weight: 700; }

/* Journey planner --------------------------------------------- */
.controls {
  margin-top: 34px;
  border: var(--border);
  background: var(--card);
  padding: 20px;
  box-shadow: 5px 5px 0 var(--ink);
}
.controls-title { margin: 0 0 16px; font-weight: 700; }
.controls-grid {
  display: grid;
  grid-template-columns: 2fr 1.2fr 1.3fr;
  gap: 18px;
}
.field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.field label, .field-label { font-weight: 700; color: var(--ink-soft); }

input[type="search"], select {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  padding: 12px 14px;
  min-height: 44px;
  border: var(--border);
  background: var(--paper);
  color: var(--ink);
  border-radius: 0;
  appearance: none;
  -webkit-appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23181510' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
}
input[type="search"]:focus-visible, select:focus-visible { outline-offset: 0; }

.saved-toggle {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  text-align: left;
  border: var(--border);
  background: var(--paper);
  padding: 8px 14px;
  min-height: 44px;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.saved-toggle-title { font-weight: 700; font-size: 0.75rem; }
.saved-toggle-action { color: var(--ink-soft); }
.saved-toggle[aria-pressed="true"] {
  background: var(--ink);
  color: var(--amber);
  box-shadow: inset 0 0 0 2px var(--amber);
}
.saved-toggle[aria-pressed="true"] .saved-toggle-action { color: var(--amber); }
.saved-toggle:hover { background: var(--amber); color: var(--ink); }
.saved-toggle[aria-pressed="true"]:hover .saved-toggle-action,
.saved-toggle[aria-pressed="true"]:hover { color: var(--ink); }

.route-count { margin: 16px 0 0; color: var(--ink-soft); font-weight: 700; }

/* The route ---------------------------------------------------- */
.route-wrap { margin-top: 38px; padding-bottom: 26px; }
.route { list-style: none; margin: 0; padding: 0; }

.terminus, .stop { display: grid; grid-template-columns: var(--rail-w) 1fr; }

.rail { position: relative; }
.rail::before {
  content: "";
  position: absolute;
  left: calc(50% - 5px);
  top: -9px;
  bottom: -9px;
  width: 10px;
  background: var(--line, var(--ink));
}
.route > :first-child .rail::before {
  top: 14px;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}
.route > :last-child .rail::before {
  bottom: 14px;
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
}
.stop + .stop, .terminus + .stop, .stop + .terminus { margin-top: var(--gap); }

.terminus .rail::before { background: var(--ink); }
.terminus .cap {
  position: absolute;
  left: calc(50% - 9px);
  top: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink);
  border: 4px solid var(--paper);
  box-shadow: 0 0 0 2px var(--ink);
}
.terminus.bottom .cap { top: auto; bottom: 4px; }
.terminus-label { align-self: center; color: var(--ink-soft); padding-left: 8px; }

/* Station dots -------------------------------------------------- */
.dot {
  position: absolute;
  left: calc(50% - 17px);
  top: 12px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--card);
  border: 4px solid var(--line, var(--ink));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--line, var(--ink));
  box-shadow: 0 0 0 2px var(--paper);
}

/* Stop cards ---------------------------------------------------- */
.stop-card {
  border: var(--border);
  background: var(--card);
  padding: 18px 20px 16px;
  margin-left: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.stop-card:hover { transform: translate(-2px, -2px); box-shadow: 5px 5px 0 var(--line, var(--ink)); }

.stop-kicker { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.stop-no { color: var(--ink-soft); font-weight: 700; }
.plate {
  color: var(--line, var(--ink));
  border: 2px solid var(--line, var(--ink));
  padding: 3px 8px;
  font-weight: 700;
}
.punched-tag { color: var(--line-food); font-weight: 700; }
.punched-tag::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--line-food);
  box-shadow: 0 0 0 2px var(--ink);
  margin-right: 7px;
  vertical-align: -1px;
}
.stop-title {
  font-size: clamp(1.25rem, 2.6vw, 1.5rem);
  line-height: 1.25;
  margin: 0;
  font-weight: 700;
}
.stop-summary { margin: 0; color: var(--ink-soft); font-size: 0.98rem; max-width: 62ch; }
.stop-foot {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
  border-top: 1px solid color-mix(in srgb, var(--ink) 25%, transparent);
  padding-top: 12px;
}
.stop-meta { margin: 0; color: var(--ink-soft); }
.open-btn {
  background: var(--line, var(--ink));
  color: var(--card);
  border: 2px solid var(--ink);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 12px 16px;
  min-height: 44px;
  transition: background 0.15s ease, color 0.15s ease;
}
.open-btn:hover { background: var(--ink); color: var(--amber); }

/* Empty state ---------------------------------------------------- */
.empty {
  border: var(--border);
  background: var(--board);
  color: var(--amber);
  padding: 40px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: 5px 5px 0 var(--ink);
  -webkit-mask-image: radial-gradient(circle, #000 52%, transparent 62%);
  mask-image: radial-gradient(circle, #000 52%, transparent 62%);
  -webkit-mask-size: 4px 4px;
  mask-size: 4px 4px;
}
.empty[hidden] { display: none; }
.empty-board { font-size: 1.6rem; font-weight: 700; margin: 0; letter-spacing: 0.2em; }
.empty-text { margin: 0; max-width: 46ch; color: var(--amber); font-family: var(--font-body); font-size: 1rem; line-height: 1.6; text-transform: none; letter-spacing: 0; }
.empty .btn { background: var(--amber); color: var(--ink); border-color: var(--amber); }
.empty .btn:hover { background: var(--paper); border-color: var(--paper); }

/* Footer --------------------------------------------------------- */
.footer {
  margin-top: 30px;
  border-top: var(--border);
  padding: 20px 0 30px;
}
.footer .mono { color: var(--ink-soft); margin: 0; line-height: 1.9; }

/* ================================================================
   Detail view — the station platform
   ================================================================ */
.detail[hidden] { display: none; }
.detail {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--paper);
  animation: arrive 0.35s cubic-bezier(0.22, 0.9, 0.36, 1) both;
}
@keyframes arrive {
  from { transform: translateY(3%); opacity: 0.4; }
  to { transform: translateY(0); opacity: 1; }
}
.detail-scroll { height: 100%; overflow-y: auto; overscroll-behavior: contain; }

.detail-topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--board);
  color: var(--amber);
  border-bottom: 4px solid var(--ink);
}
.detail-topbar-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-top: 10px;
  padding-bottom: 10px;
}
.detail-where { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.detail-topbar .btn { background: transparent; color: var(--amber); border-color: var(--amber); }
.detail-topbar .btn:hover { background: var(--amber); color: var(--ink); }

.detail-inner { padding-top: 44px; padding-bottom: 70px; }

.detail-head { text-align: center; }
.detail-category {
  display: inline-block;
  margin-bottom: 18px;
  padding: 6px 12px;
  border: 3px solid var(--line, var(--ink));
  color: var(--line, var(--ink));
  background: var(--card);
  font-weight: 700;
}
.detail-title {
  display: inline-block;
  margin: 0 auto;
  font-size: clamp(1.8rem, 5vw, 3rem);
  line-height: 1.15;
  background: var(--card);
  border: 4px solid var(--ink);
  box-shadow: 6px 6px 0 var(--ink);
  padding: 22px 26px;
  max-width: 100%;
}
.detail-meta { margin: 18px 0 0; color: var(--ink-soft); font-weight: 700; }

.poster { margin: 40px 0; border: 4px solid var(--ink); background: var(--card); }
.poster img { display: block; width: 100%; height: auto; aspect-ratio: 3 / 2; object-fit: cover; border-bottom: 4px solid var(--ink); }
.poster figcaption {
  padding: 10px 14px;
  color: var(--ink-soft);
  border-top: 1px dashed var(--ink-soft);
}

.detail-body { max-width: 66ch; margin: 0 auto; font-size: 1.13rem; line-height: 1.75; }
.detail-body p { margin: 0 0 1.3em; }
.detail-body p:first-of-type::first-letter {
  font-size: 3.1em;
  font-weight: 700;
  float: left;
  line-height: 0.85;
  padding: 0.08em 0.14em 0 0;
  color: var(--line, var(--ink));
}

/* Ticket ---------------------------------------------------------- */
.ticket {
  position: relative;
  margin: 56px auto 0;
  max-width: 620px;
  display: grid;
  grid-template-columns: 118px 1fr;
  border: 3px dashed var(--ink);
  background: var(--card);
  box-shadow: 6px 6px 0 var(--ink);
}
.ticket-stub {
  border-right: 3px dashed var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px 10px;
  font-weight: 700;
  line-height: 2;
  background: repeating-linear-gradient(-45deg, var(--paper) 0 10px, color-mix(in srgb, var(--ink) 6%, var(--paper)) 10px 20px);
}
.ticket-main { padding: 22px; display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
.ticket-main .mono { color: var(--ink-soft); font-weight: 700; }
.save-btn {
  background: var(--ink);
  color: var(--amber);
  border: 2px solid var(--ink);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 14px 20px;
  min-height: 44px;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.save-btn:hover { background: var(--amber); color: var(--ink); }
.save-btn:active { transform: translateY(1px); }
.punch-hole {
  position: absolute;
  top: -14px;
  right: 26px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--paper);
  border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 3px var(--card), 0 0 0 3px var(--paper);
  transform: rotate(12deg);
  display: none;
}
.ticket.punched .punch-hole { display: block; }
.ticket.punched { border-style: solid; }

/* Reduced motion --------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* Small viewports ---------------------------------------------------- */
@media (max-width: 700px) {
  :root { --rail-w: 48px; --gap: 14px; }
  .wrap { padding: 0 14px; }
  .masthead-top { padding-top: 26px; padding-bottom: 18px; }
  .roundel { width: 64px; height: 64px; }
  .controls { margin-top: 22px; padding: 16px; }
  .controls-grid { grid-template-columns: 1fr; gap: 16px; }
  .route-wrap { margin-top: 26px; }
  .dot { width: 28px; height: 28px; left: calc(50% - 14px); font-size: 0.68rem; border-width: 3px; }
  .rail::before { width: 8px; left: calc(50% - 4px); }
  .stop-card { padding: 14px 14px 12px; margin-left: 4px; }
  .stop-foot { flex-direction: column; align-items: stretch; gap: 10px; }
  .open-btn { text-align: center; }
  .ticket { grid-template-columns: 1fr; }
  .ticket-stub { border-right: none; border-bottom: 3px dashed var(--ink); padding: 10px; }
  .detail-inner { padding-top: 28px; }
  .detail-title { padding: 16px 18px; }
  .detail-topbar-inner { flex-direction: column; align-items: flex-start; gap: 8px; }
}

@media (max-width: 430px) {
  .board .mono { font-size: 0.62rem; }
  .empty-board { font-size: 1.15rem; letter-spacing: 0.12em; }
}

@media (min-width: 701px) and (max-width: 860px) {
  .controls-grid { grid-template-columns: 1fr 1fr; }
  .field:first-child { grid-column: 1 / -1; }
}
