:root {
  --ink: #1c1612;
  --ink-soft: #3c2f25;
  --forest: #14261e;
  --moss: #3e5c49;
  --leather: #6a4128;
  --brass: #b6893e;
  --gold: #e6c36a;
  --parchment: #f4e4c4;
  --parchment-deep: #e7d3a8;
  --muted: #8d7760;
  --line: rgba(90, 58, 32, 0.35);
  --shadow: 0 18px 50px rgba(12, 10, 8, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--forest);
  color: var(--ink);
  font-family: "Source Serif 4", Palatino, "Palatino Linotype", Georgia, serif;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
  isolation: isolate;
  background: #1a2a22;
}

.leaflet-tile-pane {
  filter: sepia(0.42) saturate(0.62) contrast(1.05) brightness(0.9);
}

.leaflet-control-attribution {
  background: rgba(244, 228, 196, 0.88) !important;
  color: var(--ink-soft) !important;
  font-family: "Source Serif 4", Georgia, serif !important;
}

.leaflet-bar a {
  background: var(--parchment) !important;
  color: var(--leather) !important;
  border-bottom-color: var(--line) !important;
}

#embers {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.wall {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

.wall * { pointer-events: none; }

.tag {
  --age: 1;
  position: absolute;
  max-width: 15rem;
  font-family: "Permanent Marker", "Marker Felt", "Comic Sans MS", cursive;
  font-size: calc(var(--size, 1) * 1.3rem);
  line-height: 1.12;
  color: var(--spray);
  opacity: var(--age);
  transform: rotate(var(--tilt, 0deg));
  transition: opacity 600ms ease;
  overflow-wrap: anywhere;
}

.tag.is-gone { opacity: 0; }

.tag-msg {
  position: relative;
  display: block;
  text-shadow:
    0 0 1px rgba(10, 8, 6, 0.95),
    1px 2px 0 rgba(10, 8, 6, 0.6),
    0 0 14px color-mix(in srgb, var(--spray) 55%, transparent),
    0 0 3px color-mix(in srgb, var(--spray) 80%, transparent);
}

.tag-name {
  display: block;
  margin-top: 0.15rem;
  text-align: right;
  font-size: 0.56em;
  letter-spacing: 0.04em;
  color: #fbf6ea;
  text-shadow: 0 0 2px rgba(10, 8, 6, 0.95), 1px 1px 0 rgba(10, 8, 6, 0.7);
}

.tag-name::before { content: "— "; }

.drip {
  position: absolute;
  top: 82%;
  width: 3px;
  height: var(--len, 10px);
  border-radius: 0 0 3px 3px;
  background: linear-gradient(var(--spray), color-mix(in srgb, var(--spray) 70%, transparent));
  box-shadow: 0 0 4px color-mix(in srgb, var(--spray) 50%, transparent);
  transform-origin: top;
  z-index: -1;
}

.drip::after {
  content: "";
  position: absolute;
  left: -1px;
  bottom: -2px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: inherit;
}

.tag.is-fresh .tag-msg { animation: spray-in 850ms cubic-bezier(0.3, 0.7, 0.3, 1) both; }
.tag.is-fresh .tag-name { animation: tag-name-in 500ms ease 650ms both; }
.tag.is-fresh .drip { animation: drip-down 1400ms ease-in both; }

@keyframes spray-in {
  0% { clip-path: inset(0 100% 0 0); filter: blur(5px); opacity: 0.4; }
  70% { filter: blur(0.8px); opacity: 1; }
  100% { clip-path: inset(0 0 0 0); filter: none; }
}

@keyframes tag-name-in {
  from { opacity: 0; transform: translateY(-3px); }
  to { opacity: 1; transform: none; }
}

@keyframes drip-down {
  from { transform: scaleY(0); }
  to { transform: scaleY(1); }
}

.chrome {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.chrome > * {
  pointer-events: auto;
}

.banner {
  position: absolute;
  top: 1.1rem;
  left: 1.1rem;
  max-width: min(28rem, calc(100vw - 2.2rem));
  padding: 1rem 1.25rem 1.05rem;
  background: var(--parchment);
  border: 1px solid #a67c2d;
  box-shadow: var(--shadow);
}

.kicker {
  margin: 0;
  font-family: Cinzel, Palatino, serif;
  font-size: 0.68rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--leather);
}

h1, h2 {
  font-family: Cinzel, Palatino, serif;
  font-weight: 700;
  letter-spacing: 0.04em;
}

h1 {
  margin: 0.2rem 0 0.35rem;
  font-size: clamp(1.8rem, 3vw, 2.5rem);
  line-height: 1.05;
  color: var(--forest);
}

h2 {
  margin: 0 0 0.7rem;
  font-size: 1.05rem;
  color: var(--forest);
}

.status {
  margin: 0;
  color: var(--ink-soft);
  font-style: italic;
}

.ledger {
  position: absolute;
  top: 10.2rem;
  left: 1.1rem;
  width: min(22rem, calc(100vw - 2.2rem));
  max-height: calc(100vh - 10rem);
  overflow: auto;
  padding: 1rem 1.1rem 0.85rem;
  background: var(--parchment-deep);
  border: 1px solid #6a4128;
  box-shadow: var(--shadow);
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
  margin: 0 0 0.9rem;
}

.metrics div { min-width: 0; }

dt {
  font-family: Cinzel, Palatino, serif;
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--leather);
}

dd {
  margin: 0.15rem 0 0;
  font-size: 1.15rem;
  color: var(--ink);
}

.course-panel {
  margin: 0 0 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.course-panel h2 { margin-bottom: 0.3rem; }

.course-progress {
  margin: 0 0 0.6rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.splits {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.splits th {
  font-family: Cinzel, Palatino, serif;
  font-size: 0.58rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--leather);
  text-align: left;
  padding: 0 0.3rem 0.3rem 0;
}

.splits td {
  padding: 0.28rem 0.3rem 0.28rem 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.splits td:first-child {
  max-width: 7rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.splits tr.reached td { color: var(--ink); }

.cheers {
  margin: 0 0 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
  color: var(--leather);
  font-family: Cinzel, Palatino, serif;
  letter-spacing: 0.03em;
}

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

.history li + li { margin-top: 0.4rem; }

.history button {
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.65rem;
  border: 1px solid transparent;
  background: rgba(255, 248, 230, 0.35);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.history button strong {
  display: block;
  font-family: Cinzel, Palatino, serif;
  font-size: 0.92rem;
  font-weight: 500;
}

.history button span {
  color: var(--muted);
  font-size: 0.92rem;
}

.history button:hover,
.history button[aria-current="true"] {
  border-color: var(--brass);
  background: rgba(230, 195, 106, 0.28);
}

.footnote {
  margin: 0.9rem 0 0.2rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
}

.slip {
  position: absolute;
  right: 1.1rem;
  top: 1.1rem;
  width: min(20rem, calc(100vw - 2.2rem));
  max-height: calc(100vh - 2.2rem);
  overflow: auto;
  padding: 1rem 1.1rem 1.1rem;
  background: linear-gradient(180deg, #f7e7c8, #ead6ad);
  border: 1px solid rgba(166, 124, 45, 0.8);
  box-shadow: var(--shadow);
}

.slip h2 { margin-top: 0.25rem; }

.cheer-slip {
  top: auto;
  bottom: 5.6rem;
}

.watch-form button[type="submit"]:disabled { opacity: 0.6; cursor: wait; }

.slip p { margin: 0 0 0.8rem; color: var(--ink-soft); }

.slip-close {
  float: right;
  border: 0;
  background: transparent;
  color: var(--leather);
  font-family: Cinzel, Palatino, serif;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.horn {
  position: absolute;
  right: 1.2rem;
  bottom: 1.4rem;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.75rem 1rem 0.75rem 0.8rem;
  border: 1px solid #8a6428;
  border-radius: 999px;
  background:
    radial-gradient(circle at 30% 30%, #f0d48a, #b07d32 55%, #6d4a1c);
  color: #2a1c10;
  font-family: Cinzel, Palatino, serif;
  letter-spacing: 0.06em;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 236, 190, 0.7);
  cursor: pointer;
}

.horn svg { width: 2rem; height: 2rem; }

.horn:hover { filter: brightness(1.06); }

.horn:disabled {
  cursor: not-allowed;
  filter: grayscale(0.45) brightness(0.85);
}

.horn.struck { transform: translateY(1px) scale(0.98); }

.watch {
  display: inline-block;
  margin-top: 0.75rem;
  padding: 0.45rem 0.8rem;
  border: 1px solid #8a6428;
  background: var(--forest);
  color: var(--gold);
  font-family: Cinzel, Palatino, serif;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
  cursor: pointer;
}

.watch.is-on {
  background: var(--gold);
  color: #1c1612;
}

.watch-form label {
  display: block;
  margin: 0 0 0.8rem;
  font-family: Cinzel, Palatino, serif;
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--leather);
}

.watch-form input {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.5rem 0.55rem;
  border: 1px solid var(--line);
  background: #fff8e6;
  color: var(--ink);
  font-family: "Source Serif 4", Palatino, Georgia, serif;
  font-size: 1rem;
  letter-spacing: 0;
  text-transform: none;
}

.watch-form button[type="submit"] {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid #8a6428;
  background: var(--forest);
  color: var(--gold);
  font-family: Cinzel, Palatino, serif;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 1.4rem;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.7rem 1rem;
  background: rgba(20, 38, 30, 0.92);
  color: var(--parchment);
  border: 1px solid rgba(230, 195, 106, 0.45);
  font-family: Cinzel, Palatino, serif;
  letter-spacing: 0.04em;
}

.beacon-wrap { background: transparent; border: 0; }

.beacon {
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 6px rgba(230, 195, 106, 0.28);
}

body[data-status="on_the_trail"] .beacon {
  animation: pulse 2.4s ease-out infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(230, 195, 106, 0.55); }
  100% { box-shadow: 0 0 0 16px rgba(230, 195, 106, 0); }
}

.leaflet-bottom.leaflet-left { margin-bottom: 0.4rem; }

@media (max-width: 800px) {
  .banner {
    right: 0.8rem;
    max-width: none;
    padding-right: 4.75rem;
  }

  .ledger {
    top: auto;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 38vh;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
  }

  .horn {
    top: 1.15rem;
    right: 1.15rem;
    bottom: auto;
    padding: 0.55rem;
  }

  .horn span { display: none; }

  .leaflet-bottom.leaflet-left {
    top: auto;
    right: auto;
    bottom: 0;
    left: 0;
    margin-bottom: 40vh;
  }

  .slip {
    top: auto;
    left: auto;
    right: 0.6rem;
    bottom: calc(38vh + 3.4rem);
    width: min(16rem, calc(100vw - 5rem));
    max-height: 32vh;
  }
  .cheer-slip {
    top: 4.9rem;
    bottom: auto;
    left: 0.6rem;
    right: 0.6rem;
    width: auto;
    max-height: calc(62vh - 5.5rem);
  }
  .toast { bottom: calc(38vh + 0.6rem); left: 0.8rem; right: 5.5rem; transform: none; }
  .tag { max-width: 8.5rem; font-size: calc(var(--size, 1) * 0.98rem); }
}

@media (prefers-reduced-motion: reduce) {
  .beacon { animation: none; }
  #embers { display: none; }
  .tag, .tag * { animation: none !important; transition: none !important; }
}
