:root {
  --ash: #e9e3d8;
  --board: #f6f2ea;
  --plank: #d9ccb6;
  --line: #ddd2bf;
  --ink: #2e2822;
  --muted: #75695b;
  --oak: #9a6a3a;
  --oak-deep: #7b5128;
  --spruce: #3c5a4b;
  --focus: #1f5f8b;
  --font: "Avenir Next", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.45 var(--font); color: var(--ink); background: var(--ash); display: flex; flex-direction: column; }
[hidden] { display: none !important; }
a { color: var(--oak-deep); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.top { display: flex; align-items: center; gap: 28px; padding: 0 20px; height: 52px; background: var(--ink); color: #f1e9db; flex: none; }
.brand { display: flex; align-items: center; gap: 10px; color: #f1e9db; text-decoration: none; font-weight: 650; letter-spacing: .01em; font-size: 17px; }
.brand-mark { width: 18px; height: 18px; border-radius: 50%; background: repeating-linear-gradient(90deg, #c89a64 0 3px, #a9774a 3px 5px, #d6ab78 5px 8px); box-shadow: inset 0 0 0 2px #2e2822, 0 0 0 1px #c89a64; }
.top nav { display: flex; gap: 6px; }
.top nav a { color: #cfc3b0; text-decoration: none; padding: 6px 12px; border-radius: 6px; }
.top nav a:hover { color: #fff; }
.top nav a.on { color: #fff; background: #4a3f34; }
.badge { margin-left: 6px; background: var(--oak); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 12px; }
.updated { margin-left: auto; font-size: 13px; color: #b7aa95; }

main { flex: 1; min-height: 0; }
main.map { display: grid; grid-template-columns: 410px 1fr; }
#panel { overflow-y: auto; background: var(--board); border-right: 1px solid var(--line); padding: 16px 18px 24px; }
#map { min-height: 300px; background: var(--ash); }
.leaflet-tile-pane { filter: sepia(.38) saturate(.75) brightness(1.02); }

#panel section, #panel form { margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
#panel p { margin: 0 0 8px; }
.where strong { color: var(--spruce); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.field { display: grid; grid-template-columns: 120px 1fr; align-items: center; gap: 8px; margin-bottom: 8px; }
.field label { color: var(--muted); }
select, input[type=search], input[type=text] { font: inherit; color: var(--ink); background: #fffdf8; border: 1px solid var(--plank); border-radius: 6px; padding: 7px 9px; width: 100%; min-width: 0; }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.check input { accent-color: var(--oak); width: 16px; height: 16px; }
button, .button { font: inherit; font-weight: 600; border-radius: 6px; padding: 7px 13px; cursor: pointer; border: 1px solid var(--oak); text-decoration: none; display: inline-block; }
button.ghost { background: transparent; color: var(--oak-deep); }
button.ghost:hover { background: #efe5d3; }
button.primary, .button.primary { background: var(--oak); color: #fff; }
button.primary:hover, .button.primary:hover { background: var(--oak-deep); }
.save .row input { flex: 1; width: auto; }
.hint { color: var(--muted); font-size: 13px; }
#arealist { list-style: none; padding: 0; margin: 6px 0; }
#arealist li { display: flex; justify-content: space-between; align-items: center; padding: 3px 0; }
#arealist button { padding: 2px 9px; font-size: 13px; }

.count { color: var(--muted); font-size: 13px; min-height: 1.4em; }
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.card { display: grid; grid-template-columns: 74px 1fr; background: #fffdf8; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; overflow: hidden; text-align: left; font: inherit; padding: 0; width: 100%; color: inherit; }
.card:hover { border-color: var(--oak); }
.card .km { background: linear-gradient(90deg, #e4d3b6, #ead9bd); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 8px 4px; border-right: 1px solid var(--plank); font-variant-numeric: tabular-nums; }
.card .km b { font-size: 21px; line-height: 1.1; color: var(--oak-deep); }
.card .km span { font-size: 12px; color: var(--muted); }
.card .body { padding: 9px 12px; }
.card h3 { margin: 0 0 2px; font-size: 16px; font-weight: 650; }
.card .sub { color: var(--muted); font-size: 13px; }
.card .rate { margin-top: 4px; font-size: 13px; }
.card .rate b { color: var(--oak-deep); }
.tags { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; }
.tag { font-size: 12px; background: #eee5d4; border-radius: 4px; padding: 1px 7px; color: var(--ink); }
.empty { color: var(--muted); padding: 10px 0; }

.pin { width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--oak); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.pin.on { background: var(--ink); }
.me { width: 18px; height: 18px; border-radius: 50%; background: var(--spruce); border: 3px solid #fff; box-shadow: 0 0 0 2px var(--spruce), 0 1px 5px rgba(0,0,0,.4); cursor: grab; }
.cell { display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; background: rgba(123,81,40,.82); border-radius: 50%; border: 2px solid #fff; font-variant-numeric: tabular-nums; }
.leaflet-popup-content h4 { margin: 0 0 3px; font-size: 15px; }
.leaflet-popup-content p { margin: 0 0 2px; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 2000; max-width: 340px; }
.toast { background: var(--ink); color: #f6efe2; padding: 10px 14px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.3); }
.toast.bad { background: #7a2e22; }

.page { max-width: 720px; margin: 0 auto; padding: 28px 20px 60px; overflow-y: auto; }
main.saved { overflow-y: auto; background: var(--board); }
.page h1 { margin: 0 0 4px; font-size: 26px; }
.page h2 { font-size: 18px; margin: 0; }
.lede { color: var(--muted); margin: 0 0 20px; }
.problem { color: #7a2e22; }
ul.saved, ul.matches { list-style: none; padding: 0; margin: 0 0 24px; display: grid; gap: 10px; }
ul.saved > li, ul.matches > li { background: #fffdf8; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
ul.saved .head { display: flex; justify-content: space-between; align-items: center; }
.state { font-size: 12px; border-radius: 4px; padding: 1px 8px; }
.state.on { background: #dbe6dd; color: var(--spruce); }
.state.paused { background: #f0d9d3; color: #7a2e22; }
.kept, .meta { margin: 4px 0; color: var(--muted); }
ul.matches ul { margin: 4px 0 0; padding-left: 20px; }
.page h2 + .empty, .page h2 + ul { margin-top: 10px; }
.page h2:not(:first-child) { margin-top: 10px; }

@media (max-width: 800px) {
  main.map { grid-template-columns: 1fr; grid-template-rows: 55vh auto; }
  #map { order: -1; }
  #panel { border-right: 0; }
  body { height: auto; min-height: 100%; }
  html, body { height: auto; }
  main.map { display: flex; flex-direction: column; }
  #map { height: 55vh; flex: none; }
  .top { gap: 12px; padding: 0 12px; }
  .updated { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
