:root {
  --bg: #0f1115;
  --panel: #1a1e26;
  --panel-2: #232834;
  --text: #e7e9ee;
  --muted: #9aa3b2;
  --accent: #e4572e;      /* raccoon rusty orange */
  --accent-2: #4b5563;
  --border: #2b313c;
  --ok: #10b981;
  --err: #ef4444;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .6rem 1rem; background: var(--panel); border-bottom: 1px solid var(--border);
  position: relative; z-index: 1200;
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); }
.brand span { color: var(--accent); }
.topbar nav { display: flex; align-items: center; gap: 1rem; }
.topbar nav a { color: var(--text); }
.who { color: var(--muted); font-size: .9rem; }

button, .btn-ghost {
  cursor: pointer; border: none; border-radius: 10px;
  background: var(--accent); color: #fff; padding: .6rem 1rem;
  font-size: 1rem; font-weight: 600;
}
button:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost.small { padding: .3rem .6rem; font-size: .85rem; }
button.link, .link { background: none; color: var(--accent); padding: 0; font-weight: 600; }

/* ---------- centered cards (login/register) ---------- */
body.centered { display: flex; flex-direction: column; min-height: 100%; }
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.6rem; max-width: 420px;
  margin: 2.5rem auto; width: calc(100% - 2rem);
}
.card.wide { max-width: 860px; }
.card h1 { margin-top: 0; }
label { display: block; margin: .8rem 0; font-size: .9rem; color: var(--muted); }
input, select, textarea {
  display: block; width: 100%; margin-top: .3rem; padding: .6rem .7rem;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; font-size: 1rem;
}
input[type=color] { height: 42px; padding: 2px; }
.muted { color: var(--muted); font-size: .9rem; }
.error { color: var(--err); font-weight: 600; }
.error.hidden { display: none; }

/* ---------- app shell / views ---------- */
body.map-body { overflow: hidden; }
#app { display: flex; flex-direction: column; height: calc(100vh - 54px); }
.viewbar {
  display: flex; align-items: center; gap: .4rem; padding: .4rem .6rem;
  background: var(--panel); border-bottom: 1px solid var(--border); z-index: 1100;
}
.vtab, .vtool {
  background: transparent; color: var(--muted); border: 1px solid transparent;
  padding: .4rem .8rem; border-radius: 999px; font-size: .92rem; font-weight: 600;
}
.vtab.active { background: var(--panel-2); color: var(--text); }
.vtab:hover, .vtool:hover { color: var(--text); filter: none; }
.vspacer { flex: 1; }
.vtool { border: 1px solid var(--border); }
.vtool.on { background: var(--accent); color: #fff; border-color: var(--accent); }

.view { flex: 1; position: relative; display: none; min-height: 0; }
.view.active { display: block; }
#view-wall.view.active, #view-stats.view.active { overflow-y: auto; }

#map { position: absolute; inset: 0; }
.leaflet-container { background: #0b0d10; }

.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.legend {
  position: absolute; top: 1rem; right: 1rem; z-index: 800;
  padding: .7rem .9rem; max-width: 60vw; font-size: .9rem;
}
.legend h3 { margin: 0 0 .4rem; font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.legend .row { display: flex; align-items: center; gap: .5rem; padding: .18rem 0; cursor: pointer; user-select: none; }
.legend .row.off { opacity: .4; }
.legend .dot, .dot { width: 14px; height: 14px; border-radius: 50%; flex: 0 0 auto; display: inline-block; }

.fab {
  position: absolute; bottom: 1.4rem; right: 1.4rem; z-index: 800;
  width: 60px; height: 60px; border-radius: 50%; font-size: 2rem; line-height: 1;
  box-shadow: 0 8px 24px rgba(0,0,0,.5); padding: 0;
}
.place-hint {
  position: absolute; bottom: 1.4rem; left: 50%; transform: translateX(-50%);
  z-index: 850; background: var(--panel); border: 1px solid var(--border);
  padding: .7rem 1rem; border-radius: 12px; font-size: .95rem; text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,.5); max-width: 92vw;
}
.place-hint button { margin: 0 .2rem; padding: .3rem .6rem; font-size: .9rem; }

/* ---------- add form ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 1000; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center;
}
.form { width: 480px; max-width: 100%; max-height: 90%; overflow: auto; padding: 1.4rem; margin: 0 0 0 0; border-radius: 16px 16px 0 0; }
@media (min-width: 640px) { .overlay { align-items: center; } .form { border-radius: 16px; } }
.form h2 { margin-top: 0; }
.form .coords { color: var(--muted); font-size: .85rem; margin: 0 0 .5rem; }
.form-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1rem; }

.hidden { display: none !important; }

/* ---------- popups ---------- */
.leaflet-popup-content-wrapper { background: var(--panel); color: var(--text); border-radius: 12px; }
.leaflet-popup-tip { background: var(--panel); }
.sticker-popup { min-width: 180px; max-width: 240px; }
.sticker-popup img { width: 100%; border-radius: 8px; margin-bottom: .4rem; display: block; }
.sticker-popup h4 { margin: .1rem 0; font-size: 1rem; }
.sticker-popup .meta { color: var(--muted); font-size: .8rem; margin: .1rem 0; }
.sticker-popup .cat { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; }
.sticker-popup .note { margin: .4rem 0 0; font-size: .9rem; white-space: pre-wrap; }
.sticker-popup .del { color: var(--err); font-size: .8rem; margin-top: .5rem; display: inline-block; cursor: pointer; }

/* ---------- admin ---------- */
.admin { max-width: 900px; margin: 1.5rem auto; padding: 0 1rem; }
.admin table { width: 100%; border-collapse: collapse; margin-top: .8rem; font-size: .9rem; }
.admin th, .admin td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.admin code { background: var(--panel-2); padding: .2rem .4rem; border-radius: 6px; font-size: .8rem; word-break: break-all; }
.inline { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.inline input[type=text] { width: auto; flex: 1; min-width: 160px; margin: 0; }
.inline input[type=color] { width: 48px; margin: 0; }
.copy-btn { background: var(--accent-2); padding: .25rem .5rem; font-size: .8rem; margin-left: .4rem; }
.badge { padding: .15rem .5rem; border-radius: 999px; font-size: .78rem; background: var(--panel-2); color: var(--muted); }
.badge.open { background: #064e3b; color: #6ee7b7; }
.badge.used { background: var(--panel-2); }
.badge.admin { background: #7c2d12; color: #fdba74; }
.cats { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: .6rem; }
.cats li { display: flex; align-items: center; gap: .4rem; background: var(--panel-2); padding: .3rem .7rem; border-radius: 999px; font-size: .9rem; }

/* ---------- raccoon pins ---------- */
.rpin-wrap { background: none; border: none; }
.rpin {
  width: 38px; height: 38px; border-radius: 50% 50% 50% 50%;
  background: var(--c, #8a8f98); border: 3px solid #fff;
  box-shadow: 0 3px 8px rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  position: relative; transition: transform .12s ease;
}
.rpin span { font-size: 20px; line-height: 1; filter: drop-shadow(0 1px 1px rgba(0,0,0,.4)); }
.rpin::after {
  content: ""; position: absolute; bottom: -9px; left: 50%; transform: translateX(-50%);
  border-left: 7px solid transparent; border-right: 7px solid transparent;
  border-top: 10px solid #fff;
}
.rpin-wrap:hover .rpin { transform: scale(1.12); }

.cluster { background: none; }
.cluster-dot {
  width: 44px; height: 44px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #e4572e, #a83118);
  border: 3px solid #fff; color: #fff; display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: 15px; line-height: 1;
  box-shadow: 0 3px 10px rgba(0,0,0,.55);
}
.cluster-dot b { font-size: 12px; }

/* ---------- reactions & comments in popup ---------- */
.reactions { display: flex; flex-wrap: wrap; gap: .3rem; margin: .55rem 0 .3rem; }
.react-chip {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: .2rem .45rem; border-radius: 999px; font-size: .95rem; line-height: 1;
  display: inline-flex; align-items: center; gap: .25rem;
}
.react-chip b { font-size: .78rem; color: var(--muted); font-weight: 700; }
.react-chip.mine { border-color: var(--accent); background: #3a241c; }
.react-chip.mine b { color: #fca; }

.comments { margin-top: .5rem; border-top: 1px solid var(--border); padding-top: .5rem; }
.clist { display: flex; flex-direction: column; gap: .25rem; max-height: 120px; overflow-y: auto; margin-bottom: .4rem; }
.comment { font-size: .85rem; background: var(--panel-2); padding: .25rem .45rem; border-radius: 8px; position: relative; }
.comment b { color: var(--accent); }
.cdel { position: absolute; right: .3rem; top: .2rem; cursor: pointer; color: var(--muted); font-size: .75rem; }
.cdel:hover { color: var(--err); }
.cform { display: flex; gap: .3rem; }
.cform input { margin: 0; padding: .35rem .5rem; font-size: .85rem; }
.cform button { padding: .35rem .6rem; }
.small { font-size: .8rem; }

/* ---------- wall ---------- */
.wall-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem; padding: 1.2rem;
}
.wall-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; display: flex; flex-direction: column; }
.wall-card:hover { border-color: var(--accent-2); }
.wc-photo { aspect-ratio: 4/3; background: var(--panel-2); overflow: hidden; }
.wc-photo img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; transition: transform .2s ease; }
.wc-photo img:hover { transform: scale(1.05); }
.wc-photo .noimg { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 2.4rem; opacity: .5; }
.wc-body { padding: .6rem .7rem; display: flex; flex-direction: column; gap: .25rem; flex: 1; }
.wc-title { font-weight: 700; }
.wc-meta { color: var(--muted); font-size: .8rem; display: flex; align-items: center; gap: .15rem; flex-wrap: wrap; }
.wc-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; font-size: .82rem; color: var(--muted); padding-top: .3rem; }
.wc-map { background: var(--panel-2); color: var(--text); padding: .25rem .55rem; font-size: .8rem; }
.empty { text-align: center; color: var(--muted); margin-top: 3rem; font-size: 1.05rem; }

/* ---------- stats ---------- */
.stats-wrap { padding: 1.2rem; max-width: 960px; margin: 0 auto; }
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 1rem; text-align: center; }
.tile .te { font-size: 1.8rem; }
.tile .tn { font-size: 2rem; font-weight: 800; color: var(--accent); }
.tile .tl { color: var(--muted); font-size: .85rem; }
.stat-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 1rem 1.1rem; margin-bottom: 1rem; opacity: 0; }
.stat-card.rise { animation: rise .4s ease forwards; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.stat-card h3 { margin: 0 0 .7rem; font-size: .95rem; }
.barrow { display: grid; grid-template-columns: 1fr 2fr auto; align-items: center; gap: .5rem; margin: .35rem 0; font-size: .88rem; }
.bl { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bt { background: var(--panel-2); border-radius: 999px; height: 10px; overflow: hidden; }
.bf { display: block; height: 100%; border-radius: 999px; transition: width .5s ease; }
.bn { color: var(--muted); font-weight: 700; min-width: 1.5rem; text-align: right; }
.months { display: flex; align-items: flex-end; gap: .5rem; overflow-x: auto; padding-top: .5rem; }
.month { display: flex; flex-direction: column; align-items: center; gap: .3rem; }
.month .mbar { width: 22px; background: linear-gradient(var(--accent), #a83118); border-radius: 5px 5px 0 0; }
.month span { font-size: .68rem; color: var(--muted); white-space: nowrap; }
.badges { display: flex; flex-wrap: wrap; gap: .5rem; }
.badge-chip { display: inline-flex; align-items: center; gap: .35rem; padding: .4rem .7rem; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); font-size: .85rem; color: var(--muted); opacity: .55; }
.badge-chip.got { opacity: 1; color: var(--text); border-color: var(--accent); background: #2a1d18; }
.badge-chip .be { font-size: 1.1rem; filter: grayscale(1); }
.badge-chip.got .be { filter: none; }

/* ---------- lightbox ---------- */
.lightbox { position: fixed; inset: 0; z-index: 3000; background: rgba(0,0,0,.9); display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.6); }
.lb-close { position: absolute; top: 1rem; right: 1rem; background: rgba(255,255,255,.12); width: 44px; height: 44px; border-radius: 50%; font-size: 1.2rem; }

/* ---------- owner actions & edit form extras ---------- */
.owner-actions { display: flex; gap: .8rem; margin-top: .6rem; border-top: 1px solid var(--border); padding-top: .5rem; }
.owner-actions .edit, .owner-actions .del { cursor: pointer; font-size: .82rem; }
.owner-actions .edit { color: var(--muted); }
.owner-actions .edit:hover { color: var(--text); }
.owner-actions .del { color: var(--muted); }
.owner-actions .del:hover { color: var(--err); }
.checkline { display: flex; flex-direction: row; align-items: center; gap: .5rem; color: var(--text); font-size: .9rem; }
.checkline input { width: auto; margin: 0; }
#f-move { align-self: flex-start; margin-bottom: .3rem; }

/* ---------- account & admin management ---------- */
.ok { color: var(--ok); font-weight: 600; }
.banner { padding: .6rem .9rem; border-radius: 10px; background: var(--panel-2); margin: .6rem 0 1rem; }
.ok.banner { background: #06281f; }
.error.banner { background: #2a1414; }
.card hr, hr { border: none; border-top: 1px solid var(--border); margin: 1.4rem 0; }
.card h2 { font-size: 1.05rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.row-actions form { display: flex; gap: .3rem; align-items: center; margin: 0; }
.pw-form input { width: 130px; margin: 0; padding: .3rem .45rem; font-size: .82rem; }
.btn-ghost.danger { color: #fca5a5; border-color: #7f1d1d; }
.btn-ghost.danger:hover { background: #2a1414; }
.cat-edit-list { display: flex; flex-direction: column; gap: .5rem; }
.cat-edit-row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.cat-edit-row .inline { flex: 1; }
.cat-edit-row input[type=text] { flex: 1; min-width: 120px; margin: 0; }
.cat-edit-row input[type=color] { width: 44px; margin: 0; }

/* ---------- leaflet controls, dark theme ---------- */
.leaflet-bar a, .leaflet-control-layers {
  background: var(--panel) !important; color: var(--text) !important;
  border-color: var(--border) !important;
}
.leaflet-bar a:hover { background: var(--panel-2) !important; }
.leaflet-control-layers-expanded { padding: .5rem .8rem !important; }
.leaflet-control-layers label { margin: .2rem 0; color: var(--text); font-size: .9rem; }
.leaflet-control-layers-toggle { filter: invert(1) hue-rotate(180deg); }
.leaflet-control-attribution {
  background: rgba(26,30,38,.82) !important; color: var(--muted) !important;
}
.leaflet-control-attribution a { color: var(--accent) !important; }
