/* Out in 20 · game screen.
   Look and feel live in Tailwind utilities (see client/tailwind.css). This file keeps only what
   utilities cannot express: the room viewport and canvas, labels positioned by script, the 2D
   fallback illustration, the lens, popover placement, and animations. */
html,
body {
  margin: 0;
  background: #16293b;
  color: #12263a;
  font-family: 'DM Sans', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
*,
*::before,
*::after {
  box-sizing: border-box;
}
main {
  margin: 0;
  padding: 0;
  max-width: none;
}
[hidden] {
  display: none !important;
}
button {
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:disabled {
  cursor: not-allowed;
}
input,
select,
textarea {
  font: inherit;
}
:focus-visible {
  outline: 3px solid #2779a8;
  outline-offset: 3px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* The scene fills the device; the DOM controls float over it. */
.scene {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #16293b;
  isolation: isolate;
}
.room-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.room-viewport:focus-visible {
  outline-offset: -3px;
}
.room-world {
  position: relative;
  width: 100%;
  height: 100%;
}
.room-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  z-index: 0;
}
.three-room .room-art,
.three-room .stars,
.three-room .moonbeam,
.three-room .world-state,
.three-room .actor-layer {
  display: none;
}
.three-room .room-world {
  touch-action: none;
  user-select: none;
  cursor: grab;
}
.three-room .room-viewport {
  overflow: clip;
  touch-action: none;
}
.three-room .room-canvas {
  cursor: grab;
}
.three-room .room-world.camera-dragging,
.three-room .room-world.camera-dragging * {
  cursor: grabbing !important;
}
.room-world.object-hover,
.room-world.object-hover .room-canvas {
  cursor: pointer;
}
.room-arrival .room-canvas {
  animation: room-arrival 0.55s ease-out;
}

/* Object labels: the script sets left/top (3D projection or the fallback percentages below). */
.hotspot {
  position: absolute;
  z-index: 3;
  transform: translate(-50%, -50%);
}
.hotspot.out-of-view {
  opacity: 0;
  pointer-events: none;
}
.hotspot.out-of-view:focus-visible {
  opacity: 1;
}
.scene.arrival .hotspot[aria-pressed='true'] {
  animation: discover-glow 0.8s ease-out;
}
.quiet-labels .hotspot {
  font-size: 0;
  width: 44px;
  height: 44px;
  padding: 0;
}
.quiet-labels .hotspot::before {
  content: '';
  display: block;
  width: 12px;
  height: 12px;
  margin: auto;
  border-radius: 50%;
  background: #12263a;
}
/* A teammate examining an object is flagged on its label. */
.hotspot[data-crew]::after {
  content: attr(data-crew) ' is here';
  position: absolute;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  border-radius: 999px;
  background: #ffbf2f;
  color: #12263a;
  box-shadow: 0 2px 8px rgba(18, 38, 58, 0.35);
  pointer-events: none;
}
.spot-desk {
  left: 23%;
  top: 67%;
}
.spot-power {
  left: 11%;
  top: 43%;
}
.spot-telescope {
  left: 54%;
  top: 48%;
}
.spot-cabinet {
  left: 76%;
  top: 49%;
}
.spot-chart {
  left: 28%;
  top: 31%;
}
.spot-door {
  left: 90%;
  top: 49%;
}
.spot-return {
  left: 6%;
  top: 62%;
}

/* 2D fallback (used when WebGL is unavailable or switched off). */
.room-art {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: fill;
  filter: brightness(0.82) saturate(0.9);
}
.moonbeam,
.layout-illustration .stars,
.layout-illustration .moonbeam,
.layout-illustration .world-state {
  display: none;
}
.actor-layer,
.world-state {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.actor-layer {
  z-index: 2;
}
.walking .walker {
  animation: bob 0.29s ease-in-out infinite alternate;
}
.walking .leg-left {
  animation: stride 0.29s infinite alternate;
  transform-origin: 0 -24px;
}
.walking .leg-right {
  animation: stride 0.29s infinite alternate-reverse;
  transform-origin: 0 -24px;
}
.destination {
  fill: rgba(255, 191, 47, 0.2);
  stroke: #ffbf2f;
  stroke-width: 2;
  opacity: 0;
}
.scene.moving .destination {
  opacity: 0.8;
}

/* The observatory's lens: blurred until the focus wheel is right. */
.lens-view {
  position: relative;
  aspect-ratio: 1;
  background: radial-gradient(circle, #1c394e 0, #092033 65%, #050e18 70%);
  border: 12px solid #8d815f;
  border-radius: 50%;
  box-shadow:
    inset 0 0 30px #000,
    0 4px 10px rgba(0, 0, 0, 0.2);
  margin: 12px auto;
  max-width: 250px;
  overflow: hidden;
}
.constellations {
  display: grid;
  gap: 16px;
  place-content: center;
  height: 100%;
  text-align: center;
  filter: blur(5px);
  opacity: 0.65;
  transition:
    filter 0.2s,
    opacity 0.2s;
}
.focused .constellations {
  filter: blur(0);
  opacity: 1;
}
.constellations > div {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  color: #ebe5da;
}
.constellations span {
  font-size: 18px;
  letter-spacing: 4px;
}
.constellations b {
  font: 600 18px 'Fredoka', system-ui, sans-serif;
  color: #ffbf2f;
}
.lens-crosshair {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 95px sans-serif;
  opacity: 0.1;
  color: #d7cfbf;
  pointer-events: none;
}

/* Popover placement: right by default, left for the locks so pinned clues sit opposite. */
#inspector {
  position: absolute;
  z-index: 20;
  top: 92px;
  right: 24px;
  width: min(410px, calc(100% - 48px));
  max-height: calc(100% - 92px - 100px);
  overflow: auto;
}
#inspector[data-anchor='cabinet'],
#inspector[data-anchor='door'] {
  right: auto;
  left: 24px;
}
.pinned-clues {
  position: absolute;
  z-index: 5;
  left: 24px;
  top: 190px;
  width: min(330px, 30%);
  max-height: calc(100% - 190px - 120px);
  overflow: auto;
}
.scene:has(#inspector[data-anchor='cabinet']:not([hidden])) .pinned-clues,
.scene:has(#inspector[data-anchor='door']:not([hidden])) .pinned-clues {
  left: auto;
  right: 24px;
  top: 92px;
  max-height: calc(100% - 92px - 100px);
}
@media (max-width: 760px) {
  #inspector {
    left: 0 !important;
    right: 0 !important;
    top: auto;
    bottom: 0;
    width: auto;
    max-height: 80dvh;
    border-radius: 28px 28px 0 0 !important;
  }
  .pinned-clues {
    display: none;
  }
}

/* Motion */
#inspector.incorrect {
  animation: lock-shake 0.25s ease-in-out;
}
.clock-box.notice {
  animation: clock-notice 1s ease-in-out 3;
}
@keyframes bob {
  to {
    transform: translateY(-2px);
  }
}
@keyframes stride {
  to {
    transform: rotate(18deg);
  }
}
@keyframes lock-shake {
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}
@keyframes room-arrival {
  from {
    opacity: 0.35;
  }
  to {
    opacity: 1;
  }
}
@keyframes discover-glow {
  30% {
    box-shadow:
      0 0 0 8px rgba(255, 191, 47, 0.35),
      0 0 32px rgba(255, 191, 47, 0.5);
  }
}
@keyframes clock-notice {
  50% {
    box-shadow: 0 0 0 3px #ffbf2f;
  }
}
@media (prefers-reduced-motion: reduce) {
  .clock-box.notice {
    animation: none;
    box-shadow: 0 0 0 3px #ffbf2f;
  }
  .room-arrival .room-canvas,
  #inspector.incorrect {
    animation: none;
  }
}

/* How-to-play highlights the element being described. */
.tour-target {
  position: relative;
  z-index: 30;
  outline: 4px solid #ffbf2f;
  outline-offset: 4px;
  border-radius: 16px;
}

/* While a lock is open on the left, the popover carries the guidance, so the objective steps aside. */
.scene:has(#inspector[data-anchor='cabinet']:not([hidden])) #objective-card,
.scene:has(#inspector[data-anchor='door']:not([hidden])) #objective-card,
.scene:has(#inspector[data-anchor='cabinet']:not([hidden])) #role-chip,
.scene:has(#inspector[data-anchor='door']:not([hidden])) #role-chip {
  display: none;
}

/* A quick-start lobby stays compact; the room collection expands only on request. */
#session-dialog {
  width: min(640px, calc(100vw - 2rem));
}
#session-dialog.crew-chooser,
#session-dialog.room-chooser:has(#room-customize[open]) {
  width: min(1040px, calc(100vw - 2rem));
}
#room-customize[open] > summary > span {
  transform: rotate(45deg);
}
@media (prefers-reduced-motion: reduce) {
  #room-customize > summary > span {
    transition: none;
  }
}
