/* Treat Trail — mobile-first Halloween theme */
[hidden] { display: none !important; }
:root {
  --bg: #160d22; --bg2: #21142f; --card: #2a1a3c; --card2: #33214a; --line: #4a3363;
  --text: #f6efff; --muted: #c5b5da; --orange: #ff8a1f; --orange2: #ffb35c; --purple: #9b5de5; --green: #5ee08a;
  --danger: #ff5d73; --radius: 16px; --shadow: 0 6px 20px rgba(0,0,0,.35);
  --sugarfree: #4cc9f0; --noncandy: #2ec4b6; --nonsweet: #f4a261; --nutfree: #b5e48c; --candy: #ff7eb6;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Color Emoji", sans-serif; color: var(--text);
  background: radial-gradient(1200px 500px at 50% -200px, #3b1f5c 0%, transparent 70%), var(--bg); min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
body.locked > :not(#gate):not(script) { display: none !important; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
a { color: var(--orange2); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header + tabs */
.app-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px 8px; max-width: 760px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 34px; filter: drop-shadow(0 0 10px rgba(255,138,31,.6)); }
.brand h1 { font-size: 24px; letter-spacing: .3px; color: var(--orange); text-shadow: 0 0 18px rgba(255,138,31,.35); }
.tagline { margin: 0; font-size: 12.5px; color: var(--muted); }
.countdown { font-size: 12px; background: var(--card); border: 1px solid var(--line); padding: 5px 10px; border-radius: 999px; white-space: nowrap; color: var(--orange2); }
.tabs { position: sticky; top: 0; z-index: 1000; display: flex; gap: 6px; padding: 8px 12px; max-width: 760px; margin: 0 auto;
  background: rgba(22,13,34,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.tab { flex: 1; border: 0; border-radius: 12px; padding: 10px 4px; font: inherit; font-size: 13.5px; font-weight: 600; color: var(--muted); background: transparent; cursor: pointer; white-space: nowrap; }
.tab.active { background: linear-gradient(135deg, var(--orange), #ff6b00); color: #1b0f00; box-shadow: 0 4px 14px rgba(255,138,31,.35); }
main { max-width: 760px; margin: 0 auto; padding: 12px 12px 30px; }
.view { display: none; } .view.active { display: block; }

/* Controls */
.search-wrap input, .field input, .field textarea, .field select, #town-filter, .idea-form input, .idea-form select {
  width: 100%; font: inherit; color: var(--text); background: var(--bg2); border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 12px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(255,138,31,.2); }
::placeholder { color: #8e7aa8; }
.town-wrap { display: flex; align-items: center; gap: 8px; margin: 10px 0 2px; }
.town-wrap label { font-weight: 700; font-size: 14px; white-space: nowrap; color: var(--orange2); }
#town-filter { padding: 9px 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1.5px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-size: 14px; font-weight: 600; padding: 8px 12px; border-radius: 999px; cursor: pointer; }
.chip.on { color: #120a1c; border-color: transparent; }
.chip-sugarfree.on { background: var(--sugarfree); } .chip-noncandy.on { background: var(--noncandy); } .chip-nonsweet.on { background: var(--nonsweet); }
.chip-nutfree.on { background: var(--nutfree); } .chip-candy.on { background: var(--candy); }
.list-meta { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); margin: 4px 2px 6px; }
.toggle { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.toggle input { accent-color: var(--orange); width: 18px; height: 18px; }

/* Cards */
.card { background: linear-gradient(180deg, var(--card2), var(--card)); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.cards { display: grid; gap: 12px; }
.town-group { display: grid; gap: 12px; }
@media (min-width: 640px) { .town-group { grid-template-columns: 1fr 1fr; } }
.town-head { font-size: 17px; color: var(--orange2); margin: 10px 2px -2px; display: flex; align-items: center; gap: 8px; }
.town-head span { font-size: 12px; background: var(--purple); color: #fff; border-radius: 999px; padding: 1px 8px; }
.house { position: relative; overflow: hidden; }
.house.has-photo .thumb { width: calc(100% + 28px); margin: -14px -14px 10px; height: 140px; object-fit: cover; display: block; border-bottom: 1px solid var(--line); }
.house.mine { border-color: var(--orange); }
.house.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%,100% { box-shadow: var(--shadow); } 30% { box-shadow: 0 0 0 4px var(--orange), 0 0 30px rgba(255,138,31,.6); } }
.house-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.town-tag { font-weight: 800; font-size: 14px; color: #1b0f00; background: var(--orange2); padding: 2px 10px; border-radius: 999px; }
.example-tag, .mine-tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; padding: 2px 8px; border-radius: 999px; }
.example-tag { background: #4a3363; color: var(--muted); } .mine-tag { background: var(--orange); color: #1b0f00; }
.house h3 { font-size: 18px; margin: 4px 0 2px; }
.addr { margin: 0; color: var(--muted); font-size: 14px; }
.hours { margin: 6px 0; font-size: 14px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.status { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.status.open { background: rgba(94,224,138,.18); color: var(--green); border: 1px solid var(--green); }
.status.later { background: rgba(155,93,229,.2); color: #d6bcff; } .status.closed { background: #3a2a4a; color: #9a8ab0; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; color: #120a1c; white-space: nowrap; }
.badge-candy { background: var(--candy); } .badge-sugarfree { background: var(--sugarfree); } .badge-noncandy { background: var(--noncandy); }
.badge-nonsweet { background: var(--nonsweet); } .badge-nutfree { background: var(--nutfree); }
.safety { display: flex; flex-wrap: wrap; gap: 6px; }
.safe { font-size: 12px; color: var(--muted); background: rgba(255,255,255,.05); padding: 2px 8px; border-radius: 8px; }
.notes { margin: 8px 0 0; font-size: 14px; background: rgba(255,138,31,.08); border-left: 3px solid var(--orange); padding: 6px 10px; border-radius: 0 8px 8px 0; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.empty { text-align: center; padding: 30px 10px; font-size: 40px; } .empty p { font-size: 15px; color: var(--muted); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 700; border: 0; border-radius: 12px; padding: 12px 16px; cursor: pointer; text-decoration: none; color: var(--text); background: var(--card2); border: 1.5px solid var(--line); }
.btn.small { padding: 8px 12px; font-size: 14px; }
.btn.primary { background: linear-gradient(135deg, var(--orange), #ff6b00); color: #1b0f00; border: 0; box-shadow: 0 4px 14px rgba(255,138,31,.35); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; color: var(--danger); border-color: rgba(255,93,115,.5); }
.btn.directions { background: var(--purple); color: #fff; border: 0; }
.card-actions .directions { flex: 1 1 140px; }
.icon-btn { border: 0; background: transparent; color: var(--text); font-size: 18px; cursor: pointer; padding: 4px 8px; }

/* Form */
.form h2 { font-size: 21px; color: var(--orange2); }
.hint { color: var(--muted); font-size: 13.5px; margin: 6px 0 10px; }
.field { display: block; margin: 0 0 14px; border: 0; padding: 0; min-width: 0; }
.field > span, .field legend, .field .label { display: block; font-weight: 700; font-size: 14px; margin-bottom: 6px; padding: 0; }
.field small { display: block; color: var(--muted); font-size: 12px; margin-top: 5px; }
.row { display: flex; gap: 10px; } .row .field { flex: 1; } .row .field.state { flex: 0 0 90px; }
.checks { display: grid; gap: 8px; margin-bottom: 8px; }
.check { display: flex; align-items: center; gap: 10px; background: var(--bg2); border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--orange); flex: none; }
.check:has(input:checked) { border-color: var(--orange); background: rgba(255,138,31,.1); }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; } .form-actions .primary { flex: 1; }
.error { color: var(--danger); font-weight: 600; font-size: 14px; min-height: 1em; margin: 4px 0 10px; }
.photo-pick { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.photo-pick img { width: 100%; max-height: 200px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }

/* Legend */
.legend-inline { background: rgba(155,93,229,.12); border: 1px solid rgba(155,93,229,.45); border-radius: 12px; padding: 8px 12px; margin: 4px 0 8px; }
.legend-inline summary { cursor: pointer; font-weight: 700; font-size: 14px; color: #d6bcff; }
.browse-legend { margin: 0 0 8px; }
.legend-list { list-style: none; padding: 0; margin: 10px 0 4px; display: grid; gap: 8px; }
.legend-list li { display: grid; grid-template-columns: 118px 1fr; gap: 10px; align-items: center; font-size: 13.5px; }
.legend-list .badge { justify-self: start; }
.legend-note { font-size: 13px; color: var(--muted); margin: 8px 0 2px; }
.legend-panel h4 { margin: 12px 0 0; color: var(--orange2); font-size: 14px; }
.pin-demo { display: flex; justify-content: flex-start; }
.map-wrap { position: relative; }
.map { height: calc(100vh - 190px); min-height: 380px; border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; background: #2a1a3c; }
.legend-pill { position: absolute; z-index: 800; left: 50%; transform: translateX(-50%); bottom: 14px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 2px solid var(--orange); background: rgba(22,13,34,.95); color: var(--text); font: inherit; font-weight: 700; font-size: 14px; padding: 7px 16px; border-radius: 999px; cursor: pointer; box-shadow: var(--shadow); white-space: nowrap; }
.legend-strip { font-size: 16px; letter-spacing: 2px; }
.legend-pill-text { color: var(--orange2); font-size: 13px; }
.legend-panel { position: absolute; z-index: 900; left: 8px; right: 8px; bottom: 8px; max-height: 75%; overflow: auto; background: rgba(22,13,34,.97); border: 2px solid var(--orange); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.legend-head { display: flex; justify-content: space-between; align-items: center; } .legend-head h3 { color: var(--orange2); }

/* Map pins & popups */
.pin { background: none; border: 0; }
.pin-house { display: flex; flex-direction: column; align-items: center; }
.pin-emoji { font-size: 30px; line-height: 1; filter: drop-shadow(0 2px 3px rgba(0,0,0,.6)); }
.pin-treats { font-size: 11px; background: rgba(22,13,34,.9); border: 1px solid var(--orange); border-radius: 999px; padding: 0 4px; margin-top: -2px; white-space: nowrap; }
.pin-town { width: 44px; height: 44px; border-radius: 50%; background: var(--purple); color: #fff; border: 3px solid var(--orange); display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 3px 10px rgba(0,0,0,.5); line-height: 1; }
.pin-town b { font-size: 16px; } .pin-town span { font-size: 8px; max-width: 40px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-list .pin-town { width: 36px; height: 36px; }
.leaflet-popup-content-wrapper { background: #2a1a3c; color: var(--text); border-radius: 14px; } .leaflet-popup-tip { background: #2a1a3c; }
.leaflet-popup-content { margin: 12px; font-size: 14px; }
.popup-photo { width: 100%; height: 110px; object-fit: cover; border-radius: 10px; margin-bottom: 6px; display: block; }
.popup-town { color: var(--orange2); font-weight: 700; }
.leaflet-container a.popup-dir, .popup-dir { display: flex; width: 100%; margin-top: 6px; color: #fff; padding: 10px; }

/* Ideas */
.ideas-intro h2 { color: var(--orange2); font-size: 21px; }
.idea-form { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 520px) { .idea-form { grid-template-columns: 150px 1fr 1fr; } .idea-form #i-text { grid-column: span 2; } }
#ideas { display: grid; gap: 12px; margin-top: 12px; }
.idea-list { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 8px; }
.idea { display: flex; align-items: center; gap: 12px; background: var(--bg2); border-radius: 12px; padding: 8px 10px; }
.vote { flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; width: 48px; min-height: 48px; border-radius: 12px; border: 2px solid var(--line); background: transparent; color: var(--muted); font: inherit; font-weight: 800; cursor: pointer; line-height: 1.05; }
.vote .arrow { font-size: 14px; } .vote .count { font-size: 16px; color: var(--text); }
.vote.voted { background: var(--orange); border-color: var(--orange); color: #1b0f00; } .vote.voted .count { color: #1b0f00; }
.idea-text { font-size: 15px; }

/* Gate */
.gate { position: fixed; inset: 0; z-index: 5000; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(600px 400px at 50% 20%, #4a2370 0%, transparent 70%), var(--bg); }
.gate-card { width: 100%; max-width: 380px; text-align: center; background: linear-gradient(180deg, var(--card2), var(--card)); border: 1px solid var(--line); border-radius: 22px; padding: 26px 22px; box-shadow: var(--shadow); }
.gate-pumpkin { font-size: 64px; filter: drop-shadow(0 0 22px rgba(255,138,31,.7)); animation: glow 2.4s ease-in-out infinite; }
@keyframes glow { 50% { filter: drop-shadow(0 0 8px rgba(255,138,31,.3)); transform: scale(1.04); } }
.gate-card h1 { color: var(--orange); font-size: 30px; margin: 6px 0; } .gate-card p { color: var(--muted); }
.gate-card .field { text-align: left; } .gate-card .btn { width: 100%; }
#gate-code { text-align: center; font-size: 26px; letter-spacing: 8px; font-weight: 800; }
.gate-foot { font-size: 12px; }

/* Toast + footer */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 40px); opacity: 0; z-index: 4000; background: var(--orange); color: #1b0f00; font-weight: 700; padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow); transition: .25s; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.foot { text-align: center; font-size: 12px; color: #8e7aa8; padding: 10px 16px 24px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.idea-meta { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.btn:disabled, .vote:disabled { opacity: .6; cursor: progress; }
