/* Yu Yue's cabin, the page's opening scene: cabin.js draws it on a canvas
   over the whole window. When she is asked to work the page comes up around
   her. The scene is on the root: `cabin` while the cabin is all there is;
   `arrive` while the page and the cabin are both up, the cabin behind, with
   the step in `data-cabin`: `room` (the conversation slides in, the wall's
   machine is still hers), `page` (the page's machine is up, the room is still
   the cabin's), `flat` (the page's room is up) and `leave` (on the way home). */
.cabin { position: fixed; inset: 0; z-index: 40; overflow: hidden; background: var(--bg); }
.cabin[hidden] { display: none; }
.cabin-loading { position: fixed; inset: 0; z-index: 41; display: grid; place-content: center; justify-items: center; gap: 12px; background: var(--bg); color: var(--ink2); }
.loading-dots { display: inline-block; font-family: var(--mono); animation: cabin-dots 1.2s step-end infinite; }
@keyframes cabin-dots {
  0% { clip-path: inset(0 2ch 0 0); }
  33.333% { clip-path: inset(0 1ch 0 0); }
  66.667%, 100% { clip-path: inset(0); }
}
:root:not([data-scene="cabin"]) .cabin-loading { display: none; }
/* The page still supplies the room's measurements. Fetch its book type and portrait when it comes into view. */
:root[data-scene="cabin"] { --serif: "Songti SC", "STSong", serif; --sc: var(--serif); --han: var(--serif); --mono: ui-monospace, monospace; }
:root[data-scene="cabin"] .operator .figure { background-image: none; }
:root[data-scene="cabin"] .app * { animation-play-state: paused; }
.cabin-ink { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.cabin-ink.pointing { cursor: pointer; }
.cabin-ink.dragging { cursor: grabbing; }
/* A button over her wherever she is, for the keyboard and the screen reader. */
.cabin-her { position: absolute; padding: 0; border: 0; border-radius: 8px; background: none; }
/* What she says, as in the page's yard. */
.cabin-say {
  position: absolute;
  z-index: 2;
  max-width: 260px;
  padding: 7px 14px 8px;
  border: 1px solid var(--ink);
  border-radius: 14px 14px 14px 3px;
  background: var(--bg);
  box-shadow: 1.5px 2.5px var(--bg), 2.5px 3.5px var(--ink2);
  font-size: 15px;
  line-height: 1.5;
  transform-origin: 0 100%;
  animation: pop .46s var(--spring) both;
}
.cabin-say .go { display: inline-block; margin: 2px 16px 0 0; padding: 0; border: 0; background: none; font-family: var(--sc); font-size: 13px; letter-spacing: .1em; color: var(--ink2); text-decoration: underline; text-decoration-color: var(--ink3); text-underline-offset: 4px; }
.cabin-say span { display: block; }
.cabin-say .go:hover { color: var(--ink); }
.cabin.fading { animation: cabin-fade .46s ease both; }
@keyframes cabin-fade { to { opacity: 0; } }

:root[data-scene="cabin"] .app { visibility: hidden; }
:root[data-scene="arrive"] .cabin { z-index: 0; background: none; }
:root[data-scene="arrive"] .app { position: relative; z-index: 1; }
/* The conversation comes in from the right, and goes back out that way. */
:root[data-scene="arrive"] .right { background: var(--bg); }
:root[data-scene="arrive"][data-cabin="room"] .right { animation: cabin-slide .75s cubic-bezier(.2, .7, .2, 1) both; }
:root[data-scene="arrive"][data-cabin="leave"] .right { animation: cabin-unslide .6s cubic-bezier(.6, 0, .8, .4) both; }
@keyframes cabin-slide { from { translate: 100% 0; } }
@keyframes cabin-unslide { to { translate: 100% 0; } }
/* The machine on her wall turns into the page's; her room into the page's yard. */
:root[data-scene="arrive"] .machine { background: var(--bg); transition: opacity .5s; }
:root[data-scene="arrive"][data-cabin="room"] .machine, :root[data-scene="arrive"][data-cabin="leave"] .machine { opacity: 0; }
:root[data-scene="arrive"] .yard { background: none; }
:root[data-scene="arrive"] .yard > * { transition: opacity .35s; }
:root[data-scene="arrive"]:not([data-cabin="flat"]) .yard > * { opacity: 0; pointer-events: none; }
/* With the cabin showing through the yard, no paper of the page lies behind her
   drawing for it to be multiplied into (it would show white). Here the drawing
   carries the paper itself, cut to her shape. */
:root[data-scene="arrive"] .operator { mix-blend-mode: normal; }
:root[data-scene="arrive"] .operator .figure {
  background-color: var(--bg);
  background-blend-mode: var(--pet-blend);
  -webkit-mask: url(yuyue-seated.webp) var(--gaze, 66.6667%) 0 / 400% 100% no-repeat;
  mask: url(yuyue-seated.webp) var(--gaze, 66.6667%) 0 / 400% 100% no-repeat;
}
:root[data-scene="arrive"] .operator.typing .figure {
  -webkit-mask: url(yuyue-typing.webp) 0 0 / 600% 100% no-repeat;
  mask: url(yuyue-typing.webp) 0 0 / 600% 100% no-repeat;
}

@media (prefers-reduced-motion: reduce) {
  .cabin, .cabin-say, .right, .loading-dots { animation: none !important; }
}
