/* =========================================================================
   Buffalo Landlord Lookup — Quiet Instrument
   Two voices: Hanken Grotesk (text) + IBM Plex Mono (numerals).
   Monochrome + a single signal red. Hairlines only.
   ========================================================================= */

:root {
  --ink:     #0c0c0c;
  --ink-2:   #3a3a39;
  --paper:   #fafaf7;
  --paper-2: #f1efe9;
  --rule:    #e5e3dd;
  --rule-2:  #c9c7bf;
  --signal:  #b9292d;

  /* Concern ramp — grays + signal */
  --s0: #dcd9d2;   /* clean — almost vanishes */
  --s1: #b8b4ab;   /* minor */
  --s2: #88847d;   /* notable */
  --s3: var(--signal);   /* severe */
  --s4: #6e1418;   /* demolished — dark red */

  --sans: "Hanken Grotesk", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection { background: var(--ink); color: var(--paper); }

a {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--rule-2);
}
a:hover { text-decoration-color: var(--ink); }

button { font-family: inherit; }

/* ----- Masthead ---------------------------------------------------------- */
.masthead {
  position: absolute;
  top: 0; left: 0;
  padding: 22px 24px 18px;
  z-index: 20;
  pointer-events: none;
}
.masthead > * { pointer-events: auto; }

.masthead-title {
  margin: 0;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.015em;
  color: var(--ink);
}
.masthead-meta {
  margin: 4px 0 0;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 400;
  color: var(--ink-2);
  letter-spacing: 0;
}

/* ----- Search ------------------------------------------------------------ */
#search-row {
  position: absolute;
  top: 76px; left: 24px;
  width: 360px;
  max-width: calc(100vw - 48px);
  z-index: 25;
}
#search {
  width: 100%;
  padding: 8px 0;
  font-family: var(--sans);
  font-size: 16px;
  font-weight: 400;
  background: transparent;
  color: var(--ink);
  border: 0;
  border-bottom: 1px solid var(--rule-2);
  border-radius: 0;
  outline: none;
  transition: border-color 120ms;
}
#search::placeholder { color: var(--ink-2); opacity: 0.65; }
#search:focus { border-bottom-color: var(--ink); }

#search-results {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  background: var(--paper);
  border: 1px solid var(--rule);
  max-height: 320px;
  overflow-y: auto;
  display: none;
}
#search-results.open { display: block; }
#search-results li {
  padding: 9px 14px;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 1px solid var(--rule);
  border-left: 2px solid transparent;
  transition: background 80ms, border-color 80ms;
}
#search-results li:last-child { border-bottom: 0; }
#search-results li:hover,
#search-results li.active {
  background: var(--paper-2);
  border-left-color: var(--ink);
}
#search-results li.empty { color: var(--ink-2); cursor: default; }
#search-results li.empty:hover { background: transparent; border-left-color: transparent; }

/* ----- Map --------------------------------------------------------------- */
#map {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 32px;
  background: var(--paper-2);
}

.maplibregl-ctrl-group {
  background: var(--paper) !important;
  border: 1px solid var(--rule-2) !important;
  box-shadow: none !important;
  border-radius: 0 !important;
}
.maplibregl-ctrl-group button {
  background-color: var(--paper) !important;
  border-bottom: 1px solid var(--rule) !important;
  width: 30px !important; height: 30px !important;
}
.maplibregl-ctrl-group button:last-child { border-bottom: 0 !important; }
.maplibregl-ctrl-group button:hover { background-color: var(--paper-2) !important; }
.maplibregl-ctrl-attrib {
  background: rgba(250, 250, 247, 0.85) !important;
  font-family: var(--mono) !important;
  font-size: 10px !important;
  color: var(--ink-2) !important;
}
.maplibregl-ctrl-attrib a { color: var(--ink) !important; }

/* ----- Side panel -------------------------------------------------------- */
#panel {
  position: absolute;
  top: 0; right: 0;
  width: 540px;
  max-width: 100vw;
  height: calc(100% - 32px);
  background: var(--paper);
  border-left: 1px solid var(--rule-2);
  z-index: 30;
  overflow-y: auto;
  padding: 32px 36px 40px;
  transition: transform 160ms ease-out;
}
#panel.hidden { transform: translateX(100%); }

#panel-close {
  position: absolute;
  top: 14px; right: 18px;
  background: none;
  border: 0;
  color: var(--ink-2);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  transition: color 100ms;
}
#panel-close:hover { color: var(--ink); }

#panel h2 {
  margin: 0 0 6px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--ink-2);
  text-transform: none;
}
#panel h3 {
  margin: 28px 0 10px;
  padding-top: 14px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
  border-top: 1px solid var(--rule);
  text-transform: none;
  letter-spacing: 0;
}

#panel .addr {
  font-family: var(--sans);
  font-weight: 500;
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: -0.018em;
  color: var(--ink);
  margin: 2px 0 6px;
  word-break: break-word;
}
#panel .owner {
  color: var(--ink-2);
  font-size: 13px;
  margin: 0 0 6px;
  word-wrap: break-word;
}
#panel .owner strong { font-weight: 500; color: var(--ink); }

/* Violations / complaints */
#panel ul.violations,
#panel ul.complaints {
  list-style: none;
  padding: 0;
  margin: 0;
}
#panel ul.violations li,
#panel ul.complaints li {
  padding: 10px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink);
}
#panel ul.violations li:last-child,
#panel ul.complaints li:last-child { border-bottom: 0; }
#panel ul.violations .date,
#panel ul.complaints .date {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-2);
  margin-bottom: 3px;
}

/* ----- Stats: number-over-label, no boxes ------------------------------- */
.stat-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 28px 36px;
  margin: 18px 0 8px;
  padding: 14px 0 14px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.stat {
  flex: 0 0 auto;
  min-width: 64px;
}
.stat .num {
  display: block;
  font-family: var(--mono);
  font-weight: 500;
  font-size: 26px;
  line-height: 1.05;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.stat .label {
  display: block;
  margin-top: 4px;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 400;
  color: var(--ink-2);
  text-transform: none;
  letter-spacing: 0;
}
.stat.bad .num  { color: var(--signal); }
.stat.warn .num { color: var(--ink); position: relative; }
.stat.warn .num::after {
  content: "";
  position: absolute;
  left: 0; right: 30%;
  bottom: -3px;
  height: 1px;
  background: var(--signal);
}

/* ----- CTA buttons ------------------------------------------------------- */
button.cta {
  display: block;
  width: 100%;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--ink);
  padding: 10px 14px;
  margin: 14px 0 0;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  cursor: pointer;
  transition: background 100ms, color 100ms;
  text-align: center;
}
button.cta:hover { background: var(--ink); color: var(--paper); }
button.cta:disabled { opacity: 0.4; cursor: not-allowed; }
button.cta.toggled {
  background: var(--ink);
  color: var(--paper);
}
button.cta.toggled:hover { background: var(--paper); color: var(--ink); }

/* ----- Portfolio table --------------------------------------------------- */
table.portfolio {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 4px;
}
table.portfolio thead th {
  text-align: left;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-2);
  padding: 8px 8px 8px 0;
  border-bottom: 1px solid var(--rule);
  letter-spacing: 0;
  text-transform: none;
}
table.portfolio td {
  padding: 9px 8px 9px 0;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
  color: var(--ink);
}
table.portfolio tbody tr {
  cursor: pointer;
  transition: background 80ms;
}
table.portfolio tbody tr:hover td { background: var(--paper-2); }
table.portfolio td.num {
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  padding-right: 4px;
}
table.portfolio td.num.warn { color: var(--ink); }
table.portfolio td.num.bad  { color: var(--signal); font-weight: 500; }

/* ----- Disclaimer / notes ------------------------------------------------ */
.disclaimer {
  margin-top: 22px;
  padding: 14px 0 0;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-2);
}

/* ----- Colophon (footer) ------------------------------------------------- */
.colophon {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 32px;
  padding: 0 16px;
  background: var(--paper);
  border-top: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-2);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.colophon .sep { color: var(--rule-2); }

/* ----- Legend ------------------------------------------------------------ */
.legend {
  position: absolute;
  bottom: 48px; left: 24px;
  background: transparent;
  border: 0;
  padding: 8px 12px;
  font-family: var(--sans);
  font-size: 12px;
  z-index: 20;
  color: var(--ink);
}
.legend::before {
  content: "";
  display: block;
  width: 32px;
  height: 1px;
  background: var(--rule-2);
  margin: 0 0 8px;
}
.legend .legend-row {
  display: grid;
  grid-template-columns: 14px 32px 1fr;
  align-items: center;
  gap: 10px;
  padding: 2px 0;
}
.legend .legend-range {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink);
  text-align: right;
}
.legend .legend-label {
  color: var(--ink-2);
  font-size: 12px;
}
.legend .dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 0;
  border: 0;
}
.dot.s0 { background: var(--s0); }
.dot.s1 { background: var(--s1); }
.dot.s2 { background: var(--s2); }
.dot.s3 { background: var(--s3); }
.dot.s4 { background: var(--s4); }

/* ----- Tabs / kind toggle ----------------------------------------------- */
.kind-toggle,
.tabs {
  display: flex;
  gap: 0;
  margin: 10px 0 16px;
  border-bottom: 1px solid var(--rule);
  font-family: var(--sans);
}
.kind-toggle button,
.tabs button {
  flex: 1;
  background: none;
  border: 0;
  border-bottom: 1px solid transparent;
  color: var(--ink-2);
  padding: 8px 8px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: -1px;
  transition: color 100ms, border-color 100ms;
}
.kind-toggle button:hover,
.tabs button:hover { color: var(--ink); }
.kind-toggle button.active,
.tabs button.active {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

/* ----- Leaderboard ------------------------------------------------------- */
.leaderboard {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--rule);
}
.leaderboard li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 14px;
  align-items: baseline;
  padding: 10px 4px;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  transition: background 80ms;
}
.leaderboard li:hover { background: var(--paper-2); }
.leaderboard .rank {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-2);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.leaderboard .name {
  font-family: var(--sans);
  font-weight: 500;
  font-size: 14px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.leaderboard .name .sub {
  display: block;
  margin-top: 3px;
  font-family: var(--sans);
  font-weight: 400;
  font-size: 12px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.leaderboard .stat-num {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.leaderboard li.top1 .stat-num { color: var(--signal); }

/* Constituent-LLC sub-list */
.leaderboard.llc-list {
  border-top: 1px solid var(--rule);
}
.leaderboard.llc-list li {
  grid-template-columns: 1fr auto;
  padding: 9px 4px;
}
.leaderboard.llc-list .stat-num { font-size: 12.5px; }

/* ----- Reopen-panel button ---------------------------------------------- */
#reopen-panel {
  position: absolute;
  top: 24px; right: 24px;
  z-index: 25;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--ink);
  padding: 8px 14px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
  transition: background 100ms, color 100ms;
}
#reopen-panel:hover { background: var(--ink); color: var(--paper); }
#reopen-panel.hidden { display: none; }

/* ----- Filter chip ------------------------------------------------------- */
#filter-chip {
  position: absolute;
  top: 78px;
  left: calc(24px + 360px + 12px);
  z-index: 25;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--ink);
  padding: 6px 12px;
  font-family: var(--sans);
  font-size: 12px;
  cursor: pointer;
  max-width: 380px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 100ms;
}
#filter-chip:hover { background: var(--paper-2); }
#filter-chip.hidden { display: none; }
#filter-chip strong { font-weight: 500; }
#filter-chip .count { color: var(--ink-2); }
#filter-chip .clear {
  margin-left: 10px;
  color: var(--ink-2);
  font-weight: 400;
}
#filter-chip:hover .clear { color: var(--signal); }

/* ----- Empty / error ---------------------------------------------------- */
.empty {
  color: var(--ink-2);
  font-size: 13px;
  padding: 6px 0;
}
.error {
  padding: 12px 14px;
  margin-top: 10px;
  border: 1px solid var(--signal);
  color: var(--signal);
  font-size: 13px;
}

/* ----- Panel header row + Copy link ------------------------------------ */
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin: 0 0 4px;
  padding-right: 32px;
}
.panel-head h2 { margin: 0; }

.copy-link-btn {
  font-family: var(--sans);
  font-size: 12px;
  background: transparent;
  color: var(--ink-2);
  border: 0;
  padding: 0;
  cursor: pointer;
  white-space: nowrap;
  transition: color 120ms;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: var(--rule-2);
}
.copy-link-btn:hover {
  color: var(--ink);
  text-decoration-color: var(--ink);
}
.copy-link-btn.copied {
  color: var(--signal);
  text-decoration-color: var(--signal);
}

/* ----- Confidence ------------------------------------------------------- */
.conf-badge {
  display: inline-block;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-2);
  margin: 6px 0 8px;
  letter-spacing: 0;
  text-transform: none;
  padding: 0;
  background: transparent;
  border: 0;
}
.conf-badge::before {
  content: "Confidence ";
  color: var(--ink-2);
}
.conf-badge.conf-high   { color: var(--ink); font-weight: 500; }
.conf-badge.conf-medium { color: var(--ink-2); }
.conf-badge.conf-low    { color: var(--ink-2); text-decoration: line-through; text-decoration-color: var(--ink-2); }

.conf-dot {
  display: inline-block;
  width: 5px; height: 5px;
  margin-right: 8px;
  vertical-align: 2px;
  background: var(--ink);
}
.conf-dot.conf-high   { background: var(--ink); }
.conf-dot.conf-medium { background: var(--ink-2); }
.conf-dot.conf-low    { background: var(--rule-2); }

/* ----- Evidence (plain paragraph) -------------------------------------- */
.evidence {
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-2);
  margin: 4px 0 12px;
  padding: 0;
  border: 0;
}
.evidence strong { font-weight: 500; color: var(--ink); }

/* ----- Section metadata row (sits under an h3 with freshness pills) ----- */
.section-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin: -4px 0 10px;
}
.section-meta .freshness-pill { margin-left: 0; }

/* ----- Freshness pill --------------------------------------------------- */
.freshness-pill {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--ink-2);
  margin-left: 8px;
  padding: 2px 6px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  vertical-align: 2px;
  text-transform: none;
  white-space: nowrap;
}
.freshness-pill.fresh {
  color: var(--ink);
  border-color: var(--rule-2);
}
.freshness-pill.aging {
  color: var(--ink-2);
  border-color: var(--rule-2);
}
.freshness-pill.stale {
  color: var(--signal);
  border-color: var(--signal);
}

/* ----- Audit disclosure ("How these names are grouped") ----------------- */
.audit-details {
  margin: 4px 0 14px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: 6px 0;
}
.audit-details > summary {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--ink-2);
  cursor: pointer;
  padding: 4px 0;
  list-style: none;
  user-select: none;
}
.audit-details > summary::-webkit-details-marker { display: none; }
.audit-details > summary::before {
  content: "▸ ";
  display: inline-block;
  width: 12px;
  color: var(--rule-2);
}
.audit-details[open] > summary::before { content: "▾ "; }
.audit-details[open] > summary { color: var(--ink); }

.audit-list {
  list-style: none;
  margin: 6px 0 4px;
  padding: 0;
  font-size: 13px;
  line-height: 1.55;
}
.audit-list > li {
  padding: 3px 0;
  border-bottom: 1px dotted var(--rule);
}
.audit-list > li:last-child { border-bottom: 0; }
.audit-key {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-2);
  margin-right: 6px;
  min-width: 7em;
}
.audit-list .sub {
  display: inline;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-2);
}
.audit-foot {
  margin: 8px 0 0;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--ink-2);
}

/* ----- Bottom-sheet handle (phone only; hidden until phone breakpoint) ---- */
.panel-handle {
  display: none;
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 28px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  z-index: 2;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  border-radius: 14px 14px 0 0;
  transition: background 120ms;
}
.panel-handle:hover,
.panel-handle:focus-visible { background: var(--paper-2); outline: none; }
.panel-handle:active { cursor: grabbing; background: var(--paper-2); }
.panel-handle > span {
  display: block;
  width: 56px;
  height: 5px;
  margin: 11px auto 0;
  background: var(--ink-2);
  border-radius: 3px;
  opacity: 0.55;
  transition: opacity 120ms, transform 120ms;
}
.panel-handle:hover > span,
.panel-handle:active > span { opacity: 0.85; transform: scaleX(1.05); }
.audit-summary-mobile { display: none; }

/* One-time hint bounce — JS adds .nudge-once to the panel when the sheet
   first appears on a phone, removes it after the animation runs. */
@keyframes sheet-nudge {
  0%   { transform: translateY(0); }
  18%  { transform: translateY(-22px); }
  36%  { transform: translateY(0); }
  54%  { transform: translateY(-10px); }
  72%  { transform: translateY(0); }
  100% { transform: translateY(0); }
}
#panel.nudge-once { animation: sheet-nudge 1100ms ease-out 1; }

/* ----- Tablet (481-880px) ------------------------------------------------ */
@media (max-width: 880px) and (min-width: 481px) {
  .masthead { padding: 16px 18px 12px; }
  #search-row { top: 70px; left: 18px; right: 18px; width: auto; max-width: none; }
  #filter-chip { top: auto; bottom: 50px; left: 18px; right: 18px; max-width: none; }
  #panel { width: 360px; padding: 28px 22px 32px; }
  #reopen-panel { top: auto; bottom: 44px; right: 14px; }
  .colophon { font-size: 10.5px; }
}

/* ----- Phone (≤480px) — bottom sheet over map --------------------------- */
@media (max-width: 480px) {
  /* Chrome */
  .masthead { padding: 12px 14px 8px; }
  .masthead-title { font-size: 18px; }
  .masthead-meta { display: none; }

  #search-row {
    top: 44px; left: 12px; right: 12px;
    width: auto; max-width: none;
  }
  #search {
    padding: 12px 0;
    font-size: 16px;        /* avoid iOS zoom */
    min-height: 44px;
  }
  #search-results { max-height: 40vh; }
  #search-results li { padding: 12px 14px; min-height: 44px; }

  /* Hide MapLibre nav controls on phones — pinch-to-zoom is native; the
     controls otherwise overlap the search bar's right edge. */
  .maplibregl-ctrl-top-right { display: none; }

  /* Map fills below the search row; sheet floats above */
  #map { bottom: 0; }
  .colophon { display: none; }
  .legend { display: none; }
  #reopen-panel { display: none; }
  #filter-chip {
    top: auto;
    left: 12px; right: 12px;
    bottom: calc(120px + 12px);   /* sit above the sheet at peek */
    max-width: none;
    padding: 10px 14px;
    font-size: 13px;
    min-height: 44px;
    text-align: center;
  }

  /* Bottom sheet ------------------------------------------------------- */
  #panel {
    top: auto; right: 0; left: 0; bottom: 0;
    width: 100%; max-width: 100%;
    height: 55vh;
    padding: 38px 18px 26px;
    border-left: 0;
    border-top: 1px solid var(--rule-2);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.06);
    transition: height 200ms ease-out, transform 200ms ease-out;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  #panel.hidden {
    transform: none;
    height: 60px;            /* peek strip when closed */
    padding-top: 28px;
    padding-bottom: 8px;
    overflow: hidden;
  }
  #panel.hidden #panel-content { display: none; }
  #panel.sheet-peek {
    height: 120px;
  }
  #panel.sheet-half {
    height: 55vh;
  }
  #panel.sheet-full {
    height: 92vh;
  }
  /* While the user is dragging the handle, freeze the inner scroll so the
     gesture only resizes the sheet — not the content underneath. */
  #panel.dragging {
    overflow: hidden;
    touch-action: none;
  }

  .panel-handle { display: block; }
  #panel-close {
    top: 34px; right: 8px;     /* below the handle strip */
    font-size: 24px;
    padding: 6px 10px;
    min-width: 44px; min-height: 44px;
  }

  /* Tighten panel typography for the small screen */
  #panel { padding-top: 30px; }
  #panel .addr { font-size: 22px; }
  #panel h3 { margin-top: 18px; padding-top: 10px; }
  .stat-grid { gap: 16px 22px; }
  .stat .num { font-size: 22px; }

  /* Wider tap targets on common interactive elements */
  button.cta { padding: 12px 14px; min-height: 44px; }
  .copy-link-btn { padding: 6px 0; }
  .leaderboard li { padding: 12px 6px; min-height: 44px; }
  .kind-toggle button,
  .tabs button { padding: 12px 6px; min-height: 44px; }

  /* Tabs scroll horizontally on phones (5 boards × 2 kinds doesn't fit) */
  .tabs,
  .kind-toggle {
    overflow-x: auto;
    flex-wrap: nowrap;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }
  .tabs::-webkit-scrollbar,
  .kind-toggle::-webkit-scrollbar { display: none; }
  .tabs button,
  .kind-toggle button {
    flex: 0 0 auto;
    scroll-snap-align: start;
    min-width: max-content;
    padding-left: 14px; padding-right: 14px;
  }

  /* Portfolio table → stacked cards
     Each <tr> becomes a card; each <td> becomes a labeled flex row using the
     data-label attribute set in JS. */
  table.portfolio,
  table.portfolio thead,
  table.portfolio tbody,
  table.portfolio tr,
  table.portfolio td {
    display: block;
    width: 100%;
  }
  table.portfolio thead { display: none; }
  table.portfolio tr {
    border: 1px solid var(--rule);
    padding: 10px 12px;
    margin-bottom: 8px;
    cursor: pointer;
  }
  table.portfolio td {
    border: 0;
    padding: 4px 0;
    text-align: left !important;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
  }
  table.portfolio td.num { padding: 4px 0; font-size: 13px; }
  table.portfolio td:first-child {
    font-weight: 500;
    border-bottom: 1px solid var(--rule);
    padding-bottom: 8px;
    margin-bottom: 4px;
    display: block;          /* address line is full width */
  }
  table.portfolio td[data-label]::before {
    content: attr(data-label);
    font-family: var(--sans);
    font-size: 11px;
    color: var(--ink-2);
    letter-spacing: 0;
    text-transform: none;
    margin-right: 12px;
  }

  /* Operator audit: swap "How these names are grouped" for a one-line summary */
  .audit-summary-desktop { display: none; }
  .audit-summary-mobile  { display: inline; }
  .audit-list .audit-key { display: block; min-width: 0; margin-bottom: 2px; }
  .audit-list > li { padding: 6px 0; }
}

/* Use dynamic-viewport units when available so iOS Safari address-bar
   collapse doesn't break the sheet height. */
@supports (height: 100dvh) {
  @media (max-width: 480px) {
    #panel.sheet-half { height: 55dvh; }
    #panel.sheet-full { height: 92dvh; }
  }
}

/* Suppress 300ms tap delay on common interactive elements */
button, a, .leaderboard li, table.portfolio tbody tr, #search-results li,
.tabs button, .kind-toggle button, .panel-handle, #filter-chip {
  touch-action: manipulation;
}

/* ----- Reduced motion --------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
