:root {
  --paper: #f4f1ea;
  --ink: #1c1c1a;
  --ink-2: #55534d;
  --accent: #d6662e;
  --glass: rgba(250, 248, 243, 0.82);
  --line: rgba(28, 28, 26, 0.14);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--font); }
body { -webkit-font-smoothing: antialiased; overflow-x: hidden; }

#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100lvh; display: block; touch-action: pan-y; }
body.free #scene { touch-action: none; }
#scroll { position: relative; width: 1px; pointer-events: none; }

/* camera finish over the 3D: vignette and a little film grain, once we're inside */
#finish { position: fixed; inset: 0; pointer-events: none; z-index: 1; opacity: 0; transition: opacity .6s ease;
  background: radial-gradient(ellipse 85% 80% at 50% 48%, transparent 58%, rgba(28, 20, 12, 0.32) 100%); }
#finish::after { content: ''; position: absolute; inset: -60px; background-image: var(--grain); opacity: .07;
  mix-blend-mode: overlay; animation: grain .9s steps(5) infinite; }
@keyframes grain { 20% { transform: translate(-22px, 14px); } 40% { transform: translate(18px, -26px); }
  60% { transform: translate(-30px, -8px); } 80% { transform: translate(10px, 28px); } }
body[data-stage="descend"] #finish, body[data-stage="walk"] #finish, body[data-stage="end"] #finish,
body.free #finish { opacity: 1; }
@media (prefers-reduced-motion: reduce) { #finish::after { animation: none; } }

#fade { position: fixed; inset: 0; background: var(--paper); opacity: 0; pointer-events: none; transition: opacity .22s ease; z-index: 30; }
#fade.on { opacity: 1; }
#loading { position: fixed; inset: 0; display: grid; place-items: center; font: 500 13px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); z-index: 40; background: var(--paper); }

/* top bar */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: max(14px, env(safe-area-inset-top)) 20px 12px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; color: inherit; text-decoration: none; }
.brand span { font: 500 10px var(--mono); margin-left: 6px; padding: 2px 5px; border: 1px solid var(--ink); border-radius: 3px; vertical-align: 2px; }
.plan-name { font: 400 12px var(--mono); color: var(--ink-2); letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.btn { white-space: nowrap; }
@media (max-width: 640px) {
  .topbar { gap: 10px; padding-left: 16px; padding-right: 16px; }
  .topbar .btn { padding: 8px 13px; font-size: 12px; }
}
.topbar .btn { margin-left: auto; }
#progress { position: fixed; top: 0; left: 0; right: 0; height: 2px; background: var(--accent); transform-origin: 0 50%; transform: scaleX(0); z-index: 21; }
body.free #progress { opacity: 0; }

.btn {
  font: 500 13px var(--font); color: var(--paper); background: var(--ink);
  border: 1px solid var(--ink); border-radius: 999px; padding: 9px 16px; cursor: pointer;
  transition: transform .15s ease, background .15s ease, color .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.ghost { background: var(--glass); color: var(--ink); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.btn.small { padding: 7px 13px; font-size: 12px; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* plan sheet */
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.label, .dim, .note { position: absolute; left: 0; top: 0; white-space: nowrap; text-align: center; will-change: transform; }
.label { text-shadow: 0 0 3px var(--paper), 0 0 3px var(--paper), 0 0 6px var(--paper); }
.label b { display: block; font: 600 11px var(--font); letter-spacing: .06em; text-transform: uppercase; }
.label span { display: block; font: 400 10.5px var(--mono); color: var(--ink-2); margin-top: 1px; }
.dim { font: 500 11px var(--mono); background: var(--paper); padding: 0 5px; }
.note { font: 500 10px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
@media (max-width: 640px) {
  .label b { font-size: 8.5px; letter-spacing: .02em; }
  .label span { font-size: 8.5px; }
  .dim { font-size: 9px; }
  .note { font-size: 8.5px; }
}

.titleblock {
  position: fixed; left: 20px; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 6;
  width: min(330px, calc(100vw - 40px));
  border: 1.5px solid var(--ink); background: var(--paper); padding: 14px 16px 12px;
  transition: opacity .3s ease, transform .3s ease;
}
.tb-kicker { font: 500 10px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-2); }
.titleblock h1 { font-size: 26px; line-height: 1.1; margin: 6px 0 2px; letter-spacing: -0.02em; font-weight: 600; text-wrap: balance; }
.tb-sub { font-size: 13px; color: var(--ink-2); }
.tb-facts { font: 500 12px var(--mono); margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--line); }
.tb-note { font: 400 10.5px var(--mono); color: var(--ink-2); margin-top: 6px; }
.tb-edit { display: inline-block; margin-top: 8px; font: 500 10.5px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--ink); text-underline-offset: 3px; }
a.btn { display: inline-block; text-decoration: none; }
.north { position: fixed; right: 24px; transition: opacity .3s ease, transform .3s ease; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 6; width: 34px; height: 34px; border: 1.5px solid var(--ink); border-radius: 50%; display: grid; place-items: center; font: 600 11px var(--mono); transition: opacity .3s ease; }
.north::before { content: ''; position: absolute; top: -9px; left: 50%; border: 6px solid transparent; border-bottom: 9px solid var(--ink); transform: translateX(-50%); border-top: 0; }
body.portrait .north { transform: rotate(90deg); }
#hint { position: fixed; white-space: nowrap; left: 50%; bottom: max(26px, env(safe-area-inset-bottom)); transform: translateX(-50%); font: 500 12px var(--mono); letter-spacing: .08em; text-transform: uppercase; z-index: 6; transition: opacity .3s ease; }
#hint i { font-style: normal; display: inline-block; animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(4px); } }
@media (max-width: 640px) {
  .titleblock { bottom: max(16px, env(safe-area-inset-bottom)); left: 16px; padding: 11px 13px 10px; }
  .titleblock h1 { font-size: 21px; }
  .tb-note { display: none; }
  #hint { bottom: 168px; }
  .north { bottom: auto; top: 76px; right: 16px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .titleblock { padding: 8px 10px; width: 250px; }
  .titleblock h1 { font-size: 17px; }
  .tb-sub, .tb-note { display: none; }
}

body:not([data-stage="plan"]) .titleblock,
body:not([data-stage="plan"]) .north,
body:not([data-stage="plan"]) #hint,
body.free .titleblock, body.free .north, body.free #hint { opacity: 0; pointer-events: none; }
body:not([data-stage="plan"]) .titleblock { transform: translateY(8px); }

/* walk */
#roomTag {
  position: fixed; left: 20px; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 8;
  display: flex; align-items: baseline; gap: 10px;
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px;
  opacity: 0; transform: translateY(6px); transition: opacity .35s ease, transform .35s ease;
  pointer-events: none;
}
#roomTag.on { opacity: 1; transform: none; }
#roomTag .num { font: 500 11px var(--mono); color: var(--accent); }
#roomTag .name { font-weight: 600; font-size: 17px; letter-spacing: -0.01em; }
#roomTag .area { font: 400 12px var(--mono); color: var(--ink-2); }
body.free #roomTag { bottom: calc(max(20px, env(safe-area-inset-bottom)) + 64px); }

#minimap {
  position: fixed; right: 20px; top: 64px; z-index: 8;
  background: var(--glass); border: 1px solid var(--line); border-radius: 10px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  opacity: 0; pointer-events: none; transition: opacity .35s ease;
}
#minimap.on { opacity: 1; }
body.walking #minimap.on { pointer-events: auto; cursor: pointer; }
@media (max-width: 640px) { #minimap { right: 12px; top: 68px; } }

#endCard {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -46%); z-index: 12;
  width: min(460px, calc(100vw - 32px)); text-align: center;
  background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 18px; padding: 26px 22px 22px;
  opacity: 0; pointer-events: none; transition: opacity .4s ease, transform .4s ease;
}
body[data-stage="end"]:not(.free) #endCard { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%); }
#endCard h2 { margin: 0 0 6px; font-size: 26px; letter-spacing: -0.02em; }
#endCard p { margin: 0 0 18px; color: var(--ink-2); font-size: 14px; }
#endCard .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* free mode */
#freeBar {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translate(-50%, 12px); z-index: 14;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center;
  background: var(--glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 8px;
  width: max-content; max-width: calc(100vw - 24px);
  opacity: 0; pointer-events: none; transition: opacity .3s ease, transform .3s ease;
}
body.free #freeBar { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
body.free .topbar #btnExplore { display: none; }
.seg { display: flex; gap: 4px; background: rgba(28, 28, 26, 0.06); border-radius: 999px; padding: 3px; }
.seg .btn { background: transparent; color: var(--ink); border-color: transparent; }
body.walking #freeWalk, body.dollhouse #freeDoll { background: var(--ink); color: var(--paper); }
.cut { display: none; align-items: center; gap: 8px; font: 500 11px var(--mono); text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); }
body.dollhouse .cut { display: flex; }
.cut input { width: 120px; accent-color: var(--ink); }
.free-hint { font: 400 11.5px var(--mono); color: var(--ink-2); }
.walk-only, .doll-only { display: none; }
body.walking .walk-only, body.dollhouse .doll-only { display: inline; }
@media (max-width: 640px) {
  #freeBar { gap: 8px; flex-wrap: nowrap; }
  .free-hint, .cut span { display: none !important; }
  .cut input { width: 76px; }
  .seg .btn { padding: 7px 11px; }
}

body:not(.ready) .topbar, body:not(.ready) .titleblock { opacity: 0; }

/* Page text below the tour (project pages): slides up over the 3D when the tour ends. */
.page { position: relative; z-index: 15; background: var(--paper); }
body.free .page { visibility: hidden; }
.topbar { transition: background .25s ease, box-shadow .25s ease; }
body.reading .topbar { background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: 0 1px 0 var(--line); }
body.reading #progress { opacity: 0; }

/* WebGL unavailable: keep the page readable */
body.failed .topbar { opacity: 1; }
body.failed .titleblock, body.failed .north, body.failed #hint { display: none; }
#loading.failed { position: relative; inset: auto; min-height: 46vh; padding: 110px 24px 40px; text-align: center; text-transform: none; letter-spacing: 0; line-height: 1.5; z-index: auto; }
