/* Объёмный дом, собранный из шахматки.
   Никаких библиотек: каждое окно — обычная кнопка, а объём даёт CSS-перспектива.
   Это осознанный выбор. Окна остаются элементами страницы: их видит поиск,
   по ним ходит клавиатура, их красят фильтры — со сценой на canvas так не выйдет. */

.h3d {
  --rx: -12deg;            /* наклон камеры сверху */
  --ry: -22deg;            /* поворот вокруг вертикали */
  --depth: 84px;           /* толщина дома */
  --win-w: 52px;
  --win-h: 34px;
  --gap: 7px;
  --wall: #cfc6b7;
  --wall-dark: #b3a996;
  --wall-side: #a2988a;
  --free: #2f8f6d;
  --booked: #d9a441;
  --contract: #c1462b;
  --sold: #6f6a63;
  --sky1: #eef3f6;
  --sky2: #dfe7ec;
}

.h3d-stage {
  position: relative;
  min-height: 540px;
  padding: 30px 0 10px;
  perspective: 1700px;
  perspective-origin: 50% 42%;
  background: linear-gradient(180deg, var(--sky1) 0%, var(--sky2) 68%, #d3cfc4 100%);
  border-radius: 16px;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  user-select: none;
}
.h3d-stage.dragging { cursor: grabbing; }

.h3d-scene {
  transform-style: preserve-3d;
  transform: rotateX(var(--rx)) rotateY(var(--ry));
  transition: transform .12s linear;
  margin: 0 auto;
  width: max-content;
}
.h3d-stage.spin .h3d-scene { transition: transform .9s ease-out; }

/* --- корпус --- */
.h3d-body { position: relative; transform-style: preserve-3d; }

.h3d-face {
  position: relative;
  transform-style: preserve-3d;
  background: linear-gradient(180deg, var(--wall) 0%, var(--wall-dark) 100%);
  padding: 14px 16px 18px;
  border-radius: 3px;
  box-shadow: 0 24px 60px rgba(31, 42, 46, .28);
}

/* боковины и крыша — чтобы дом читался как объём, а не как картинка */
.h3d-side, .h3d-roof, .h3d-back {
  position: absolute;
  background: var(--wall-side);
  border-radius: 2px;
  /* без этого дальняя стена просвечивает сквозь дом и читается как лишняя панель */
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.h3d-side.left  { left: 0;  top: 0; height: 100%; width: var(--depth);
  transform-origin: left center;  transform: rotateY(-90deg); }
.h3d-side.right { right: 0; top: 0; height: 100%; width: var(--depth);
  transform-origin: right center; transform: rotateY(90deg); }
.h3d-roof { left: 0; top: 0; width: 100%; height: var(--depth);
  transform-origin: center top; transform: rotateX(90deg);
  background: linear-gradient(180deg, #ded6c8, #c2b9a9); }
.h3d-back { left: 0; top: 0; width: 100%; height: 100%;
  transform: translateZ(calc(-1 * var(--depth))); background: #9d9385; }

/* земля под домом */
.h3d-ground {
  position: absolute; left: 50%; bottom: 8%;
  width: 130%; height: 320px;
  transform: translateX(-50%) rotateX(90deg);
  background: radial-gradient(ellipse at center, rgba(120,130,110,.55), rgba(120,130,110,0) 70%);
  pointer-events: none;
}

/* --- этажи и окна --- */
.h3d-floor { display: flex; gap: var(--gap); margin-bottom: var(--gap); align-items: center; }
.h3d-floor:last-child { margin-bottom: 0; }

.h3d-fnum {
  width: 26px; flex: 0 0 26px; text-align: right;
  font: 600 11px/1 system-ui, sans-serif; color: #6b6660; opacity: .75;
}

.h3d-sec-gap { width: 14px; flex: 0 0 14px; }

.h3d-win {
  width: var(--win-w); height: var(--win-h);
  border: 0; padding: 0; border-radius: 3px;
  background: var(--sold);
  box-shadow: inset 0 -6px 10px rgba(0, 0, 0, .18), inset 0 2px 3px rgba(255, 255, 255, .22);
  cursor: pointer; position: relative;
  transition: transform .12s ease, filter .12s ease, opacity .18s ease;
  font: 600 10px/1 system-ui, sans-serif; color: rgba(255, 255, 255, .92);
}
.h3d-win[data-st="free"]     { background: var(--free); }
.h3d-win[data-st="booked"]   { background: var(--booked); }
.h3d-win[data-st="contract"] { background: var(--contract); }
.h3d-win[data-st="sold"]     { background: var(--sold); }

.h3d-win:hover, .h3d-win:focus-visible {
  transform: translateZ(16px) scale(1.08);
  filter: brightness(1.18);
  outline: 2px solid #fff; outline-offset: 1px;
}
.h3d-win.sel { transform: translateZ(22px) scale(1.12); outline: 2px solid #1f2a2e; }
.h3d-win.dim { opacity: .17; pointer-events: none; }
.h3d-empty { width: var(--win-w); height: var(--win-h); background: rgba(0,0,0,.07); border-radius: 3px; }

/* мягкое свечение свободных — то, ради чего застройщик и смотрит */
.h3d-stage.glow .h3d-win[data-st="free"] {
  box-shadow: inset 0 -6px 10px rgba(0,0,0,.18), 0 0 14px 2px rgba(47, 143, 109, .75);
}

/* --- подъезды --- */
.h3d-entr {
  display: flex; gap: var(--gap); margin-top: 12px; padding-left: 42px;
  transform: translateZ(1px);
  font: 600 11px/1 system-ui, sans-serif; color: #5f594f;
}
.h3d-entr span { text-align: center; opacity: .8; }

/* --- панель управления --- */
.h3d-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin: 14px 0 10px;
}
.h3d-bar select, .h3d-bar button {
  font: inherit; font-size: 15px; padding: 8px 12px;
  border: 1px solid #ddd4c4; border-radius: 9px; background: #fff; cursor: pointer;
}
.h3d-bar button.on { background: #1f2a2e; color: #f4efe6; border-color: #1f2a2e; }
.h3d-bar .spacer { margin-left: auto; }
.h3d-bar .cnt { font-size: 14px; color: #6b6660; }

.h3d-legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 8px 0 0; padding: 0; list-style: none;
  font-size: 14px; color: #4a453e; }
.h3d-legend i { display: inline-block; width: 14px; height: 14px; border-radius: 3px;
  margin-right: 6px; vertical-align: -2px; }

/* --- карточка выбранной квартиры --- */
.h3d-card {
  position: absolute; right: 14px; top: 14px; width: 260px; z-index: 5;
  background: #fff; border-radius: 14px; padding: 16px 18px;
  box-shadow: 0 18px 44px rgba(31, 42, 46, .22);
  font-size: 15px;
}
.h3d-card[hidden] { display: none; }
.h3d-card h3 { margin: 0 0 4px; font-size: 19px; }
.h3d-card dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 10px 0 12px; }
.h3d-card dt { color: #6b6660; font-size: 14px; }
.h3d-card dd { margin: 0; font-weight: 600; }
.h3d-card .badge { display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 13px; color: #fff; }
.h3d-card a.go { display: block; text-align: center; background: #c1462b; color: #fff;
  text-decoration: none; padding: 10px; border-radius: 10px; font-weight: 600; }
.h3d-card .close { position: absolute; right: 10px; top: 8px; border: 0; background: none;
  font-size: 20px; line-height: 1; color: #9b948a; cursor: pointer; }

.h3d-hint { font-size: 14px; color: #6b6660; margin: 6px 0 0; }
.h3d-nowebgl { display: none; }

@media (max-width: 760px) {
  .h3d { --win-w: 30px; --win-h: 22px; --gap: 5px; --depth: 46px; }
  .h3d-stage { min-height: 360px; perspective: 1100px; }
  .h3d-card { position: static; width: auto; margin-top: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .h3d-scene, .h3d-win { transition: none; }
}

/* ===== ЖК целиком: корпуса на площадке =====================================
   Та же CSS-перспектива, что и у дома по окнам. Каждый корпус — кнопка с
   пятью гранями; окна нарисованы градиентом, чтобы не плодить сотни узлов:
   в этом виде важен дом, а не окно. Клик по дому ведёт в вид по окнам. */
.h3d { --gp-wall: #d9d1c2; --gp-wall-side: #b9af9d; --gp-win: rgba(38, 52, 64, .42);
       --gp-ground: #c9cfb6; --gp-road: #7c7a74; }
.h3d-views { display: inline-flex; border: 1px solid #ddd4c4; border-radius: 9px; overflow: hidden; }
.h3d-views button { border: 0; border-radius: 0; margin: 0; }
.h3d-views button[aria-pressed="true"] { background: #1f2a2e; color: #f4efe6; }
.h3d.mode-site .facade-only { display: none; }
.h3d.mode-site .h3d-body, .h3d.mode-site .h3d-ground { display: none !important; }
.h3d.mode-facade .gp-site { display: none; }
.h3d.mode-site .h3d-stage { perspective: 2000px; perspective-origin: 50% 38%; }
.h3d.mode-site .h3d-stage { min-height: 640px; padding-top: 0; }

.gp-site {
  position: relative; width: var(--pw); height: var(--ph);
  transform-style: preserve-3d; margin: 0 auto;
}
/* площадка: лежит горизонтально, ближний край — к зрителю */
.gp-plate {
  position: absolute; left: 0; bottom: 0; width: var(--pw); height: var(--pd);
  transform-origin: 50% 100%; transform: rotateX(-90deg);
  background: var(--gp-ground);
  border-radius: 14px;
  box-shadow: 0 0 0 6px rgba(120, 125, 100, .25), 0 40px 80px rgba(31, 42, 46, .25);
  overflow: hidden;
}
.gp-yard {
  position: absolute; inset: 44px 26px 44px 26px; border-radius: 12px;
  background:
    radial-gradient(circle at 30% 40%, rgba(255,255,255,.35), transparent 34%),
    radial-gradient(circle at 70% 60%, rgba(255,255,255,.28), transparent 30%),
    #d3d8bf;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.25);
}
/* дорога вдоль ближнего края */
.gp-road {
  position: absolute; left: 0; right: 0; top: 0; height: 30px;
  background:
    repeating-linear-gradient(90deg, #f1e9d2 0 22px, transparent 22px 44px) center / 100% 2px no-repeat,
    var(--gp-road);
}

.gp-tree {
  position: absolute; left: var(--x); bottom: 0; width: var(--s); height: calc(var(--s) * 1.6);
  transform: translateZ(var(--z)) translateX(-50%) rotateY(calc(-1 * var(--ry))) rotateX(calc(-1 * var(--rx)));
  transform-origin: 50% 100%;
  background:
    radial-gradient(circle at 50% 35%, #4f8f5a 0 45%, transparent 47%),
    linear-gradient(#6b5a45, #6b5a45) 50% 100% / 3px 40% no-repeat;
  pointer-events: none;
}

.gp-bld {
  position: absolute; left: var(--x); bottom: 0; width: var(--w); height: var(--h);
  transform: translateZ(var(--z)); transform-style: preserve-3d;
  border: 0; padding: 0; background: none; cursor: pointer;
  transition: transform .18s ease;
}
.gp-bld:hover, .gp-bld:focus-visible { transform: translateZ(var(--z)) translateY(-6px); outline: none; }
.gp-face {
  position: absolute; left: 0; top: 0; width: 100%; height: 100%;
  background-color: var(--gp-wall);
  background-image:
    linear-gradient(90deg, transparent 0 4px, var(--gp-win) 4px 11px, transparent 11px 16px),
    linear-gradient(180deg, transparent 0 2px, rgba(255,255,255,.55) 2px 3px, transparent 3px 11px);
  background-size: 16px 11px;
  box-shadow: inset 0 -8px 12px rgba(0,0,0,.08);
}
.gp-face.front { transform: translateZ(var(--d)); }
.gp-face.back  { transform: translateZ(0); background-color: var(--gp-wall-side); }
.gp-face.left  { width: var(--d); transform-origin: left center; transform: rotateY(-90deg);
                 background-color: var(--gp-wall-side); }
.gp-face.right { width: var(--d); left: auto; right: 0; transform-origin: right center;
                 transform: rotateY(90deg); background-color: var(--gp-wall-side); }
.gp-face.roof  { height: var(--d); transform-origin: center top; transform: rotateX(90deg);
                 background: linear-gradient(180deg, #ece6da, #cfc7b8); box-shadow: none; }
.gp-bld:hover .gp-face, .gp-bld:focus-visible .gp-face { filter: brightness(1.08); }

/* строящийся корпус: верхняя треть — голый каркас, без окон */
.gp-bld.building .gp-face:not(.roof)::after {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 32%;
  background:
    repeating-linear-gradient(180deg, #8e877c 0 2px, #a39b8e 2px 11px);
}
.gp-bld.building .gp-face.roof { background: #9a9287; }

/* кран — плоская фигура, всегда лицом к камере */
.gp-crane {
  position: absolute; left: 30%; top: 0; width: 96px; height: 96px;
  transform-origin: 0 100%;
  transform: translateZ(calc(var(--d) / 2)) translateY(-100%) rotateY(calc(-1 * var(--ry))) rotateX(calc(-1 * var(--rx)));
  pointer-events: none;
}
.gp-crane i { position: absolute; background: #d9532b; display: block; }
.gp-crane .mast { left: 10px; bottom: 0; width: 5px; height: 96px;
  background: repeating-linear-gradient(180deg, #d9532b 0 5px, #f0a48c 5px 8px); }
.gp-crane .jib  { left: 0; top: 0; width: 96px; height: 4px; }
.gp-crane .cab  { left: 4px; top: 4px; width: 16px; height: 9px; background: #f2c14e; }
.gp-crane .hook { left: 74px; top: 4px; width: 1px; height: 34px; background: #4a4a4a; }
.gp-crane .hook::after { content: ""; position: absolute; left: -5px; bottom: -6px; width: 11px; height: 6px;
  background: #4a4a4a; border-radius: 0 0 4px 4px; }

/* подпись над крышей, всегда лицом к камере */
.gp-tag {
  position: absolute; left: 50%; top: 0; min-width: 150px;
  transform-origin: 50% 100%;
  transform: translateZ(calc(var(--d) / 2)) translate(-50%, calc(-100% - 8px)) rotateY(calc(-1 * var(--ry))) rotateX(calc(-1 * var(--rx)));
  background: rgba(255,255,255,.94); border-radius: 10px; padding: 7px 10px;
  box-shadow: 0 10px 24px rgba(31,42,46,.18);
  font: 12px/1.3 system-ui, sans-serif; color: #1f2a2e; text-align: left;
  pointer-events: none; white-space: nowrap;
}
.gp-tag b { display: block; font-size: 13px; }
.gp-tag span { display: block; color: #4a453e; }
.gp-tag em { display: block; font-style: normal; color: #c1462b; font-weight: 600; margin-top: 2px; }
.gp-tag .bar { display: block; height: 4px; background: #e6ddcd; border-radius: 2px; margin-top: 5px; overflow: hidden; }
.gp-tag .bar i { display: block; height: 100%; background: #c1462b; }
.gp-bld.building .gp-tag { transform: translateZ(calc(var(--d) / 2)) translate(-50%, calc(-100% - 112px)) rotateY(calc(-1 * var(--ry))) rotateX(calc(-1 * var(--rx))); }

@media (max-width: 760px) {
  .h3d.mode-site .h3d-stage { min-height: 420px; perspective: 1300px; }
  .gp-site { transform: scale(.62); transform-origin: 50% 100%; }
}

/* ===== WebGL-сцена площадки (three.js) ===================================
   Рисуется поверх CSS-площадки; та остаётся запасным вариантом без WebGL. */
.gl-stage { display: none; position: absolute; inset: 0; z-index: 2; }
.h3d.mode-site.has-gl .gl-stage { display: block; }
.h3d.mode-site.has-gl .h3d-scene { visibility: hidden; }
.h3d.mode-site .h3d-stage { background: linear-gradient(180deg, #bcd6ea 0%, #e6f0f6 55%, #d6dccc 100%); transition: background .6s ease; }
.h3d-stage.gl-evening { background: linear-gradient(180deg, #1d2742 0%, #45507a 45%, #d98a5a 78%, #3a3f4e 100%) !important; }
.gl-canvas { display: block; width: 100%; height: 100%; }
.gl-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.gl-label {
  position: absolute; left: 0; top: 0; will-change: transform;
  background: rgba(255,255,255,.94); border-radius: 10px; padding: 7px 10px;
  box-shadow: 0 10px 24px rgba(31,42,46,.22);
  font: 12px/1.3 system-ui, sans-serif; color: #1f2a2e; white-space: nowrap;
  transition: box-shadow .15s ease;
}
.gl-label::after { content: ""; position: absolute; left: 50%; bottom: -6px; width: 10px; height: 10px;
  background: inherit; transform: translateX(-50%) rotate(45deg); }
.gl-label.hover { box-shadow: 0 0 0 2px #c1462b, 0 12px 28px rgba(31,42,46,.3); }
.gl-label b { display: block; font-size: 13px; }
.gl-label span { display: block; color: #4a453e; }
.gl-label em { display: block; font-style: normal; color: #c1462b; font-weight: 600; margin-top: 2px; }
.gl-label em:empty { display: none; }
.gl-label .bar { display: block; height: 4px; background: #e6ddcd; border-radius: 2px; margin-top: 5px; overflow: hidden; }
.gl-label .bar i { display: block; height: 100%; background: #c1462b; }
.gl-stage.evening .gl-label { background: rgba(26,31,46,.92); color: #f4efe6; }
.gl-stage.evening .gl-label span { color: #cfc9bd; }
.gl-stage.evening .gl-label em { color: #f2b64d; }
.h3d:not(.mode-site) .site-only { display: none; }
.h3d.mode-site:not(.has-gl) .gl-only { display: none; }
.h3d-bar button#f-evening.on { background: #1d2742; color: #f4efe6; border-color: #1d2742; }

/* ===== город: районы в объёме ============================================= */
.h3d.city .h3d-stage { min-height: 640px; }
.h3d.city .gl-stage { display: block; }
.h3d.city:not(.has-gl) .gl-stage { display: none; }
.gl-fallback { display: none; padding: 40px 20px; text-align: center; color: #4a453e; }
.h3d.city:not(.has-gl) .gl-fallback { display: block; }
.gl-label.district { background: rgba(31,42,46,.9); color: #f4efe6; font-size: 13px; padding: 8px 12px; }
.gl-label.district b { font-size: 15px; letter-spacing: .01em; }
.gl-label.district span { color: #d9d2c2; }
.gl-label.district::after { background: rgba(31,42,46,.9); }
.gl-label.live { box-shadow: 0 0 0 2px #c1462b, 0 10px 24px rgba(31,42,46,.22); }
.gl-label.live em { color: #2f8f6d; }
.gl-stage.evening .gl-label.district { background: rgba(244,239,230,.94); color: #1f2a2e; }
.gl-stage.evening .gl-label.district span { color: #4a453e; }
.city-list { columns: 2; column-gap: 28px; padding-left: 18px; font-size: 15px; }
.city-list li { break-inside: avoid; margin: 0 0 6px; }
.city-list li.live a { font-weight: 700; }
h2 small { font-size: 60%; color: #6b6660; font-weight: 500; }
@media (max-width: 760px) { .city-list { columns: 1; } .h3d.city .h3d-stage { min-height: 460px; } }

/* на узком экране подписи над домами компактнее: имя и цифры, без сроков и полосок */
@media (max-width: 760px) {
  .gl-label { font-size: 11px; padding: 4px 7px; }
  .gl-label b { font-size: 11.5px; }
  .gl-label.house em, .gl-label.house .bar, .gl-label:not(.district):not(.house) .bar { display: none; }
  .gl-label.district { font-size: 12px; }
}
