:root {
  --paper: #efe1c3;
  --paper-deep: #dcc49a;
  --ink: #24190f;
  --muted: #7a6048;
  --line: rgba(80, 55, 34, .24);
  --brown: #4a2f1e;
  --red: #a74432;
  --gold: #b38a3f;
  --panel: rgba(255, 248, 230, .78);
  --shadow: 0 20px 54px rgba(45, 30, 16, .16);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    linear-gradient(rgba(74, 45, 24, .05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(74, 45, 24, .05) 1px, transparent 1px),
    radial-gradient(circle at 15% 8%, rgba(255, 255, 255, .32), transparent 28%),
    var(--paper);
  background-size: 44px 44px, 44px 44px, auto, auto;
  font-family: "Noto Serif SC", "Songti SC", SimSun, serif;
}

a {
  color: var(--brown);
  text-decoration-color: rgba(167, 68, 50, .45);
  text-underline-offset: 4px;
}

.title-link {
  color: inherit;
  text-decoration: none;
}

.title-link:hover {
  color: var(--red);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  padding: 16px 22px 18px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 28px;
  min-height: 48px;
  margin-bottom: 8px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--red);
  font-size: 12px;
  font-style: italic;
  letter-spacing: 3px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 34px;
  line-height: 1.15;
  font-weight: 800;
}

h2 {
  margin-bottom: 0;
  font-size: 21px;
  line-height: 1.2;
}

h3 {
  margin-bottom: 0;
  font-size: 16px;
}

.topbar__stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(86px, auto));
  gap: 20px;
  align-items: end;
  max-width: 650px;
}

.topbar__stats span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.topbar__stats strong {
  display: block;
  overflow: hidden;
  max-width: 140px;
  font-size: 20px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: 315px minmax(390px, 1fr) 380px;
  gap: 14px;
  height: calc(100vh - 72px);
  min-height: 0;
  align-items: center;
  overflow-x: hidden;
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(5px);
}

.panel {
  height: calc(100% - 70px);
  min-height: 0;
  padding: 14px;
}

.index-panel,
.detail-panel {
  display: flex;
  flex-direction: column;
}

.panel-title,
.map-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(74, 47, 30, .34);
  color: var(--brown);
  background: rgba(255, 248, 230, .55);
  cursor: pointer;
  font-size: 21px;
  line-height: 1;
}

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

.field {
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.field span,
.check-row {
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  height: 32px;
  border: 1px solid rgba(74, 47, 30, .28);
  border-radius: 0;
  color: var(--ink);
  background: rgba(255, 253, 243, .72);
  padding: 0 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(167, 68, 50, .12);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 8px 0 6px;
}

.check-row input {
  width: 16px;
  height: 16px;
}

.list-count {
  color: var(--muted);
  font-size: 13px;
}

.letter-list {
  display: grid;
  gap: 7px;
  min-height: 0;
  margin: 8px -6px 0 0;
  padding-right: 6px;
  overflow: auto;
  overflow-x: hidden;
  max-height: calc(100% - 132px);
}

.letter-card {
  position: relative;
  width: 100%;
  border: 1px solid rgba(74, 47, 30, .18);
  background: rgba(252, 240, 208, .62);
  color: var(--ink);
  cursor: pointer;
  padding: 9px 12px;
  text-align: left;
}

.letter-card:hover,
.letter-card.is-active {
  border-color: rgba(74, 47, 30, .34);
  background: #d9c18f;
}

.letter-card__top,
.letter-card__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.letter-card__pages {
  display: none;
  color: var(--muted);
  font-size: 12px;
}

.letter-card strong {
  display: block;
  margin: 0 0 5px;
  overflow: visible;
  font-size: 16px;
  line-height: 1.35;
  white-space: normal;
}

.letter-card p {
  margin: 0;
  overflow: visible;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  padding-right: 54px;
  white-space: normal;
}

.letter-card__meta {
  position: absolute;
  right: 12px;
  bottom: 13px;
  margin-top: 0;
  color: var(--muted);
  font-size: 12px;
  justify-content: flex-end;
}

.badge {
  color: var(--red);
  padding: 0;
}

.map-panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
  padding: 10px 8px 8px;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.map-heading {
  flex: 0 0 auto;
  margin-bottom: 12px;
}

.map-heading h2 span {
  color: var(--red);
  font-size: .86em;
}

.map-wrap {
  position: relative;
  min-height: 0;
  flex: 1;
  border: 0;
  background: none;
  overflow: hidden;
}

#routeMap {
  display: block;
  width: 100%;
  height: 100%;
}

.route {
  fill: none;
  stroke: rgba(85, 48, 30, .42);
  stroke-dasharray: 5 7;
  stroke-linecap: round;
  cursor: pointer;
}

.route:hover,
.route.is-active {
  stroke: var(--red);
  filter: url(#routeGlow);
}

.route.is-muted {
  opacity: .18;
}

.place-dot {
  fill: var(--brown);
  stroke: rgba(255, 248, 230, .9);
  stroke-width: 2;
}

.place-dot.destination {
  fill: var(--red);
}

.place-label {
  fill: var(--muted);
  font-size: 13px;
  pointer-events: none;
}

.map-caption {
  display: none;
}

.timeline {
  flex: 0 0 auto;
  margin-top: 8px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.timeline__note {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 8px;
}

.timeline__note strong {
  font-size: 15px;
}

.timeline__note span {
  color: var(--muted);
  font-size: 12px;
}

.timeline__track {
  position: relative;
  height: 30px;
  border-top: 2px solid rgba(74, 47, 30, .36);
}

.timeline__track::before,
.timeline__track::after {
  position: absolute;
  top: -8px;
  bottom: 8px;
  content: "";
  border-left: 1px solid rgba(167, 68, 50, .45);
}

.timeline__track::before {
  left: 36%;
}

.timeline__track::after {
  left: 64%;
}

.timeline__track span {
  position: absolute;
  top: 8px;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.timeline__track span:first-child {
  transform: none;
}

.timeline__track span:last-child {
  transform: translateX(-100%);
}

.detail-panel {
  position: relative;
  overflow: hidden;
}

.detail-heading {
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.letter-sheet {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
  margin-bottom: 8px;
  border: 1px solid rgba(74, 47, 30, .24);
  background:
    linear-gradient(135deg, rgba(90, 63, 38, .12) 0 1px, transparent 1px 28px),
    #d9c18f;
  padding: 18px;
}

.letter-sheet::before,
.letter-sheet::after {
  position: absolute;
  content: "";
  border: 1px solid rgba(167, 68, 50, .18);
  pointer-events: none;
}

.letter-sheet::before {
  inset: 8px;
}

.letter-sheet::after {
  right: 20px;
  bottom: 18px;
  width: 64px;
  height: 40px;
  border-radius: 50%;
  transform: rotate(-14deg);
}

.letter-sheet div {
  position: relative;
  z-index: 1;
  min-height: 58px;
  border-bottom: 1px solid rgba(74, 47, 30, .2);
  padding-bottom: 10px;
}

.letter-sheet div:nth-child(4) {
  grid-column: auto;
}

.letter-sheet__label {
  margin: 0 0 5px;
  color: var(--red);
  font-size: 11px;
  font-style: italic;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.letter-sheet strong,
.letter-sheet span,
.letter-sheet a {
  display: block;
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.45;
}

.letter-sheet a {
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
}

.letter-sheet span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.scan-preview-trigger {
  cursor: zoom-in;
}

.scan-popover {
  position: absolute;
  right: 24px;
  top: 118px;
  z-index: 8;
  width: 250px;
  border: 1px solid rgba(179, 138, 63, .5);
  background: rgba(35, 24, 16, .95);
  box-shadow: 0 18px 42px rgba(35, 24, 16, .38);
  opacity: 0;
  padding: 9px;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .16s ease, transform .16s ease;
}

.scan-popover.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.scan-popover img {
  display: block;
  width: 100%;
  max-height: 300px;
  object-fit: contain;
}

.scan-popover p {
  margin: 7px 0 0;
  color: var(--gold);
  font-size: 12px;
  text-align: center;
}

.body-block {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  margin-top: 8px;
}

.body-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.body-subtitle {
  display: none;
}

.body-title span {
  color: var(--muted);
  font-size: 12px;
}

pre {
  flex: 1;
  max-height: 260px;
  min-height: 96px;
  margin: 0;
  border: 1px solid rgba(74, 47, 30, .18);
  background: rgba(255, 253, 243, .58);
  color: var(--ink);
  font-family: "Noto Serif SC", "Songti SC", SimSun, serif;
  font-size: 14px;
  line-height: 1.75;
  overflow: auto;
  padding: 11px;
  white-space: pre-wrap;
}

@media (max-width: 1220px) {
  body {
    min-width: 0;
  }

  .workspace {
    grid-template-columns: 315px 1fr;
    height: auto;
  }

  .detail-panel {
    grid-column: 1 / -1;
    min-height: 620px;
  }
}

.home-page {
  overflow-x: hidden;
}

.home-shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px;
}

.home-hero {
  min-height: 640px;
  border-bottom: 1px solid var(--line);
  padding: 24px 0 28px;
}

.text-link {
  color: var(--brown);
  text-decoration-color: rgba(167, 68, 50, .5);
  text-underline-offset: 5px;
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) 360px;
  gap: 64px;
  align-items: start;
}

.hero-copy h1 {
  max-width: 780px;
  margin: 0 0 24px;
  font-size: clamp(56px, 8vw, 112px);
  letter-spacing: 0;
  line-height: .98;
}

.movie-intro {
  max-width: 720px;
  margin: 0 0 20px;
  border-left: 3px solid rgba(167, 68, 50, .55);
  padding-left: 16px;
}

.movie-intro__label {
  margin: 0 0 6px;
  color: var(--red);
  font-size: 12px;
  font-style: italic;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.movie-intro p:last-child {
  margin-bottom: 0;
  color: #5d4834;
  font-size: 17px;
  line-height: 1.8;
}

.hero-lede {
  max-width: 700px;
  color: var(--muted);
  font-size: 22px;
  line-height: 1.75;
}

.hero-actions {
  display: flex;
  align-items: center;
  gap: 22px;
  margin-top: 34px;
}

.primary-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid rgba(74, 47, 30, .38);
  background: var(--brown);
  color: #f8edd2;
  padding: 0 20px;
  text-decoration: none;
}

.primary-link:hover {
  background: #2d1d12;
}

.hero-letter,
.story-side section {
  position: relative;
  border: 1px solid rgba(74, 47, 30, .24);
  background:
    linear-gradient(135deg, rgba(90, 63, 38, .10) 0 1px, transparent 1px 30px),
    rgba(255, 248, 230, .74);
  box-shadow: var(--shadow);
}

.hero-letter {
  align-self: start;
  margin-top: 8px;
  overflow: hidden;
  padding: 0;
}

.letter-fold {
  height: 56px;
  background: #e6d0a2;
  border-bottom: 1px solid rgba(90, 63, 38, .18);
}

.letter-body {
  position: relative;
  z-index: 1;
  padding: 24px 28px 28px;
}

.hero-letter::before,
.hero-letter::after {
  position: absolute;
  content: "";
  pointer-events: none;
}

.hero-letter::before {
  inset: 10px;
  border: 1px solid rgba(90, 63, 38, .16);
}

.hero-letter::after {
  right: 24px;
  bottom: 24px;
  width: 76px;
  height: 46px;
  border: 1px solid rgba(167, 68, 50, .26);
  border-radius: 50%;
  transform: rotate(-12deg);
}

.letter-mark {
  margin: 0 0 12px;
  color: var(--red);
  font-size: 12px;
  font-style: italic;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.hero-letter .letter-body > p:not(.letter-mark) {
  color: var(--ink);
  font-size: 18px;
  line-height: 1.7;
}

.hero-letter dl {
  display: grid;
  gap: 12px;
  margin: 22px 0 0;
}

.hero-letter dl div {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.hero-letter dt {
  color: var(--red);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.hero-letter dd {
  margin: 5px 0 0;
  color: var(--muted);
}

.home-routes {
  margin: 32px 0;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

.home-routes h2,
.story-main h2 {
  font-size: 32px;
}

.home-routes svg {
  display: block;
  width: 100%;
  height: 260px;
  margin-top: 10px;
}

.home-route-lines path {
  fill: none;
  stroke: rgba(105, 63, 43, .42);
  stroke-width: 2.5;
  stroke-dasharray: 5 8;
}

.home-route-points circle {
  fill: var(--brown);
  stroke: rgba(255, 248, 230, .92);
  stroke-width: 2;
}

.home-route-points .destination {
  fill: var(--red);
}

.home-route-points text {
  fill: var(--muted);
  font-size: 15px;
}

.story-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 56px;
  align-items: start;
}

.story-main {
  max-width: 820px;
}

.story-main h2 {
  margin: 44px 0 14px;
}

.story-main p {
  color: #4e3a2a;
  font-size: 18px;
  line-height: 2;
}

.story-main blockquote {
  margin: 36px 0;
  border-left: 4px solid var(--red);
  color: var(--ink);
  font-size: 30px;
  line-height: 1.55;
  padding-left: 22px;
}

.story-side {
  display: grid;
  gap: 18px;
  position: sticky;
  top: 18px;
}

.story-side section {
  padding: 22px;
}

.story-side h3 {
  margin-bottom: 12px;
  font-size: 22px;
}

.story-side ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.9;
}

.poem-card {
  background: #d9c18f !important;
}

.poem-card p:not(.eyebrow) {
  margin-bottom: 12px;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.9;
}

.poem-card span {
  color: var(--muted);
  font-size: 13px;
}

.block-link {
  width: 100%;
  margin-top: 10px;
}

.site-footer {
  margin-top: 54px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  padding: 22px 0 6px;
  text-align: center;
}

@media (max-width: 900px) {
  .home-shell {
    padding: 18px;
  }

  .hero-grid,
  .story-layout {
    grid-template-columns: 1fr;
  }

  .home-hero {
    min-height: auto;
  }

  .topbar__stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .story-side {
    position: static;
  }
}
