/* Hand-drawn map: torn paper, pencil, washi tape. */
:root {
  --paper: #fbf5e6;
  --paper-2: #f4ead5;
  --ink: #3b3328;
  --ink-soft: #6b5f4f;
  --pe: #d9663d;
  --public: #4f74b3;
  --chain: #8c96a3;
  --green: #5f8f55;
  --tape: rgba(236, 196, 92, 0.78);
  --shadow: rgba(70, 50, 25, 0.28);
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .27 0 0 0 0 .17 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  --hand: "Caveat", "Bradley Hand", "Segoe Print", cursive;
  --body: "Patrick Hand", "Chalkboard SE", "Comic Sans MS", system-ui, sans-serif;
}
body.night {
  --paper: #2d3561;
  --paper-2: #232a4d;
  --ink: #f1ead8;
  --ink-soft: #c3bfd9;
  --tape: rgba(255, 214, 107, 0.55);
  --shadow: rgba(5, 8, 25, 0.55);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--paper-2);
  color: var(--ink);
  font: 17px/1.35 var(--body);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 2px; }
button { font: inherit; color: inherit; cursor: pointer; }
#map { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; outline: none; }
#map.dragging { cursor: grabbing; }
#map.pointing { cursor: pointer; }
#map:focus-visible { box-shadow: inset 0 0 0 3px var(--pe); }

/* Paper sheets: the outer element carries the shadow, the inner one is clipped to a torn outline. */
.sheet { position: fixed; z-index: 2; filter: drop-shadow(1px 3px 3px var(--shadow)); }
.paper {
  position: relative;
  background: var(--grain), var(--paper);
  padding: 16px 20px;
}
.tape {
  position: absolute;
  top: 2px;
  left: 50%;
  width: 92px;
  height: 22px;
  margin-left: -46px;
  background: repeating-linear-gradient(90deg, transparent 0 7px, rgba(255, 255, 255, 0.25) 7px 9px), var(--tape);
  transform: rotate(-3deg);
  clip-path: polygon(0 8%, 6% 0, 12% 10%, 18% 0, 100% 0, 96% 14%, 100% 30%, 95% 52%, 100% 74%, 96% 100%, 0 100%, 4% 80%, 0 60%, 5% 40%);
}

.title { z-index: 3; top: 14px; left: 14px; width: min(360px, calc(100vw - 28px)); transform: rotate(-0.6deg); }
.title .paper { padding: 14px 20px 22px; }
.home { font: 700 20px var(--hand); color: var(--pe); text-decoration: none; }
.title h1 { font: 700 38px/1 var(--hand); margin: 2px 0 6px; }
.title p { margin: 0 0 12px; color: var(--ink-soft); font-size: 16px; }
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-bottom: 2px solid var(--ink);
  border-radius: 2px 20px 3px 12px / 12px 3px 16px 2px;
  background: repeating-linear-gradient(transparent 0 27px, rgba(79, 116, 179, 0.18) 27px 28px);
}
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  font: 22px var(--hand);
  color: var(--ink);
  outline: none;
}
.search input::placeholder { color: var(--ink-soft); opacity: 0.8; }
#results { margin-top: 8px; max-height: 40vh; overflow: auto; }
#results button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px dashed rgba(107, 95, 79, 0.4);
  background: none;
  padding: 6px 4px;
}
#results button:hover, #results button:focus-visible, #results button[aria-selected="true"] { background: rgba(236, 196, 92, 0.3); outline: none; }
#results small { display: block; color: var(--ink-soft); font-size: 14px; }
#results .none { padding: 6px 4px; color: var(--ink-soft); }

.legend { left: 14px; bottom: 34px; width: 300px; transform: rotate(0.8deg); }
.legend .paper { padding: 26px 18px 14px; }
.legend h2 { font: 700 24px var(--hand); margin: 0 0 6px; }
#legend button {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: none;
  padding: 3px 2px;
  text-align: left;
  border-radius: 6px;
}
#legend button:hover { background: rgba(236, 196, 92, 0.25); }
#legend button[aria-pressed="false"] { opacity: 0.38; }
#legend button[aria-pressed="false"] .label { text-decoration: line-through; text-decoration-thickness: 2px; }
#legend canvas { width: 40px; height: 34px; }
#legend .count { font: 700 20px var(--hand); color: var(--ink-soft); }
.fine { margin: 6px 0 0; font-size: 13.5px; color: var(--ink-soft); }

.controls { position: fixed; z-index: 2; right: 16px; bottom: 40px; display: grid; gap: 8px; }
.controls button {
  width: 46px;
  height: 46px;
  border: 2px solid var(--ink);
  background: var(--grain), var(--paper);
  font: 700 26px/1 var(--hand);
  border-radius: 48% 52% 45% 55% / 55% 45% 52% 48%;
  box-shadow: 1px 2px 0 var(--shadow);
  transition: transform 0.15s;
}
.controls button:hover { transform: rotate(-6deg) scale(1.06); }
.controls button:focus-visible { outline: 3px solid var(--pe); outline-offset: 2px; }

#tip {
  position: fixed;
  z-index: 3;
  pointer-events: none;
  max-width: 240px;
  padding: 3px 10px 4px;
  background: var(--grain), #fffbe8;
  color: #3b3328;
  font: 700 21px/1.1 var(--hand);
  box-shadow: 1px 2px 3px var(--shadow);
  transform: rotate(-2deg);
}
#tip small { display: block; font: 14px var(--body); color: #6b5f4f; }

#card { top: 14px; right: 14px; width: min(400px, calc(100vw - 28px)); max-height: calc(100vh - 28px); transform: rotate(0.5deg); }
#card .paper { max-height: calc(100vh - 28px); overflow: auto; padding: 30px 24px 26px; }
#card .close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: none;
  font: 700 32px/1 var(--hand);
}
#card .eyebrow { font: 700 18px var(--hand); color: var(--pe); }
#card h2 { font: 700 34px/1 var(--hand); margin: 2px 0 4px; padding-right: 24px; }
#card h3 { font: 700 24px var(--hand); margin: 16px 0 4px; }
#card p { margin: 4px 0; }
#card .addr { color: var(--ink-soft); margin-bottom: 10px; }
#card .badge {
  display: inline-block;
  padding: 2px 10px;
  border: 2px solid var(--ink);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  font-size: 15px;
  transform: rotate(-1deg);
}
#card .badge.pe { border-color: var(--pe); color: var(--pe); }
#card .callout, #card .claim, #card .estimate {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1.5px dashed rgba(107, 95, 79, 0.55);
  border-radius: 4px 14px 6px 12px;
}
#card .callout.pe { border-color: var(--pe); background: rgba(217, 102, 61, 0.08); }
#card .callout.public { border-color: var(--public); background: rgba(79, 116, 179, 0.08); }
#card .estimate { border-style: dotted; }
#card small, #card .note { display: block; margin-top: 6px; font-size: 13.5px; color: var(--ink-soft); }
#card .traits { display: grid; gap: 4px; }
#card .trait { display: grid; grid-template-columns: 118px 1fr; gap: 8px; font-size: 15px; }
#card .trait > span:first-child { font-weight: 700; }
#card .trait.unknown > span:last-child { color: var(--ink-soft); }
#card a { color: var(--public); }
body.night #card a { color: #a9c3f5; }

.credit {
  position: fixed;
  z-index: 1;
  right: 72px;
  bottom: 8px;
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
  text-align: right;
}
#status {
  position: fixed;
  z-index: 1;
  left: 50%;
  top: 50%;
  margin: 0;
  transform: translate(-50%, -50%) rotate(-2deg);
  font: 700 30px var(--hand);
}
#status:empty { display: none; }

@media (max-width: 720px) {
  .title { top: 8px; left: 8px; width: calc(100vw - 16px); }
  .title .paper { padding: 10px 14px 16px; }
  .title h1 { font-size: 30px; }
  .title p { display: none; }
  .legend { left: 8px; right: 8px; bottom: 22px; width: auto; transform: none; }
  .legend .paper { padding: 20px 12px 8px; }
  .legend h2, .legend .fine { display: none; }
  #legend { display: grid; grid-template-columns: 1fr 1fr; column-gap: 6px; }
  #legend button { grid-template-columns: 32px 1fr auto; font-size: 14px; }
  #legend canvas { width: 32px; height: 28px; }
  .controls { right: 10px; bottom: auto; top: 150px; }
  .controls button { width: 40px; height: 40px; font-size: 22px; }
  .credit { right: 8px; left: 8px; bottom: 4px; font-size: 10.5px; text-align: center; white-space: nowrap; overflow: hidden; }
  .credit .wide { display: none; }
  #card { top: auto; bottom: 0; right: 0; left: 0; width: auto; transform: none; max-height: 70vh; }
  #card .paper { max-height: 70vh; }
}
@media (prefers-reduced-motion: reduce) {
  .controls button { transition: none; }
}
