:root {
  --paper: #F3F5F9; --card: #FFFFFF; --ink: #1B2A4A; --muted: #5B6780; --line: #DCE1EA;
  --gold: #F2A900; --leaf: #1F8A5B; --brick: #C8402F; --amber: #9A6A00;
  --plate: #1B2A4A; --primary: #1B2A4A; --on-primary: #FFFFFF;
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --tabs-h: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0E1525; --card: #172038; --ink: #EDF0F7; --muted: #9AA6C0; --line: #2A3654;
    --leaf: #4CC38A; --brick: #F0806F; --amber: #F2C14E;
    --plate: #0A101D; --primary: #F2A900; --on-primary: #1B2A4A;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.45 var(--body); overscroll-behavior-y: none; }
h1, h2, h3, .score b, .plaque { font-family: var(--display); }
h1 { font-size: 1.75rem; font-weight: 800; line-height: 1.1; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 0; line-height: 1.25; }
h3 { font-size: 1.05rem; font-weight: 600; margin: 0 0 8px; }
p { margin: 0 0 8px; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.muted { color: var(--muted); font-size: 0.9rem; }
.sub { color: var(--muted); margin: 4px 0 0; }

#app { max-width: 640px; margin: 0 auto; min-height: 100dvh; padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px); }
main { padding: 0 16px; }
.top { padding: calc(env(safe-area-inset-top) + 20px) 16px 14px; }
.top.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; position: sticky; top: 0; z-index: 5;
  background: var(--paper); padding-bottom: 10px; padding-top: calc(env(safe-area-inset-top) + 12px); border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.back { font-weight: 600; text-decoration: none; padding: 10px 0; }
.back::before { content: "‹ "; }
.bar-title { font-weight: 600; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 20px; border-radius: 12px;
  border: 2px solid var(--primary); background: var(--primary); color: var(--on-primary); font-weight: 600; text-decoration: none; width: 100%; }
.btn.small { min-height: 40px; padding: 0 14px; width: auto; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--brick); border-color: var(--brick); margin-top: 12px; }
.quiet { background: none; border: 0; padding: 8px 0; color: var(--muted); text-decoration: underline; font-size: 0.85rem; }
.links { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 0; }
.links .btn { width: auto; flex: 1 1 auto; min-height: 44px; padding: 0 12px; font-size: 0.92rem; }

/* Bottom tabs and add button */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { flex: 1; max-width: 160px; height: var(--tabs-h); display: grid; place-items: center; text-decoration: none; font-weight: 600;
  font-size: 0.9rem; color: var(--muted); border-top: 3px solid transparent; }
.tabs a[aria-current] { color: var(--ink); border-top-color: var(--gold); }
/* The centre tab is the one main action: add a house */
.tabs a.add { border-top-color: transparent; }
.tabs a.add span { display: grid; place-items: center; width: 52px; height: 40px; border-radius: 14px; background: var(--gold); color: #1B2A4A;
  font: 800 1.7rem/1 var(--display); transition: transform 0.12s; }
.tabs a.add:active span { transform: scale(0.94); }

.with-gear { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.gear { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; color: var(--muted); flex: none; }
.gear:hover { color: var(--ink); background: var(--card); }

/* Notes on the home screen */
.note { display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--muted);
  border-radius: 10px; padding: 12px 14px; margin: 0 0 10px; font-size: 0.92rem; text-decoration: none; }
.note.link { border-left-color: var(--gold); font-weight: 600; }
.note.warn { border-left-color: var(--brick); }

/* The house-number plaque: rank shown the way a door shows its number */
.plaque { display: inline-grid; place-items: center; min-width: 40px; height: 40px; padding: 0 8px; background: var(--plate); color: var(--gold);
  font-weight: 800; font-size: 1.25rem; border-radius: 8px; border: 2px solid var(--gold); box-shadow: 0 0 0 2px var(--plate); flex: none; }

/* House cards */
/* House cards: photo first; a house with no photo is a compact row */
.cards { display: grid; gap: 14px; }
.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; text-decoration: none;
  transition: transform 0.15s, box-shadow 0.15s; }
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgb(27 42 74 / 0.12); }
.card:active { transform: scale(0.99); }
.card.dim { opacity: 0.6; }
.cover { position: relative; aspect-ratio: 16 / 10; background: var(--line); overflow: hidden; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.3s; }
.card:hover .cover img { transform: scale(1.03); }
.cover .plaque { position: absolute; left: 12px; top: 12px; }
.cover .score { position: absolute; right: 12px; top: 12px; background: var(--card); color: var(--ink); border-radius: 12px; padding: 6px 10px; }
.cover .score b { font-size: 1.6rem; }
.cover .score.none { max-width: none; padding: 8px 10px; }
.card-body { display: flex; gap: 12px; align-items: center; padding: 12px 14px 14px; }
.card-text { min-width: 0; flex: 1; }
.card-body p { margin: 2px 0 0; font-size: 0.9rem; }
.card-body h2 { font-size: 1.15rem; }
.loc { color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px !important; }
.tag { font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); }
.tag.good { color: var(--leaf); border-color: var(--leaf); }
.tag.bad { color: var(--brick); border-color: var(--brick); }
.tag.warn { color: var(--amber); border-color: var(--amber); }
.score { text-align: center; padding: 0 6px; }
.score b { display: block; font-size: 2rem; font-weight: 800; line-height: 1; }
.score span { font-size: 0.7rem; color: var(--muted); }
.score.none { font-size: 0.75rem; color: var(--muted); max-width: 60px; }

.empty { text-align: center; padding: 48px 12px; }
.empty p { color: var(--muted); margin: 8px auto 20px; max-width: 34ch; }
.empty .btn + .btn { margin-top: 10px; }

/* House page sections */
.seg-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; margin: 0 0 12px; background: var(--line); border-radius: 14px; }
.seg-tabs button { min-height: 44px; border: 0; border-radius: 10px; background: transparent; font-weight: 600; color: var(--muted); position: relative; }
.seg-tabs button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgb(27 42 74 / 0.15); }
.seg-tabs .dot { position: absolute; top: 8px; right: 10px; width: 8px; height: 8px; border-radius: 50%; background: var(--brick); }
.fine > section { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.btn.ghost + .btn.danger { margin-top: 10px; }
.btn:active { transform: scale(0.98); }

/* Detail */
.title { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.title h1 { font-size: 1.5rem; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin: 0 0 12px; }
details.panel > summary { font-family: var(--display); font-weight: 600; font-size: 1.05rem; cursor: pointer; padding: 4px 0; }
details.panel[open] > summary { margin-bottom: 10px; }

.media { margin: 0 -16px 16px; }
.strip { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 0 16px 6px; }
.shot { flex: 0 0 88%; max-width: 520px; margin: 0; scroll-snap-align: center; }
.shot:only-child { flex-basis: 100%; max-width: none; }
.shot > button { display: block; padding: 0; border: 0; background: none; width: 100%; }
.shot img, .shot video { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 12px; background: var(--line); display: block; }
.shot figcaption, .voice > div { display: flex; justify-content: space-between; gap: 8px; }
.shot figcaption button:first-child, .voice button:first-child { background: none; border: 0; padding: 8px 0; text-align: left; font-size: 0.88rem; }
.strip-empty { padding: 28px 16px; margin: 0 16px 8px; text-align: center; color: var(--muted); border: 2px dashed var(--line); border-radius: 12px; }
.voice { padding: 0 16px; margin-top: 6px; }
.voice audio { width: 100%; height: 40px; }
.capture { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 8px 16px 0; }
.cap { display: grid; place-items: center; min-height: 52px; border-radius: 12px; border: 2px solid var(--ink); background: var(--card); font-weight: 600;
  font-size: 0.9rem; text-align: center; padding: 4px; cursor: pointer; }
.cap.rec { background: var(--brick); border-color: var(--brick); color: #fff; }

.score-head { display: flex; gap: 14px; align-items: center; }
.score-head .score b { font-size: 3rem; }
.score-head h3 { margin: 0; }
.flag { color: var(--brick); font-weight: 600; font-size: 0.92rem; margin: 10px 0 0; padding-left: 10px; border-left: 3px solid var(--brick); }
.breakdown { margin-top: 12px; }
.breakdown summary { font-weight: 600; cursor: pointer; padding: 8px 0; }
.bars { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 8px; }
.bars li { display: grid; grid-template-columns: 1fr 90px 52px; gap: 8px; align-items: center; font-size: 0.88rem; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--gold); }
.bv { text-align: right; font-variant-numeric: tabular-nums; }
.bars .unknown { color: var(--muted); }
.bars .unknown .bv { font-size: 0.75rem; }

.rate { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.rate-label { min-width: 0; }
.rate-label small { display: block; color: var(--muted); font-size: 0.78rem; }
.stars { display: flex; gap: 4px; flex: none; }
.stars button { width: 36px; height: 38px; padding: 0; border-radius: 10px; border: 1px solid var(--line); background: transparent; font-weight: 600; }
.stars button[aria-pressed="true"] { background: var(--gold); border-color: var(--gold); color: #1B2A4A; }

.facts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin: 0; }
.facts-grid .wide { grid-column: 1 / -1; }
.issues ul { list-style: none; margin: 0; padding: 0; }
.issues li { padding: 8px 0 8px 10px; border-top: 1px solid var(--line); border-left: 3px solid var(--brick); font-size: 0.92rem; }
.issues li span { color: var(--muted); font-size: 0.8rem; display: block; }
.facts-grid dt { color: var(--muted); font-size: 0.8rem; }
.facts-grid dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; white-space: pre-wrap; }
.places { list-style: none; margin: 0 0 8px; padding: 0; }
.places li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); font-size: 0.92rem; }
.places li span:first-child { font-weight: 600; }

.thread { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.thread li { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.thread li p { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.thread .req { border-left: 4px solid var(--brick); }
.thread .req.done { border-left-color: var(--leaf); opacity: 0.75; }
.who { font-weight: 600; font-size: 0.85rem; margin-bottom: 2px !important; }
.who span { font-weight: 400; color: var(--muted); margin-left: 8px; }

/* Forms */
.field { display: block; margin: 0 0 12px; }
.field > span { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; }
.field small { color: var(--muted); font-size: 0.8rem; }
input:not([type="checkbox"]):not([type="range"]):not([type="radio"]), select, textarea { width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--paper); font-size: 16px; }
textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: 10px; min-height: 40px; font-size: 0.95rem; }
.check input { width: 22px; height: 22px; accent-color: var(--gold); flex: none; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
/* Inspection rows: one tap marks OK, Fix or N/A */
.irow { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 0.95rem; }
.seg { display: flex; flex: none; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.seg span { display: grid; place-items: center; min-width: 48px; height: 44px; padding: 0 8px; font-weight: 600; font-size: 0.85rem; cursor: pointer; }
.seg label + label span { border-left: 1px solid var(--line); }
.seg input:checked + span { background: var(--leaf); color: #fff; }
.seg input[value="fix"]:checked + span { background: var(--brick); }
.seg input[value="na"]:checked + span { background: var(--muted); }
.seg input:focus-visible + span { outline: 3px solid var(--gold); outline-offset: -3px; }
.row3 { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.row2 { display: grid; grid-template-columns: 1fr 1.4fr; gap: 6px; margin-bottom: 6px; }
#comment { display: grid; gap: 6px; }
.weight { display: grid; grid-template-columns: 1fr 120px 52px; gap: 10px; align-items: center; padding: 6px 0; font-size: 0.92rem; }
.weight input { accent-color: var(--gold); width: 100%; height: 32px; }
.weight output { text-align: right; font-weight: 600; font-size: 0.85rem; }
.savebar { position: sticky; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px); padding-top: 8px; z-index: 4; }
#edit .savebar { bottom: calc(env(safe-area-inset-bottom) + 12px); }
.savebar .btn { box-shadow: 0 6px 18px rgb(27 42 74 / 0.28); }

.gate { padding: 22vh 24px 0; max-width: 420px; margin: 0 auto; }
.gate form { margin-top: 28px; }

/* Compare */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chips button { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 14px; font-size: 0.88rem; min-height: 40px; }
.chips button[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { border-collapse: collapse; font-size: 0.88rem; min-width: 100%; background: var(--card); }
th, td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; min-width: 120px; }
tbody th, thead th:first-child { position: sticky; left: 0; background: var(--card); min-width: 104px; max-width: 120px; font-weight: 600; color: var(--muted); z-index: 1; }
td b { font-family: var(--display); font-size: 1.3rem; }

/* Map */
#map { height: calc(100dvh - var(--tabs-h) - env(safe-area-inset-bottom) - 190px); min-height: 320px; margin: 0 16px; border-radius: 16px; border: 1px solid var(--line); z-index: 0; }
.map-actions { display: flex; gap: 8px; padding: 10px 16px 0; }
.map-hint { margin: 8px 16px 0; font-weight: 600; color: var(--amber); }
.map-fail { padding: 40px 20px; text-align: center; color: var(--muted); }
.pin-house { display: grid; place-items: center; width: 34px; height: 34px; margin: -17px 0 0 -17px; background: #1B2A4A; color: #F2A900; border: 2px solid #F2A900;
  border-radius: 8px; font: 800 15px var(--display); box-shadow: 0 2px 6px rgb(0 0 0 / 0.4); }
.pin-house.flagged { border-color: #C8402F; color: #fff; background: #C8402F; }
.pin-place { display: inline-block; transform: translate(-50%, -50%); white-space: nowrap; background: #F2A900; color: #1B2A4A; font: 700 12px var(--body);
  padding: 4px 8px; border-radius: 999px; border: 2px solid #1B2A4A; box-shadow: 0 2px 6px rgb(0 0 0 / 0.4); }
.km-tip { background: #1B2A4A; color: #fff; border: 0; font-weight: 700; padding: 2px 6px; box-shadow: none; }
.km-tip::before { display: none; }
.pop-dist { margin: 6px 0 2px; padding-left: 16px; }

.lightbox { position: fixed; inset: 0; z-index: 30; background: rgb(8 12 22 / 0.94); display: grid; place-content: center; justify-items: center; gap: 12px; padding: 16px; color: #fff; }
.lightbox img { max-width: 100%; max-height: 78dvh; border-radius: 8px; }
.lightbox .btn { background: #fff; color: #1B2A4A; border-color: #fff; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px); z-index: 40;
  background: #1B2A4A; color: #fff; padding: 12px 18px; border-radius: 12px; max-width: min(92vw, 420px); font-size: 0.92rem; font-weight: 600;
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.3); border: 1px solid #F2A900; }

@media (prefers-reduced-motion: no-preference) { .strip { scroll-behavior: smooth; } }
@media (prefers-reduced-motion: reduce) { .card, .cover img, .btn, .tabs a.add span { transition: none; transform: none !important; } }
