:root {
  --cream: rgba(255, 249, 238, 0.86);
  --cream-solid: #fff9ee;
  --ink: #3b2f2a;
  --ink-soft: #7a6a5e;
  --teal: #00a187;
  --cyan: #00d0e9;
  --sage: #6f9a74;
  --line: rgba(150, 120, 90, 0.22);
  --shadow: 0 6px 18px rgba(90, 60, 30, 0.16), 0 1px 3px rgba(90, 60, 30, 0.12);
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Nunito", "Trebuchet MS", system-ui, -apple-system, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #efe4d0; font-family: var(--sans); color: var(--ink); }
body { overscroll-behavior: none; touch-action: none; -webkit-user-select: none; user-select: none; }
#app { position: fixed; inset: 0; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
.vignette { position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse 85% 75% at 50% 48%, rgba(255,248,235,0) 55%, rgba(205,180,145,0.35) 100%); }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }

/* ── HUD pills ─────────────────────────────────────────────────────────── */
.hud { position: absolute; z-index: 10; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud-tl { top: calc(12px + var(--safe-t)); left: calc(12px + var(--safe-l)); align-items: flex-start; }
.hud-tr { top: calc(12px + var(--safe-t)); right: calc(12px + var(--safe-r)); align-items: flex-end; }
.pill { background: var(--cream); backdrop-filter: blur(10px) saturate(1.1); -webkit-backdrop-filter: blur(10px) saturate(1.1);
  border: 1px solid rgba(255,255,255,0.7); box-shadow: var(--shadow); border-radius: 16px; }
.place { display: flex; align-items: center; gap: 10px; padding: 8px 14px 8px 10px; }
.place .ico { width: 26px; height: 26px; color: var(--teal); flex: none; }
.place .title { font-family: var(--serif); font-weight: 600; font-size: 19px; line-height: 1.1; letter-spacing: -0.01em; }
.place .sub { font-size: 11.5px; color: var(--ink-soft); font-weight: 700; margin-top: 1px; white-space: nowrap; }
.cam { display: flex; align-items: stretch; padding: 4px; gap: 4px; }
.cam button { min-width: 40px; height: 36px; border-radius: 12px; font-weight: 800; font-size: 14px; color: var(--ink); transition: background .15s; }
.cam button:hover { background: rgba(0,161,135,0.10); }
.cam #btnOverview { padding: 0 14px; font-size: 13.5px; }
.cam #btnZoomOut, .cam #btnZoomIn { font-size: 20px; line-height: 1; }
.cam #btnTurn { display: grid; place-items: center; }
.cam #btnTurn svg { width: 20px; height: 20px; }
.cam #btnTurn.spin svg { animation: spin .5s ease; }
@keyframes spin { to { transform: rotate(180deg); } }
.cam #btnOverview.on { background: var(--teal); color: #fff; }
.round-row { display: flex; gap: 8px; }
.round { width: 44px; height: 44px; border-radius: 14px; background: var(--cream); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.7); box-shadow: var(--shadow); display: grid; place-items: center; }
.round svg { width: 22px; height: 22px; color: var(--ink); }
.status { display: flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 999px; font-size: 11.5px; font-weight: 700; color: var(--ink-soft);
  background: rgba(255,249,238,0.78); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); box-shadow: 0 3px 10px rgba(90,60,30,0.12); }
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 3px rgba(0,161,135,0.18); }

/* ── name tags ─────────────────────────────────────────────────────────── */
#tags { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.tag { position: absolute; left: 0; top: 0; transform: translate(-50%, -100%); white-space: nowrap; will-change: transform;
  display: flex; align-items: center; gap: 8px; padding: 5px 14px 5px 10px; border-radius: 999px; font-weight: 800; font-size: 14px;
  background: rgba(255,249,238,0.92); box-shadow: 0 4px 12px rgba(90,60,30,0.18); color: var(--ink); }
.tag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--dot, var(--teal)); }

/* ── hint toast ────────────────────────────────────────────────────────── */
.hint { position: absolute; z-index: 9; left: 50%; bottom: calc(180px + var(--safe-b)); transform: translateX(-50%); max-width: calc(100% - 32px);
  padding: 9px 16px; border-radius: 999px; background: rgba(59,47,42,0.78); color: #fff8ec; font-size: 13px; font-weight: 700; text-align: center;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); transition: opacity .6s, transform .6s; pointer-events: none; }
.hint.gone { opacity: 0; transform: translate(-50%, -8px); }

/* ── proximity prompt ──────────────────────────────────────────────────── */
.prompt { position: absolute; z-index: 11; left: 50%; bottom: calc(176px + var(--safe-b)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; padding: 8px 18px 8px 8px; max-width: calc(100% - 28px);
  border-radius: 16px; background: rgba(46,38,48,0.82); color: #f6ecdf; box-shadow: 0 8px 22px rgba(40,25,20,0.28);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); font-weight: 700; font-size: 14px; white-space: nowrap;
  animation: pop .22s ease-out; }
.prompt[hidden] { display: none; }
.prompt #promptText { overflow: hidden; text-overflow: ellipsis; }
.prompt .key { flex: none; width: 30px; height: 32px; border-radius: 8px; background: #f6ecdf; color: #3b2f2a; display: grid; place-items: center;
  font-weight: 800; font-size: 14px; box-shadow: inset 0 -3px 0 rgba(0,0,0,0.15); }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 6px) scale(.97); } to { opacity: 1; transform: translate(-50%, 0) scale(1); } }

/* ── joystick + buttons ────────────────────────────────────────────────── */
.joy { position: absolute; z-index: 10; left: calc(20px + var(--safe-l)); bottom: calc(22px + var(--safe-b)); width: 136px; height: 136px; border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, rgba(70,55,50,0.38), rgba(50,40,36,0.55)); box-shadow: inset 0 2px 10px rgba(0,0,0,0.2), 0 6px 18px rgba(60,40,25,0.2);
  touch-action: none; display: none; }
.joy-ring { position: absolute; inset: 14px; border-radius: 50%; border: 2px dashed rgba(255,245,230,0.22); }
.knob { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #f2c76a, #d79f37); border: 3px solid rgba(255,248,235,0.9); box-shadow: 0 4px 10px rgba(60,40,20,0.3); }
body.touch .joy { display: block; }
.interact { position: absolute; z-index: 10; right: calc(18px + var(--safe-r)); bottom: calc(22px + var(--safe-b)); width: 104px; height: 104px; border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #3f4d47, #27302c); border: 4px solid rgba(255,249,238,0.85); color: #f6ecdf; font-weight: 800; letter-spacing: .08em; font-size: 12.5px;
  box-shadow: 0 8px 20px rgba(40,25,20,0.3); transition: transform .12s, box-shadow .2s; }
.interact.ready { border-color: var(--cyan); box-shadow: 0 0 0 5px rgba(0,208,233,0.25), 0 8px 20px rgba(40,25,20,0.3); }
.interact:active { transform: scale(.94); }
body:not(.touch) 
/* fade + loader */
.fade { position: absolute; inset: 0; z-index: 25; background: #fff7ea; opacity: 0; pointer-events: none; transition: opacity .25s; }
.fade.on { opacity: 1; }
.loader { position: absolute; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: #f6eedf; transition: opacity .5s; }
.loader img { width: min(220px, 60vw); mix-blend-mode: multiply; }
.loader p { margin: 0; font-weight: 800; color: var(--ink-soft); }
.loader.done { opacity: 0; pointer-events: none; }
.loader .err { max-width: 320px; text-align: center; color: #8a3b2b; }
.loading-dots { display: flex; gap: 6px; }
.loading-dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--teal); animation: dot 1s infinite ease-in-out; }
.loading-dots i:nth-child(2) { animation-delay: .15s; background: var(--cyan); } .loading-dots i:nth-child(3) { animation-delay: .3s; background: #e2b04a; }
@keyframes dot { 0%, 100% { transform: translateY(0); opacity: .5; } 50% { transform: translateY(-6px); opacity: 1; } }
.nojs { position: absolute; inset: 0; display: grid; place-items: center; }

/* ── responsive ────────────────────────────────────────────────────────── */
@media (max-width: 420px) {
  .place .title { font-size: 17px; }
  .place { padding: 7px 12px 7px 9px; }
  .round { width: 40px; height: 40px; }
  .status { font-size: 11px; padding: 5px 10px; }
}
/* short landscape screens (phones sideways) */
@media (orientation: landscape) and (max-height: 520px) {
  .hud-tl { flex-direction: row; align-items: center; }
  .prompt { bottom: calc(26px + var(--safe-b)); }
  .joy { width: 116px; height: 116px; left: calc(16px + var(--safe-l)); bottom: calc(14px + var(--safe-b)); }
  .interact { width: 88px; height: 88px; bottom: calc(14px + var(--safe-b)); font-size: 11px; }
    .hint { bottom: calc(28px + var(--safe-b)); }
}
/* desktop */
@media (min-width: 900px) and (min-height: 600px) {
  .prompt { bottom: calc(40px + var(--safe-b)); }
  .hint { bottom: calc(40px + var(--safe-b)); }
}

/* ── grab-a-book toast ─────────────────────────────────────────────────── */
.toast { position: absolute; z-index: 12; left: 50%; bottom: calc(238px + var(--safe-b)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; width: max-content; max-width: min(360px, calc(100% - 28px)); padding: 10px 16px 10px 10px;
  border-radius: 18px; background: var(--cream-solid); box-shadow: 0 12px 30px rgba(60,40,25,0.28); animation: toastIn .32s cubic-bezier(.2,.9,.3,1.25); }
.toast[hidden] { display: none; }
.toast.out { animation: toastOut .25s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px) scale(.94); } to { opacity: 1; transform: translate(-50%, 0) scale(1); } }
@keyframes toastOut { to { opacity: 0; transform: translate(-50%, 8px) scale(.96); } }
.toast-book { flex: none; width: 34px; height: 46px; border-radius: 4px 7px 7px 4px; background: var(--swatch, #4f7f8c);
  box-shadow: inset 5px 0 0 rgba(0,0,0,0.18), inset -2px 0 0 rgba(255,255,255,0.35), 0 3px 8px rgba(60,40,25,0.25); position: relative; }
.toast-book.wrapped::before, .toast-book.wrapped::after { content: ""; position: absolute; background: #c9a36a; }
.toast-book.wrapped::before { left: 15px; top: 0; bottom: 0; width: 3px; }
.toast-book.wrapped::after { top: 21px; left: 0; right: 0; height: 3px; }
.toast-text { min-width: 0; }
.toast-eyebrow { font-size: 10.5px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; color: var(--teal); }
.toast-title { font-family: var(--serif); font-weight: 600; font-size: 18px; line-height: 1.18; margin-top: 1px; }
.toast-sub { font-size: 12px; font-weight: 700; color: var(--ink-soft); margin-top: 2px; }

/* ── start screen / avatar picker ──────────────────────────────────────── */
.start { position: absolute; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; pointer-events: none;
  background: linear-gradient(to bottom, rgba(239,228,208,0) 30%, rgba(239,228,208,0.55) 100%); }
.start[hidden] { display: none; }
.start-card { pointer-events: auto; width: min(420px, 100%); background: var(--cream-solid); border-radius: 28px 28px 0 0; padding: 18px 20px calc(18px + var(--safe-b));
  box-shadow: 0 -10px 40px rgba(60,40,25,0.22); animation: up .35s cubic-bezier(.2,.9,.3,1); text-align: center; }
@keyframes up { from { transform: translateY(30%); opacity: .3; } to { transform: none; opacity: 1; } }
.start-logo { height: 34px; mix-blend-mode: multiply; }
.start h1 { font-family: var(--serif); font-weight: 600; font-size: 23px; line-height: 1.15; margin: 6px 0 2px; letter-spacing: -0.01em; }
.start-sub { margin: 0 0 12px; font-weight: 700; color: var(--ink-soft); font-size: 14px; }
.avatars { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.avatar-opt { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 8px 10px; border-radius: 18px; background: #f5ecdc; border: 3px solid transparent; transition: border-color .15s, background .15s, transform .12s; }
.avatar-opt svg { width: 62px; height: 62px; }
.avatar-opt b { font-size: 15px; }
.avatar-opt small { font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.avatar-opt[aria-checked="true"] { border-color: var(--teal); background: #e8f4ee; }
.avatar-opt:active { transform: scale(.97); }
.avatar-opt:focus-visible, .start-go:focus-visible, .name-field input:focus-visible { outline: 3px solid rgba(0,161,135,0.45); outline-offset: 2px; }
.name-field { display: block; text-align: left; margin: 12px 0 12px; }
.name-field span { display: block; font-size: 12px; font-weight: 800; color: var(--ink-soft); margin: 0 0 5px 4px; letter-spacing: .02em; }
.name-field input { width: 100%; font: 800 16px var(--sans); color: var(--ink); padding: 12px 14px; border-radius: 14px; border: 2px solid #eadcc4; background: #fffdf8; -webkit-user-select: text; user-select: text; }
.name-field input:focus { border-color: var(--teal); outline: none; }
.start-go { width: 100%; padding: 14px 16px; border-radius: 16px; background: var(--teal); color: #fff; font-weight: 900; font-size: 16px; letter-spacing: .02em; box-shadow: 0 6px 16px rgba(0,161,135,0.32); }
.start-go:active { transform: scale(.98); }
.start-note { margin: 8px 0 0; font-size: 11.5px; font-weight: 700; color: var(--ink-soft); }
body.starting .hud, body.starting .joy, body.starting .interact, body.starting .prompt, body.starting .hint, body.starting .toast { visibility: hidden; }
@media (min-width: 700px) {
  .start { align-items: center; justify-content: flex-end; padding-right: 6vw; background: linear-gradient(to right, rgba(239,228,208,0) 40%, rgba(239,228,208,0.5) 100%); }
  .start-card { border-radius: 28px; padding: 22px 24px; box-shadow: 0 20px 50px rgba(60,40,25,0.25); }
}
@media (orientation: landscape) and (max-height: 520px) {
  .start { align-items: center; justify-content: flex-end; padding-right: 3vw; }
  .start-card { border-radius: 22px; padding: 10px 16px; width: min(380px, 60vw); }
  .start-logo { display: none; } .start h1 { font-size: 18px; } .start-sub { margin-bottom: 6px; }
  .avatar-opt svg { width: 40px; height: 40px; } .name-field { margin: 6px 0; } .start-go { padding: 10px; } .start-note { display: none; }
  .toast { bottom: calc(120px + var(--safe-b)); }
}
@media (min-width: 900px) and (min-height: 600px) { .toast { bottom: calc(100px + var(--safe-b)); } }
body:not(.touch) .toast { bottom: calc(100px + var(--safe-b)); }
body.touch .hint, body.touch .prompt { bottom: calc(176px + var(--safe-b)); }
