:root {
  --teal: #5fb3b8;
  --teal-strong: #3f9aa0;
  --edit-blue: #3b82f6;
  --panel-bg: #121a1b;
  --panel-border: #24322f;
  --bg: #0a0e0d;
  --text: #eef2ef;
  --text-dim: #9aa89f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

/* ---------- Loader ---------- */
#loader {
  position: fixed; inset: 0; z-index: 999;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; background: var(--bg);
  transition: opacity .5s ease;
}
#loader.hidden { opacity: 0; pointer-events: none; }
.loader-mark {
  width: 200px; max-width: 60vw; height: auto; display: block;
  filter: brightness(0) invert(1);
}
.loader-bar { width: 180px; height: 3px; border-radius: 2px; background: #1e2a2a; overflow: hidden; }
.loader-bar span {
  display: block; width: 40%; height: 100%; border-radius: 2px;
  background: var(--teal);
  animation: loaderSlide 1.1s ease-in-out infinite;
}
@keyframes loaderSlide { 0%{transform:translateX(-100%)} 50%{transform:translateX(150%)} 100%{transform:translateX(350%)} }
.loader-text { font-size: 12.5px; color: var(--text-dim); }

/* ---------- App shell ---------- */
#app { position: fixed; inset: 0; opacity: 0; transition: opacity .5s ease; }
#app.ready { opacity: 1; }

.viewport { position: absolute; inset: 0; overflow: hidden; background: #05080a; }

/* Cover-fit 16:9 stage (like background-size:cover). Shapes use % of this box. */
.stage {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: max(100vw, 177.78vh); aspect-ratio: 16 / 9;
}
@media (max-aspect-ratio: 4/3) {
  .stage { width: min(100vw, 177.78vh); }
}

/* Persistent facade backdrop. Changes between main<->pair (fades via
   .bd-fading); unchanged between pair<->block (same shared photo). On
   floor-plan view it stays faintly visible behind a grayish dimming overlay. */
.backdrop {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: fill; display: block; user-select: none; -webkit-user-drag: none;
  opacity: 1; transition: opacity .45s ease;
}
.stage.bd-fading .backdrop { opacity: 0; }
.view-dim {
  position: absolute; inset: 0; background: rgba(20,26,28,.88);
  opacity: 0; transition: opacity .45s ease; pointer-events: none;
}
.stage.floor-view .view-dim { opacity: 1; }

/* Floor-plan image layer (hidden except on floor-plan view) */
.bg-image {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; display: block; user-select: none; -webkit-user-drag: none;
  opacity: 0; transition: opacity .45s ease;
}
.stage.floor-view .bg-image { opacity: 1; }
.stage.fading .bg-image { opacity: 0; }

.shape-layer, .edit-layer { position: absolute; inset: 0; }
.edit-layer { pointer-events: none; }

/* ---------- Shapes (each is a crop container over its own sprite) ---------- */
.shape {
  position: absolute; overflow: hidden; pointer-events: none;
  opacity: 0; transition: opacity .18s ease, filter .18s ease;
  will-change: opacity;
}
.shape-img {
  position: absolute; display: block; pointer-events: none;
  user-select: none; -webkit-user-drag: none;
}
.shape.hot {
  opacity: .62;
  filter: brightness(1.08) drop-shadow(0 0 16px rgba(95,179,184,.6));
}
.shape.flat.hot {
  opacity: .6;
  filter: brightness(1.06) drop-shadow(0 0 16px rgba(143,208,141,.65));
}
.stage.hovering { cursor: pointer; }

@keyframes twinkle { 0%,100%{opacity:0} 45%{opacity:.5} }
.shape.twinkle { animation: twinkle .9s ease-in-out 1 backwards; }

/* ---------- Tooltip ---------- */
.tooltip {
  position: fixed; z-index: 60; pointer-events: none;
  background: rgba(10,16,16,.92); color: #fff;
  border: 1px solid rgba(255,255,255,.14); border-radius: 8px;
  padding: 7px 11px; font-size: 12.5px; font-weight: 600;
  transform: translate(-50%, -130%); white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
/* Facade labels (floor number / block name): bold white text, fixed next
   to the shape, not following the cursor. */
.tooltip.tooltip--white {
  background: none; border: none; box-shadow: none; padding: 0;
  color: #fff; font-size: 17px; font-weight: 800; letter-spacing: .01em;
  text-shadow: 0 2px 8px rgba(0,0,0,.65), 0 0 3px rgba(0,0,0,.55);
  transform: translateY(-50%);
}
/* Block-letter subtitle under the floor number — both blocks of a pair are
   hoverable on the same photo at once, so this disambiguates which one. */
.t-sub--white {
  display: block; font-size: 11px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: rgba(255,255,255,.8); margin-top: 1px;
}

/* ---------- Floating controls ---------- */
.fab {
  display: inline-flex; align-items: center; gap: 7px;
  height: 44px; padding: 0 14px; border-radius: 999px;
  border: 1px solid rgba(255,255,255,.18); background: rgba(10,16,16,.55);
  backdrop-filter: blur(7px); color: #fff; cursor: pointer;
  font-size: 13px; font-weight: 600;
  transition: background .15s ease, transform .12s ease, border-color .15s ease;
}
.fab:hover { background: rgba(63,154,160,.85); border-color: rgba(255,255,255,.3); }
.fab:active { transform: scale(.95); }
.fab[hidden] { display: none; }
.fab svg { flex: none; }

.fab-back { position: fixed; top: 20px; left: 20px; z-index: 40; }

.fab-edit {
  position: fixed; bottom: 20px; left: 20px; z-index: 40;
  width: 44px; padding: 0; justify-content: center;
}
.fab-edit.active { background: var(--edit-blue); border-color: var(--edit-blue); }

.brand {
  position: fixed; top: 24px; right: 24px; z-index: 40;
  width: 132px; height: auto; pointer-events: none;
  filter: brightness(0) invert(1) drop-shadow(0 2px 10px rgba(0,0,0,.5));
}
.brand[hidden] { display: none; }

.floor-nav {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 40;
  display: flex; align-items: center; gap: 10px;
}
.floor-nav[hidden] { display: none; }
.floor-nav .fab { width: 44px; padding: 0; justify-content: center; }
.floor-nav-label { width: auto; min-width: 92px; padding: 0 18px; cursor: default; white-space: nowrap; justify-content: center; }
.floor-nav-label:hover { background: rgba(10,16,16,.55); }

.icon-btn {
  width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; border: none; background: rgba(255,255,255,.08); color: var(--text);
  font-size: 18px; line-height: 1; cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,.18); }

/* ---------- Edit mode ---------- */
.edit-layer .ebox {
  position: absolute; pointer-events: auto; cursor: move;
  outline: 1.5px dashed rgba(255,255,255,.5); outline-offset: -1px;
}
.edit-layer .ebox.sel { outline: 2px solid var(--edit-blue); z-index: 5; }
.edit-layer .ebox .elabel {
  position: absolute; left: 4px; top: 4px; font-size: 11px; font-weight: 700;
  color: #fff; background: rgba(10,16,16,.8); padding: 2px 6px; border-radius: 4px;
  white-space: nowrap; pointer-events: none;
}
.edit-layer .ebox .ehandle {
  position: absolute; width: 13px; height: 13px; background: #fff;
  border: 2px solid var(--edit-blue); border-radius: 3px; transform: translate(-50%,-50%);
}
.ehandle.h-nw{left:0;top:0;cursor:nw-resize} .ehandle.h-n{left:50%;top:0;cursor:n-resize}
.ehandle.h-ne{left:100%;top:0;cursor:ne-resize} .ehandle.h-e{left:100%;top:50%;cursor:e-resize}
.ehandle.h-se{left:100%;top:100%;cursor:se-resize} .ehandle.h-s{left:50%;top:100%;cursor:s-resize}
.ehandle.h-sw{left:0;top:100%;cursor:sw-resize} .ehandle.h-w{left:0;top:50%;cursor:w-resize}

body.edit-on .shape { opacity: .28 !important; animation: none !important; }
body.edit-on .stage { cursor: default; }

.edit-panel {
  position: fixed; right: 18px; top: 74px; bottom: 74px; width: 300px; z-index: 50;
  background: var(--panel-bg); border: 1px solid var(--panel-border); border-radius: 14px;
  padding: 16px; overflow-y: auto; box-shadow: 0 16px 44px rgba(0,0,0,.5);
}
.edit-panel[hidden] { display: none; }
.edit-panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.edit-hint { font-size: 12px; color: var(--text-dim); line-height: 1.5; margin: 0 0 12px; }
.edit-field-label { display:block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); margin: 6px 0 4px; }
.edit-select {
  width: 100%; background: #0d1414; color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 8px; padding: 8px 9px; font-size: 13px;
}
.edit-num-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.edit-num-grid label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); display: flex; flex-direction: column; gap: 3px; }
.edit-num-grid input {
  background: #0d1414; color: var(--text); border: 1px solid var(--panel-border);
  border-radius: 7px; padding: 7px 8px; font-size: 13px; font-family: inherit;
}
.edit-num-grid input:focus, .edit-select:focus { outline: none; border-color: var(--teal); }
.edit-panel-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid rgba(255,255,255,.16); background: rgba(63,154,160,.2);
  color: var(--text); padding: 9px 12px; border-radius: 9px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn:hover { background: rgba(63,154,160,.35); }
.btn-ghost { background: transparent; }
.edit-save { font-size: 11.5px; color: var(--teal); min-height: 16px; margin: 10px 0 0; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .brand { width: 104px; top: 18px; right: 16px; }
  .fab-back { top: 14px; left: 14px; }
  .edit-panel { left: 12px; right: 12px; width: auto; top: auto; bottom: 74px; height: 44vh; }
}
