:root {
  --paper: #f6f0e4;
  --ink: #2b2620;
  --faded: #8a7f6d;
  --line: #d8cfbc;
  --a: #c8502e; /* Strasbourg runner */
  --b: #2e5fc8; /* Vienna runner */
  --serif: "Iowan Old Style", "Palatino", "Georgia", serif;
  --sans: -apple-system, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; margin: 0; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  display: flex;
  flex-direction: column;
}

#topbar {
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  gap: 12px;
}

#topbar h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: 0.02em;
}

#tagline { color: var(--faded); font-size: 13px; }

#scoreboard {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 8px;
}

.score { display: flex; flex-direction: column; }
.score-b { text-align: right; }
.score .who { font-size: 12px; color: var(--faded); }
.score .km { font-family: var(--serif); font-size: 20px; font-weight: 600; }
.score-a .km { color: var(--a); }
.score-b .km { color: var(--b); }

.gap { text-align: center; }
.gap #gap-km { font-family: var(--serif); font-size: 16px; }
.gap-label { display: block; font-size: 11px; color: var(--faded); }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }

#map { flex: 1; min-height: 45vh; background: #e9e2d2; position: relative; }

#orient {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 10;
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fffdf7;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
#orient button {
  border: none;
  background: transparent;
  font: 12px var(--sans);
  color: var(--faded);
  padding: 6px 10px;
  cursor: pointer;
}
#orient button + button { border-left: 1px solid var(--line); }
#orient button.active { background: var(--ink); color: var(--paper); }

.maplibregl-popup-content {
  font: 12px var(--sans);
  color: var(--ink);
  background: #fffdf7;
  padding: 6px 9px;
  border-radius: 6px;
}

#panel {
  padding: 14px 16px calc(env(safe-area-inset-bottom, 0px) + 14px);
  overflow-y: auto;
  max-height: 45vh;
}

#panel h2 { font-family: var(--serif); font-size: 18px; margin-bottom: 6px; }
.explain, #panel p { font-size: 14px; line-height: 1.45; }
.explain { color: var(--faded); margin-bottom: 10px; }

.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  background: #fffdf7;
  margin-bottom: 10px;
}

.slot-buttons { display: flex; gap: 10px; margin: 12px 0 8px; flex-wrap: wrap; }

.btn {
  display: inline-block;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  color: #fff;
  cursor: pointer;
  font-family: var(--sans);
}
.btn-a { background: var(--a); }
.btn-b { background: var(--b); }
.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 500;
}
.btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }

.fineprint { font-size: 12px; color: var(--faded); margin-top: 6px; }

#candidates { display: grid; gap: 10px; }

.candidate {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fffdf7;
  cursor: pointer;
  transition: border-color 0.15s;
}
.candidate.selected { border-color: var(--ink); }
.candidate h3 { font-family: var(--serif); font-size: 16px; }
.candidate .meta { font-size: 12px; color: var(--faded); margin: 2px 0 6px; }
.candidate p { font-size: 13px; line-height: 1.4; }
.candidate .propose-row { margin-top: 8px; }

#proposal-banner { border-color: var(--ink); }
#proposal-banner .actions, #game .actions, #global-actions { display: flex; gap: 8px; margin-top: 10px; }

#story { font-size: 14px; line-height: 1.5; }
#story strong.a { color: var(--a); }
#story strong.b { color: var(--b); }

#notice {
  border: 1px dashed var(--faded);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13px;
  margin-bottom: 10px;
  background: #fffdf7;
}

#tagline { display: flex; align-items: center; gap: 6px; }
#info-btn {
  border: 1px solid var(--line);
  background: #fffdf7;
  color: var(--faded);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

#quip { font-style: italic; color: var(--faded); font-size: 13px; margin-top: 4px; }

#sync-error { color: var(--a); }

#celebration, #info {
  position: fixed;
  inset: 0;
  background: rgba(43, 38, 32, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.info-inner {
  background: var(--paper);
  border-radius: 14px;
  padding: 24px 22px;
  max-width: 360px;
  margin: 16px;
  max-height: 85vh;
  overflow-y: auto;
}
.info-inner h2 { font-family: var(--serif); font-size: 24px; margin-bottom: 10px; }
.info-inner p { font-size: 14px; line-height: 1.5; margin-bottom: 10px; }
.info-inner .pact {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffdf7;
  padding: 12px;
}
.info-inner .btn { margin-top: 4px; }
.celebration-inner {
  background: var(--paper);
  border-radius: 14px;
  padding: 28px 24px;
  text-align: center;
  max-width: 320px;
  margin: 16px;
}
.celebration-inner h2 { font-family: var(--serif); font-size: 26px; margin-bottom: 8px; }

.runner-marker {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 3px solid #fffdf7;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.runner-marker.a { background: var(--a); }
.runner-marker.b { background: var(--b); }
.meet-marker {
  font-size: 18px;
  line-height: 18px;
  text-align: center;
  filter: grayscale(0.2);
}

.confetti {
  position: fixed;
  top: -12px;
  width: 8px;
  height: 14px;
  z-index: 2001;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(720deg); }
}

@media (min-width: 900px) {
  main { flex-direction: row; }
  #map { min-height: 0; }
  #panel { width: 360px; max-height: none; border-left: 1px solid var(--line); }
}
