:root {
  --bg: #0d1210;
  --bg-soft: #121a15;
  --panel: #17211b;
  --panel-2: #1e2b23;
  --panel-3: #24342b;
  --text: #e9f1ea;
  --muted: #9cb2a3;
  --border: rgba(255, 255, 255, 0.09);
  --green: #4ade80;
  --green-dim: rgba(74, 222, 128, 0.14);
  --red: #f87171;
  --red-dim: rgba(248, 113, 113, 0.13);
  --amber: #fbbf24;
  --amber-dim: rgba(251, 191, 36, 0.14);
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

/* Author `display` rules override the UA [hidden] rule, so enforce it globally. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 20% -10%, #16241b 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; letter-spacing: -0.02em; }

button, input, select, textarea { font: inherit; color: inherit; }

a { color: var(--amber); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 500;
  background: rgba(13, 18, 16, 0.86);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { width: 34px; height: 34px; color: var(--amber); flex: none; }
.brand h1 { font-size: 1.35rem; font-weight: 800; }
.trip-line { margin: 1px 0 0; font-size: 0.82rem; color: var(--muted); }

.topbar-stats {
  display: flex;
  gap: 14px;
  font-size: 0.82rem;
  color: var(--muted);
  margin-left: auto;
}
.topbar-stats b { color: var(--text); font-size: 0.95rem; }
.stat { text-align: center; }
.stat span { display: block; }

.topbar-actions { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
}
.btn:hover { background: var(--panel-3); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--amber); border-color: transparent; color: #201a08; font-weight: 700; }
.btn.primary:hover { background: #fcd34d; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 0.8rem; }

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 22px 60px;
}

/* Map */
.map-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
#map { height: 380px; background: #0f1712; }
.leaflet-container { background: #0f1712; font: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
}
.leaflet-popup-content { margin: 12px 14px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }

.map-legend {
  position: absolute;
  bottom: 10px;
  right: 10px;
  z-index: 400;
  background: rgba(13, 18, 16, 0.85);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  gap: 12px;
}
.map-legend .dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  margin-right: 4px;
}
.dot.pos { background: var(--green); }
.dot.zero { background: #8ba694; }
.dot.neg { background: var(--red); }

.marker-pin {
  width: 30px; height: 30px;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(0, 0, 0, 0.4);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
  font-weight: 800;
}
.marker-pin span { transform: rotate(45deg); font-size: 0.78rem; color: #0b0f0c; }
.marker-pin.pos { background: var(--green); }
.marker-pin.zero { background: #a9c2b2; }
.marker-pin.neg { background: var(--red); }

.map-popup { width: 210px; }
.map-popup img {
  width: 100%;
  height: 110px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}
.map-popup h4 { margin: 8px 0 2px; font-size: 0.88rem; line-height: 1.25; }
.map-popup .muted { font-size: 0.76rem; }
.map-popup .popup-actions { margin-top: 8px; display: flex; gap: 6px; }

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.83rem;
  color: var(--muted);
  cursor: pointer;
}
.chip.active { background: var(--amber-dim); border-color: var(--amber); color: var(--amber); font-weight: 600; }
.sort-control {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.83rem;
  color: var(--muted);
}
.sort-control select {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 10px;
  cursor: pointer;
}

/* Cards */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: rgba(255, 255, 255, 0.16); }
.card.flash { animation: flash 1.6s ease; }
@keyframes flash {
  0%, 100% { box-shadow: none; }
  25%, 70% { box-shadow: 0 0 0 3px var(--amber); }
}

.card-media { position: relative; cursor: zoom-in; background: var(--panel-2); }
.card-media img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; display: block; }
.photo-count, .lead-badge {
  position: absolute;
  font-size: 0.72rem;
  padding: 4px 9px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
}
.photo-count { right: 10px; bottom: 10px; background: rgba(0, 0, 0, 0.6); color: #fff; }
.lead-badge { left: 10px; top: 10px; background: var(--amber); color: #201a08; font-weight: 700; }

.card-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; flex: 1; }
.card-head h3 { font-size: 1.02rem; line-height: 1.3; }
.area-line { font-size: 0.8rem; color: var(--muted); margin-top: 3px; }

.specs { display: flex; gap: 8px; flex-wrap: wrap; font-size: 0.8rem; }
.spec {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 9px;
  color: var(--muted);
}
.spec b { color: var(--text); }

.rating-row { display: flex; align-items: baseline; gap: 8px; }
.rating-score {
  background: var(--amber-dim);
  color: var(--amber);
  font-weight: 800;
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 0.85rem;
}
.rating-label { font-size: 0.8rem; color: var(--muted); }
.price-row { display: flex; align-items: baseline; gap: 7px; }
.price { font-size: 1.45rem; font-weight: 800; }
.price small { font-size: 0.8rem; color: var(--muted); font-weight: 400; }
.price-note { font-size: 0.74rem; color: var(--muted); }

.amenity-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.amenity {
  font-size: 0.74rem;
  color: var(--muted);
  background: var(--panel-2);
  border-radius: 999px;
  padding: 3px 9px;
  border: 1px solid var(--border);
}
.amenity.key { color: var(--amber); border-color: rgba(251, 191, 36, 0.35); background: var(--amber-dim); }

.vote-row { display: flex; align-items: center; gap: 8px; margin-top: auto; }
.vote-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 12px;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.vote-btn svg { width: 17px; height: 17px; }
.vote-btn:hover { border-color: rgba(255, 255, 255, 0.25); }
.vote-btn.up.active { background: var(--green-dim); border-color: var(--green); color: var(--green); }
.vote-btn.down.active { background: var(--red-dim); border-color: var(--red); color: var(--red); }
.voters { font-size: 0.75rem; color: var(--muted); flex: 1; line-height: 1.35; }
.notes-toggle { margin-left: auto; }

.notes { border-top: 1px dashed var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.note { background: var(--panel-2); border-radius: 10px; padding: 9px 12px; }
.note-head { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--muted); margin-bottom: 3px; }
.note-head b { color: var(--text); }
.note p { margin: 0; font-size: 0.86rem; white-space: pre-wrap; }
.note-form { display: flex; flex-direction: column; gap: 8px; }
.note-form textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  resize: vertical;
  min-height: 62px;
}
.note-form .btn { align-self: flex-end; }
.no-notes { font-size: 0.8rem; color: var(--muted); }

.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.muted { color: var(--muted); }
.tiny { font-size: 0.75rem; }
.footnote { margin-top: 34px; font-size: 0.78rem; color: var(--muted); text-align: center; }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 6, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal.small { max-width: 380px; }
.modal h2 { font-size: 1.15rem; }
.modal p { margin: 0; font-size: 0.86rem; line-height: 1.45; }
.modal input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  width: 100%;
}
.modal input:focus, .note-form textarea:focus, select:focus {
  outline: none;
  border-color: var(--amber);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.form-error { color: var(--red); font-size: 0.83rem; }

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 5, 0.94);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-figure {
  margin: 0;
  max-width: min(1200px, 92vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.lightbox-figure img {
  max-width: 100%;
  max-height: 74vh;
  object-fit: contain;
  border-radius: 10px;
}
.lightbox-figure figcaption { font-size: 0.82rem; color: var(--muted); }
.lightbox-close {
  position: absolute;
  top: 14px;
  right: 18px;
  background: none;
  border: none;
  color: #fff;
  font-size: 2.2rem;
  cursor: pointer;
  line-height: 1;
  opacity: 0.75;
}
.lightbox-close:hover { opacity: 1; }
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: #fff;
  font-size: 2rem;
  width: 48px;
  height: 84px;
  border-radius: 12px;
  cursor: pointer;
}
.lightbox-nav:hover { background: rgba(255, 255, 255, 0.18); }
.lightbox-nav.prev { left: 14px; }
.lightbox-nav.next { right: 14px; }
.lightbox-thumbs {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 90vw;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 6px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 10px;
}
.lightbox-thumbs img {
  width: 62px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0.55;
  border: 2px solid transparent;
}
.lightbox-thumbs img.active { opacity: 1; border-color: var(--amber); }

/* Toasts */
.toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--panel-3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.86rem;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
  max-width: 90vw;
}
.toast.error { border-color: rgba(248, 113, 113, 0.5); color: #fca5a5; }
.toast.success { border-color: rgba(74, 222, 128, 0.5); color: #86efac; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(0,0,0,0.25); border-top-color: #201a08; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  .topbar-inner { padding: 12px 14px; gap: 12px; }
  .topbar-stats { order: 3; width: 100%; margin-left: 0; justify-content: space-between; }
  main { padding: 14px 14px 50px; }
  #map { height: 300px; }
  .grid { grid-template-columns: 1fr; }
  .lightbox-nav { display: none; }
  .sort-control { margin-left: 0; }
}

/* Virtual tuba */
.tuba-btn { border-color: rgba(251, 191, 36, 0.45); background: var(--amber-dim); color: var(--amber); font-weight: 700; }
.tuba-btn:hover { background: rgba(251, 191, 36, 0.22); }
.tuba-glyph { font-size: 1.05rem; }

.tuba-panel {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(600px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -14px 44px rgba(0, 0, 0, 0.55);
  padding: 16px 18px 22px;
  z-index: 900;
  flex-direction: column;
  gap: 12px;
}
.tuba-head { display: flex; align-items: center; gap: 14px; }
.tuba-head h3 { font-size: 1.02rem; }
.tuba-oompah {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.tuba-oompah input { accent-color: var(--amber); width: 15px; height: 15px; cursor: pointer; }
.tuba-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.tuba-close:hover { color: var(--text); }
.tuba-hint { margin: 0; font-size: 0.8rem; color: var(--muted); line-height: 1.4; }

.tuba-valves { display: flex; gap: 12px; justify-content: center; padding-top: 4px; }
.tuba-valve {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: radial-gradient(circle at 34% 28%, var(--panel-3), var(--panel-2) 70%);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  user-select: none;
  touch-action: none;
  transition: transform 0.06s, box-shadow 0.12s, border-color 0.12s;
}
.tuba-valve:hover { border-color: rgba(255, 255, 255, 0.28); }
.tuba-valve.pressed {
  transform: scale(0.93);
  border-color: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-dim), 0 0 22px rgba(251, 191, 36, 0.4);
}
.tuba-note { font-size: 1.1rem; font-weight: 800; }
.tuba-key {
  font-size: 0.66rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  min-width: 16px;
  text-align: center;
}

@media (max-width: 760px) {
  .tuba-valves { gap: 8px; }
  .tuba-valve { width: 60px; height: 60px; }
  .tuba-note { font-size: 0.95rem; }
}
