/*
 * jamesjapan.com
 * The visual idea is Japanese railway wayfinding: every region is a line with
 * its own colour, region headings are station signs, and places are stops.
 */

:root {
  --paper: #f3f5f2;
  --plate: #ffffff;
  --ink: #14213a;
  --ink-soft: #55607a;
  --rule: #d3d9df;

  --kanto: #23763f;
  --kansai: #b3500e;
  --kyushu: #c2253a;
  --okinawa: #0b7285;
  --nagano: #6746ad;
  --hokkaido: #2459b8;

  /* The colour of whichever line the current element belongs to. */
  --line: var(--ink-soft);

  --font:
    "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  --text-column: 42rem;
}

.line-kanto {
  --line: var(--kanto);
}

.line-kansai {
  --line: var(--kansai);
}

.line-kyushu {
  --line: var(--kyushu);
}

.line-okinawa {
  --line: var(--okinawa);
}

.line-nagano {
  --line: var(--nagano);
}

.line-hokkaido {
  --line: var(--hokkaido);
}

.line-topic {
  --line: var(--ink-soft);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

a:hover {
  background: color-mix(in srgb, var(--line) 14%, transparent);
}

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

p {
  margin: 1rem 0 0;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 3;
  padding: 0.5rem 0.75rem;
  background: var(--ink);
  color: var(--plate);
}

.skip-link:focus {
  top: 1rem;
}

/* Page frame */

.layout {
  max-width: 64rem;
  margin: 0 auto;
}

main,
.page {
  padding: 0 1.25rem 5rem;
}

.page {
  max-width: calc(var(--text-column) + 2.5rem);
  margin: 0 auto;
}

/* Masthead */

.masthead {
  padding-top: 3rem;
}

.masthead h1 {
  margin: 0;
  font-size: clamp(2.6rem, 8vw, 4.75rem);
  font-weight: 900;
  line-height: 1.02;
  letter-spacing: -0.025em;
}

.masthead-kanji {
  margin: 0.9rem 0 0;
  color: var(--ink-soft);
  font-size: 1.25rem;
  font-weight: 500;
  letter-spacing: 0.2em;
}

/* One band per regional line, in the order they appear in the guide. */
.masthead-lines {
  height: 0.5rem;
  margin-top: 1.75rem;
  background: linear-gradient(
    to right,
    var(--kanto) 0 16.66%,
    var(--kansai) 16.66% 33.33%,
    var(--kyushu) 33.33% 50%,
    var(--okinawa) 50% 66.66%,
    var(--nagano) 66.66% 83.33%,
    var(--hokkaido) 83.33% 100%
  );
}

.masthead-links {
  margin-top: 1.25rem;
  font-weight: 700;
}

.masthead-compact h1 {
  font-size: clamp(1.9rem, 6vw, 2.75rem);
}

/* Route map navigation */

.route {
  margin: 0;
  padding: 0;
  list-style: none;
}

.route-stop {
  position: relative;
}

.route-stop::before {
  content: "";
  position: absolute;
  background: var(--rule);
}

.route-stop a {
  display: block;
  color: var(--ink-soft);
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.5rem;
  text-decoration: none;
  white-space: nowrap;
}

.route-stop a:hover {
  background: none;
  color: var(--ink);
}

.route-stop a::before {
  content: "";
  position: absolute;
  left: 0;
  width: 1rem;
  height: 1rem;
  border: 4px solid var(--line);
  border-radius: 50%;
  background: var(--plate);
}

.route-stop a[aria-current="true"] {
  color: var(--ink);
  font-weight: 700;
}

.route-stop a[aria-current="true"]::before {
  background: var(--line);
}

.route-kanji {
  margin-left: 0.4rem;
  font-size: 0.8rem;
  font-weight: 400;
}

@media (min-width: 56.0625rem) {
  .layout {
    display: grid;
    grid-template-columns: 12rem minmax(0, var(--text-column));
    column-gap: 4.5rem;
    padding: 0 1.5rem;
  }

  main {
    padding-inline: 0;
  }

  .masthead {
    padding-top: 5rem;
  }

  .rail {
    position: sticky;
    top: 0;
    align-self: start;
    max-height: 100vh;
    padding: 5.75rem 0 2rem;
    overflow-y: auto;
  }

  .route-stop {
    padding: 0 0 1.15rem 1.85rem;
  }

  .route-stop::before {
    left: 6px;
    top: 0;
    bottom: 0;
    width: 4px;
  }

  .route-stop:first-child::before {
    top: 0.75rem;
  }

  .route-stop:last-child::before {
    bottom: auto;
    height: 0.75rem;
  }

  .route-stop a::before {
    top: 0.25rem;
  }

  .section {
    scroll-margin-top: 1.5rem;
  }
}

@media (max-width: 56rem) {
  .rail {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 0.8rem 1.25rem 0.55rem;
    overflow-x: auto;
    border-bottom: 1px solid var(--rule);
    background: var(--paper);
    scrollbar-width: none;
  }

  .rail::-webkit-scrollbar {
    display: none;
  }

  .route {
    display: flex;
    width: max-content;
  }

  .route-stop {
    padding: 1.4rem 1.6rem 0 0;
  }

  .route-stop::before {
    left: 0;
    right: 0;
    top: 6px;
    height: 4px;
  }

  .route-stop:first-child::before {
    left: 0.5rem;
  }

  .route-stop:last-child {
    padding-right: 0;
  }

  .route-stop:last-child::before {
    right: auto;
    width: 0.5rem;
  }

  .route-stop a::before {
    top: 0;
  }

  .route-kanji {
    display: none;
  }

  .section {
    scroll-margin-top: 4.5rem;
  }
}

/* Sections */

.section {
  padding-top: 4.5rem;
}

.sign {
  width: min(100%, 24rem);
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--plate);
  text-align: center;
}

.sign-face {
  padding: 1.35rem 1rem 1.1rem;
}

.sign-kanji {
  display: block;
  /* Cancel the trailing letter-spacing so the kanji stay optically centred. */
  margin-right: -0.14em;
  font-size: 3.1rem;
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 0.14em;
}

.sign-name {
  margin: 0.4rem 0 0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.08em;
}

.sign-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 2.25rem;
  padding: 0 0.9rem;
  background: var(--line);
  color: var(--plate);
  font-size: 0.85rem;
  font-weight: 700;
}

.sign-band a {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--plate);
  text-decoration: none;
}

.sign-band a:hover {
  background: none;
  text-decoration: underline;
  text-decoration-color: var(--plate);
}

.sign-band a:focus-visible {
  outline-color: var(--plate);
}

.sign-previous::before,
.sign-next::after {
  content: "";
  border: 0.35rem solid transparent;
}

.sign-previous::before {
  border-left-width: 0;
  border-right-color: var(--plate);
}

.sign-next::after {
  border-right-width: 0;
  border-left-color: var(--plate);
}

.topic-title {
  margin: 0;
  padding-top: 1.1rem;
  border-top: 4px solid var(--ink);
  font-size: 2rem;
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.area {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 2.75rem 0 0;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.3;
}

.area::before {
  content: "";
  flex: none;
  width: 1.25rem;
  height: 4px;
  background: var(--line);
}

/* Lists: top-level items are stops on the section's line. */

.stops,
.branch {
  margin: 0;
  padding: 0;
  list-style: none;
}

.stops {
  margin-top: 1.5rem;
}

.stops > li {
  position: relative;
  padding: 0 0 1.15rem 1.75rem;
}

.stops > li:last-child {
  padding-bottom: 0;
}

.stops > li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 0.9rem;
  bottom: -0.5rem;
  width: 2px;
  background: color-mix(in srgb, var(--line) 35%, transparent);
}

.stops > li:last-child::before {
  display: none;
}

.stops > li::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0.5rem;
  width: 10px;
  height: 10px;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
}

.stops > li.is-done::after {
  background: var(--line);
}

.name,
.text,
.note {
  display: block;
}

.name {
  font-weight: 700;
}

.note {
  color: var(--ink-soft);
  font-size: 0.97rem;
  line-height: 1.55;
}

.todo,
.status {
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-style: italic;
}

.status {
  margin-left: 0.5rem;
  font-weight: 500;
}

.branch {
  margin-top: 0.55rem;
}

.branch > li {
  position: relative;
  padding: 0 0 0.55rem 1.15rem;
}

.branch > li:last-child {
  padding-bottom: 0;
}

.branch > li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.72rem;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink-soft);
}

.branch .name {
  font-weight: 500;
}

.branch > li > .name:has(+ .branch) {
  font-weight: 700;
}

/* Lists of bare names flow into columns. */
.stops-compact {
  columns: 2;
  column-gap: 2rem;
}

.stops-compact > li {
  padding-bottom: 0.6rem;
  break-inside: avoid;
}

/* Linked and unlinked names sit side by side here, so they share one weight. */
.stops-compact > li > .name,
.stops-compact > li > .text {
  font-weight: 500;
}

.stops-compact > li::before {
  display: none;
}

@media (min-width: 40rem) {
  .stops-compact {
    columns: 3;
  }
}

/* Numbered lists are real sequences, so the stop carries its number. */
.stops-numbered {
  counter-reset: step;
}

.stops-numbered > li {
  padding-left: 2.5rem;
  counter-increment: step;
}

.stops-numbered > li::before {
  left: 0.72rem;
  top: 1.6rem;
}

.stops-numbered > li::after {
  content: counter(step);
  top: 0.05rem;
  display: grid;
  place-items: center;
  width: 1.6rem;
  height: 1.6rem;
  background: var(--plate);
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
}

ol.branch {
  counter-reset: answer;
}

ol.branch > li {
  padding-left: 1.5rem;
  counter-increment: answer;
}

ol.branch > li::before {
  content: counter(answer, lower-alpha) ".";
  top: 0;
  width: auto;
  height: auto;
  background: none;
  color: var(--ink-soft);
  font-weight: 700;
}

/* Footer and small pages */

.colophon {
  margin-top: 5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.colophon a + a {
  margin-left: 1.25rem;
}

.page-error {
  padding-top: 18vh;
}

.page-error h1 {
  margin: 0;
  font-size: clamp(5rem, 22vw, 9rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.03em;
}

.page-error .error-reason {
  margin-top: 0.75rem;
  font-size: 1.5rem;
  font-weight: 700;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
