:root {
  --bg: #faf9f5;
  --surface: #ffffff;
  --text: #1f1e1d;
  --muted: #73716b;
  --faint: #a19f98;
  --line: #e7e5df;
  --line-strong: #d4d1c9;
  --ink: #1f1e1d;          /* primary button */
  --ink-text: #faf9f5;
  --accent: #c96442;       /* used sparingly: live dot, focus, selected */
  --ok: #4d7c5b;
  --warn: #b5832a;
  --bad: #b5443a;
  --serif: "Source Serif 4", "Tiempos Text", Georgia, serif;
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1b1a; --surface: #252422; --text: #ecebe7; --muted: #a09e97; --faint: #77756f;
    --line: #34332f; --line-strong: #46443f; --ink: #ecebe7; --ink-text: #1c1b1a;
  }
}

* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans); }
a { color: inherit; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
a:hover { text-decoration-color: currentColor; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
::selection { background: color-mix(in srgb, var(--accent) 25%, transparent); }

/* ------------------------------------------------------------ top bar */
.topbar {
  display: flex; align-items: center; gap: 28px; height: 60px; padding: 0 28px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1000;
}
.wordmark { font-family: var(--serif); font-size: 21px; text-decoration: none; letter-spacing: -0.01em; }
.nav { display: flex; gap: 2px; }
.nav button, .nav a {
  background: none; border: 0; font: 500 14px var(--sans); color: var(--muted); padding: 6px 12px;
  border-radius: 8px; cursor: pointer; text-decoration: none;
}
.nav button:hover, .nav a:hover { color: var(--text); }
.nav button.active { color: var(--text); background: color-mix(in srgb, var(--text) 6%, transparent); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 18px; font-size: 13px; }
.live { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); }
.live .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.live.on .dot { background: var(--accent); animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.who { display: inline-flex; align-items: center; gap: 10px; }
.linkish { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; cursor: pointer; }
.linkish:hover { color: var(--text); }

/* ------------------------------------------------------------ type */
.display { font-family: var(--serif); font-weight: 400; font-size: 44px; line-height: 1.12; letter-spacing: -0.015em; margin: 0 0 16px; }
.display.sm { font-size: 30px; margin: 0; }
.lede { color: var(--muted); font-size: 17px; max-width: 34em; margin: 0 0 28px; }
.section { font: 500 12px var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 28px 0 10px; }
.col-side .section { margin-top: 6px; }

/* ------------------------------------------------------------ controls */
input, select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 8px; transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: none; border-color: var(--text); box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 8%, transparent);
}
::placeholder { color: var(--faint); }
.btn {
  font: 500 14px var(--sans); padding: 9px 16px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); white-space: nowrap;
}
.btn:hover { border-color: var(--text); }
.btn.primary { background: var(--ink); color: var(--ink-text); border-color: var(--ink); }
.btn.primary:hover { opacity: .88; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.lg { padding: 12px 22px; font-size: 15px; }
.btn:disabled { opacity: .45; cursor: default; }
.inline-form { display: flex; gap: 8px; max-width: 420px; }

/* ------------------------------------------------------------ layout */
main { max-width: 1120px; margin: 0 auto; padding: 36px 28px 80px; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 56px; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; gap: 24px; }
  .topbar { gap: 14px; padding: 0 16px; }
  .live #live-text { display: none; }
  main { padding: 24px 16px 60px; }
  .display { font-size: 34px; }
}
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.filters { display: flex; gap: 8px; }
.filters select { width: auto; padding: 8px 32px 8px 12px; }

/* ------------------------------------------------------------ maps */
.map { height: 260px; border-radius: var(--radius); border: 1px solid var(--line); margin-bottom: 8px; z-index: 0; background: var(--surface); }
.leaflet-tile-pane { filter: grayscale(1) contrast(.92) brightness(1.04); }
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane { filter: grayscale(1) invert(1) contrast(.85) brightness(.9); }
}
.leaflet-container { font: 12px var(--sans); }
.leaflet-control-attribution { background: color-mix(in srgb, var(--bg) 80%, transparent) !important; color: var(--muted) !important; }
.leaflet-bar a { color: var(--text) !important; background: var(--surface) !important; border-color: var(--line) !important; }

/* ------------------------------------------------------------ task list */
.list { border-top: 1px solid var(--line); }
.task {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: baseline;
  padding: 16px 4px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.task:hover .t-title { text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 4px; }
.task.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 10%, transparent); } to { background: transparent; } }
.t-type { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.t-title { font-family: var(--serif); font-size: 18px; line-height: 1.35; }
.t-meta { font-size: 13px; color: var(--muted); margin-top: 4px; }
.t-right { text-align: right; font-size: 13px; color: var(--muted); display: grid; gap: 2px; justify-items: end; }
.t-budget { color: var(--text); font-weight: 500; font-size: 14px; }
.empty { color: var(--muted); padding: 28px 4px; font-size: 14px; border-bottom: 1px solid var(--line); }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-open { color: var(--ok); }
.st-claimed { color: var(--accent); }
.st-submitted { color: var(--warn); }
.st-completed { color: var(--text); }
.st-cancelled { color: var(--faint); }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line-strong); border-radius: 4px; padding: 0 5px; margin-left: 4px; vertical-align: 1px; }

/* ------------------------------------------------------------ activity */
.feed { list-style: none; padding: 0; margin: 0; max-height: 72vh; overflow: auto; }
.feed li { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; line-height: 1.45; }
.feed li a { text-decoration: none; font-weight: 500; }
.feed li a:hover { text-decoration: underline; }
.feed time { color: var(--faint); font-size: 12px; display: block; margin-top: 2px; }
.feed .empty-feed { border: 0; }

/* ------------------------------------------------------------ post form */
.step-label { font: 500 12px var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 30px 0 12px; }
#post-form > .step-label:first-child { margin-top: 0; }
.type-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 700px) { .type-options { grid-template-columns: 1fr; } }
.type-option {
  text-align: left; padding: 16px; border-radius: var(--radius); border: 1px solid var(--line-strong);
  background: var(--surface); cursor: pointer; font: inherit; color: var(--text); transition: border-color .15s;
}
.type-option:hover { border-color: var(--muted); }
.type-option[aria-checked="true"] { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.type-option .to-name { font-family: var(--serif); font-size: 17px; margin-bottom: 4px; }
.type-option .to-desc { font-size: 13px; color: var(--muted); line-height: 1.45; }

.field { margin-bottom: 20px; }
.field > label { display: block; font-weight: 500; font-size: 14px; margin-bottom: 6px; }
.field .opt { font-weight: 400; color: var(--faint); font-size: 13px; margin-left: 4px; }
.field .help { font-size: 13px; color: var(--muted); margin-top: 6px; display: flex; justify-content: space-between; gap: 12px; }
.field.invalid input, .field.invalid textarea { border-color: var(--bad); }
.field .err { color: var(--bad); font-size: 13px; margin-top: 6px; }
.counter { white-space: nowrap; font-variant-numeric: tabular-nums; }
.counter.met { color: var(--ok); }
.row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 700px) { .row { grid-template-columns: 1fr; } }
.loc-row { display: flex; gap: 8px; margin-bottom: 8px; }
.loc-group { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; background: color-mix(in srgb, var(--surface) 50%, transparent); }
.mini-map { height: 200px; border-radius: 8px; border: 1px solid var(--line); z-index: 0; }

.msg { margin-top: 12px; font-size: 14px; }
.msg.err { color: var(--bad); }
.msg.ok { color: var(--ok); }

/* ------------------------------------------------------------ modal */
.modal { position: fixed; inset: 0; background: rgba(20, 19, 17, .32); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 2000; overflow: auto; }
.modal-card { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 32px; width: 100%; max-width: 640px; position: relative; box-shadow: 0 24px 60px rgba(0,0,0,.12); }
.close { position: absolute; top: 14px; right: 16px; border: 0; background: none; font-size: 22px; color: var(--muted); cursor: pointer; }
.close:hover { color: var(--text); }
.modal-card h2 { font-family: var(--serif); font-weight: 400; font-size: 26px; line-height: 1.25; margin: 6px 36px 8px 0; }
.kv { margin: 22px 0 0; border-top: 1px solid var(--line); }
.kv > div { display: grid; grid-template-columns: 150px 1fr; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.kv .sub { color: var(--muted); font-size: 12px; }
@media (max-width: 560px) { .kv > div { grid-template-columns: 1fr; gap: 2px; } .modal-card { padding: 24px 20px; } }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 22px; }
.notice { margin-top: 18px; padding: 12px 14px; border-radius: 8px; font-size: 14px; border: 1px solid var(--line-strong); }
.notice.bad { border-color: color-mix(in srgb, var(--bad) 45%, transparent); color: var(--bad); }
.proof { margin-top: 22px; }
.proof img { max-width: 100%; border-radius: 8px; display: block; margin-top: 10px; border: 1px solid var(--line); }
.gps-ok { color: var(--ok); } .gps-bad { color: var(--bad); }
.history { list-style: none; padding: 0; margin: 0; font-size: 13px; color: var(--muted); }
.history li { padding: 3px 0; }
.submit-box { display: grid; gap: 10px; margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--line); }
.preview { max-width: 180px; border-radius: 8px; border: 1px solid var(--line); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--ink-text); padding: 10px 16px; border-radius: 8px; z-index: 3000; font-size: 14px; max-width: calc(100vw - 32px); }

/* ------------------------------------------------------------ auth */
.auth { max-width: 1040px; margin: 9vh auto 80px; padding: 0 28px; display: grid; grid-template-columns: 1fr 520px; gap: 56px; align-items: start; }
@media (max-width: 960px) { .auth { grid-template-columns: 1fr; gap: 24px; margin-top: 6vh; padding: 0 16px; } }
.auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; }
.seg { display: inline-flex; padding: 3px; border-radius: 9px; background: color-mix(in srgb, var(--text) 6%, transparent); margin-bottom: 22px; }
.seg button { border: 0; background: none; font: 500 14px var(--sans); color: var(--muted); padding: 7px 14px; border-radius: 7px; cursor: pointer; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.row.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 560px) { .row.two { grid-template-columns: 1fr; } }
.btn.wide { width: 100%; }
.post-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 20px; margin-top: 4px; }
.post-actions .msg { margin: 0; }

/* ------------------------------------------------------------ avatars */
.avatar-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
@media (max-width: 560px) { .avatar-grid { grid-template-columns: repeat(5, 1fr); } }
.avatar-opt { padding: 0; border: 2px solid transparent; border-radius: 9px; background: none; cursor: pointer; aspect-ratio: 1; overflow: hidden; transition: transform .12s, border-color .12s; }
.avatar-opt img { width: 100%; height: 100%; display: block; image-rendering: pixelated; border-radius: 7px; }
.avatar-opt:hover { transform: translateY(-1px); }
.avatar-opt[aria-checked="true"] { border-color: var(--text); }
.avatar-name { font-size: 13px; color: var(--muted); margin-top: 8px; min-height: 1.5em; }
.av { width: 22px; height: 22px; border-radius: 5px; image-rendering: pixelated; vertical-align: -6px; margin-right: 6px; }
.av.lg { width: 40px; height: 40px; border-radius: 8px; vertical-align: middle; }
.av.xl { width: 112px; height: 112px; border-radius: 14px; margin: 0; }
.me-chip { display: inline-flex; align-items: center; gap: 2px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: 500 13px var(--sans); padding: 3px 10px 3px 3px; border-radius: 99px; cursor: pointer; }
.me-chip .av { margin-right: 6px; vertical-align: middle; border-radius: 99px; }
.me-chip.active, .me-chip:hover { border-color: var(--text); }
.user-link { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; }
.user-link:hover .un { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }

/* ------------------------------------------------------------ type bar */
.typebar { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 18px; gap: 4px; overflow-x: auto; }
.typebar button { background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: 10px 14px 12px; font: 500 14px var(--sans); color: var(--muted); cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; }
.typebar button:hover { color: var(--text); }
.typebar button.active { color: var(--text); border-bottom-color: var(--text); }
.typebar .count { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); background: color-mix(in srgb, var(--text) 7%, transparent); border-radius: 99px; padding: 0 7px; min-width: 22px; text-align: center; }
.typebar button.active .count { background: var(--ink); color: var(--ink-text); }

/* ------------------------------------------------------------ profile */
.profile-head { display: flex; gap: 22px; align-items: center; margin-bottom: 24px; }
.profile-head h1 { margin: 0; }
.profile-head .handle { color: var(--muted); font-size: 14px; margin-top: 2px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; background: var(--surface); }
.stats > div { padding: 14px 16px; border-left: 1px solid var(--line); }
.stats > div:first-child { border-left: 0; }
.stats .k { font-size: 12px; color: var(--muted); }
.stats .v { font-family: var(--serif); font-size: 22px; margin-top: 2px; overflow-wrap: anywhere; line-height: 1.25; }
.stats .v.small { font-family: var(--sans); font-size: 14px; padding-top: 6px; }
@media (max-width: 640px) { .stats { grid-template-columns: 1fr 1fr; } .stats > div:nth-child(3) { border-left: 0; } .stats > div:nth-child(n+3) { border-top: 1px solid var(--line); } }
.profile-edit { margin-top: 16px; }
.stars { display: inline-flex; gap: 2px; }
.stars button { background: none; border: 0; padding: 2px; font-size: 22px; line-height: 1; color: var(--line-strong); cursor: pointer; }
.stars button.on, .stars:hover button { color: var(--accent); }
.stars button:hover ~ button { color: var(--line-strong); }
.rate-box { margin-top: 22px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 14px; }

.site-footer { display: flex; gap: 20px; justify-content: center; padding: 0 16px 36px; font-size: 13px; }
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--text); text-decoration: underline; }
