:root {
  --plum: #4a1e3f;
  --plum-deep: #35152d;
  --plum-soft: #7a4468;
  --pearl: #f7f2ea;
  --pearl-2: #efe7db;
  --cream: #fffdf9;
  --ink: #24202a;
  --ink-soft: #5c5563;
  --rose: #d4568c;
  --line: rgba(74, 30, 63, 0.14);
  --shadow-sm: 0 4px 14px rgba(53, 21, 45, 0.07);
  --shadow-md: 0 10px 34px rgba(53, 21, 45, 0.1);
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
}

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

html, body {
  width: 100%;
  min-height: 100%;
  background: var(--pearl);
  font-family: var(--sans);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
body.editor-open { overflow: hidden; }
canvas { display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

.hidden { display: none !important; }

/* ------------------------------------------------------------ home */
.home {
  max-width: 1120px;
  margin: 0 auto;
  padding: 56px 32px 96px;
}
.brandbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 64px;
}
.brandbar .mark { color: var(--plum); }
.brandbar .wordmark {
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--plum);
}
.brandbar .role {
  margin-left: auto;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.hero { max-width: 720px; margin-bottom: 56px; }
.hero .eyebrow {
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--plum-soft);
  margin-bottom: 18px;
}
.hero h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.4rem, 5.4vw, 3.9rem);
  line-height: 1.04;
  letter-spacing: -0.02em;
  color: var(--plum-deep);
}
.hero h1 em { font-style: italic; color: var(--plum-soft); }
.hero p {
  margin-top: 20px;
  font-size: 1.05rem;
  line-height: 1.65;
  color: var(--ink-soft);
  max-width: 56ch;
}

.section-label {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 22px;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--plum-soft);
}
.section-label:after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 22px;
}
.room-card {
  display: flex;
  flex-direction: column;
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 220ms cubic-bezier(.2,.7,.3,1), box-shadow 220ms ease;
}
.room-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.room-card .thumb {
  height: 132px;
  background: linear-gradient(140deg, var(--plum) 0%, #6a2c58 58%, var(--rose) 140%);
  position: relative;
  overflow: hidden;
}
.room-card .thumb svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.room-card .body { padding: 20px 22px 22px; display: flex; flex-direction: column; flex: 1; }
.room-card h3 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
  color: var(--plum-deep);
  margin-bottom: 7px;
}
.room-card .desc { font-size: 0.88rem; line-height: 1.55; color: var(--ink-soft); flex: 1; }
.room-card .meta {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--plum-soft);
}
.room-card .meta .dot { width: 4px; height: 4px; border-radius: 50%; background: var(--line); }
.room-card .open {
  margin-top: 18px;
  align-self: flex-start;
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--plum);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 500;
  border: 1px solid var(--plum);
  cursor: pointer;
  transition: background 180ms ease;
}
.room-card .open:hover { background: var(--plum-deep); }

.room-card.new {
  background: transparent;
  border-style: dashed;
  border-color: rgba(74, 30, 63, 0.26);
  box-shadow: none;
}
.room-card.new .thumb {
  background: repeating-linear-gradient(45deg, var(--pearl-2), var(--pearl-2) 12px, #e7dccd 12px, #e7dccd 24px);
}
.room-card.new .open { background: transparent; color: var(--plum); }
.room-card.new .open:hover { background: rgba(74, 30, 63, 0.07); }

.home-foot {
  margin-top: 64px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--ink-soft);
}

/* ------------------------------------------------------------ editor */
#editor-view { position: fixed; inset: 0; }
#scene-mount { position: absolute; inset: 0; }

.topnav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 54px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: rgba(74, 30, 63, 0.96);
  backdrop-filter: blur(14px);
  color: #f4ecf3;
  z-index: 30;
  box-shadow: 0 2px 18px rgba(53, 21, 45, 0.18);
}
.topnav .home-link {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #f4ecf3;
  padding-right: 12px;
  border-right: 1px solid rgba(255, 255, 255, 0.16);
}
.topnav label {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.72;
  margin-right: -6px;
}
.topnav select,
.topnav .navbtn {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 7px;
  padding: 6px 10px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.topnav select { max-width: 220px; }
.topnav .section-name { font-size: 13px; font-weight: 500; letter-spacing: 0.01em; opacity: 0.95; padding-right: 4px; }
.topnav .navbtn:hover { background: rgba(255, 255, 255, 0.2); }
.topnav .navbtn.primary { background: var(--rose); border-color: var(--rose); font-weight: 500; }
.topnav .navbtn.primary:hover { background: #c04a7d; }
.topnav .spacer { flex: 1; }
.topnav .saved-hint { font-size: 11px; opacity: 0.8; }

.hud, .controls, .editor-panel, .editor-status, .view-buttons { z-index: 20; }

.hud {
  position: fixed;
  top: 70px;
  left: 16px;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.93);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 10px;
  max-width: 340px;
  box-shadow: var(--shadow-sm);
}
.hud h1 {
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--plum-deep);
}
.hud .sub { font-size: 12px; color: var(--ink-soft); line-height: 1.5; margin-bottom: 10px; }
.hud .specs { font-size: 11px; color: var(--ink-soft); line-height: 1.6; }
.hud .specs strong { color: var(--ink); font-weight: 600; }

.controls {
  position: fixed;
  bottom: 16px;
  left: 16px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.93);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 11px;
  color: var(--ink-soft);
  line-height: 1.7;
  box-shadow: var(--shadow-sm);
}
.controls strong { color: var(--ink); font-weight: 600; }
kbd {
  display: inline-block;
  padding: 1px 6px;
  margin: 0 1px;
  background: #f0edea;
  border: 1px solid #ddd6ce;
  border-radius: 3px;
  font-family: var(--sans);
  font-size: 10px;
  color: var(--ink);
}

.view-buttons {
  position: fixed;
  top: 70px;
  right: 16px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 60vw;
  justify-content: flex-end;
}
.view-btn {
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.93);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 180ms ease;
  box-shadow: var(--shadow-sm);
}
.view-btn:hover { background: #fff; transform: translateY(-1px); }
.view-btn.active { background: var(--plum); border-color: var(--plum); color: #fff; }

.editor-panel {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  font-size: 12px;
  flex-wrap: wrap;
  max-width: 90vw;
  justify-content: center;
}
.editor-panel button {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  transition: all 150ms ease;
}
.editor-panel button:hover { background: var(--pearl-2); }
.editor-panel button.active { background: var(--plum); color: #fff; border-color: var(--plum); }
.editor-panel .sep { width: 1px; background: var(--line); margin: 2px 4px; }
.editor-panel kbd { font-size: 9px; padding: 0 4px; margin-left: 4px; }

.editor-status {
  position: fixed;
  bottom: 74px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  background: rgba(74, 30, 63, 0.93);
  color: #fff;
  border-radius: 6px;
  font-size: 11px;
  display: none;
  box-shadow: var(--shadow-sm);
}
.editor-status.visible { display: block; }
.editor-status .label { opacity: 0.7; margin-right: 4px; }

.loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--pearl);
  z-index: 40;
  transition: opacity 400ms ease;
}
.loading.hidden { opacity: 0; pointer-events: none; }
.spinner {
  width: 32px;
  height: 32px;
  border: 2px solid rgba(74, 30, 63, 0.16);
  border-top-color: var(--rose);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(35, 16, 30, 0.5);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
}
.modal {
  width: min(420px, calc(100vw - 32px));
  background: var(--cream);
  border-radius: 14px;
  padding: 26px 26px 22px;
  box-shadow: 0 24px 60px rgba(35, 16, 30, 0.3);
}
.modal h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.4rem;
  color: var(--plum-deep);
  margin-bottom: 8px;
}
.modal p { font-size: 0.87rem; color: var(--ink-soft); line-height: 1.55; margin-bottom: 18px; }
.modal input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background: #fff;
}
.modal input:focus { outline: 2px solid rgba(212, 86, 140, 0.4); outline-offset: 1px; }
.modal .row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.modal .row.left { justify-content: space-between; }
.modal button {
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
}
.modal button.primary { background: var(--plum); border-color: var(--plum); color: #fff; }
.modal button.primary:hover { background: var(--plum-deep); }
.modal button.danger { color: #a2264b; border-color: rgba(162, 38, 75, 0.3); }
.modal .err { color: #a2264b; font-size: 0.82rem; margin-top: 10px; }

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--plum-deep);
  color: #fff;
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 0.86rem;
  z-index: 70;
  box-shadow: var(--shadow-md);
  animation: rise 240ms cubic-bezier(.2,.8,.3,1);
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }

@media (max-width: 900px) {
  .topnav { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
  .topnav .saved-hint { width: 100%; }
  .view-buttons {
    top: auto;
    bottom: 98px;
    left: 8px;
    right: 8px;
    max-width: none;
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }
  .view-btn { flex: 0 0 auto; }
  .hud {
    top: auto;
    bottom: 148px;
    left: 8px;
    right: 8px;
    max-width: none;
    max-height: 34vh;
    overflow-y: auto;
  }
  .controls { display: none; }
  .editor-panel {
    bottom: 10px;
    left: 8px;
    right: 8px;
    transform: none;
    max-width: none;
    padding: 6px;
    gap: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
  }
  .editor-panel button { flex: 0 0 auto; white-space: nowrap; }
  .editor-panel .sep { flex: 0 0 auto; }
  .editor-status { bottom: 60px; }
  .home { padding: 32px 20px 64px; }
}
