/* Another Man's Treasure — Neo-Brutalist, maps-style. Full-screen map, floating cards,
   thick ink outlines, hard offset shadows, flat saturated color reserved for pickup data. */
:root {
  --bg: #f4f1e8; --card: #fffdf7; --ink: #111111; --muted: #4a4740; --line: #111111;
  --shadow: 4px 4px 0 var(--ink); --shadow-sm: 2px 2px 0 var(--ink);
  --accent: #ffd60a; --accent-ink: #111; --go: #1fbf75;
  --out: #ff8c1a; --truck: #1f5fd6; --soon: #ffd60a; --done: #a3a3a3; --quiet: #ffffff;
  --chip: #ffffff; --chip-on: #111111; --chip-on-ink: #ffd60a; --err: #d62828;
  --radius: 10px;
  --tiles: grayscale(1) contrast(0.85) brightness(1.08);
  --tiles-opacity: 0.55;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15140f; --card: #1f1e18; --ink: #f4f1e8; --muted: #c9c4b6; --line: #f4f1e8;
    --chip: #1f1e18; --chip-on: #f4f1e8; --chip-on-ink: #111; --quiet: #1f1e18;
    --tiles: grayscale(1) invert(1) contrast(0.8) brightness(0.85);
    --tiles-opacity: 0.6;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.4 "Space Grotesk", system-ui, sans-serif; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--card); border: 2px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer; font-weight: 600; box-shadow: var(--shadow-sm); transition: transform .05s, box-shadow .05s; }
button:hover { background: var(--bg); }
button:active { transform: translate(2px, 2px); box-shadow: none; }
button.primary { background: var(--accent); color: var(--accent-ink); }
button.wide { width: 100%; margin: 6px 0 10px; }
button.icon { width: 38px; height: 38px; padding: 0; font-size: 18px; line-height: 1; }
input, select, textarea { background: var(--card); border: 2px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; }
select { font-weight: 600; cursor: pointer; }
a { color: inherit; }

.card { background: var(--card); border: 2.5px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* the map */
#map { position: fixed; inset: 0; z-index: 0; background: var(--bg); }
.leaflet-tile-pane { filter: var(--tiles); opacity: var(--tiles-opacity); }
.leaflet-container { font: inherit; background: var(--bg); }
.leaflet-control-zoom { border: 2.5px solid var(--line) !important; box-shadow: var(--shadow) !important; border-radius: 8px !important; }
.leaflet-control-zoom a { background: var(--card) !important; color: var(--ink) !important; border-color: var(--line) !important; }
.leaflet-control-attribution { background: var(--card) !important; color: var(--muted) !important; font-size: 10px; }
.leaflet-pane.hatch { pointer-events: none; }

/* top bar */
#topbar { position: fixed; top: 12px; left: 12px; right: 12px; z-index: 1000; display: flex; gap: 8px; align-items: center; pointer-events: none; flex-wrap: wrap; }
#topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 8px; background: var(--card); border: 2.5px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 12px 4px 4px; height: 42px; }
.logo { background: var(--accent); color: #111; border: 2px solid var(--line); border-radius: 6px; font-weight: 700; padding: 2px 6px; font-size: 13px; }
.brand .name { font-weight: 700; font-size: 15px; white-space: nowrap; }
#topbar select { width: auto; height: 42px; border-width: 2.5px; box-shadow: var(--shadow); border-radius: var(--radius); }
#topbar .icon { height: 42px; width: 42px; border-width: 2.5px; box-shadow: var(--shadow); border-radius: var(--radius); }
.seg { display: inline-flex; border: 2.5px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: var(--card); }
.seg button { border: 0; border-radius: 0; box-shadow: none; border-right: 2px solid var(--line); padding: 0 12px; height: 37px; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--ink); color: var(--accent); }
.seg.full { display: flex; box-shadow: var(--shadow-sm); margin-bottom: 8px; }
.seg.full button { flex: 1; height: 34px; font-size: 13px; }

/* side panel / bottom sheet */
#panel { position: fixed; z-index: 900; top: 72px; left: 12px; bottom: 12px; width: 360px; display: flex; flex-direction: column; overflow: hidden; }
.tabs { display: flex; border-bottom: 2.5px solid var(--line); background: var(--card); }
.tabs button { flex: 1; border: 0; border-radius: 0; box-shadow: none; background: none; padding: 10px 2px; font-size: 13px; border-right: 2px solid var(--line); }
.tabs button:last-child { border-right: 0; }
.tabs button.on { background: var(--accent); color: #111; }
.tabs .sheet-toggle { display: none; flex: 0 0 40px; }
.pill { display: inline-block; background: var(--ink); color: var(--card); border-radius: 10px; padding: 0 6px; font-size: 11px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--err); vertical-align: middle; }
.dot[hidden] { display: none; }
.tab { display: none; padding: 12px 14px 16px; overflow-y: auto; flex: 1; }
.tab.on { display: block; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; margin: 14px 0 6px; }
.fine { color: var(--muted); font-size: 13px; margin: 6px 0; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.row input { width: auto; accent-color: #111; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border-radius: 999px; padding: 3px 10px; font-size: 13px; box-shadow: none; border-width: 2px; }
.chip.on { background: var(--chip-on); color: var(--chip-on-ink); }
.chip .sw { display: inline-block; width: 10px; height: 10px; border: 1.5px solid currentColor; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* now tab */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 2px 0 10px; }
.stat { border: 2px solid var(--line); border-radius: 8px; padding: 8px; box-shadow: var(--shadow-sm); }
.stat b { display: block; font-size: 26px; line-height: 1.05; }
.stat span { font-size: 12px; font-weight: 500; }
.stat.out { background: var(--out); color: #111; } .stat.truck { background: var(--truck); color: #fff; } .stat.soon { background: var(--soon); color: #111; }
.bets a { font-weight: 700; }
.list .item { border-bottom: 2px dashed var(--line); padding: 8px 0; }
.list .item:last-child { border-bottom: 0; }
.list .item .sub { color: var(--muted); font-size: 12px; }
.list .item.expired { opacity: .5; }
.list .item button { padding: 2px 8px; font-size: 12px; margin-top: 4px; }

.gallery { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.card-find { border: 2px solid var(--line); border-radius: 8px; overflow: hidden; cursor: pointer; box-shadow: var(--shadow-sm); background: var(--card); }
.card-find .ph { aspect-ratio: 4/3; background: var(--bg) center/cover no-repeat; display: grid; place-items: center; font-size: 32px; border-bottom: 2px solid var(--line); }
.card-find .meta { padding: 6px 8px; font-size: 12px; }
.card-find .meta b { display: block; font-size: 13px; text-transform: capitalize; }
.empty { color: var(--muted); font-style: italic; padding: 10px 0; }
.elsewhere { display: flex; flex-wrap: wrap; gap: 6px; }
.elsewhere a { font-size: 13px; font-weight: 600; border: 2px solid var(--line); border-radius: 999px; padding: 3px 10px; text-decoration: none; box-shadow: var(--shadow-sm); background: var(--card); }
.lookup { display: flex; gap: 6px; }

/* status badges (same everywhere: popups, lists, legend) */
.state { display: inline-block; font-size: 11px; font-weight: 700; border: 2px solid var(--line); border-radius: 6px; padding: 0 6px; text-transform: uppercase; letter-spacing: .03em; color: #111; }
.state.items_out { background: var(--out); } .state.running { background: var(--truck); color: #fff; }
.state.soon { background: var(--soon); } .state.cleared { background: var(--done); } .state.quiet { background: #fff; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; border: 1.5px solid var(--line); border-radius: 6px; padding: 0 5px; }
.bar { height: 10px; border: 2px solid var(--line); border-radius: 4px; overflow: hidden; margin: 6px 0; background: var(--card); }
.bar i { display: block; height: 100%; background: var(--truck); }

.leaflet-top.leaflet-right { top: 64px; }
.sw.out { background: var(--out); } .sw.truck { background: var(--truck); } .sw.soon { background: repeating-linear-gradient(90deg, var(--soon) 0 5px, transparent 5px 8px), var(--card); }
.sw.done { background: var(--done); } .sw.quiet { background: var(--card); border-style: dashed !important; }

/* add button + menu */
#fab { position: fixed; z-index: 1000; right: 18px; bottom: 24px; width: 58px; height: 58px; border-radius: 50%; font-size: 32px; line-height: 1; padding: 0; background: var(--accent); color: #111; border-width: 3px; box-shadow: var(--shadow); }
.menu { position: fixed; z-index: 1100; padding: 6px; display: flex; flex-direction: column; gap: 6px; min-width: 210px; }
.menu[hidden] { display: none; }
.menu button { text-align: left; box-shadow: none; }
.menu .menu-head { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 2px 4px; }

#modeBar { position: fixed; z-index: 1050; top: 72px; left: 50%; transform: translateX(-50%); padding: 8px 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; max-width: calc(100% - 24px); font-weight: 600; }
#modeBar[hidden] { display: none; }
#zoomHint { position: fixed; z-index: 800; top: 72px; left: calc(50% + 186px); transform: translateX(-50%); padding: 6px 14px; font-weight: 700; }
#zoomHint[hidden] { display: none; }
#staleBanner { position: fixed; z-index: 850; top: 124px; left: 384px; right: 64px; padding: 8px 12px; font-weight: 600; background: var(--accent); color: #111; }
#staleBanner[hidden] { display: none; }

/* time slider */
#timeBar { position: fixed; z-index: 820; left: 384px; right: 96px; bottom: 24px; padding: 8px 10px; display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
#timeBar.active { background: var(--accent); color: #111; }
#timeBar.active button:not(.primary) { background: #fff; color: #111; }
#timeBar b { min-width: 46px; white-space: nowrap; }
#timeRange { flex: 1 1 140px; min-width: 120px; padding: 0; border: 0; background: transparent; accent-color: var(--ink); }
#timeBar.active #timeRange { accent-color: #111; }
#timeBar button { padding: 3px 8px; font-size: 12px; box-shadow: none; }
#timeBar [hidden] { display: none; }
#timeNote { flex-basis: 100%; margin: 0; color: inherit; }

/* map labels and pins */
.area-label { background: var(--card); border: 2px solid var(--line); border-radius: 5px; box-shadow: var(--shadow-sm); padding: 0 5px; font: 700 11px/16px "Space Grotesk", system-ui; color: var(--ink); white-space: nowrap; }
.area-label::before { display: none; }
.area-label.items_out { background: var(--out); color: #111; } .area-label.running { background: var(--truck); color: #fff; }
.area-label.soon { background: var(--soon); color: #111; }
.pin { position: relative; }
.pin .box { width: 32px; height: 32px; background: var(--card); border: 2.5px solid var(--line); border-radius: 8px; box-shadow: var(--shadow-sm); display: grid; place-items: center; font-size: 18px; }
.pin.note .box { background: var(--accent); border-radius: 50% 50% 50% 4px; font-size: 15px; }
.pin b { position: absolute; top: -8px; right: -8px; background: var(--err); color: #fff; border: 2px solid var(--line); font: 700 11px/14px system-ui; min-width: 18px; height: 18px; border-radius: 9px; text-align: center; padding: 0 3px; }

/* popups */
.leaflet-popup-content-wrapper { background: var(--card); color: var(--ink); border: 2.5px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.leaflet-popup-tip { background: var(--card); border: 2.5px solid var(--line); box-shadow: none; }
.leaflet-popup-content { margin: 12px 14px; min-width: 220px; font-size: 13.5px; }
.leaflet-popup-content img { width: 100%; border: 2px solid var(--line); border-radius: 6px; display: block; margin-bottom: 6px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--ink); font-weight: 700; }
.pop-title { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.when { margin: 6px 0 2px; font-weight: 700; }
.sub { color: var(--muted); font-size: 12px; }
.area-line { font-size: 12px; margin-top: 8px; padding-top: 6px; border-top: 2px dashed var(--line); }
details.src { font-size: 12px; color: var(--muted); margin-top: 6px; }
details.src summary { cursor: pointer; font-weight: 600; }
.want { font-size: 13px; margin-top: 6px; font-weight: 600; }
.popup-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.popup-btns button { padding: 3px 9px; font-size: 12px; }
.popup-btns button.on { background: var(--ink); color: var(--accent); }

/* dialogs */
dialog { border: 3px solid var(--line); border-radius: 14px; background: var(--card); color: var(--ink); width: min(460px, calc(100vw - 32px)); padding: 18px; box-shadow: 6px 6px 0 var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0 0 6px; font-size: 20px; }
dialog form { display: grid; gap: 10px; }
dialog label, .field { display: grid; gap: 4px; font-size: 13px; font-weight: 600; }
dialog textarea { min-height: 90px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btns { display: flex; justify-content: flex-end; gap: 8px; }
.err { color: var(--err); min-height: 1em; margin: 0; font-size: 13px; font-weight: 600; }
.help-row { display: grid; grid-template-columns: 26px 1fr; gap: 8px; margin: 8px 0; font-size: 14px; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--card); border: 2.5px solid var(--line); padding: 9px 14px; border-radius: 10px; z-index: 2000; max-width: calc(100vw - 32px); font-weight: 600; }

/* phone: panel becomes a bottom sheet; map stays the main thing */
@media (max-width: 760px) {
  #topbar { top: 8px; left: 8px; right: 8px; gap: 6px; }
  .brand .name { display: none; }
  .brand { padding: 4px; }
  #topbar select { max-width: 118px; height: 40px; }
  .seg button { padding: 0 8px; font-size: 12.5px; height: 35px; }
  #topbar .icon { width: 40px; height: 40px; }
  #panel { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; height: 46vh; transition: height .2s; }
  #panel.collapsed { height: 47px; }
  #panel.collapsed .tab { display: none; }
  .tabs .sheet-toggle { display: block; }
  .tabs button { font-size: 12px; padding: 12px 1px; }
  #fab { right: 14px; bottom: calc(46vh + 18px); }
  body.sheet-collapsed #fab { bottom: 66px; }
  #zoomHint { top: 104px; left: 50%; }
  #staleBanner { top: 104px; left: 8px; right: 8px; }
  #timeBar { left: 8px; right: 82px; bottom: 66px; padding: 6px 8px; }
  body:not(.sheet-collapsed) #timeBar { display: none; }
  #timeBar .tb-icon { display: none; }
  .leaflet-control-zoom { display: none; }
}

/* ===================== Accessibility layer (WCAG 2.2: AA throughout, AAA where it's visual) =====================
   - text ≥ 13px (body 16px); contrast ≥ 4.5:1 for text, ≥ 3:1 for borders and focus
   - every control shows a 3px focus ring; touch screens get 44×44px targets (2.5.5 AAA)
   - color is never the only signal: areas carry text labels, statuses have names, stripes have a key
   - motion is minimal and switched off for people who ask for less                                      */
body { font-size: 16px; line-height: 1.5; }
.fine { font-size: 14px; }
.sub, .list .item .sub, .area-line, details.src, .card-find .meta { font-size: 13px; }
h3 { font-size: 13px; }
.tabs button { font-size: 14px; }
.state, .tag, .pill { font-size: 12px; }
.leaflet-popup-content { font-size: 14.5px; }
dialog label, .field { font-size: 14px; }
.err, .want, .elsewhere a, .chip { font-size: 14px; }
.popup-btns button, .list .item button, #timeBar button { font-size: 13px; padding: 5px 10px; min-height: 36px; }
button, select, .chip, .seg button, .tabs button { min-height: 36px; }

/* focus: visible on every control, both themes */
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus, #1f5fd6); outline-offset: 2px; box-shadow: 0 0 0 5px var(--card); border-radius: 6px; }
.leaflet-container:focus-visible { outline-offset: -4px; }
.leaflet-marker-icon:focus-visible .box { outline: 3px solid var(--focus, #1f5fd6); outline-offset: 2px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --focus: #ffd60a; } }

/* screen-reader-only text and the skip link */
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: fixed; z-index: 3000; left: 12px; top: -80px; background: var(--accent); color: #111; border: 3px solid #111; border-radius: 8px; padding: 10px 14px; font-weight: 700; }
.skip:focus { top: 12px; }

/* touch screens: 44px targets */
@media (pointer: coarse) {
  button, select, input, .chip, .seg button, .tabs button, .elsewhere a, .popup-btns button, .menu button, #timeBar button { min-height: 44px; }
  .chip { padding: 6px 14px; }
  #timeRange { height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  .sw, .state, .area-label, .chip.on { forced-color-adjust: none; }
  :focus-visible { outline: 3px solid CanvasText; }
}

/* stripes key (only while Income or Safety is on) */
#shadeKey { position: fixed; z-index: 830; top: 72px; left: 384px; right: 64px; padding: 6px 10px; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; font-size: 14px; }
#shadeKey[hidden] { display: none; }
.key { display: inline-flex; align-items: center; gap: 6px; }
.keyrow { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.sw { display: inline-block; width: 22px; height: 16px; border: 2px solid var(--line); border-radius: 3px; flex: none; }
.sw.done { background: var(--done); } .sw.quiet { background: var(--card); border-style: dashed; }
.sw.pending { background: repeating-linear-gradient(45deg, #8a877f 0 3px, transparent 3px 7px), var(--card); border-style: dotted; }
.help-row { align-items: start; }
.help-row .sw { margin-top: 3px; }
#helpBody h3 { margin-top: 16px; }
button.linkish { background: none; border: 0; box-shadow: none; padding: 0 4px; text-decoration: underline; font-weight: 700; min-height: 0; }

/* schedule claims in area popups */
.claim { font-size: 13px; margin-top: 8px; padding: 6px 8px; border: 2px dashed var(--line); border-radius: 6px; }
.claim.ok { border-style: solid; background: var(--bg); }
.claim .popup-btns { margin-top: 6px; }
.area-label.pending { background: var(--card); color: var(--ink); border-style: dashed; }

/* request dialog */
fieldset.plain { border: 0; padding: 0; margin: 0; }
fieldset.plain legend { font-size: 14px; font-weight: 600; padding: 0; margin-bottom: 6px; }
.btns.left { justify-content: flex-start; flex-wrap: wrap; }
dialog textarea { min-height: 96px; }

@media (max-width: 760px) {
  #shadeKey { top: 104px; left: 8px; right: 8px; }
  #staleBanner { top: 150px; }
  .tabs button { font-size: 13px; }
}
