/* ---------------------------------------------------------------------------
   Design direction: a night-adapted survey chart, not a neon Miami pastiche.
   This gets read on a phone, in a dark room, mid-session, at a glance. Legibility
   and tap size beat atmosphere. Colour is reserved for state (found / needs work /
   active), never decoration.
--------------------------------------------------------------------------- */

:root {
  --ink:        #0B161C;
  --chart:      #10202A;
  --chart-hi:   #162C38;
  --rule:       #24404F;
  --rule-soft:  #1A303C;
  --text:       #DCE6EA;
  --dim:        #85A3B0;
  --sound:      #7FA9BC;
  --found:      #6FA86A;
  --mark:       #D4A24A;
  --danger:     #C4705F;

  --rail: 296px;
  --bar: 52px;

  --sans: 'Barlow', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --cond: 'Barlow Condensed', 'Barlow', ui-sans-serif, system-ui, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--mark); outline-offset: 2px; }

/* ------------------------------------------------------------------- shell */

.shell {
  display: grid;
  grid-template-rows: var(--bar) 1fr;
  grid-template-columns: var(--rail) 1fr;
  grid-template-areas: 'bar bar' 'rail map';
  height: 100dvh;
}

.bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  background: var(--chart);
  border-bottom: 1px solid var(--rule);
  position: relative;
}

.wordmark {
  font-family: var(--cond);
  font-weight: 600;
  font-size: 21px;
  letter-spacing: 0.06em;
  margin: 0;
  white-space: nowrap;
}
.wordmark span { color: var(--sound); font-weight: 400; }

/* The headline stat is a rule that fills, not a number in a box. */
.survey {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.survey-track {
  flex: 1;
  height: 3px;
  background: var(--rule-soft);
  position: relative;
  min-width: 60px;
}
.survey-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: var(--found);
  transition: width 220ms ease-out;
}
.survey-num {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.survey-num b { color: var(--text); font-weight: 500; }

/* --------------------------------------------------------------------- rail */

.rail {
  grid-area: rail;
  background: var(--chart);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--rule-soft);
}
.rail-head h2 {
  font-family: var(--cond);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.04em;
  margin: 0;
  color: var(--dim);
}

.linkish {
  background: none;
  border: none;
  padding: 2px 4px;
  color: var(--sound);
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--rule);
}
.linkish:hover { text-decoration-color: var(--sound); }

.cats { flex: 1; overflow-y: auto; padding: 4px 0 12px; }

.cat {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  border-left: 2px solid transparent;
  padding: 9px 16px 10px 14px;
  text-align: left;
}
.cat:hover { background: var(--chart-hi); }
.cat[aria-pressed='false'] { opacity: 0.38; }
.cat[data-active='true'] { border-left-color: var(--mark); background: var(--chart-hi); }

.cat-swatch {
  width: 10px; height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0,0,0,.45);
}
.cat-body { min-width: 0; }
.cat-name {
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cat-meter {
  height: 2px;
  background: var(--rule-soft);
  margin-top: 6px;
  position: relative;
}
.cat-meter i {
  position: absolute; inset: 0 auto 0 0;
  width: 0;
  background: var(--found);
  transition: width 200ms ease-out;
}
.cat-count {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
.cat-count b { color: var(--found); font-weight: 500; }

.rail-foot {
  border-top: 1px solid var(--rule-soft);
  padding: 12px 16px;
  display: grid;
  gap: 8px;
}

.btn {
  border: 1px solid var(--rule);
  background: var(--chart-hi);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 2px;
  font-family: var(--cond);
  font-size: 15px;
  letter-spacing: 0.03em;
  transition: background 120ms, border-color 120ms;
}
.btn:hover { background: #1C3642; border-color: var(--sound); }
.btn-primary { background: var(--mark); border-color: var(--mark); color: #20160A; font-weight: 600; }
.btn-primary:hover { background: #E0B05A; border-color: #E0B05A; }
.btn-quiet { background: none; }
.btn-danger { border-color: var(--danger); color: var(--danger); background: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.hint { font-size: 12.5px; color: var(--dim); margin: 0; }

/* ---------------------------------------------------------------------- map */

#map {
  grid-area: map;
  background: var(--ink);
  min-height: 0;
}
.leaflet-container { background: var(--ink); font-family: var(--sans); }
.leaflet-control-zoom a {
  background: var(--chart);
  color: var(--text);
  border-color: var(--rule) !important;
}
.leaflet-control-zoom a:hover { background: var(--chart-hi); }
.leaflet-control-attribution {
  background: rgba(11,22,28,.82) !important;
  color: var(--dim) !important;
  font-size: 11px;
}
.leaflet-control-attribution a { color: var(--sound) !important; }

.leaflet-popup-content-wrapper {
  background: var(--chart);
  color: var(--text);
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: 0 10px 30px rgba(0,0,0,.55);
}
.leaflet-popup-tip { background: var(--chart); border: 1px solid var(--rule); }
.leaflet-popup-content { margin: 12px 14px; min-width: 190px; }
.leaflet-popup-close-button { color: var(--dim) !important; }

.pop-title { font-family: var(--cond); font-size: 17px; letter-spacing: .02em; margin: 0 0 2px; }
.pop-cat { font-size: 12px; color: var(--dim); margin: 0 0 8px; }
.pop-detail { font-size: 13.5px; margin: 0 0 10px; color: #C3D4DB; }
.pop-shot { width: 100%; border: 1px solid var(--rule); border-radius: 2px; margin-bottom: 10px; display: block; }
.pop-actions { display: flex; gap: 6px; }
.pop-actions .btn { flex: 1; padding: 8px 10px; font-size: 14px; }

/* Pin marks are drawn on canvas; this styles the draft marker only. */
.draft-mark {
  width: 26px; height: 26px;
  margin: -13px 0 0 -13px;
  border: 2px solid var(--mark);
  border-radius: 50%;
  background: rgba(212,162,74,.22);
  box-shadow: 0 0 0 1px rgba(0,0,0,.5);
}

/* -------------------------------------------------------------------- sheet */

.scrim {
  position: fixed; inset: 0;
  background: rgba(6,13,17,.72);
  display: none;
  z-index: 900;
}
.scrim[data-open='true'] { display: block; }

.sheet {
  position: fixed;
  z-index: 901;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(460px, calc(100vw - 24px));
  max-height: min(86dvh, 760px);
  overflow-y: auto;
  background: var(--chart);
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: 0 24px 60px rgba(0,0,0,.6);
  display: none;
}
.sheet[data-open='true'] { display: block; }
.sheet-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--rule-soft);
}
.sheet-head h2 { font-family: var(--cond); font-size: 20px; font-weight: 600; letter-spacing: .03em; margin: 0; }
.sheet-body { padding: 16px 18px; display: grid; gap: 14px; }
.sheet-foot {
  padding: 14px 18px 18px;
  display: flex; gap: 8px;
  border-top: 1px solid var(--rule-soft);
}
.sheet-foot .btn { flex: 1; }

.field { display: grid; gap: 6px; }
.field > label { font-size: 13px; color: var(--dim); }
.field input[type='text'],
.field textarea,
.field select {
  background: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 9px 11px;
  width: 100%;
}
.field textarea { resize: vertical; min-height: 72px; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--sound); outline: none; }

.coord {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.notice {
  border-left: 2px solid var(--mark);
  background: rgba(212,162,74,.07);
  padding: 9px 12px;
  font-size: 13px;
  color: #CFC09D;
}
.notice.bad { border-left-color: var(--danger); background: rgba(196,112,95,.08); color: #DDB2A8; }
.notice.good { border-left-color: var(--found); background: rgba(111,168,106,.08); color: #B4CFAF; }

/* -------------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: var(--chart-hi);
  border: 1px solid var(--rule);
  border-left: 2px solid var(--found);
  border-radius: 2px;
  padding: 10px 16px;
  font-size: 14px;
  z-index: 950;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms;
}
.toast[data-show='true'] { opacity: 1; }

/* --------------------------------------------------------------- placing UI */

body[data-placing='true'] #map { cursor: crosshair; }
.placing-bar {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: var(--bar);
  background: var(--mark);
  color: #20160A;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 14px;
  font-family: var(--cond);
  font-size: 16px;
  letter-spacing: .03em;
  z-index: 30;
}
body[data-placing='true'] .placing-bar { display: flex; }
.placing-bar button {
  background: rgba(32,22,10,.15);
  border: 1px solid rgba(32,22,10,.4);
  color: #20160A;
  border-radius: 2px;
  padding: 5px 12px;
  font-family: var(--sans);
  font-size: 13px;
}

/* ------------------------------------------------------------------- mobile */

@media (max-width: 760px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--bar) 1fr auto;
    grid-template-areas: 'bar' 'map' 'rail';
  }
  .rail {
    border-right: none;
    border-top: 1px solid var(--rule);
    max-height: 46dvh;
  }
  .rail[data-collapsed='true'] .cats,
  .rail[data-collapsed='true'] .rail-foot { display: none; }
  .rail-head { padding: 10px 14px; }
  .cat { padding-top: 11px; padding-bottom: 12px; }  /* thumb-sized rows */
  .wordmark { font-size: 18px; }
  .survey-num { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
