:root {
  --rail-paper: #f4ede2;
  --rail-paper-strong: #fbf7ef;
  --rail-panel: rgba(250, 245, 236, 0.92);
  --rail-panel-line: rgba(28, 38, 56, 0.12);
  --rail-ink: #182235;
  --rail-muted: #5f6879;
  --rail-navy: #121926;
  --rail-navy-soft: #1a2435;
  --rail-red: #9b4a39;
  --rail-red-soft: rgba(155, 74, 57, 0.14);
  --rail-teal: #4c8192;
  --rail-gold: #d5aa5a;
  --rail-cream: #efe2c7;
  --rail-shadow: 0 18px 34px rgba(24, 34, 53, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--rail-ink);
  font-family: "IBM Plex Mono", monospace;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0.4)),
    radial-gradient(circle at top left, rgba(76, 129, 146, 0.14), transparent 26%),
    radial-gradient(circle at top right, rgba(155, 74, 57, 0.14), transparent 30%),
    linear-gradient(140deg, #efe6d8 0%, #f6f0e7 40%, #e8dfd1 100%);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(24, 34, 53, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(24, 34, 53, 0.035) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.76), transparent 76%);
}

.rail-page {
  width: min(1520px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 34px;
  position: relative;
  z-index: 1;
}

.rail-topbar,
.route-hero,
.board-card {
  border: 1px solid var(--rail-panel-line);
  box-shadow: var(--rail-shadow);
}

.rail-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-radius: 28px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.04), transparent 42%),
    linear-gradient(135deg, #101723, #182236);
  position: sticky;
  top: 10px;
  z-index: 12;
}

.rail-home,
.rail-coffee,
.rail-account-menu summary,
.rail-account-panel a,
.rail-account-panel button,
#manualFireButton,
#practiceRouteButton,
#startRouteOverlayButton,
#practiceOverlayButton,
.mobile-fire {
  text-decoration: none;
  border: 1px solid transparent;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.rail-home {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: #f8f6f2;
  font-family: "Saira Condensed", sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.rail-home img {
  width: 42px;
  height: 42px;
  padding: 5px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
}

.rail-topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.rail-account-menu {
  position: relative;
}

.rail-account-menu summary,
.rail-coffee {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  font-family: "Saira Condensed", sans-serif;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  list-style: none;
}

.rail-account-menu summary::-webkit-details-marker {
  display: none;
}

.rail-account-menu summary {
  background: rgba(255, 255, 255, 0.06);
  color: #f8f6f2;
  border-color: rgba(255, 255, 255, 0.12);
}

.rail-coffee {
  background: linear-gradient(135deg, #a44939, #d17d4d);
  color: #fff5ef;
  border-color: rgba(155, 74, 57, 0.55);
}

.rail-home:hover,
.rail-account-menu[open] summary,
.rail-account-panel a:hover,
.rail-account-panel button:hover,
.rail-coffee:hover,
#manualFireButton:hover,
#practiceRouteButton:hover,
#startRouteOverlayButton:hover,
#practiceOverlayButton:hover,
.mobile-fire:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 24px rgba(24, 34, 53, 0.14);
}

.rail-account-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 248px;
  padding: 14px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(17, 25, 38, 0.98);
  box-shadow: 0 24px 34px rgba(0, 0, 0, 0.24);
}

.rail-account-panel p {
  margin: 0 0 12px;
  color: rgba(248, 246, 242, 0.76);
  line-height: 1.55;
}

.rail-account-panel a,
.rail-account-panel button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 42px;
  border-radius: 14px;
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
  color: #f8f6f2;
  font: inherit;
  cursor: pointer;
}

.rail-shell {
  padding-top: 18px;
}

.route-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 18px;
  padding: 22px;
  border-radius: 32px;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0.34)),
    radial-gradient(circle at 70% 0%, rgba(76, 129, 146, 0.16), transparent 24%),
    radial-gradient(circle at 20% 100%, rgba(155, 74, 57, 0.12), transparent 28%),
    var(--rail-panel);
}

.hero-copy h1,
.card-head h2,
.arena-head h2,
.overlay-card h3 {
  margin: 0;
  font-family: "Saira Condensed", sans-serif;
  letter-spacing: 0.02em;
}

.hero-copy h1 {
  font-size: clamp(3.4rem, 6vw, 6rem);
  line-height: 0.9;
}

.eyebrow,
.card-kicker,
.overlay-kicker {
  margin: 0 0 8px;
  color: var(--rail-red);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.hero-copy p:last-child {
  margin: 14px 0 0;
  max-width: 58ch;
  color: var(--rail-muted);
  line-height: 1.72;
}

.hero-rules {
  display: grid;
  gap: 12px;
}

.hero-rules article,
.stop-list article,
.event-item,
.bounty-card,
.archive-row {
  border: 1px solid var(--rail-panel-line);
  border-radius: 22px;
}

.hero-rules article {
  min-height: 118px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.36);
}

.hero-rules strong,
.event-item strong,
.stop-list strong,
.bounty-card strong,
.archive-row strong {
  display: block;
  font-family: "Saira Condensed", sans-serif;
  font-size: 1.3rem;
  letter-spacing: 0.02em;
}

.hero-rules span {
  display: block;
  margin-top: 8px;
  color: var(--rail-muted);
  line-height: 1.6;
}

.route-grid {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
}

.dispatch-column,
.main-column {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.board-card {
  padding: 18px;
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.34)),
    var(--rail-panel);
}

.arena-card {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02)),
    linear-gradient(180deg, var(--rail-navy) 0%, #151b26 100%);
  color: #f7f2eb;
}

.arena-card .card-kicker,
.arena-card h2,
.arena-card .arena-metrics {
  color: inherit;
}

.card-head,
.arena-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.card-head h2,
.arena-head h2 {
  font-size: 2rem;
}

.stop-brief,
.desk-note,
.archive-row p,
.bounty-card p,
.event-item span {
  color: var(--rail-muted);
  line-height: 1.6;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.metrics-grid article {
  padding: 14px;
  border-radius: 20px;
  border: 1px solid var(--rail-panel-line);
  background: rgba(255, 255, 255, 0.44);
}

.metrics-grid span,
.progress-label-row span,
.stop-list span,
.event-item span,
.archive-row span,
.bounty-progress-label {
  color: var(--rail-muted);
  font-size: 0.82rem;
}

.metrics-grid strong {
  display: block;
  margin-top: 10px;
  font-family: "Saira Condensed", sans-serif;
  font-size: 1.9rem;
  letter-spacing: 0.02em;
}

.route-progress-wrap {
  margin-top: 16px;
}

.progress-label-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.route-progress,
.bounty-progress {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(24, 34, 53, 0.1);
}

.route-progress span,
.bounty-progress span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
}

.route-progress span {
  background: linear-gradient(90deg, var(--rail-red), var(--rail-gold));
}

.stop-list,
.event-list,
.bounty-list,
.archive-list {
  display: grid;
  gap: 12px;
}

.stop-list article {
  padding: 14px;
  background: rgba(255, 255, 255, 0.42);
}

.stop-list article.is-active {
  border-color: rgba(155, 74, 57, 0.36);
  background: rgba(155, 74, 57, 0.08);
}

.stop-list article.is-cleared {
  border-color: rgba(76, 129, 146, 0.32);
  background: rgba(76, 129, 146, 0.08);
}

.stop-list p,
.event-item p,
.bounty-card p,
.archive-row p {
  margin: 6px 0 0;
}

.button-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

#manualFireButton,
#practiceRouteButton,
#startRouteOverlayButton,
#practiceOverlayButton,
.mobile-fire {
  min-height: 50px;
  padding: 0 18px;
  border-radius: 18px;
  font-family: "Saira Condensed", sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
}

#manualFireButton,
#startRouteOverlayButton,
.mobile-fire {
  background: linear-gradient(135deg, var(--rail-red), #d17d4d);
  color: #fff7ef;
  border-color: rgba(155, 74, 57, 0.38);
}

#practiceRouteButton,
#practiceOverlayButton {
  background: linear-gradient(135deg, rgba(76, 129, 146, 0.18), rgba(24, 34, 53, 0.06));
  color: var(--rail-ink);
  border-color: rgba(76, 129, 146, 0.24);
}

#practiceOverlayButton {
  background: linear-gradient(135deg, rgba(76, 129, 146, 0.28), rgba(255, 255, 255, 0.06));
  color: #f7f2eb;
  border-color: rgba(255, 255, 255, 0.16);
}

.event-item,
.bounty-card,
.archive-row {
  padding: 14px;
  background: rgba(255, 255, 255, 0.4);
}

.event-item--hot {
  border-left: 4px solid var(--rail-red);
}

.event-item--cool {
  border-left: 4px solid var(--rail-teal);
}

.event-item--warn {
  border-left: 4px solid var(--rail-gold);
}

.arena-head {
  margin-bottom: 14px;
}

.arena-metrics {
  display: grid;
  gap: 4px;
  justify-items: end;
  color: rgba(247, 242, 235, 0.76);
  font-family: "Saira Condensed", sans-serif;
  font-size: 1.2rem;
}

.arena-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background:
    radial-gradient(circle at center, rgba(255, 255, 255, 0.03), transparent 42%),
    linear-gradient(180deg, #161d29, #0f151f);
}

.arena-wrap::before,
.arena-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.arena-wrap::before {
  background:
    linear-gradient(90deg, rgba(155, 74, 57, 0.2), transparent 18%, transparent 82%, rgba(76, 129, 146, 0.18)),
    radial-gradient(circle at center, transparent 42%, rgba(0, 0, 0, 0.16) 100%);
}

.arena-wrap::after {
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 32px 32px;
  opacity: 0.16;
}

#railCanvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  touch-action: none;
}

.arena-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(10, 14, 20, 0.18);
  transition: opacity 0.18s ease, visibility 0.18s ease;
}

.arena-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-card {
  width: min(440px, 100%);
  padding: 22px;
  border-radius: 26px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background:
    linear-gradient(135deg, rgba(17, 25, 38, 0.96), rgba(25, 39, 60, 0.94)),
    rgba(17, 25, 38, 0.96);
  box-shadow: 0 28px 44px rgba(0, 0, 0, 0.28);
}

.overlay-card h3 {
  font-size: clamp(2.3rem, 5vw, 3.1rem);
  color: #f7f2eb;
}

.overlay-card p:last-of-type {
  margin: 12px 0 0;
  color: rgba(247, 242, 235, 0.78);
  line-height: 1.62;
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.mobile-fire {
  position: absolute;
  right: 14px;
  bottom: 14px;
  min-width: 80px;
  display: none;
}

.arena-overlay:not(.is-hidden) + .mobile-fire {
  opacity: 0;
  pointer-events: none;
}

.lower-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.bounty-card.is-complete {
  border-color: rgba(76, 129, 146, 0.32);
  background: rgba(76, 129, 146, 0.08);
}

.bounty-card strong {
  font-size: 1.25rem;
}

.bounty-progress {
  margin-top: 10px;
}

.bounty-progress span {
  background: linear-gradient(90deg, var(--rail-teal), var(--rail-gold));
}

.archive-row.is-best {
  border-color: rgba(155, 74, 57, 0.36);
  background: rgba(155, 74, 57, 0.08);
}

@media (max-width: 1180px) {
  .route-grid {
    grid-template-columns: 1fr;
  }

  .dispatch-column {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .rail-page {
    width: min(100%, calc(100% - 16px));
    padding-top: 12px;
  }

  .rail-topbar {
    position: static;
    flex-direction: column;
    align-items: stretch;
    border-radius: 24px;
  }

  .rail-topbar-actions {
    justify-content: space-between;
  }

  .route-hero,
  .dispatch-column,
  .lower-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .rail-page {
    width: min(100%, calc(100% - 10px));
  }

  .route-hero,
  .board-card,
  .rail-topbar {
    border-radius: 24px;
  }

  .hero-copy h1 {
    font-size: 4rem;
  }

  .card-head h2,
  .arena-head h2 {
    font-size: 1.55rem;
  }

  .arena-head {
    align-items: start;
  }

  .arena-metrics {
    justify-items: start;
  }

  .metrics-grid {
    grid-template-columns: 1fr 1fr;
  }

  .overlay-card {
    width: min(304px, calc(100% - 20px));
    padding: 14px;
  }

  .overlay-card h3 {
    font-size: 1.9rem;
  }

  .overlay-card p:last-of-type {
    font-size: 0.91rem;
    line-height: 1.52;
  }

  .overlay-actions {
    margin-top: 14px;
  }

  #startRouteOverlayButton,
  #practiceOverlayButton {
    min-height: 44px;
    padding: 0 12px;
    font-size: 0.94rem;
  }

  .arena-wrap {
    min-height: 360px;
  }

  #railCanvas {
    aspect-ratio: 1 / 1;
    min-height: 360px;
  }
}

@media (hover: none) and (pointer: coarse) and (max-width: 980px) {
  .mobile-fire {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}
