:root {
  --bg: #150e09;
  --bg-soft: #1b120c;
  --panel: #20150e;
  --panel-2: #2a1b12;
  --panel-glass: rgba(32, 21, 14, 0.9);
  --text: #f4ede3;
  --text-strong: #fffaf2;
  --muted: #ad9d8a;
  --border: rgba(215, 169, 89, 0.18);
  --border-strong: rgba(226, 181, 98, 0.42);
  --primary: #d7a850;
  --primary-bright: #f0cf8b;
  --primary-deep: #a87328;
  --primary-hover: rgba(215, 168, 80, 0.13);
  --danger: #e78370;
  --shadow: 0 18px 46px rgba(5, 3, 2, 0.45);
  --shadow-soft: 0 10px 30px rgba(5, 3, 2, 0.3);
  --radius: 4px;
  --radius-sm: 2px;
  --font: "Satoshi", "Avenir Next", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; color: var(--text); background: var(--bg); font-family: var(--font); }
body {
  background:
    radial-gradient(circle at 12% 8%, rgba(139, 84, 35, 0.22), transparent 30%),
    linear-gradient(145deg, var(--bg-soft), var(--bg));
}
button, input { color: inherit; font: inherit; }
button, input, canvas { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, canvas:focus-visible { outline: 1px solid var(--primary-bright); outline-offset: 3px; }

.app { display: grid; grid-template-columns: 324px minmax(0, 1fr); width: 100%; height: 100%; }
.sidebar {
  position: relative; z-index: 2; display: flex; flex-direction: column; gap: 12px; overflow: auto;
  padding: 20px 18px 18px; border-right: 1px solid var(--border);
  background: radial-gradient(circle at 0 0, rgba(167, 102, 41, 0.14), transparent 34%), linear-gradient(180deg, #21160f 0%, #1a110b 58%, #160f0a 100%);
  box-shadow: 12px 0 36px rgba(4, 2, 1, 0.22);
}
.sidebar::after { position: absolute; inset: 0 0 auto; height: 1px; content: ""; background: linear-gradient(90deg, transparent, rgba(240, 207, 139, 0.5), transparent); pointer-events: none; }
.sidebar::-webkit-scrollbar, .room-list::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track, .room-list::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb, .room-list::-webkit-scrollbar-thumb { border-radius: 999px; background: rgba(215, 168, 80, 0.3); }

.brand { display: flex; align-items: center; gap: 14px; min-height: 44px; margin: 1px 2px 2px; }
.logo { display: block; flex: 0 0 auto; width: 86px; height: auto; }
.logo img { display: block; width: 100%; height: auto; object-fit: contain; filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.35)); }
h1 { margin: 0; color: var(--text-strong); font-size: 0.95rem; font-weight: 500; line-height: 1.12; letter-spacing: 0.075em; text-transform: uppercase; }
.sub { margin-top: 4px; color: var(--muted); font-size: 0.68rem; font-weight: 500; letter-spacing: 0.13em; text-transform: uppercase; }

.card {
  position: relative; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(255,255,255,.018), transparent 42%), linear-gradient(180deg, rgba(48,31,20,.96), rgba(36,23,15,.97));
  box-shadow: var(--shadow-soft);
}
.card::before { position: absolute; inset: -1px auto auto -1px; width: 42px; height: 1px; content: ""; background: var(--primary); opacity: .78; }
.card h2 { margin-bottom: 12px; color: #c8b69d; font-size: .68rem; font-weight: 500; letter-spacing: .14em; text-transform: uppercase; }
.card p, .empty { margin-bottom: 8px; color: var(--muted); font-size: .8rem; line-height: 1.45; }

.search-wrapper { position: relative; margin-bottom: 2px; }
.search-wrapper svg { position: absolute; top: 50%; left: 10px; width: 14px; height: 14px; color: #bda98e; pointer-events: none; transform: translateY(-50%); }
input[type="search"] {
  width: 100%; min-height: 32px; padding: .3rem .7rem .3rem 34px; border: 1px solid var(--border); border-radius: var(--radius-sm); outline: none;
  color: var(--text); background: rgba(12,8,5,.4); font-size: .83rem;
  transition: border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
}
input[type="search"]::placeholder { color: #887b6c; }
input[type="search"]:hover { border-color: rgba(215,168,80,.3); }
input[type="search"]:focus { border-color: var(--border-strong); background: rgba(10,6,4,.62); box-shadow: 0 0 0 2px rgba(215,168,80,.08); }

.rooms-card { display: flex; flex: 1 1 auto; flex-direction: column; min-height: 0; padding: 10px; }
.rooms-card h2 { margin-bottom: 4px; }
.rooms-card h2, .search-wrapper, #unselectRoom { flex: 0 0 auto; }
.room-list { display: grid; flex: 1 1 auto; align-content: start; min-height: 0; max-height: none; gap: 0; overflow: auto; padding-right: 7px; list-style: none; }
.floor-divider { display: flex; align-items: center; gap: 6px; margin: 3px 2px; color: rgba(202,184,159,.58); font-size: .5rem; font-weight: 500; letter-spacing: .14em; line-height: 1; text-transform: uppercase; }
.floor-divider:first-child { margin-top: 0; }
.floor-divider::after { flex: 1; height: 1px; content: ""; background: linear-gradient(90deg, rgba(215,168,80,.25), transparent); }
.floor-divider span { flex: 0 0 auto; white-space: nowrap; }
.room-list-item { min-width: 0; min-height: 30px; padding-bottom: 2px; }
.room-btn {
  position: relative; display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 28px; padding: 2px 8px; overflow: hidden;
  border: 1px solid transparent; border-radius: var(--radius-sm); color: var(--text); background: rgba(255,255,255,.025); text-align: left; cursor: pointer;
  transition: color 180ms ease, border-color 180ms ease, background 180ms ease, transform 180ms ease;
}
.room-btn::before { position: absolute; inset: 4px auto 4px 0; width: 1px; content: ""; background: var(--primary); opacity: 0; transform: scaleY(.35); transition: opacity 180ms ease, transform 180ms ease; }
.room-btn:hover { border-color: rgba(215,168,80,.16); background: rgba(215,168,80,.07); transform: translateX(2px); }
.room-btn.active { border-color: var(--border-strong); background: linear-gradient(90deg, rgba(215,168,80,.18), rgba(215,168,80,.065)); }
.room-btn:hover::before, .room-btn.active::before { opacity: 1; transform: scaleY(1); }
.room-btn-main { display: flex; align-items: center; min-width: 0; gap: 7px; }
.room-icon { flex: 0 0 auto; width: 12px; height: 12px; color: var(--primary); opacity: .86; }
.room-name { overflow: hidden; color: var(--text-strong); font-size: .74rem; font-weight: 500; letter-spacing: .01em; text-overflow: ellipsis; white-space: nowrap; }
.room-tag { padding: 4px 10px; border-radius: 999px; color: var(--primary-bright); background: var(--primary-hover); font-size: .72rem; font-weight: 600; opacity: 0; transition: opacity 180ms ease; }
.room-btn:hover .room-tag, .room-btn.active .room-tag { opacity: 1; }

.layers-card { flex: 0 0 auto; overflow: hidden; padding: 0; }
.layers-heading { margin: 0 !important; }
.section-toggle {
  display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 44px; padding: 0 14px;
  border: 0; color: #c8b69d; background: transparent; font-size: .68rem; font-weight: 500; letter-spacing: .14em;
  text-align: left; text-transform: uppercase; cursor: pointer;
  transition: color 180ms ease, background 180ms ease;
}
.section-toggle:hover { color: var(--primary-bright); background: rgba(215,168,80,.055); }
.section-chevron { flex: 0 0 auto; width: 17px; height: 17px; color: var(--primary); transition: transform 180ms ease; }
.layers-card.expanded .section-chevron { transform: rotate(180deg); }
.layers-content { padding: 2px 14px 14px; }
.layers-content[hidden] { display: none; }

.row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 7px; color: #cfc2b1; font-size: .79rem; }
.row strong { color: var(--primary-bright); font-size: .72rem; font-variant-numeric: tabular-nums; font-weight: 500; letter-spacing: .04em; }
.slider-group { margin-bottom: 12px; }
.range { width: 100%; height: 16px; margin: 0; border: 0; outline: none; background: transparent; cursor: pointer; appearance: none; -webkit-appearance: none; }
.range::-webkit-slider-runnable-track { height: 2px; border-radius: 2px; background: linear-gradient(90deg, var(--primary-deep), rgba(213,176,112,.32)); }
.range::-webkit-slider-thumb { width: 14px; height: 14px; margin-top: -6px; border: 1px solid #f3d596; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 4px rgba(215,168,80,.1), 0 3px 10px rgba(0,0,0,.35); cursor: grab; appearance: none; -webkit-appearance: none; }
.range::-moz-range-track { height: 2px; border-radius: 2px; background: linear-gradient(90deg, var(--primary-deep), rgba(213,176,112,.32)); }
.range::-moz-range-thumb { width: 14px; height: 14px; border: 1px solid #f3d596; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 4px rgba(215,168,80,.1), 0 3px 10px rgba(0,0,0,.35); cursor: grab; }
.range:focus-visible::-webkit-slider-thumb { outline: 1px solid var(--primary-bright); outline-offset: 3px; }

.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 5px; }
.btn {
  display: flex; align-items: center; justify-content: center; min-height: 36px; padding: .45rem .7rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: #d9cdbc; background: rgba(11,7,5,.34); font-size: .76rem; font-weight: 500; letter-spacing: .045em; cursor: pointer;
  transition: color 180ms ease, border-color 180ms ease, background 180ms ease, transform 180ms ease;
}
.btn:hover { border-color: var(--border-strong); color: var(--text-strong); background: rgba(215,168,80,.09); transform: translateY(-1px); }
.btn-primary { border-color: var(--primary); color: #1b1109; background: linear-gradient(135deg, var(--primary-bright), var(--primary)); font-weight: 700; }
.btn-primary:hover { border-color: #f4d99f; color: #150d07; background: linear-gradient(135deg, #f6dda8, #dcae58); }
#unselectRoom { display: none; width: 100%; margin-top: 12px; }

.viewer { position: relative; width: 100%; height: 100%; overflow: hidden; background: radial-gradient(circle at 62% 34%, rgba(119,70,31,.13), transparent 36%), var(--bg); }
#scene { display: block; width: 100%; height: 100%; outline: none; }
.status {
  position: absolute; z-index: 10; top: 20px; right: 20px; display: flex; flex-direction: column; gap: 6px; max-width: 320px; padding: 12px 15px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); background: var(--panel-glass); box-shadow: var(--shadow); backdrop-filter: blur(14px);
  font-size: .78rem; font-weight: 400; line-height: 1.4;
}
.status::before { position: absolute; inset: -1px auto -1px -1px; width: 2px; content: ""; background: var(--primary); }
.status.error { border-color: rgba(231,131,112,.65); }
.status.error::before { background: var(--danger); }
.status-title { color: var(--text-strong); font-weight: 600; letter-spacing: .02em; }
.status.error .status-title { color: #f1a092; }

.tooltip {
  position: absolute; z-index: 100; min-width: max-content; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); background: rgba(25,16,10,.94); box-shadow: 0 12px 28px rgba(3,2,1,.48); backdrop-filter: blur(10px); pointer-events: none;
  opacity: 0; transform: translate(-50%, -100%); transition: opacity 150ms ease, transform 100ms ease;
}
.tooltip .floor { margin-bottom: 4px; color: var(--primary-bright); font-size: .66rem; font-weight: 600; letter-spacing: .13em; text-transform: uppercase; }
.tooltip .name { color: var(--text-strong); font-size: .84rem; font-weight: 500; }
.tooltip::after { position: absolute; top: 100%; left: 50%; margin-left: -6px; border-width: 6px; border-style: solid; border-color: rgba(25,16,10,.94) transparent transparent; content: ""; }
.active-tooltip { z-index: 99; border-color: var(--border-strong); box-shadow: 0 8px 30px rgba(183,117,40,.28); }
.active-tooltip::after { border-color: rgba(25,16,10,.94) transparent transparent; }
.fab-layers, .sheet-handle { display: none; }

@media (max-width: 960px) {
  .app { position: relative; display: block; height: 100vh; height: 100dvh; overflow: hidden; }
  .viewer { position: absolute; z-index: 1; inset: 0; height: 100% !important; }
  .sidebar { position: absolute; z-index: 10; inset: 0; max-height: none; padding: 0; overflow: hidden; border: 0; background: transparent; box-shadow: none; pointer-events: none; }
  .sidebar::after { display: none; }
  .sidebar > * { pointer-events: auto; }
  .brand { position: absolute; top: 12px; left: 12px; max-width: calc(100vw - 78px); min-height: 48px; margin: 0; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: rgba(28,18,12,.82); box-shadow: var(--shadow-soft); backdrop-filter: blur(14px); }
  .brand .sub { display: none; }
  .logo { width: 66px; }
  h1 { font-size: .78rem; }
  .card { background: rgba(39,25,16,.95); box-shadow: var(--shadow); backdrop-filter: blur(14px); }
  .fab-layers { position: absolute; z-index: 9999; top: 12px; right: 12px; display: flex; align-items: center; justify-content: center; width: 48px; height: 48px; border: 1px solid var(--border); border-radius: 50%; color: var(--primary-bright); background: rgba(28,18,12,.86); box-shadow: var(--shadow-soft); backdrop-filter: blur(14px); cursor: pointer; touch-action: none; transition: color 180ms ease, border-color 180ms ease, background 180ms ease; }
  .fab-layers.active { border-color: var(--primary); color: #1a1008; background: var(--primary); }
  .rooms-card { position: absolute; z-index: 15; right: 0; bottom: 0; left: 0; display: flex; flex: none; flex-direction: column; height: 30vh; margin: 0; padding: 8px 16px 16px; border-width: 1px 0 0; border-radius: 18px 18px 0 0; background: linear-gradient(180deg, rgba(48,30,19,.97), rgba(25,16,10,.98)); box-shadow: 0 -18px 48px rgba(3,2,1,.55); transition: height 300ms cubic-bezier(.2,.8,.2,1); }
  .rooms-card::before { top: -1px; left: 50%; width: 90px; background: linear-gradient(90deg, transparent, var(--primary), transparent); transform: translateX(-50%); }
  .rooms-card.expanded { height: 85vh; }
  .sheet-handle { display: flex; flex-shrink: 0; align-items: center; justify-content: center; width: 100%; height: 32px; margin-top: -12px; margin-bottom: -4px; border: 0; outline: none; background: transparent; cursor: pointer; touch-action: none; }
  .sheet-handle::after { display: block; width: 38px; height: 3px; border-radius: 999px; content: ""; background: rgba(240,207,139,.46); transition: background 180ms ease; }
  .sheet-handle:hover::after, .sheet-handle:active::after { background: var(--primary-bright); }
  .rooms-card h2 { display: none; }
  .rooms-card .room-list { flex: 1; max-height: none; gap: 4px; overflow-y: auto; padding-right: 4px; }
  .rooms-card .search-wrapper { margin-bottom: 10px; }
  .rooms-card .search-wrapper svg { left: 12px; width: 16px; height: 16px; }
  .rooms-card input[type="search"] { min-height: 42px; padding: .55rem .8rem .55rem 38px; }
  .rooms-card .floor-divider { gap: 8px; margin: 8px 2px 2px; font-size: .59rem; }
  .rooms-card .floor-divider:first-child { margin-top: 2px; }
  .rooms-card .room-list-item { min-height: 0; padding-bottom: 0; }
  .rooms-card .room-btn { min-height: 40px; padding: 6px 10px; }
  .rooms-card .room-btn::before { inset-block: 7px; }
  .rooms-card .room-btn-main { gap: 9px; }
  .rooms-card .room-icon { width: 15px; height: 15px; }
  .rooms-card .room-name { font-size: .82rem; }
  .layers-card { position: absolute; top: 74px; right: 12px; width: min(288px, calc(100vw - 24px)); margin: 0; opacity: 0; pointer-events: none; transform: translateY(-10px); transition: opacity 180ms ease, transform 180ms ease; }
  .layers-card.show { opacity: 1; pointer-events: auto; transform: translateY(0); }
  .status { top: 74px; right: 12px; left: 12px; max-width: none; }
}

@media (max-width: 430px) {
  .brand { gap: 10px; padding-inline: 10px; }
  .logo { width: 56px; }
  h1 { font-size: .72rem; letter-spacing: .055em; }
  .rooms-card { padding-inline: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
