:root {
  --gasket: #100c0a;
  --frame: #2b231e;
  --frame-hi: #4a3d34;
  --sill: #3c322b;
  --seat: #2b323b;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #14100e;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #e8e0d4;
}

/* ---------- scene / carriage ---------- */

#scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
  animation: sway 7s ease-in-out infinite;
}

@keyframes sway {
  0%   { transform: translate(0, 0) rotate(0deg); }
  18%  { transform: translate(0.7px, -1.6px) rotate(0.05deg); }
  37%  { transform: translate(-0.9px, 0.9px) rotate(-0.06deg); }
  55%  { transform: translate(0.5px, 1.4px) rotate(0.04deg); }
  74%  { transform: translate(-0.6px, -1px) rotate(-0.04deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

/* interior wall: light spill from the window, panel seams, vertical shading */
#carriage {
  position: absolute;
  inset: -2vmin;
  background:
    radial-gradient(58% 42% at 50% 45%, rgba(255, 232, 195, 0.11), transparent 72%),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.22) 0 1px, transparent 1px 13vw),
    linear-gradient(180deg, #191411 0%, #2a221d 24%, #2d251f 58%, #150f0d 100%);
  transition: filter 0.5s ease;
}

/* overhead luggage rack */
.rack {
  position: absolute;
  left: 0;
  right: 0;
  top: 10%;
  height: 2vh;
  background: linear-gradient(180deg, #4c4038 0%, #2e2622 55%, #181310 100%);
  box-shadow:
    0 1.6vh 3.4vh rgba(0, 0, 0, 0.55),
    0 -0.5vh 2vh rgba(0, 0, 0, 0.3);
  transition: opacity 0.5s ease;
}

/* reading-light glow spilling down from under the rack */
.rack::after {
  content: "";
  position: absolute;
  left: 4%;
  right: 4%;
  top: 100%;
  height: 16vh;
  background: radial-gradient(68% 100% at 50% 0%, rgba(255, 226, 175, 0.13), transparent 72%);
  pointer-events: none;
}

/* headrest of the seat in front, bottom-left, out of focus */
.seatback {
  position: absolute;
  left: -9vw;
  bottom: -10vh;
  width: 36vw;
  height: 32vh;
  border-radius: 5vmin 11vmin 0 0;
  background: linear-gradient(158deg, #222831 0%, #141920 52%, #0a0d11 100%);
  box-shadow:
    inset 0 1px 0 rgba(190, 210, 235, 0.07),
    0 -1vh 6vh rgba(0, 0, 0, 0.6);
  filter: blur(4px);
  transform: rotate(-1.5deg);
  transition: opacity 0.5s ease;
}

/* ---------- the window ---------- */

#window-wrap {
  position: absolute;
  left: 50%;
  top: 47%;
  width: clamp(300px, 57vw, 1020px);
  height: clamp(190px, 45vh, 560px);
  transform: translate(-50%, -50%);
  transition: width 0.5s ease, height 0.5s ease, left 0.5s ease, top 0.5s ease;
}

#window {
  position: absolute;
  inset: 0;
  container-type: size;
  overflow: hidden;
  border-radius: clamp(10px, 2.4vmin, 30px);
  background: #000;
  box-shadow:
    /* glass edge, rubber gasket, then the painted frame */
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    0 0 0 0.7vmin var(--gasket),
    0 0 0 1.5vmin var(--frame),
    0 0 0 1.6vmin var(--frame-hi),
    0 2.5vmin 6vmin rgba(0, 0, 0, 0.6);
  transition: border-radius 0.5s ease;
}

/* rolled-up sunshade above the pane */
.shade {
  position: absolute;
  left: -1%;
  right: -1%;
  bottom: 100%;
  height: 1.7vh;
  margin-bottom: 2.2vmin;
  border-radius: 1vh;
  background: linear-gradient(180deg, #5c4d42 0%, #3a2f27 60%, #241c17 100%);
  box-shadow: 0 0.7vh 1.8vh rgba(0, 0, 0, 0.5);
  transition: opacity 0.5s ease;
}

/* ledge under the pane */
.sill {
  position: absolute;
  left: -3%;
  right: -3%;
  top: 100%;
  height: 3vh;
  margin-top: 2.2vmin;
  border-radius: 0 0 1vmin 1vmin;
  background: linear-gradient(180deg, #52453b 0%, #33291f 45%, #1e1714 100%);
  box-shadow: 0 1.4vh 3vh rgba(0, 0, 0, 0.5);
  transition: opacity 0.5s ease;
}

/* daylight catching the front edge of the sill */
.sill::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(255, 226, 178, 0.4), transparent);
}

/* ---------- media inside the pane ---------- */

#media {
  position: absolute;
  inset: 0;
  background: #000;
}

.media-slot {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 1.6s ease;
}

.media-slot.visible { opacity: 1; }

/* Oversize the player 1.7× the pane (container units keep 16:9) so YouTube's
   title bar, progress bar and watermark all fall outside the visible glass. */
.media-slot iframe {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 170%;
  height: 170%;
  width: max(170cqw, 302cqh);
  height: max(95.6cqw, 170cqh);
  transform: translate(-50%, -50%);
  border: 0;
  pointer-events: none;
}

/* Mapillary stills: cover the pane with a slow drift */
.media-slot img.still {
  position: absolute;
  top: 50%;
  left: 50%;
  min-width: 112%;
  min-height: 112%;
  width: auto;
  height: auto;
  transform: translate(-50%, -50%);
  object-fit: cover;
  filter: saturate(0.96) brightness(0.97);
}

.media-slot.visible img.still {
  animation: drift 6s linear forwards;
}

@keyframes drift {
  from { transform: translate(-50%, -50%) scale(1); }
  to   { transform: translate(-52.5%, -50.4%) scale(1.06); }
}

/* ---------- glass ---------- */

/* canvas is a replaced element: inset alone won't stretch it, so size it explicitly */
#rain {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.75;
}

#reflection {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(112deg,
      transparent 0%, transparent 36%,
      rgba(255, 255, 255, 0.055) 39%, rgba(255, 255, 255, 0.014) 45%,
      transparent 48%, transparent 66%,
      rgba(255, 255, 255, 0.035) 69%, transparent 73%),
    radial-gradient(ellipse at 84% 112%, rgba(255, 236, 200, 0.06), transparent 55%);
}

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 9vmin 1.5vmin rgba(5, 3, 2, 0.7);
}

/* smudge/haze so the pane reads as glass, not a cutout */
#glass {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(120% 90% at 30% 15%, rgba(190, 205, 225, 0.05), transparent 60%);
}

/* ---------- status / messages ---------- */

#status {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-width: 30em;
  padding: 1em 1.4em;
  background: rgba(12, 9, 7, 0.86);
  border: 1px solid rgba(255, 236, 200, 0.15);
  border-radius: 10px;
  font-size: 0.95rem;
  line-height: 1.45;
  text-align: center;
  z-index: 5;
}

/* ---------- controls ---------- */

#controls {
  position: fixed;
  left: 50%;
  bottom: 3.5vmin;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.7rem 0.9rem;
  background: rgba(14, 11, 9, 0.78);
  border: 1px solid rgba(255, 236, 200, 0.12);
  border-radius: 14px;
  backdrop-filter: blur(10px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

body.idle #controls,
body.idle #attribution {
  opacity: 0;
  pointer-events: none;
}

body.idle { cursor: none; }

#controls .row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#controls .row.secondary {
  font-size: 0.8rem;
  color: #b8ac9a;
}

#place {
  width: 21rem;
  max-width: 52vw;
  padding: 0.55em 0.8em;
  font-size: 0.95rem;
  color: #f0e8da;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 236, 200, 0.18);
  border-radius: 8px;
  outline: none;
}

#place:focus { border-color: rgba(255, 216, 150, 0.5); }

#controls button {
  padding: 0.5em 0.85em;
  font-size: 0.9rem;
  color: #e8e0d4;
  background: rgba(255, 236, 200, 0.08);
  border: 1px solid rgba(255, 236, 200, 0.16);
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

#controls button:hover { background: rgba(255, 236, 200, 0.16); }

.mode-toggle {
  display: inline-flex;
  border: 1px solid rgba(255, 236, 200, 0.16);
  border-radius: 8px;
  overflow: hidden;
}

.mode-toggle button {
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
}

.mode-toggle button.active {
  background: rgba(255, 216, 150, 0.22) !important;
  color: #ffe9c4;
}

#controls .toggle.on {
  background: rgba(255, 216, 150, 0.22);
  color: #ffe9c4;
}

#now-showing {
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.8;
}

/* ---------- attribution ---------- */

#attribution {
  position: fixed;
  right: 2vmin;
  bottom: 1.6vmin;
  z-index: 10;
  font-size: 0.62rem;
  color: rgba(220, 205, 180, 0.5);
  transition: opacity 0.6s ease;
}

#attribution a { color: inherit; }

/* portrait / phones: a taller pane, seat out of the way */
@media (max-aspect-ratio: 1/1) {
  #window-wrap {
    width: 82vw;
    height: 38vh;
    top: 42%;
  }
  .seatback { left: -14vw; bottom: -12vh; width: 46vw; }
}

@media (max-width: 640px) {
  #place { width: 12rem; }
  #now-showing { display: none; }
}

/* ---------- fill mode: the view takes the whole screen ----------
   Last in the file so it overrides the responsive sizing above. */

/* keep the centering transform so only the box size animates */
body.fill #window-wrap {
  left: 50%;
  top: 50%;
  width: 100vw;
  height: 100vh;
}

body.fill #window { border-radius: 0; box-shadow: inset 0 0 0 0.5vmin var(--gasket); }
body.fill .shade,
body.fill .sill,
body.fill .rack,
body.fill .seatback { opacity: 0; }
body.fill #carriage { filter: brightness(0.4); }

/* ---------- reduced motion: keep the view, drop the rocking ---------- */

@media (prefers-reduced-motion: reduce) {
  #scene { animation: none; }
  .media-slot.visible img.still { animation: none; }
  #window-wrap,
  .media-slot { transition-duration: 0.01ms; }
}
