:root {
  --bg: #0b0f14;
  --bg-elev: #141b24;
  --panel: rgba(20, 27, 36, 0.82);
  --border: rgba(255, 255, 255, 0.10);
  --text: #eef2f6;
  --muted: #9aa7b4;
  --accent: #2f7bff;
  --accent-2: #17c1a6;
  --radius: 16px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.app, .viewer { height: 100%; }

.viewer { display: flex; flex-direction: column; }

/* Brand */
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { color: var(--accent-2); font-size: 1.4rem; line-height: 1; }
.brand-name { font-weight: 700; letter-spacing: -0.01em; }

/* Home */
.home {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 70% -10%, rgba(47,123,255,0.18), transparent 60%),
              radial-gradient(900px 500px at 10% 110%, rgba(23,193,166,0.14), transparent 60%);
}
.home-card {
  max-width: 460px; text-align: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px; box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.home-card h1 { font-size: 1.7rem; margin: 22px 0 10px; letter-spacing: -0.02em; }
.home-card p { color: var(--muted); line-height: 1.6; }
.home-hint {
  display: inline-block; margin-top: 20px; padding: 8px 14px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 10px; color: var(--accent-2); font-size: 0.9rem;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; gap: 12px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: linear-gradient(180deg, rgba(11,15,20,0.95), rgba(11,15,20,0.6));
  border-bottom: 1px solid var(--border);
  position: relative; z-index: 5;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.titles { display: flex; flex-direction: column; min-width: 0; }
.project-title { font-weight: 650; font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-address { color: var(--muted); font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; gap: 8px; flex-shrink: 0; }

/* Buttons */
.btn {
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text);
  padding: 9px 16px; border-radius: 12px; font-size: 0.9rem; font-weight: 600;
  cursor: pointer; transition: transform .12s ease, background .2s ease, opacity .2s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.96); }
.btn-ghost { background: transparent; }
.btn-ar { background: linear-gradient(135deg, var(--accent), #1e5fd0); border-color: transparent; color: #fff; }
.btn-copy { padding: 9px 14px; }

/* Stage */
.stage { position: relative; flex: 1; min-height: 0; background:
  radial-gradient(1000px 500px at 50% -10%, rgba(47,123,255,0.10), transparent 60%), #0d1218; }
model-viewer { width: 100%; height: 100%; --poster-color: transparent; background: transparent; }

.poster-fallback { position: absolute; inset: 0; display: grid; place-items: center; }
.poster-fallback img { max-width: 100%; max-height: 100%; object-fit: contain; opacity: 0.5; }
.poster-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px; text-align: center; padding: 24px;
  background: rgba(8,11,15,0.55);
}
.poster-overlay p { color: var(--text); max-width: 300px; line-height: 1.5; }

/* Loader */
.loader { position: absolute; inset: 0; display: grid; place-items: center; background: #0d1218; }
.spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.12); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-box {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  padding: 32px; color: var(--muted);
}

/* Rooms nav */
.rooms {
  display: flex; gap: 10px; overflow-x: auto; padding: 14px 16px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(11,15,20,0.96), rgba(11,15,20,0.5));
  border-top: 1px solid var(--border); scrollbar-width: none;
}
.rooms::-webkit-scrollbar { display: none; }
.room-chip {
  flex-shrink: 0; display: flex; flex-direction: column; gap: 6px;
  width: 118px; cursor: pointer; border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden; background: var(--bg-elev);
  transition: border-color .2s ease, transform .12s ease;
}
.room-chip:active { transform: scale(0.97); }
.room-chip.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(47,123,255,0.35); }
.room-chip .thumb { width: 100%; height: 70px; object-fit: cover; background: #1c2530; }
.room-chip .thumb.empty { display: grid; place-items: center; color: var(--muted); font-size: 1.4rem; }
.room-chip .label { padding: 7px 10px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Modal */
.modal { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(0,0,0,0.6); z-index: 50; }
.modal-card { width: 100%; max-width: 520px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.modal-head h2 { font-size: 1.2rem; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 1.6rem; cursor: pointer; line-height: 1; }
.modal-sub { color: var(--muted); font-size: 0.9rem; margin-bottom: 18px; }
.field-label { display: block; font-size: 0.78rem; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.code-row { display: flex; gap: 8px; align-items: stretch; }
.code {
  flex: 1; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.8rem; resize: none;
}
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--accent-2); color: #04211c; font-weight: 700; padding: 10px 18px;
  border-radius: 12px; box-shadow: var(--shadow); z-index: 100; opacity: 0; transition: opacity .2s ease;
}
.toast.show { opacity: 1; }
