:root {
  --ink: #eef1f6;
  --muted: #9aa5b8;
  --glass: rgba(14, 19, 30, 0.72);
  --line: rgba(255, 255, 255, 0.1);
  --gold: #ffbf6b;
  --mine: #fff1c4;
  --avail: #5fd4c4;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: #070a12;
  color: var(--ink);
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.loading {
  position: fixed; inset: 0; display: grid; place-items: center;
  font-family: "Cormorant Garamond", serif; font-size: 1.4rem; color: var(--muted);
  background: #070a12; transition: opacity 0.6s; z-index: 20;
}
.loading.done { opacity: 0; pointer-events: none; }
.loading.failed { font-family: Inter, system-ui, sans-serif; font-size: 0.95rem; padding: 24px; text-align: center; }
.loading.failed div { max-width: 460px; }
.loading.failed b { display: block; color: var(--ink); font-size: 1.1rem; margin-bottom: 6px; }
.loading.failed code { color: var(--gold); }

.top, .controls, .panel, .tip {
  position: fixed;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* Header */
.top {
  top: 16px; left: 16px; right: 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 18px;
}
.brand h1 {
  margin: 0; font-family: "Cormorant Garamond", serif; font-weight: 600;
  font-size: 1.9rem; letter-spacing: 0.02em; line-height: 1.1;
}
.brand p { margin: 0; color: var(--muted); font-size: 0.8rem; letter-spacing: 0.04em; }

.stats { display: grid; grid-template-columns: auto auto; column-gap: 22px; min-width: 200px; }
.stat b { display: block; font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; }
.stat:first-child b { color: var(--gold); }
.stat:nth-child(2) b { color: var(--avail); }
.bar { grid-column: 1 / -1; height: 4px; margin-top: 8px; background: rgba(95, 212, 196, 0.25); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--gold); transition: width 0.6s; }

/* Left controls */
.controls {
  top: 116px; left: 16px; width: 250px;
  padding: 16px; display: flex; flex-direction: column; gap: 14px;
  max-height: calc(100% - 170px); overflow: auto;
}

.search { display: flex; gap: 6px; }
.search input, .book input {
  flex: 1; min-width: 0; padding: 9px 11px; font: inherit; color: var(--ink);
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); border-radius: 9px;
}
.search input:focus, .book input:focus { outline: 2px solid var(--gold); outline-offset: 0; }
.search button {
  padding: 0 14px; font: inherit; font-weight: 600; color: #1a1206;
  background: var(--gold); border: 0; border-radius: 9px; cursor: pointer;
}
.search-msg { margin: -8px 0 0; min-height: 0; color: #ff9b8a; font-size: 0.78rem; }
.search-msg:empty { display: none; }

.group { display: flex; flex-direction: column; gap: 6px; }
.label { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; }
.label b { color: var(--ink); text-transform: none; letter-spacing: 0; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: rgba(255, 255, 255, 0.05); border-radius: 9px; padding: 3px; }
.seg button {
  font: inherit; font-size: 0.8rem; color: var(--muted); background: none; border: 0;
  padding: 6px 0; border-radius: 7px; cursor: pointer;
}
.seg button[aria-checked="true"] { color: var(--ink); background: rgba(255, 255, 255, 0.12); }

input[type="range"] { width: 100%; accent-color: var(--gold); }

.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 0.82rem; }
.legend li { display: flex; align-items: center; gap: 8px; }
.sw { width: 14px; height: 10px; border-radius: 3px; }
.sw-avail { background: #2a3c52; border: 1px solid #4b6683; }
.sw-sold { background: var(--gold); box-shadow: 0 0 10px var(--gold); }
.sw-mine { background: var(--mine); box-shadow: 0 0 12px var(--mine); }

.facilities summary { cursor: pointer; color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; }
.facilities dl { margin: 8px 0 0; font-size: 0.8rem; }
.facilities dt { color: var(--gold); font-weight: 600; margin-top: 6px; }
.facilities dd { margin: 0; color: var(--muted); }

.link { align-self: flex-start; font: inherit; font-size: 0.78rem; color: var(--muted); background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; }
.link:hover { color: var(--ink); }

/* Unit panel */
.panel { top: 116px; right: 16px; width: 300px; padding: 20px; max-height: calc(100% - 140px); overflow: auto; }
.panel[hidden] { display: none; }
.close {
  position: absolute; top: 10px; right: 12px; width: 30px; height: 30px;
  font-size: 1.3rem; line-height: 1; color: var(--muted); background: none; border: 0; cursor: pointer; border-radius: 8px;
}
.close:hover { color: var(--ink); background: rgba(255, 255, 255, 0.08); }
.eyebrow { margin: 0; color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; }
.panel h2 { margin: 2px 0 8px; font-family: "Cormorant Garamond", serif; font-size: 2rem; font-weight: 600; letter-spacing: 0.02em; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.pill.available { color: #062420; background: var(--avail); }
.pill.sold { color: #1a1206; background: var(--gold); }
.pill.mine { color: #1a1206; background: var(--mine); }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin: 16px 0; }
.facts dt { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; }
.facts dd { margin: 0; font-weight: 500; }

.plan { margin: -4px 0 16px; }
.plan summary { cursor: pointer; color: var(--muted); font-size: 0.78rem; }
.plan summary:hover { color: var(--ink); }
.plan img { display: block; width: 100%; height: auto; margin-top: 10px; border-radius: 10px; background: #b9b9b1; }

.book { display: flex; flex-direction: column; gap: 10px; }
.book[hidden] { display: none; }
.book label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 0.78rem; }
.primary {
  margin-top: 4px; padding: 11px; font: inherit; font-weight: 600; color: #1a1206;
  background: linear-gradient(180deg, #ffd08a, var(--gold)); border: 0; border-radius: 10px; cursor: pointer;
  box-shadow: 0 6px 24px rgba(255, 191, 107, 0.25);
}
.primary:hover { filter: brightness(1.06); }
.booked-box p, .sold-box { margin: 0 0 8px; color: var(--muted); }
.booked-box p b { color: var(--mine); }

/* Hover tooltip */
.tip { padding: 8px 12px; pointer-events: none; z-index: 10; border-radius: 10px; white-space: nowrap; }
.tip[hidden] { display: none; }
.tip b { display: block; font-size: 0.95rem; }
.tip span { color: var(--muted); font-size: 0.78rem; }
.tip .st { font-weight: 600; }
.tip .st.available { color: var(--avail); }
.tip .st.sold { color: var(--gold); }
.tip .st.mine { color: var(--mine); }

.note {
  position: fixed; left: 16px; bottom: 10px; margin: 0; max-width: 520px;
  color: rgba(154, 165, 184, 0.7); font-size: 0.7rem;
}

/* Phone: controls become a compact strip, the panel a bottom sheet */
@media (max-width: 760px) {
  .top { top: 10px; left: 10px; right: 10px; padding: 10px 14px; }
  .brand h1 { font-size: 1.4rem; }
  .brand p { font-size: 0.7rem; }
  .stats { min-width: 0; column-gap: 10px; flex-shrink: 0; }
  .stat b { font-size: 1.05rem; }
  .stat span { font-size: 0.62rem; letter-spacing: 0.04em; }
  .controls {
    top: auto; bottom: 34px; left: 10px; right: 10px; width: auto;
    padding: 12px; gap: 10px; max-height: 42vh;
  }
  .legend { flex-direction: row; flex-wrap: wrap; gap: 4px 12px; }
  .facilities, #reset { display: none; }
  .panel {
    top: auto; bottom: 0; left: 0; right: 0; width: auto;
    border-radius: var(--radius) var(--radius) 0 0; max-height: 72vh; overflow: auto; z-index: 5;
  }
  .note { bottom: 8px; left: 10px; right: 10px; }
}
