@font-face {
  font-family: 'Klavika';
  src: url('../fonts/KlavikaWebBasicLight.woff2') format('woff2'), url('../fonts/KlavikaWebBasicLight.woff') format('woff');
  font-weight: 300; font-style: normal; font-display: swap;
}
:root {
  --ink: #1f2833; --muted: #6a7480; --line: #d9dde2; --bg: #eef0f3; --card: #ffffffee;
  --slate: #2f3b4c; --accent: #415268; --sale: #c8102e; --sel: #ff7300;
  --r: 14px; --shadow: 0 6px 24px rgba(20, 30, 45, .16);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font-family: 'Klavika', system-ui, sans-serif; font-weight: 300; font-synthesis: none;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
button, input, a { font: inherit; color: inherit; }
#view, #view canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* top bar */
#bar { position: fixed; top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px; display: flex; align-items: center;
  justify-content: space-between; gap: 10px; pointer-events: none; z-index: 5; }
#bar > * { pointer-events: auto; }
h1 { margin: 0; white-space: nowrap; font-weight: 300; font-size: 22px; letter-spacing: .14em; color: #fff; background: var(--slate);
  padding: 8px 14px 6px; border-radius: 10px; box-shadow: var(--shadow); }
nav { display: flex; gap: 8px; }
.pill { white-space: nowrap; border: 0; background: var(--card); padding: 9px 15px 7px; border-radius: 999px; box-shadow: var(--shadow);
  cursor: pointer; font-size: 16px; letter-spacing: .02em; }
.pill[aria-expanded="true"] { background: var(--slate); color: #fff; }
.pill.icon { padding: 8px 10px 6px; display: grid; place-items: center; }

/* side panel (desktop) / bottom sheet (phone) */
#panel { position: fixed; z-index: 6; top: 70px; left: 12px; bottom: 12px; width: 330px; background: var(--card);
  backdrop-filter: blur(8px); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px 18px 18px; overflow: auto; }
#panel h2 { margin: 0 0 12px; font-weight: 300; font-size: 22px; }
#panel section + section { margin-top: 22px; }
.grab { display: none; }
.close { position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 26px; line-height: 1;
  cursor: pointer; color: var(--muted); padding: 4px 8px; }

/* toggle switches */
.switch { display: flex; align-items: center; gap: 12px; padding: 9px 0; font-size: 17px; cursor: pointer; border-bottom: 1px solid var(--line); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { flex: 0 0 auto; width: 42px; height: 24px; border-radius: 12px; background: #c4cad1; position: relative; transition: background .15s; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--accent); }
.switch.sale input:checked + span { background: var(--sale); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--sel); outline-offset: 2px; }
.switch em { font-style: normal; color: var(--muted); margin-left: auto; }
.wide { margin-top: 16px; width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 0 8px; cursor: pointer; font-size: 17px; }

/* the home finder tree */
#tree, #tree ul { list-style: none; margin: 0; padding: 0; }
#tree > li { border-bottom: 1px solid var(--line); }
#tree .ent { width: 100%; text-align: left; border: 0; background: none; padding: 10px 0 8px; cursor: pointer; font-size: 17px;
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
#tree .ent small { color: var(--muted); font-size: 14px; }
#tree .ent::before { content: '›'; display: inline-block; width: 14px; transition: transform .15s; color: var(--muted); }
#tree li.open > .ent::before { transform: rotate(90deg); }
#tree .ent span { flex: 1; }
#tree ul { display: none; padding: 0 0 10px 14px; }
#tree li.open > ul { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
#tree .home { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 6px 5px; cursor: pointer; font-size: 15px; text-align: center; }
#tree .home.forsale { border-color: var(--sale); color: var(--sale); }
#tree .home.sel { background: var(--slate); color: #fff; border-color: var(--slate); }

/* the home's card */
#card { position: fixed; z-index: 7; right: 12px; bottom: 12px; width: 360px; background: var(--card); backdrop-filter: blur(8px);
  border-radius: var(--r); box-shadow: var(--shadow); padding: 18px 20px 20px; }
#card .unit { margin: 0; color: var(--muted); letter-spacing: .08em; font-size: 14px; }
#card h2 { margin: 4px 0 0; font-weight: 300; font-size: 26px; line-height: 1.15; padding-right: 20px; }
#c-city { margin: 2px 0 12px; color: var(--muted); }
#c-sale { margin: 0 0 12px; padding: 10px 12px 8px; border-radius: 10px; background: #fbe9ec; color: var(--sale); font-size: 16px; }
#c-sale b { font-weight: 300; font-size: 20px; display: block; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.button { display: inline-block; text-decoration: none; background: var(--slate); color: #fff; padding: 10px 16px 8px; border-radius: 10px; font-size: 17px; }
.button.sale { background: var(--sale); }

/* loading */
#loading { position: fixed; inset: 0; z-index: 20; display: grid; place-content: center; justify-items: center; gap: 14px; background: var(--bg); transition: opacity .4s; }
#loading p { margin: 0; font-size: 34px; letter-spacing: .2em; color: var(--slate); }
#loading .bar { width: 220px; height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; }
#loading .bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
#loading small { color: var(--muted); font-size: 15px; }
#loading.done { opacity: 0; pointer-events: none; }

/* phones: the panel becomes a bottom sheet, the card sits at the bottom */
@media (max-width: 760px) {
  h1 { font-size: 16px; letter-spacing: .1em; padding: 8px 10px 6px; }
  nav { gap: 6px; }
  .pill { font-size: 15px; padding: 8px 11px 6px; }
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 62vh; border-radius: 18px 18px 0 0;
    padding: 10px 18px calc(18px + env(safe-area-inset-bottom)); }
  .grab { display: block; width: 44px; height: 5px; border-radius: 3px; background: #c4cad1; margin: 0 auto 10px; }
  #card { left: 0; right: 0; bottom: 0; width: auto; border-radius: 18px 18px 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  #card h2 { font-size: 23px; }
}
