/* Janai Magic Portrait Frame — museum wall + baroque gilded frame.
   Portrait-first, iPad Safari. No external images: all chrome is CSS/SVG. */

:root {
  --gold-hi: #f9e58c;
  --gold: #c9971c;
  --gold-lo: #6e5210;
  --gold-shadow: #3d2c06;
  --wall: #17120e;
  --frame-w: clamp(28px, 6vmin, 64px);
  --plaque-h: clamp(30px, 6vmin, 56px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--wall);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation; /* kill iOS double-tap zoom on guest taps */
}

/* ---- Museum wall ---- */
#wall {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 120% 90% at 50% 30%, rgba(255, 214, 130, 0.07), transparent 60%),
    radial-gradient(ellipse 140% 120% at 50% 110%, rgba(0, 0, 0, 0.55), transparent 55%),
    linear-gradient(175deg, #1d1710 0%, #17120e 45%, #100c09 100%);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---- The frame ---- */
#frame {
  position: relative;
  /* portrait 9:16-ish canvas plus frame border, fit to viewport.
     dvh lines override vh where supported — in a plain Safari tab,
     100vh includes the toolbar and clips the nameplate. */
  width: min(92vw, calc((100vh - 4vmin) * 0.62));
  width: min(92vw, calc((100dvh - 4vmin) * 0.62));
  height: min(96vh, calc(92vw * 1.61));
  height: min(96dvh, calc(92vw * 1.61));
  padding: var(--frame-w);
  padding-bottom: calc(var(--frame-w) + var(--plaque-h));
  filter: drop-shadow(0 18px 40px rgba(0, 0, 0, 0.75));
}

.frame-edge {
  position: absolute;
  border-radius: 6px;
  pointer-events: none;
}

.frame-edge-outer {
  inset: 0;
  background:
    linear-gradient(135deg, var(--gold-hi) 0%, var(--gold) 18%, var(--gold-lo) 42%, var(--gold) 60%, var(--gold-hi) 78%, var(--gold-lo) 100%);
  box-shadow:
    inset 0 2px 3px rgba(255, 240, 190, 0.8),
    inset 0 -3px 6px rgba(30, 20, 4, 0.9);
}

.frame-edge-mid {
  inset: calc(var(--frame-w) * 0.22);
  background:
    repeating-linear-gradient(90deg,
      rgba(255, 235, 170, 0.28) 0 6px,
      rgba(90, 62, 10, 0.5) 6px 12px),
    linear-gradient(315deg, var(--gold) 0%, var(--gold-lo) 35%, var(--gold) 55%, var(--gold-hi) 85%);
  box-shadow:
    inset 0 1px 2px rgba(255, 244, 200, 0.7),
    inset 0 -2px 4px rgba(20, 13, 2, 0.9);
}

.frame-edge-inner {
  inset: calc(var(--frame-w) * 0.62);
  background: linear-gradient(160deg, var(--gold-lo), var(--gold-shadow) 50%, var(--gold-lo));
  box-shadow:
    inset 0 0 0 2px rgba(250, 226, 150, 0.55),
    inset 0 0 14px rgba(0, 0, 0, 0.95);
}

/* ---- Corner flourishes ---- */
.flourish {
  position: absolute;
  width: calc(var(--frame-w) * 2.3);
  height: calc(var(--frame-w) * 2.3);
  pointer-events: none;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.6));
}
.flourish-tl { top: calc(var(--frame-w) * -0.28); left: calc(var(--frame-w) * -0.28); }
.flourish-tr { top: calc(var(--frame-w) * -0.28); right: calc(var(--frame-w) * -0.28); transform: scaleX(-1); }
.flourish-bl { bottom: calc(var(--plaque-h) - var(--frame-w) * 0.28); left: calc(var(--frame-w) * -0.28); transform: scaleY(-1); }
.flourish-br { bottom: calc(var(--plaque-h) - var(--frame-w) * 0.28); right: calc(var(--frame-w) * -0.28); transform: scale(-1, -1); }

/* ---- Canvas (the living painting) ---- */
#canvas {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #120c05;
  border-radius: 2px;
}

.portrait-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  /* Keep in lockstep with CROSSFADE_S in app.js. Short = a match cut with the
     edges softened, not a fade. See scripts/match-cut.py for why. */
  transition: opacity 0.25s linear;
}
.portrait-video.visible { opacity: 1; }
/* The wave is the one clip that CANNOT be match-cut: it ends mid-gesture, hand
   still raised (drift 25.6 vs ~6 for the trimmed idles), and there's no frame in
   it that returns to the resting pose. So this exit keeps a real dissolve to
   mask the jump. Fix properly by generating a wave that settles back to rest. */
#wakeVideo { transition: opacity 0.9s ease-in-out; }

/* Canvas-texture overlay: woven linen via crossed repeating gradients.
   Masked out over the face zone — up close (phones, or nose-to-glass on the
   iPad) the 1px/3px grid over skin reads as pixelation/scan lines, not linen.
   The weave stays strong at the edges where the painted-canvas illusion is
   actually sold, and fades to nothing over the center-upper face band. */
#canvasTexture {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(255, 250, 235, 0.035) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.05) 0 1px, transparent 1px 3px);
  mix-blend-mode: overlay;
  -webkit-mask-image: radial-gradient(ellipse 68% 46% at 50% 38%, transparent 0 40%, #000 82%);
  mask-image: radial-gradient(ellipse 68% 46% at 50% 38%, transparent 0 40%, #000 82%);
}

/* Phone-sized viewports sit inches from the eye — halve the weave there too. */
@media (max-width: 520px) {
  #canvasTexture { opacity: 0.5; }
}

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 108% 105% at 50% 46%, transparent 58%, rgba(10, 6, 0, 0.55) 100%),
    linear-gradient(180deg, rgba(20, 12, 0, 0.18), transparent 12% 88%, rgba(10, 6, 0, 0.3));
}

/* ---- Brass nameplate ---- */
#nameplate {
  position: absolute;
  bottom: calc(var(--frame-w) * 0.16);
  left: 50%;
  transform: translateX(-50%);
  padding: clamp(5px, 1vmin, 9px) clamp(18px, 4vmin, 36px);
  background: linear-gradient(180deg, #e8c96a 0%, #b58a24 30%, #8a651a 55%, #c9a03a 85%, #7a5a14 100%);
  border-radius: 3px;
  box-shadow:
    inset 0 1px 1px rgba(255, 246, 210, 0.85),
    inset 0 -1px 2px rgba(40, 26, 4, 0.8),
    0 2px 5px rgba(0, 0, 0, 0.6);
}
#nameplate::before, #nameplate::after {
  /* screw heads */
  content: "";
  position: absolute;
  top: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  transform: translateY(-50%);
  background: radial-gradient(circle at 35% 35%, #f4e2a8, #7c5c12 70%);
  box-shadow: inset 0 -1px 1px rgba(30, 18, 2, 0.9);
}
#nameplate::before { left: 7px; }
#nameplate::after { right: 7px; }

.plaque-text {
  font-family: Georgia, 'Times New Roman', serif;
  font-variant: small-caps;
  letter-spacing: 0.22em;
  font-size: clamp(12px, 2.4vmin, 20px);
  color: #3a2a08;
  text-shadow: 0 1px 0 rgba(255, 240, 190, 0.55);
  white-space: nowrap;
}

/* ---- v1 CONVERSE mode (additive) ---- */

/* Live Simli stream sits above wake video, under texture/vignette */
/* The live avatar. `contain`, not `cover`: cover crops a square source into the
   tall frame and blows her face up to fill it, which is the zoomed-in jump Os
   saw. contain shows the avatar as generated. */
#simliVideo {
  transition: opacity 0.7s ease-in-out;
  object-fit: contain;
  /* Feather the edges so the square avatar melts into the backdrop instead of
     sitting on it as an obvious rectangle. */
  -webkit-mask-image: radial-gradient(ellipse 72% 62% at 50% 46%, #000 45%, transparent 96%);
          mask-image: radial-gradient(ellipse 72% 62% at 50% 46%, #000 45%, transparent 96%);
}

/* Blurred painting behind the avatar — fills what `contain` leaves empty, so the
   hall and candlelight continue around her rather than cutting to black. */
#simliBackdrop {
  position: absolute;
  inset: 0;
  background-image: url('assets/idle/poster.jpg');
  background-size: cover;
  background-position: center;
  filter: blur(26px) brightness(0.92) saturate(1.05);   /* dark enough and it just reads as black bars */
  transform: scale(1.18);           /* hide the blur's soft edges */
  opacity: 0;
  transition: opacity 0.7s ease-in-out;
  pointer-events: none;
}
/* Only while she's actually speaking. :has() is Safari 15.4+; the iPad is well past. */
#canvas:has(#simliVideo.visible) #simliBackdrop { opacity: 1; }

/* Nameplate glows softly once the bridge is reachable — the discreet talk button */
#nameplate.talk-ready {
  cursor: pointer;
  animation: plaque-glow 4.5s ease-in-out infinite;
}
@keyframes plaque-glow {
  0%, 100% {
    box-shadow:
      inset 0 1px 1px rgba(255, 246, 210, 0.85),
      inset 0 -1px 2px rgba(40, 26, 4, 0.8),
      0 2px 5px rgba(0, 0, 0, 0.6);
  }
  50% {
    box-shadow:
      inset 0 1px 1px rgba(255, 246, 210, 0.85),
      inset 0 -1px 2px rgba(40, 26, 4, 0.8),
      0 2px 5px rgba(0, 0, 0, 0.6),
      0 0 18px 4px rgba(249, 229, 140, 0.45);
  }
}

/* Status whisper (connecting / error) — italic serif, spoken under her breath */
#converseStatus {
  position: absolute;
  bottom: 12%;
  left: 50%;
  transform: translateX(-50%);
  font-family: Georgia, 'Times New Roman', serif;
  font-style: italic;
  font-size: clamp(13px, 2.2vmin, 18px);
  letter-spacing: 0.12em;
  color: rgba(249, 229, 140, 0.9);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
  pointer-events: none;
  transition: opacity 0.5s ease;
  white-space: nowrap;
}
#converseStatus.hidden { opacity: 0; }

/* Hold-to-talk orb: a small gilded medallion at the canvas foot */
#talkOrb {
  position: absolute;
  bottom: 4%;
  left: 50%;
  transform: translateX(-50%);
  width: clamp(54px, 9vmin, 84px);
  height: clamp(54px, 9vmin, 84px);
  border-radius: 50%;
  border: 2px solid rgba(250, 226, 150, 0.7);
  background:
    radial-gradient(circle at 35% 32%, rgba(255, 240, 190, 0.9), rgba(201, 151, 28, 0.85) 45%, rgba(110, 82, 16, 0.9) 100%);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.7), inset 0 -3px 8px rgba(40, 26, 4, 0.7);
  opacity: 0.92;
  transition: opacity 0.5s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: none; /* hold-to-talk: no scroll/zoom gestures mid-press */
}
#talkOrb::after {
  /* simple mic glyph */
  content: "";
  position: absolute;
  inset: 26% 38% 30% 38%;
  background: #3a2a08;
  border-radius: 40% 40% 46% 46% / 55% 55% 42% 42%;
  clip-path: polygon(30% 0, 70% 0, 70% 55%, 100% 55%, 100% 68%, 58% 68%, 58% 88%, 78% 88%, 78% 100%, 22% 100%, 22% 88%, 42% 88%, 42% 68%, 0 68%, 0 55%, 30% 55%);
}
#talkOrb.hidden { opacity: 0; pointer-events: none; }
#talkOrb.recording {
  transform: translateX(-50%) scale(1.12);
  animation: orb-pulse 1.1s ease-in-out infinite;
}
@keyframes orb-pulse {
  0%, 100% { box-shadow: 0 3px 12px rgba(0, 0, 0, 0.7), 0 0 0 0 rgba(249, 229, 140, 0.55); }
  50% { box-shadow: 0 3px 12px rgba(0, 0, 0, 0.7), 0 0 0 14px rgba(249, 229, 140, 0); }
}
#talkOrb.thinking {
  animation: orb-think 1.6s ease-in-out infinite;
  pointer-events: none;
}
@keyframes orb-think {
  0%, 100% { opacity: 0.9; }
  50% { opacity: 0.35; }
}

/* Landscape fallback: keep the portrait frame centered, wall fills the rest */
@media (orientation: landscape) {
  #frame {
    width: min(58vw, calc((100vh - 4vmin) * 0.62));
    width: min(58vw, calc((100dvh - 4vmin) * 0.62));
    height: 96vh;
    height: 96dvh;
  }
}
