:root {
  --ink: #f6f1e7;
  --ink-dim: rgba(246, 241, 231, .74);
  --glass: rgba(14, 22, 48, .46);
  --glass-brd: rgba(255, 255, 255, .16);
  --gold: #ffd98a;
  --gold-deep: #f3a64e;
  --red: #d9434f;
  --night: #070c1f;
  --paper: #fbf8f2;
  --paper-ink: #2a1d12;
  --font: 'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  background: var(--night);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- écrans & scène "cover" ---------- */
.screen {
  position: fixed; inset: 0;
  opacity: 0; visibility: hidden;
  transition: opacity .5s ease, visibility 0s linear .5s;
  pointer-events: none; /* l'écran qui s'efface ne capte plus les clics pendant le fondu */
}
.screen.active { pointer-events: auto; }
.screen.active { opacity: 1; visibility: visible; transition: opacity .5s ease; }
.screen.instant { transition: none !important; }

.viewport { position: absolute; inset: 0; overflow: hidden; }
.stage {
  position: absolute; left: 50%; top: 50%;
  width: max(100vw, calc(100vh * var(--ar)));
  height: max(calc(100vw / (var(--ar))), 100vh);
  transform: translate(-50%, -50%);
}
/* la tour glisse à gauche pour ne pas passer sous le panneau */
#tower-stage { transform: translate(calc(-50% + var(--shift, 0px)), -50%); transition: transform .8s cubic-bezier(.4,0,.2,1); }
.camera { position: absolute; inset: 0; transform-origin: 0 0; will-change: transform; }
.camera > img, .camera > svg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; user-select: none; -webkit-user-drag: none;
}
.snow { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* ---------- tour : étages ---------- */
#hits polygon { fill: transparent; cursor: pointer; pointer-events: all; }
#taken polygon { fill: #ffcf7a; opacity: .13; mix-blend-mode: screen; }
#hl { transition: opacity .3s ease; pointer-events: none; }
#hl-glow { opacity: .55; mix-blend-mode: screen; }
#hl-fill { opacity: .42; mix-blend-mode: screen; }
#hl-top, #hl-bot { stroke: #fff3d6; stroke-width: 5; stroke-linejoin: round; opacity: .95; }
#hl-line { stroke: #fff3d6; stroke-width: 3; opacity: .8; }
#hl-num { fill: #fff; font-family: var(--font); font-weight: 200; font-size: 84px; }
#hl.taken #hl-glow, #hl.taken #hl-fill { fill: #b9c8ff; opacity: .22; }
#hl.taken #hl-top, #hl.taken #hl-bot { stroke: #c9d4ff; opacity: .6; }
#hl.mine #hl-glow { animation: pulseGlow 1.4s ease-in-out infinite; }
#hl.riding #hl-num, #hl.riding #hl-line { opacity: 0; transition: opacity .3s ease; }
@keyframes pulseGlow { 50% { opacity: .9; } }

/* la tour : un canvas redessiné à chaque image + le calque SVG des étages */
.tower-view { position: absolute; inset: 0; }
#tower-canvas, #tower-overlay { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* compteur d'ascenseur pendant la montée */
#lift {
  position: absolute; left: clamp(20px, 6vw, 90px); top: 50%; transform: translateY(-50%);
  display: flex; align-items: baseline; gap: 14px; pointer-events: none;
  opacity: 0; transition: opacity .4s ease;
  text-shadow: 0 2px 30px rgba(0, 0, 0, .5);
}
#lift.on { opacity: 1; }
.lift-label { font-size: 15px; letter-spacing: .2em; text-transform: uppercase; color: var(--gold); }
.lift-num { font-size: clamp(64px, 11vw, 150px); font-weight: 200; line-height: 1; font-variant-numeric: tabular-nums; min-width: 2ch; }

/* ---------- panneau "Choisis ton étage" ---------- */
.panel {
  position: absolute; right: clamp(16px, 6vw, 96px); top: 50%;
  transform: translateY(-50%);
  width: min(360px, calc(100vw - 32px));
  padding: 28px;
  border-radius: 22px;
  background: var(--glass);
  border: 1px solid var(--glass-brd);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .35);
  transition: opacity .5s ease, transform .5s ease;
}
.panel.away { opacity: 0; transform: translateY(-50%) translateX(40px); pointer-events: none; }
.eyebrow { font-size: 12px; letter-spacing: .18em; text-transform: uppercase; color: var(--gold); }
.panel h1 { font-weight: 300; font-size: 40px; line-height: 1.05; margin: 10px 0 12px; }
.lead { font-size: 14px; line-height: 1.55; color: var(--ink-dim); }
.level { display: flex; align-items: baseline; gap: 12px; margin-top: 22px; }
.level-label { font-size: 13px; color: var(--ink-dim); }
.level-num { font-size: 68px; font-weight: 200; line-height: 1; font-variant-numeric: tabular-nums; }
.level-status { font-size: 14px; margin: 6px 0 16px; color: var(--gold); min-height: 1.2em; }
.level-status.taken { color: #aebde6; }
input[type=range] { width: 100%; accent-color: var(--gold); }
input[type=range]:disabled { opacity: .35; }

.btn-primary {
  margin-top: 18px; width: 100%;
  padding: 14px 20px; border: 0; border-radius: 999px;
  background: linear-gradient(180deg, #ffe6ad, #f3b25e);
  color: #2a1a08; font-weight: 500; font-size: 16px;
  display: flex; justify-content: space-between; align-items: center;
  box-shadow: 0 8px 24px rgba(243, 166, 78, .35);
  transition: transform .2s ease, filter .2s ease;
}
.btn-primary:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn-primary.small { padding: 11px 16px; font-size: 14px; justify-content: center; }
.hint { margin-top: 14px; font-size: 12px; color: var(--ink-dim); text-align: center; }

/* ---------- transition ---------- */
#videos video {
  position: fixed; inset: 0; width: 100%; height: 100%;
  object-fit: cover; z-index: 15; background: transparent;
  opacity: 0; pointer-events: none; visibility: hidden;
}
#videos video.on { visibility: visible; }
.desk-shade {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, transparent 45%, rgba(8, 10, 20, .35) 100%);
}
#flash {
  position: fixed; inset: 0; z-index: 20; pointer-events: none;
  background: radial-gradient(circle at 50% 50%, #fff8e6, #ffd99a 70%);
  opacity: 0; transition: opacity .45s ease;
}
#flash.on { opacity: 1; }

/* ---------- appartement ---------- */
.room-shade {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(120% 70% at 0% 100%, rgba(18, 9, 2, .78) 0%, rgba(18, 9, 2, .35) 40%, transparent 65%);
}
.frame-photo {
  position: absolute;
  /* cadre blanc mesuré sur room.jpg (1344×752) : x 490→774, y 119→338 */
  left: calc(490 / 1344 * 100%); top: calc(119 / 752 * 100%);
  width: calc(284 / 1344 * 100%); height: calc(219 / 752 * 100%);
  overflow: hidden; background: #f4efe6;
  opacity: 0; filter: brightness(2.2) blur(6px) saturate(0);
  transition: opacity 1.4s ease, filter 2.6s ease;
}
.frame-photo.show { opacity: 1; filter: none; }
.frame-photo img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 30%; display: block; }
.frame-photo .initials {
  width: 100%; height: 100%; display: grid; place-items: center;
  font-weight: 200; font-size: min(7vw, 12vh); color: rgba(255, 255, 255, .95); letter-spacing: .04em;
}
.frame-photo::after { /* léger reflet sur le verre */
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(115deg, rgba(255, 255, 255, .16) 0%, transparent 35%, transparent 70%, rgba(255, 220, 160, .12) 100%);
  box-shadow: inset 0 0 18px rgba(60, 30, 0, .35);
}

.reveal {
  position: absolute; left: clamp(16px, 5vw, 72px); bottom: clamp(24px, 8vh, 80px);
  max-width: min(560px, calc(100vw - 32px)); pointer-events: none;
  text-shadow: 0 2px 24px rgba(0, 0, 0, .45);
}
.reveal h2 { font-weight: 200; font-size: clamp(30px, 4.4vw, 60px); line-height: 1.04; margin: 10px 0 14px; }
.reveal h2 strong { display: block; font-weight: 400; color: #fff; }
.reveal p:last-child { font-size: 15px; line-height: 1.55; color: var(--ink-dim); max-width: 420px; }
.reveal > * { opacity: 0; transform: translateY(14px); transition: opacity .9s ease, transform .9s ease; }
.reveal.show > * { opacity: 1; transform: none; }
.reveal.show > :nth-child(2) { transition-delay: .3s; }
.reveal.show > :nth-child(3) { transition-delay: .7s; }

/* étiquettes d'envies */
.hotspot {
  position: absolute; display: flex; align-items: center; gap: 10px;
  transform: translate(-11px, -50%);
  background: none; border: 0; padding: 0;
  opacity: 0; scale: .85; transition: opacity .5s ease, scale .5s ease;
}
.hotspot.show { opacity: 1; scale: 1; }
.hotspot.left { flex-direction: row-reverse; transform: translate(calc(-100% + 11px), -50%); }
.hotspot .dot {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; border: 5px solid rgba(255, 217, 138, .95);
  animation: ping 2.2s ease-out infinite;
}
.hotspot .pill {
  background: rgba(24, 16, 10, .58); color: #fff;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, .22);
  padding: 7px 13px; border-radius: 999px; font-size: 13px; white-space: nowrap;
  transition: background .2s ease;
}
.hotspot:hover .pill, .hotspot:focus-visible .pill { background: rgba(24, 16, 10, .82); }
.hotspot.write .pill { background: rgba(150, 34, 46, .78); border-color: rgba(255, 200, 200, .35); }
.hotspot.write:hover .pill { background: rgba(150, 34, 46, .95); }
@keyframes ping {
  0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, .55); }
  70%, 100% { box-shadow: 0 0 0 14px rgba(255, 255, 255, 0); }
}

/* ---------- barre du haut ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px clamp(16px, 3vw, 32px); pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.ghost {
  background: rgba(10, 14, 30, .38); border: 1px solid rgba(255, 255, 255, .18);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: 9px 16px; border-radius: 999px; font-size: 14px;
}
.ghost:hover { background: rgba(10, 14, 30, .6); }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 6px;
  border-radius: 9px; background: var(--red); color: #fff;
  font-size: 11px; line-height: 18px; text-align: center;
}

/* ---------- carte d'envie ---------- */
.wish-card {
  position: fixed; right: clamp(16px, 4vw, 48px); bottom: clamp(16px, 6vh, 64px); z-index: 12;
  width: min(340px, calc(100vw - 32px));
  background: rgba(251, 248, 242, .97); color: var(--paper-ink);
  border-radius: 20px; padding: 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
  opacity: 0; transform: translateY(16px); pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
}
.wish-card.open { opacity: 1; transform: none; pointer-events: auto; }
.wish-emoji { font-size: 38px; line-height: 1; }
.wish-cat { margin-top: 12px; font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: #a0682c; }
.wish-card h3 { font-weight: 400; font-size: 22px; line-height: 1.2; margin: 6px 0 8px; }
.wish-card p { font-size: 14px; line-height: 1.55; color: #5a4636; }
.wish-card a { display: inline-block; margin-top: 12px; color: #a0682c; font-size: 14px; }
.close {
  position: absolute; top: 12px; right: 12px; width: 32px; height: 32px;
  border-radius: 50%; border: 0; background: rgba(0, 0, 0, .06); font-size: 14px;
}

/* ---------- chat ---------- */
#chat {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 30;
  width: min(400px, 100vw);
  background: var(--paper); color: var(--paper-ink);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .45s cubic-bezier(.2, .8, .2, 1);
  box-shadow: -20px 0 60px rgba(0, 0, 0, .3);
}
#chat.open { transform: none; }
.chat-head { position: relative; padding: 18px 56px 0 18px; }
.chat-head .close { top: 16px; right: 14px; }
.tabs { display: flex; gap: 6px; background: #efe8dc; padding: 4px; border-radius: 999px; }
.tabs button {
  flex: 1; border: 0; background: none; padding: 9px 8px; border-radius: 999px;
  font-size: 13px; color: #6b5645; position: relative; white-space: nowrap;
}
.tabs button.active { background: #fff; color: var(--paper-ink); box-shadow: 0 2px 8px rgba(0, 0, 0, .08); }
.tabs .dot { position: absolute; top: 6px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.chat-note {
  margin: 14px 18px 0; padding: 12px 14px; border-radius: 12px;
  background: #fff4dc; color: #6b4a1e; font-size: 13px; line-height: 1.5;
}
.msgs { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 82%; }
.msg .who { font-size: 11px; color: #9a8572; margin: 0 4px 3px; }
.msg .bubble { padding: 10px 14px; border-radius: 18px; font-size: 14px; line-height: 1.45; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .06); overflow-wrap: anywhere; }
.msg.mine { align-self: flex-end; text-align: right; }
.msg.mine .bubble { background: linear-gradient(180deg, #ffe6ad, #f6c070); text-align: left; }
.msg .time { font-size: 10px; color: #b3a08e; margin: 3px 6px 0; }
.empty { margin: auto; text-align: center; color: #9a8572; font-size: 14px; line-height: 1.6; padding: 24px; }
.empty b { display: block; font-size: 30px; margin-bottom: 8px; }
#chat-form { display: flex; gap: 8px; padding: 14px 18px 18px; border-top: 1px solid #eee4d6; }
#chat-input {
  flex: 1; min-width: 0; border: 1px solid #e3d8c8; border-radius: 999px;
  padding: 11px 16px; font: inherit; font-size: 14px; background: #fff; color: var(--paper-ink);
}
#chat-input:focus { outline: 2px solid #f3b25e; outline-offset: 0; }
#chat-form button { border: 0; border-radius: 999px; padding: 0 18px; background: var(--paper-ink); color: #fff; font-size: 14px; }
#chat-form button:disabled, #chat-input:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- barre de démo ---------- */
#devbar {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%); z-index: 40;
  display: flex; align-items: center; gap: 8px;
  background: rgba(0, 0, 0, .55); border: 1px dashed rgba(255, 255, 255, .3);
  padding: 5px 8px 5px 12px; border-radius: 999px; font-size: 12px; color: var(--ink-dim);
}
#devbar select { font: inherit; font-size: 12px; max-width: 150px; border-radius: 6px; padding: 2px 4px; }
#devbar button { border: 0; background: rgba(255, 255, 255, .12); border-radius: 50%; width: 24px; height: 24px; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  .panel { top: auto; bottom: 16px; left: 16px; right: 16px; width: auto; transform: none; padding: 18px 20px; }
  .panel.away { transform: translateY(40px); }
  .panel h1 { font-size: 28px; margin: 6px 0 4px; }
  .lead { display: none; }
  .level { margin-top: 6px; }
  .level-num { font-size: 46px; }
  .level-status { margin: 2px 0 10px; }
  .hint { display: none; }
  #devbar { top: auto; bottom: 8px; }
  #devbar span { display: none; }
  .reveal { bottom: 56px; }
  .hotspot .pill { font-size: 12px; padding: 6px 10px; }
}
@media (max-aspect-ratio: 1/1) {
  /* portrait : on laisse glisser l'appartement horizontalement */
  #room-viewport { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
  #room-viewport::-webkit-scrollbar { display: none; }
  #room-stage { left: 0; top: 0; transform: none; width: calc(100vh * var(--ar)); height: 100vh; }
}
@media (prefers-reduced-motion: reduce) {
  .hotspot .dot, #hl.pulse #hl-glow { animation: none; }
}

/* ---------- ma liste d'envies ---------- */
.top-actions { display: flex; gap: 8px; }
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 30;
  width: min(400px, 100vw);
  background: var(--paper); color: var(--paper-ink);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .45s cubic-bezier(.2, .8, .2, 1);
  box-shadow: -20px 0 60px rgba(0, 0, 0, .3);
}
.sheet.open { transform: none; }
.sheet .eyebrow { color: #a0682c; margin: 8px 0 0; }
.mywishes { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 14px 18px; display: flex; flex-direction: column; gap: 8px; }
.mywish { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; background: #fff; border-radius: 14px; box-shadow: 0 1px 3px rgba(0, 0, 0, .06); }
.mw-emoji { font-size: 22px; line-height: 1.2; }
.mw-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
.mw-text strong { font-weight: 500; }
.mw-text span { color: #7a6553; font-size: 13px; }
.mw-text a { color: #a0682c; font-size: 13px; }
.mw-tag { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: #b3a08e; white-space: nowrap; padding-top: 3px; }
.mw-del { border: 0; background: rgba(0, 0, 0, .06); border-radius: 50%; width: 26px; height: 26px; font-size: 12px; flex: none; }
.mw-del:hover { background: rgba(217, 67, 79, .15); color: var(--red); }
#list-form { display: flex; flex-direction: column; gap: 8px; padding: 14px 18px 18px; border-top: 1px solid #eee4d6; }
.list-count { margin: 0 0 2px; font-size: 12px; color: #9a8572; }
#list-form input, #list-form select {
  border: 1px solid #e3d8c8; border-radius: 12px; padding: 10px 14px;
  font: inherit; font-size: 14px; background: #fff; color: var(--paper-ink);
}
#list-form input:focus, #list-form select:focus { outline: 2px solid #f3b25e; outline-offset: 0; }
#list-form button { border: 0; border-radius: 999px; padding: 12px 18px; background: var(--paper-ink); color: #fff; font-size: 14px; margin-top: 4px; }
#list-form :disabled { opacity: .45; cursor: not-allowed; }
@media (max-width: 760px) {
  .top-actions .ghost { padding: 8px 12px; font-size: 13px; }
}

/* ---------- admin ---------- */
.admin-body { flex: 1; overflow-y: auto; padding: 0 0 18px; display: flex; flex-direction: column; gap: 14px; }
.admin-body .chat-note { margin-bottom: 0; }
.admin-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 18px; }
.admin-stats div { background: #fff; border-radius: 14px; padding: 14px; box-shadow: 0 1px 3px rgba(0, 0, 0, .06); }
.admin-stats b { display: block; font-size: 26px; font-weight: 400; }
.admin-stats span { font-size: 12px; color: #9a8572; }
#admin-draw { margin: 0 18px; width: auto; }
#admin-draw[hidden] { display: none; }
.admin-body h4 { margin: 6px 18px 0; font-size: 13px; font-weight: 500; color: #6b5645; }
.admin-missing { list-style: none; margin: 0 18px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.admin-missing li { background: #efe8dc; border-radius: 999px; padding: 5px 11px; font-size: 12px; }

/* ---------- connexion ---------- */
.login {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 20px;
  background: radial-gradient(ellipse at 50% 30%, rgba(7, 12, 31, .35), rgba(7, 12, 31, .82));
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.login[hidden] { display: none; }
.login-card {
  width: min(380px, 100%);
  background: var(--glass); border: 1px solid var(--glass-brd);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-radius: 24px; padding: 28px 26px 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
}
.login-card h1 { font-weight: 200; font-size: 36px; line-height: 1.1; margin: 8px 0 18px; }
#login-form { display: flex; flex-direction: column; gap: 10px; }
#login-form select, #login-form input {
  width: 100%; font: inherit; font-size: 16px; color: var(--paper-ink);
  background: var(--paper); border: 0; border-radius: 12px; padding: 13px 14px;
}
#login-form input { letter-spacing: .3em; }
#login-form input::placeholder { letter-spacing: normal; }
#login-form select:focus, #login-form input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
#login-code-wrap { display: flex; flex-direction: column; gap: 10px; }
#login-code-wrap[hidden] { display: none; }
.login-hint { margin: 4px 0 0; font-size: 14px; line-height: 1.5; color: var(--ink-dim); }
.login-error { margin: 0; min-height: 1.2em; font-size: 14px; color: #ff9aa2; }
.login-status { font-size: 15px; line-height: 1.5; color: var(--ink-dim); }
.login-status[hidden] { display: none; }
.login-foot { margin: 14px 0 0; font-size: 12px; color: var(--ink-dim); text-align: center; }
#login-btn { margin-top: 2px; }

.logged-out #floor-panel, .logged-out .topbar { display: none; }
@media (max-width: 760px) {
  #me-btn { padding: 8px 10px; }
  #me-name { display: none; }
}
#floor-panel.waiting .level, #floor-panel.waiting #floor-range { display: none; }
