:root {
  --ink: #26221e;
  --soft: #6d655c;
  --paper: rgba(252, 250, 246, 0.86);
  --glass: rgba(34, 30, 27, 0.72);
  --red: #d8452f;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #e9e4db;
}

#view, #door {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
#view { cursor: grab; }
#view.dragging { cursor: grabbing; }

/* ── outside: the front door ──────────────────────────────────────────────── */

body.outside { background: #0b1122; }

#caption {
  position: fixed;
  left: 50%;
  bottom: 7vh;
  transform: translateX(-50%);
  max-width: calc(100vw - 40px);
  padding: 0 8px;
  text-align: center;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(17px, 2.2vw, 23px);
  font-style: italic;
  color: #f4ecdc;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.9), 0 0 3px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s;
}
#caption.on { opacity: 1; }

#ask {
  position: fixed;
  left: 50%;
  bottom: 6vh;
  transform: translateX(-50%);
  width: min(330px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 20px 20px 16px;
  border-radius: 18px;
  background: rgba(14, 18, 30, 0.86);
  border: 1px solid rgba(255, 220, 160, 0.16);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #f4ecdc;
  animation: ask-in 0.35s ease-out;
}
@keyframes ask-in {
  from { opacity: 0; transform: translate(-50%, 14px); }
}
#ask.no { animation: ask-no 0.4s; }
@keyframes ask-no {
  20%, 60% { transform: translate(calc(-50% - 7px), 0); }
  40%, 80% { transform: translate(calc(-50% + 7px), 0); }
}
#ask label {
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: 17px;
}
#ask label + input { margin-bottom: 8px; }
#ask input {
  padding: 10px 13px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
  font: inherit;
  font-size: 15px;
  outline: none;
}
#ask input::placeholder { color: rgba(255, 255, 255, 0.35); }
#ask input:focus { border-color: #d9a85a; }
#ask-error {
  margin: 0;
  font-size: 13.5px;
  color: #ff9c85;
}
#ask-error.info { color: rgba(255, 255, 255, 0.6); }
#ask-step2 { display: flex; flex-direction: column; gap: 7px; }
.card-in a { color: var(--soft); }
.ask-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
#ask button {
  padding: 9px 16px;
  border: 0;
  border-radius: 11px;
  font: inherit;
  font-size: 14.5px;
  cursor: pointer;
}
#ask-cancel { background: transparent; color: rgba(255, 255, 255, 0.6); }
#ask-cancel:hover { color: #fff; }
#ask-go { background: #d9a85a; color: #201608; font-weight: 600; }
#ask-go:hover { background: #e6b96e; }
#ask-go:disabled { opacity: 0.55; cursor: default; }

/* the warm light you walk into when the door opens */
#fade {
  position: fixed;
  inset: 0;
  background: #f6e2bd;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.75s ease-in;
  z-index: 50;
}
#fade.on { opacity: 1; }
#fade.out { transition: opacity 0.9s ease-out; }

/* ── inside: the house ────────────────────────────────────────────────────── */

#house {
  position: fixed;
  inset: 0;
  background: #20231f;
}
body.waiting { background: linear-gradient(160deg, #efe6d6, #d9cdb8); }

#where {
  position: fixed;
  top: 16px;
  left: 16px;
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--glass);
  color: #f6f3ea;
  font-size: 15px;
  font-weight: 650;
  pointer-events: none;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
/* a steady dot: where you are looking, and what a click would act on */
#dot {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 5px;
  height: 5px;
  margin: -2.5px 0 0 -2.5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
#prompt {
  position: fixed;
  left: 50%;
  top: calc(50% + 34px);
  transform: translateX(-50%);
  padding: 5px 13px;
  border-radius: 999px;
  background: var(--glass);
  color: #f6f3ea;
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
}
#prompt::before {
  content: "E";
  display: inline-block;
  margin-right: 7px;
  padding: 0 5px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 4px;
  font: 600 11px/1.5 ui-monospace, Consolas, monospace;
}

/* ── the notepad ──────────────────────────────────────────────────────────── */

#pad {
  position: fixed;
  left: 16px;
  top: 66px;
  bottom: 84px;
  width: min(320px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  background: rgba(253, 250, 240, 0.95);
  box-shadow: 0 14px 44px rgba(40, 30, 20, 0.3);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
#pad header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px 9px 16px;
  border-bottom: 1px solid rgba(60, 45, 20, 0.12);
  font-weight: 650;
  font-size: 15px;
}
#pad-state {
  flex: 1;
  font-weight: 400;
  font-size: 12px;
  color: var(--soft);
}
#pad-close {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--soft);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
#pad-close:hover { background: rgba(60, 45, 20, 0.08); }
#pad-text {
  flex: 1;
  width: 100%;
  padding: 14px 16px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--ink);
  font: 15px/1.55 Georgia, "Times New Roman", serif;
}

/* ── top: who is here ─────────────────────────────────────────────────────── */

.pill {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--glass);
  color: #fff;
  font-size: 14px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

#hint {
  position: fixed;
  left: 16px;
  bottom: 18px;
  font-size: 13px;
  color: var(--ink);
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.66);
  pointer-events: none;
  transition: opacity 0.8s;
}
#hint.gone { opacity: 0; }

/* ── bottom right: the two of you ─────────────────────────────────────────── */

#tiles {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}
.tile {
  position: relative;
  overflow: hidden;
  border-radius: 14px;
  background: #2b2723;
  box-shadow: 0 8px 28px rgba(40, 30, 20, 0.28);
}
.tile.them { width: var(--tw, 280px); aspect-ratio: 4 / 3; }
.tile.me { width: calc(var(--tw, 280px) * 0.47); aspect-ratio: 4 / 3; }

/* the corner you drag to make the tiles bigger or smaller */
#tiles-grip {
  position: absolute;
  left: -9px;
  top: -9px;
  width: 26px;
  height: 26px;
  z-index: 2;
  cursor: nwse-resize;
  pointer-events: auto;
  touch-action: none;
}
#tiles-grip::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 5px;
  width: 11px;
  height: 11px;
  border-left: 3px solid rgba(255, 255, 255, 0.85);
  border-top: 3px solid rgba(255, 255, 255, 0.85);
  border-top-left-radius: 7px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
  opacity: 0.55;
}
#tiles-grip:hover::before { opacity: 1; }
.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.tile.me video { transform: scaleX(-1); }
.tile.off video { visibility: hidden; }
.tile .face {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
}
.tile.off .face { display: flex; }
.tile .face span {
  width: 42%;
  aspect-ratio: 1;
  max-width: 96px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #5b534b;
  color: #fff;
  font-size: 30px;
  font-weight: 600;
}
.tile.me .face span { font-size: 20px; }

/* Sound level, 0…1, set by the page many times a second: a green ring that
   swells round the initial, and a green edge on the tile when the camera is on. */
.tile { --lvl: 0; }
.tile .face span {
  box-shadow:
    0 0 0 calc(var(--lvl) * 9px + 0px) rgba(98, 222, 150, 0.9),
    0 0 0 calc(var(--lvl) * 20px + 0px) rgba(98, 222, 150, 0.3);
}
.tile.me .face span {
  box-shadow:
    0 0 0 calc(var(--lvl) * 5px) rgba(98, 222, 150, 0.9),
    0 0 0 calc(var(--lvl) * 11px) rgba(98, 222, 150, 0.3);
}
.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 3px rgb(98, 222, 150);
  opacity: min(1, calc(var(--lvl) * 2.5));
  pointer-events: none;
}
.tile.off::after { display: none; }
.tile .tag {
  position: absolute;
  left: 8px;
  bottom: 7px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(20, 18, 16, 0.6);
  color: #fff;
  font-size: 12px;
}
.tile .tag svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: #ff8f7d;
  stroke-width: 2;
  stroke-linecap: round;
}

/* ── bottom centre: mic, camera, leave ────────────────────────────────────── */

#bar {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  padding: 8px;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
#bar button {
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#bar button:hover { background: rgba(255, 255, 255, 0.26); }
#bar button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#bar .slash { display: none; }
#bar button.off { background: var(--red); }
#bar button.on { background: rgba(255, 255, 255, 0.92); color: var(--ink); }
#bar #btn-pad { position: relative; }
#pad-dot { /* the other person wrote something while the notepad was closed */
  position: absolute;
  top: 7px;
  right: 8px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #62de96;
  box-shadow: 0 0 0 2px rgba(34, 30, 27, 0.9);
}
#bar button.off .slash { display: inline; }
#bar #btn-leave { background: var(--red); }
#bar #btn-leave:hover { background: #c23a26; }

/* ── the card you see before you join ─────────────────────────────────────── */

#card {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(233, 228, 219, 0.35);
}
.card-in {
  width: min(380px, 100%);
  padding: 30px 28px 24px;
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 18px 60px rgba(60, 45, 25, 0.22);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  text-align: center;
}
.card-in h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.card-in p {
  margin: 0 0 20px;
  color: var(--soft);
  font-size: 15px;
  line-height: 1.45;
}
.card-in p.small {
  margin: 14px 0 0;
  font-size: 12.5px;
}
.card-in p.error { color: #b93a25; font-size: 13.5px; }
#join {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#join input {
  min-width: 0;
  padding: 11px 14px;
  border: 1px solid #d6cec2;
  border-radius: 12px;
  background: #fff;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  outline: none;
}
#join input:focus { border-color: #9a8f80; }
#join button {
  padding: 11px 22px;
  border: 0;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
#join button:hover { background: #3a342e; }
#join button:disabled { opacity: 0.55; cursor: default; }

@media (max-width: 720px) {
  .tile.them { width: 46vw; }
  .tile.me { width: 24vw; }
  #tiles { bottom: 84px; }
  #hint { display: none; }
}
