:root {
  --paper: #f6f1e7;
  --card: #fffdf8;
  --ink: #2f2d29;
  --ink-soft: #6b665d;
  --line: #ddd5c6;
  --accent: #c8643c;
  --accent-ink: #fff;
  --focus: #3c6fc8;
  --shadow: 0 1px 2px rgba(47, 45, 41, .08), 0 8px 24px rgba(47, 45, 41, .12);
  --radius: 14px;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", -apple-system, "Segoe UI", sans-serif;
  --hand: "Caveat", "Bradley Hand", cursive;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1f1e1b;
    --card: #2a2825;
    --ink: #f1ece2;
    --ink-soft: #b3ab9d;
    --line: #45413a;
    --accent: #e0835c;
    --focus: #8fb0ee;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #1f1e1b; --card: #2a2825; --ink: #f1ece2; --ink-soft: #b3ab9d;
  --line: #45413a; --accent: #e0835c; --focus: #8fb0ee; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

#map { position: fixed !important; inset: 0; width: 100vw; height: 100vh; height: 100dvh; background: var(--paper); }

/* ---- title and tools ---- */
.title-card {
  position: fixed; top: max(14px, env(safe-area-inset-top)); left: 16px; z-index: 2;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px 16px 11px; pointer-events: none;
}
.title-card h1 { font: 650 22px/1.1 var(--serif); margin: 0; letter-spacing: -.01em; }
.title-card p { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-soft); }

.tools {
  position: fixed; left: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 2;
  display: flex; gap: 6px; flex-wrap: wrap; max-width: calc(100vw - 32px);
}
.tool {
  min-width: 44px; height: 44px; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--card); box-shadow: var(--shadow); font-size: 20px; line-height: 1;
}
.tool.wide { font-size: 14px; font-weight: 600; padding: 0 14px; }
.tool:hover { background: var(--paper); }

/* ---- house chips on the map ---- */
.chip {
  position: relative; font: 700 14px/1 var(--hand); color: #2f2d29;
  background: #fffdf8; border: 1.5px solid #2f2d29; border-radius: 7px;
  padding: 2px 5px 1px; cursor: pointer; white-space: nowrap;
  box-shadow: 1px 1.5px 0 rgba(47, 45, 41, .35);
  transform: translateY(-34px) rotate(-2deg);
  transition: transform .15s;
}
.chip::after {
  content: ""; position: absolute; left: 50%; top: 100%; width: 1.5px; height: 10px;
  background: #2f2d29; transform: translateX(-50%);
}
.chip.quiet { border-color: #9a958c; color: #6b665d; box-shadow: none; font-size: 12px; }
.chip.quiet::after { background: #9a958c; }
.far .chip.quiet { display: none; }
.chip.sel { background: #2f2d29; color: #fffdf8; transform: translateY(-38px) scale(1.15); }
.chip:hover { transform: translateY(-36px) rotate(0); }

/* ---- hover card ---- */
.tip {
  position: fixed; left: 0; top: 0; z-index: 4; pointer-events: none;
  min-width: 170px; max-width: 260px; padding: 10px 13px 11px;
  background: var(--card); color: var(--ink); border-radius: 12px; box-shadow: var(--shadow);
  font-size: 13.5px; line-height: 1.35;
}
.tip b { display: block; font: 650 16px/1.2 var(--serif); margin-bottom: 4px; }
.tip ul { list-style: none; margin: 0; padding: 0; }
.tip li { display: flex; gap: 8px; justify-content: space-between; padding: 2px 0; }
.tip li span { font-weight: 600; }
.tip li i { font-style: normal; color: var(--ink-soft); font-size: 12.5px; text-align: right; }
.tip p { margin: 0; color: var(--ink-soft); }
.tip .tip-note { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); font-size: 12.5px; }

/* ---- the house panel ---- */
.panel {
  position: fixed; z-index: 3; top: 14px; right: 14px; bottom: 14px; width: 380px;
  background: var(--card); border-radius: 18px; box-shadow: var(--shadow);
  overflow: auto; padding: 22px 22px 26px;
}
.panel .close, .card .close {
  position: absolute; top: 10px; right: 10px; width: 40px; height: 40px;
  border: 0; background: none; font-size: 26px; cursor: pointer; border-radius: 10px; color: var(--ink-soft);
}
.panel .close:hover { background: var(--paper); }
.panel h2 { font: 650 26px/1.15 var(--serif); margin: 0 44px 4px 0; letter-spacing: -.01em; }
.panel .sub { color: var(--ink-soft); font-size: 13px; margin: 0 0 18px; }
.panel h3 { font: 600 12px/1 var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-soft); margin: 22px 0 8px; }

.people { list-style: none; margin: 0; padding: 0; }
.people li { padding: 9px 0; border-bottom: 1px solid var(--line); }
.people .line { display: flex; align-items: baseline; gap: 10px; }
.people .contact { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 3px; font-size: 13px; }
.people .contact a { color: var(--ink-soft); text-decoration: underline; text-underline-offset: 2px; overflow-wrap: anywhere; }
.people .contact a:hover { color: var(--ink); }
.people li:last-child { border-bottom: 0; }
.people .who { font-weight: 600; }
.people .kind { font-size: 12px; color: var(--ink-soft); }
.people .when { margin-left: auto; font-size: 13px; color: var(--ink-soft); text-align: right; }
.empty { color: var(--ink-soft); font-style: italic; }
.note-text { white-space: pre-wrap; margin: 0; }
.hint { font-size: 13px; color: var(--ink-soft); background: var(--paper); border-radius: 10px; padding: 10px 12px; margin: 18px 0 0; }

.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 20px; }
.primary, .secondary {
  height: 44px; padding: 0 18px; border-radius: 12px; cursor: pointer; font-weight: 600; border: 0;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:disabled { opacity: .6; cursor: default; }
.secondary { background: var(--paper); color: var(--ink); border: 1px solid var(--line); }
.link { background: none; border: 0; color: var(--ink-soft); text-decoration: underline; cursor: pointer; padding: 8px 0; }
.danger { color: #b3412a; }

/* ---- edit form ---- */
.edit-person {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; position: relative;
}
.edit-person .full { grid-column: 1 / -1; }
.edit-person .remove { position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border: 0; background: none; font-size: 20px; cursor: pointer; color: var(--ink-soft); }
label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin: 0 0 4px; }
input, select, textarea {
  width: 100%; height: 42px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card);
}
textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; }
.edit-person .full.name-row { padding-right: 30px; }

/* ---- house look picker ---- */
.styles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.style-pick {
  display: grid; justify-items: center; gap: 2px; padding: 8px 4px 6px; cursor: pointer;
  background: #fffdf8; border: 1.5px solid var(--line); border-radius: 12px; color: #2f2d29;
}
.style-pick svg { width: 60px; height: 48px; }
.style-pick span { font-size: 12px; font-weight: 600; }
.style-pick:hover { border-color: #9a958c; }
.style-pick.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.look-label { margin-top: 4px; }
.swatches { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 12px; }
.sw {
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer; padding: 0; margin: 0;
  border: 1.5px solid rgba(47, 45, 41, .35); position: relative;
}
.sw.on { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--ink); }
.sw-custom { background: conic-gradient(#e8665a, #e0b04f, #8fb28a, #7c9cc4, #a98bb8, #e8665a); overflow: hidden; }
.sw-custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.admin-row { margin: 18px 0 0; font-size: 13px; color: var(--ink-soft); }
.fine { font-size: 12.5px; color: var(--ink-soft); margin: 8px 0 0; }
.edit-person .f-phone, .edit-person .f-email { font-size: 14px; }

/* ---- sign in and dialogs ---- */
.veil {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--paper) 72%, transparent);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.card {
  position: relative; width: min(420px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--card); border-radius: 20px; box-shadow: var(--shadow); padding: 28px 26px 24px;
}
.wide-card { width: min(560px, 100%); }
.card h2 { font: 650 28px/1.1 var(--serif); margin: 6px 0 8px; }
.card .lede { color: var(--ink-soft); margin: 0 0 18px; }
.card .primary { width: 100%; margin-top: 14px; }
.card .note { font-size: 13px; background: var(--paper); border-radius: 10px; padding: 10px 12px; margin: 12px 0; }
.card #name-wrap label { margin-top: 4px; }
.msg { min-height: 1.5em; margin: 12px 0 0; font-size: 14px; color: var(--ink-soft); }
.msg.err { color: #b3412a; }
.mark { width: 64px; height: 48px; }
.mark path { fill: #fbf7ef; stroke: #2f2d29; stroke-width: 2; stroke-linejoin: round; }
.mark .roof { fill: none; stroke: #d9825b; stroke-width: 3; stroke-linecap: round; }
.mark .roof2 { stroke: #8fb28a; }

.dir-search { margin: 0 0 12px; }
.dir { list-style: none; margin: 0; padding: 0; }
.dir li button {
  display: block; width: 100%; text-align: left; border: 0; background: none; cursor: pointer;
  padding: 10px 8px; border-radius: 10px;
}
.dir li button:hover { background: var(--paper); }
.dir .addr { font-weight: 600; }
.dir .names { display: block; font-size: 13px; color: var(--ink-soft); }


.loading {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 1;
  font: 600 28px var(--hand); color: var(--ink-soft);
}

@media (max-width: 640px) {
  .title-card { padding: 8px 12px 9px; }
  .title-card h1 { font-size: 19px; }
  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 72vh;
    border-radius: 20px 20px 0 0; padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
  }
  .tools { bottom: max(12px, env(safe-area-inset-bottom)); }
  body.panel-open .tools { display: none; }
}
