/*
 * The page is the inside of the tube she is looking into.
 *
 * Both clips are laid out by JS (see layout() in app.js) so the hole in the
 * footage is wider than the window: her face covers the page, and the tube wall
 * only ever shows up in the corners, where .tube keeps it dark and out of the
 * way. Nothing here is letterboxed, so there is no edge to give the video away.
 */

@property --iris {
  syntax: '<percentage>';
  inherits: false;
  initial-value: 0%;
}

:root {
  --ink: #f4efe9;
  --ink-dim: #b3aaa0;
  --ink-faint: #8b8279;
  --line: rgba(244, 239, 233, 0.16);
  --glow: #c9a227;

  /* Sampled off the frame on screen, so the rim never fights the footage. */
  --room-warm: 46, 34, 27;

  /* Written every frame by JS: the lean, the push of a contact, and one bump. */
  --pan-x: 0px;
  --pan-y: 0px;
  --bump-x: 0px;
  --bump-y: 0px;
  --push: 1;

  --touch-x: 50%;
  --touch-y: 50%;

  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas,
    'Liberation Mono', monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #070605;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  cursor: crosshair;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ------------------------------------------------------------------- the room */

/*
 * One transform for the whole world. The cursor leans it a little, and being
 * touched pushes it a little further into your face — doing that on the
 * container means the two clips can never drift apart from each other.
 *
 * Deliberately no rotation and no oscillation. The footage is handheld and
 * magnified, so it is already moving more than a still page ever would; adding
 * a shake on top of that is what made this unpleasant to sit in front of.
 */
.room {
  position: fixed;
  inset: 0;
  z-index: 0;
  transform: translate3d(
      calc(var(--pan-x) + var(--bump-x)),
      calc(var(--pan-y) + var(--bump-y)),
      0
    )
    scale(var(--push));
  transform-origin: 50% 45%;
  will-change: transform;
  filter: saturate(var(--grade-sat)) brightness(var(--grade-bright))
    contrast(var(--grade-contrast));
  transition: filter 1.4s ease;
}

/* Size and position come from JS; both clips are stacked on the same anchor. */
.clip {
  position: absolute;
  object-fit: cover;
  background: #100c0a;
}

/*
 * The paw clip is only up during a contact, and it arrives fast — a slow
 * dissolve would read as a scene change instead of something touching you.
 */
#paw {
  opacity: 0;
  transition: opacity 0.14s ease;
}

#paw.on {
  opacity: 1;
}

/* Mood grading, held as numbers so anything inside .room gets the same pass. */
:root {
  --grade-sat: 1;
  --grade-bright: 1;
  --grade-contrast: 1;
}

body[data-mood='sleepy'] {
  --grade-sat: 0.4;
  --grade-bright: 0.62;
}
body[data-mood='hungry'] {
  --grade-sat: 0.95;
  --grade-contrast: 1.08;
}
body[data-mood='restless'] {
  --grade-sat: 1.14;
  --grade-contrast: 1.14;
}
body[data-mood='aloof'] {
  --grade-sat: 0.7;
  --grade-bright: 0.88;
}
body[data-mood='affectionate'] {
  --grade-sat: 1.16;
  --grade-bright: 1.06;
}
body[data-mood='playful'] {
  --grade-sat: 1.1;
  --grade-bright: 1.03;
}

/* ------------------------------------------------------------------ the tube */

/*
 * Cardboard close to your face: dark in the corners, tinted with the colour
 * sampled off the current frame, with a faint rim of light where the hole ends.
 * This is what hides the tube wall when the shot drifts.
 */
.tube {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    /* A circle, sized to the corners: an ellipse fitted to the window instead
       crushes the top and bottom of her face on a wide screen. */
    radial-gradient(
        circle at 50% 46%,
        transparent 30%,
        rgba(var(--room-warm), 0.34) 66%,
        rgba(8, 6, 5, 0.74) 86%,
        rgba(4, 3, 2, 0.97) 100%
      ),
    /* The lit edge of the hole, just inside the dark. */
    radial-gradient(
        circle at 50% 46%,
        transparent 70%,
        rgba(255, 240, 220, 0.07) 79%,
        transparent 89%
      ),
    linear-gradient(to top, rgba(6, 5, 4, 0.62), transparent 22%);
}

/*
 * Blinked over a cut: the picture is a face at arm's length, and a hard cut
 * between two of those reads as a jolt. Light only, no movement.
 */
.blink {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  background: #080605;
}

.blink.shut {
  animation: blink 0.3s ease-in-out;
}

@keyframes blink {
  0% {
    opacity: 0;
  }
  26% {
    opacity: 0.72;
  }
  100% {
    opacity: 0;
  }
}

/* The warmth of contact, radiating from wherever she landed. */
.warmth {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(
    60% 60% at var(--touch-x) var(--touch-y),
    rgba(255, 226, 190, 0.5),
    rgba(255, 198, 150, 0.16) 45%,
    transparent 72%
  );
}

.warmth.flash {
  animation: warmth 1.15s ease-out forwards;
}

@keyframes warmth {
  0% {
    opacity: 0;
  }
  12% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

/* ----------------------------------------------------------------- the opening */

/*
 * Shut over the whole window until the first frame is ready, then it opens from
 * the middle, the way something dark opens when a cat's head blocks the light
 * and then moves.
 */
.lid {
  position: fixed;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  background: #070605;
  --iris: 0%;
  -webkit-mask-image: radial-gradient(
    circle at 50% 46%,
    transparent var(--iris),
    #000 calc(var(--iris) + 26%)
  );
  mask-image: radial-gradient(
    circle at 50% 46%,
    transparent var(--iris),
    #000 calc(var(--iris) + 26%)
  );
  transition:
    --iris 1.5s cubic-bezier(0.22, 0.61, 0.36, 1),
    opacity 1.4s ease 0.35s;
}

body:not([data-phase='opening']) .lid {
  --iris: 130%;
  opacity: 0;
}

/* ---------------------------------------------------------------- overlay text */

.zzz {
  position: fixed;
  z-index: 4;
  left: 50%;
  bottom: 24%;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: clamp(1.1rem, 3vmin, 2rem);
  letter-spacing: 0.34em;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 0.15rem 1.4rem rgba(0, 0, 0, 0.9);
  opacity: 0;
  transition: opacity 0.9s ease;
  pointer-events: none;
}

body[data-asleep='true'] .zzz {
  opacity: 1;
  animation: drift 3.2s ease-in-out infinite;
}

@keyframes drift {
  0%,
  100% {
    transform: translateX(-50%) translateY(0);
    opacity: 0.5;
  }
  50% {
    transform: translateX(-50%) translateY(-0.5rem);
    opacity: 1;
  }
}

/* Where you touched her. */
.ripple {
  position: fixed;
  z-index: 4;
  width: 7rem;
  height: 7rem;
  margin: -3.5rem 0 0 -3.5rem;
  border-radius: 50%;
  border: 2px solid rgba(255, 236, 214, 0.7);
  animation: ripple 0.9s ease-out forwards;
  pointer-events: none;
}

@keyframes ripple {
  from {
    transform: scale(0.12);
    opacity: 0.9;
  }
  to {
    transform: scale(1.5);
    opacity: 0;
  }
}

.bubble {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: 15%;
  transform: translateX(-50%);
  margin: 0;
  max-width: min(26rem, 82vw);
  text-align: center;
  font-family: var(--mono);
  font-size: clamp(0.95rem, 2.2vmin, 1.35rem);
  text-shadow: 0 0.15rem 1.4rem rgba(0, 0, 0, 0.95);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.bubble.show {
  opacity: 1;
}

.bubble.refused {
  color: var(--ink-dim);
  font-style: italic;
  font-size: clamp(0.85rem, 1.8vmin, 1.1rem);
}

/* ---------------------------------------------------------------- masthead */

/*
 * Small, and late: the page opens on her face, and the name only fades up once
 * she has already touched you.
 */
.masthead {
  position: fixed;
  z-index: 5;
  top: max(1.1rem, env(safe-area-inset-top));
  left: clamp(1rem, 3.5vw, 2.75rem);
  max-width: min(22rem, 58vw);
  text-shadow: 0 0.15rem 1.5rem rgba(0, 0, 0, 0.95);
  pointer-events: none;
  opacity: 0;
  transform: translateY(-0.4rem);
  transition:
    opacity 1.4s ease,
    transform 1.4s ease;
}

body[data-phase='live'] .masthead {
  opacity: 1;
  transform: none;
}

h1 {
  margin: 0;
  font-size: clamp(1.7rem, 3.4vw, 2.6rem);
  line-height: 0.95;
  letter-spacing: -0.045em;
  font-weight: 650;
}

/* The one instruction the page needs, in the middle, then gone for good. */
.hint {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: 8.5%;
  transform: translateX(-50%);
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(0.72rem, 1.5vmin, 0.85rem);
  letter-spacing: 0.06em;
  color: rgba(244, 239, 233, 0.62);
  text-shadow: 0 0.15rem 1.2rem rgba(0, 0, 0, 0.95);
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.2s ease;
}

body[data-phase='live'] .hint {
  opacity: 1;
}

.hint.gone,
/* Something she just did outranks a standing instruction, and on a short
   window the two of them land on top of each other. */
.bubble.show ~ .hint {
  opacity: 0;
}

/* --------------------------------------------------------------- the readout */

/*
 * The library is still running the cat, and you can still open her up and see
 * it — but folded into a corner, because the page is her face now.
 */
.controls {
  position: fixed;
  z-index: 7;
  right: clamp(1rem, 3.5vw, 2.75rem);
  bottom: max(1rem, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 0.45rem;
  opacity: 0;
  transition: opacity 1.2s ease;
}

body[data-phase='live'] .controls {
  opacity: 1;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font: inherit;
  font-size: 0.78rem;
  color: var(--ink);
  background: rgba(11, 9, 8, 0.5);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
  backdrop-filter: blur(14px) saturate(1.1);
  -webkit-backdrop-filter: blur(14px) saturate(1.1);
  transition:
    background 0.2s ease,
    color 0.6s ease;
}

.chip:hover {
  background: rgba(11, 9, 8, 0.75);
}

.chip em {
  font-style: normal;
  color: var(--glow);
  transition: color 1.2s ease;
}

.chev {
  font-size: 0.6rem;
  color: var(--ink-faint);
  transition: transform 0.25s ease;
}

body[data-panel='open'] .chev {
  transform: rotate(180deg);
}

#soundBtn {
  color: var(--ink-faint);
  padding: 0.35rem 0.62rem;
}

#soundBtn[aria-pressed='true'] {
  color: var(--glow);
}

.hud {
  position: fixed;
  z-index: 6;
  left: clamp(1rem, 3.5vw, 2.75rem);
  right: clamp(1rem, 3.5vw, 2.75rem);
  bottom: calc(max(1rem, env(safe-area-inset-bottom)) + 3rem);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: clamp(0.9rem, 2.2vw, 2rem);
  padding: 0.85rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(11, 9, 8, 0.62);
  backdrop-filter: blur(16px) saturate(1.1);
  -webkit-backdrop-filter: blur(16px) saturate(1.1);
  opacity: 0;
  transform: translateY(0.6rem);
  pointer-events: none;
  transition:
    opacity 0.3s ease,
    transform 0.3s ease;
}

body[data-panel='open'] .hud {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.readout {
  display: grid;
  min-width: 11rem;
}

.readout strong {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-transform: lowercase;
  color: var(--glow);
  transition: color 1.2s ease;
}

.readout span {
  font-size: 0.75rem;
  color: var(--ink-dim);
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(7rem, 9rem));
  gap: 0.4rem 1.4rem;
  margin: 0;
}

.stat {
  display: grid;
  gap: 0.15rem;
}

.stat dt {
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.stat dd {
  margin: 0;
}

.bar {
  display: block;
  height: 0.3rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--ink-dim);
  transition:
    width 0.4s ease,
    background 0.6s ease;
}

/* A need past its threshold stops being decorative. */
.stat[data-alert='true'] .bar i {
  background: var(--glow);
}
.stat[data-alert='true'] dt {
  color: var(--ink);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.actions button {
  font: inherit;
  font-size: 0.82rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.32rem 0.85rem;
  cursor: pointer;
  transition:
    background 0.2s ease,
    transform 0.1s ease;
}

.actions button:hover {
  background: rgba(255, 255, 255, 0.2);
}
.actions button:active {
  transform: translateY(1px);
}

.meta-actions {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-left: auto;
  font-size: 0.76rem;
}

.meta-actions a,
.meta-actions button {
  font: inherit;
  color: var(--ink-faint);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.meta-actions a:hover,
.meta-actions button:hover {
  color: var(--ink);
  border-bottom-color: currentColor;
}

.log {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.72rem;
  color: var(--ink-faint);
}

/* Only take up a line when there is something on it. */
.log:empty {
  display: none;
}

:where(button, a):focus-visible {
  outline: 2px solid var(--glow);
  outline-offset: 3px;
  border-radius: 0.25rem;
}

.noscript {
  position: fixed;
  z-index: 7;
  inset: auto 2rem 2rem;
  color: var(--ink-dim);
}

/* ------------------------------------------------------------------ narrow */

@media (max-width: 55rem) {
  .masthead {
    max-width: 70vw;
  }

  /* Three lines of her talking, up out of the way of the standing hint. */
  .bubble {
    bottom: 19%;
    max-width: 74vw;
  }

  .hud {
    gap: 0.7rem;
    padding: 0.8rem;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
    flex: 1 1 100%;
  }

  .meta-actions {
    margin-left: 0;
  }
}

/*
 * No leaning, no shake, no iris: she still comes and goes, but the page holds
 * still while she does it.
 */
@media (prefers-reduced-motion: reduce) {
  .room {
    transform: none;
  }

  .blink.shut {
    animation: none;
  }

  .lid {
    transition: opacity 0.6s ease;
  }

  .warmth.flash {
    animation-duration: 0.9s;
  }

  .zzz,
  .ripple {
    animation: none;
  }
}
