/* Thomas presence — full face framing (fixed crop) */
.thomas-presence {
  position: relative;
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
  --tp-glow: rgba(212, 175, 55, 0.35);
  --tp-ring: #42a5f5;
}
.thomas-presence .frame {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid #243049;
  background: #0d1524;
  /* taller frame so more of the face fits */
  aspect-ratio: 4/5;
  min-height: 220px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
}
.thomas-presence img.portrait,
.thomas-presence .frame video.presence-vid,
.presence-panel .frame video.presence-vid {
  width: 100%;
  height: 100%;
  /* show full head; slight top bias only */
  object-fit: cover;
  object-position: center 28%;
  display: block;
  transform: scale(1.0);
  transition: transform 2.4s ease, filter 0.4s ease;
}
.thomas-presence.listening img.portrait { filter: brightness(1.05) saturate(1.05); }
.thomas-presence.thinking img.portrait { filter: brightness(0.95) saturate(0.9); }
.thomas-presence.speaking img.portrait {
  filter: brightness(1.08);
  animation: tp-speak-breathe 1.1s ease-in-out infinite;
}
@keyframes tp-speak-breathe {
  0%, 100% { transform: scale(1.0); }
  50% { transform: scale(1.02); }
}
.thomas-presence .ring {
  position: absolute; inset: 0;
  border-radius: 18px;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(66,165,245,0.25);
}
.thomas-presence.listening .ring {
  animation: tp-listen-ring 1.6s ease-in-out infinite;
  box-shadow: inset 0 0 0 2px rgba(66,165,245,0.55), 0 0 24px var(--tp-glow);
}
.thomas-presence.speaking .ring {
  box-shadow: inset 0 0 0 2px rgba(212,175,55,0.65), 0 0 28px var(--tp-glow);
}
@keyframes tp-listen-ring {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}
/* shorter overlay so chin/beard not covered */
.thomas-presence .line-layer {
  position: absolute; left: 0; right: 0; bottom: 0; height: 22%;
  background: linear-gradient(to top, rgba(11,18,32,0.75), transparent);
  pointer-events: none;
}
.thomas-presence .line-layer svg {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%);
  width: 72%; height: 28px; opacity: 0.85;
}
.thomas-presence.speaking .wave-path {
  animation: tp-wave 0.55s ease-in-out infinite alternate;
}
@keyframes tp-wave {
  from { d: path("M0 18 Q 20 8 40 18 T 80 18 T 120 18"); }
  to   { d: path("M0 18 Q 20 28 40 18 T 80 18 T 120 18"); }
}
.thomas-presence .meta {
  margin-top: 0.55rem;
  text-align: center;
}
.thomas-presence .meta .name {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 0.95rem;
  color: #e8eef8;
}
.thomas-presence .meta .state {
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #9aabc4;
  margin-top: 0.15rem;
}
.thomas-presence.speaking .meta .state { color: #d4af37; }
.thomas-presence.listening .meta .state { color: #42a5f5; }

/* inline chat avatar */
.msg.ta {
  align-items: flex-end;
  gap: 0.45rem;
}
.msg.ta .ta-avatar {
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  overflow: hidden;
  border: 1.5px solid #d4af37;
  box-shadow: 0 0 0 2px rgba(212,175,55,0.15);
  background: #152033;
}
.msg.ta .ta-avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: center 28%;
}
.msg.ta.speaking-live .ta-avatar {
  animation: tp-avatar-pulse 1s ease-in-out infinite;
}
@keyframes tp-avatar-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(212,175,55,0.2); }
  50% { box-shadow: 0 0 0 4px rgba(212,175,55,0.45); }
}

/* presence stage */
.presence-stage {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 0.75rem 0.65rem 0.65rem;
  border-bottom: 1px solid #243049;
  background:
    linear-gradient(180deg, rgba(15,22,38,0.98), rgba(11,18,32,0.95)),
    url("/stargate/assets/thomas_priory.jpg") center/cover;
  background-blend-mode: darken;
  position: relative;
}
.presence-stage::before {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 20%, rgba(20,30,50,0.2), rgba(8,12,20,0.88));
  pointer-events: none;
}
.presence-stage > * { position: relative; z-index: 1; }
.presence-stage .scene-label {
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #9aabc4;
  margin-bottom: 0.45rem;
}
@media (min-width: 900px) {
  .app { max-width: none; }
  /* 2026-08-25: do not grid-steal intranet-strip / betty — layout-unstack owns this */
  .presence-stage {
    display: flex;
    border-bottom: none;
    border-left: 1px solid #243049;
    min-height: 0;
    overflow: auto;
    padding-top: 1rem;
  }
  .thomas-presence { max-width: 300px; }
  .thomas-presence .frame {
    min-height: 280px;
    aspect-ratio: 4/5;
  }
  .main { grid-column: 2; }
  .rail { grid-column: 1; }
}
@media (max-width: 899px) {
  .presence-stage {
    display: flex;
    max-height: none;
    min-height: 200px;
    padding-bottom: 0.75rem;
  }
  .thomas-presence { max-width: 160px; }
  .thomas-presence .frame {
    min-height: 170px;
    border-radius: 14px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .thomas-presence.speaking img.portrait,
  .thomas-presence.listening .ring,
  .msg.ta.speaking-live .ta-avatar { animation: none; }
}

/* Voice-reactive energy */
.thomas-presence, .presence-panel {
  --voice-level: 0;
  --voice-glow: 0.2;
  --voice-scale: 1;
}
.thomas-presence .frame video.presence-vid,
.presence-panel .frame video.presence-vid {
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: center 28%;
  transform: scale(var(--voice-scale));
  transition: transform 0.06s linear;
}
.thomas-presence.speaking .ring,
.presence-panel.speaking .frame {
  box-shadow:
    inset 0 0 0 2px rgba(212, 175, 55, calc(0.35 + var(--voice-level) * 0.55)),
    0 0 calc(12px + var(--voice-level) * 28px) rgba(212, 175, 55, calc(0.2 + var(--voice-level) * 0.55));
}
.thomas-presence.speaking .wave-path,
.presence-panel.speaking .wave-path {
  stroke-width: calc(1.2 + var(--voice-level) * 2.2);
  opacity: calc(0.55 + var(--voice-level) * 0.45);
}
.thomas-presence .line-layer svg,
.presence-panel .wave {
  transform: scaleY(calc(0.6 + var(--voice-level) * 1.1));
  transform-origin: center;
  transition: transform 0.05s linear;
}


/* === layout-unstack 2026-08-25: stop panes stacking on top of each other === */
html, body {
  width: 100% !important;
  max-width: 100% !important;
  height: 100% !important;
  overflow: hidden !important;
}
.app {
  width: 100% !important;
  max-width: none !important;
  height: 100dvh !important;
  margin: 0 !important;
  display: grid !important;
  grid-template-rows: auto auto 1fr !important;
}
header {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, auto) !important;
  grid-template-areas:
    "brand mic actions"
    "fabs fabs fabs" !important;
  align-items: center !important;
  gap: 0.35rem 0.55rem !important;
  flex-wrap: unset !important;
}
header .brand { grid-area: brand; min-width: 0 !important; }
header .hdr-center { grid-area: mic; }
header .hdr-actions {
  grid-area: actions;
  flex-wrap: wrap !important;
  max-width: min(48vw, 420px) !important;
  position: relative !important;
  z-index: 5 !important;
}
header .fab-dl-bar,
header .brand .fab-dl-bar {
  grid-area: fabs !important;
  margin: 0 !important;
  width: 100%;
}
.soul-bar { position: relative; z-index: 2; }

.body {
  display: grid !important;
  grid-template-columns: 240px minmax(0, 1fr) 300px !important;
  grid-template-rows: auto minmax(0, 1fr) !important;
  min-height: 0 !important;
  overflow: hidden !important;
  position: relative !important;
}
.intranet-strip {
  grid-column: 1 / -1 !important;
  grid-row: 1 !important;
  z-index: 2;
}
.rail-backdrop {
  position: fixed !important;
  inset: 0;
  grid-column: unset !important;
  grid-row: unset !important;
}
.rail,
.rail.open,
.rail:not(.open) {
  grid-column: 1 !important;
  grid-row: 2 !important;
  position: relative !important;
  transform: none !important;
  width: auto !important;
  max-width: none !important;
  left: auto !important;
  top: auto !important;
  bottom: auto !important;
  height: auto !important;
  pointer-events: auto !important;
  z-index: 3 !important;
  box-shadow: none !important;
}
.main {
  grid-column: 2 !important;
  grid-row: 2 !important;
  min-width: 0 !important;
  min-height: 0 !important;
  z-index: 1 !important;
  overflow: hidden !important;
}
.side-stack {
  grid-column: 3 !important;
  grid-row: 2 !important;
  display: flex !important;
  flex-direction: column !important;
  min-width: 0 !important;
  min-height: 0 !important;
  overflow: hidden !important;
  border-left: 1px solid #243049;
  z-index: 2 !important;
  background: #0d1524;
}
.side-stack .presence-stage,
.presence-stage {
  display: flex !important;
  flex: 0 1 auto !important;
  max-height: 42% !important;
  min-height: 0 !important;
  overflow: auto !important;
  border-left: none !important;
  width: 100% !important;
  position: relative !important;
  z-index: 1 !important;
}
.side-stack .betty-dock,
.betty-dock {
  flex: 1 1 auto !important;
  min-height: 160px !important;
  max-height: none !important;
  margin-top: 0 !important;
  position: relative !important;
  z-index: 1 !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
}
.body:not(.has-betty) .betty-dock { display: none !important; }
.body:not(.has-betty) .presence-stage { max-height: none !important; flex: 1 1 auto !important; }

/* don't let welcome / betty duplicate the header Fabric row */
.welcome-card a[href*="Fabric-Client"],
.welcome-card a[href*="fabric"] { display: none !important; }

@media (max-width: 1180px) {
  .body {
    grid-template-columns: 220px minmax(0, 1fr) !important;
    grid-template-rows: auto minmax(0, 1fr) minmax(220px, 34vh) !important;
  }
  .rail { grid-column: 1 !important; grid-row: 2 !important; }
  .main { grid-column: 2 !important; grid-row: 2 !important; }
  .side-stack,
  .presence-stage,
  .betty-dock {
    grid-column: 1 / -1 !important;
    grid-row: 3 !important;
    flex-direction: row !important;
    max-height: 34vh !important;
    border-left: none !important;
    border-top: 1px solid #243049 !important;
  }
  .side-stack .presence-stage { max-height: none !important; width: 200px !important; flex: 0 0 200px !important; }
  .side-stack .betty-dock { flex: 1 1 auto !important; min-height: 0 !important; }
}

@media (max-width: 820px) {
  .body {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: auto minmax(0, 1fr) auto !important;
  }
  .rail, .rail:not(.open) {
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    width: min(86vw, 320px) !important;
    transform: translateX(-105%) !important;
    z-index: 80 !important;
    grid-column: unset !important;
    grid-row: unset !important;
  }
  .rail.open { transform: translateX(0) !important; }
  .main { grid-column: 1 !important; grid-row: 2 !important; }
  .side-stack { grid-column: 1 !important; grid-row: 3 !important; }
  header .hdr-actions { max-width: 100% !important; }
}

/* overlap-fix: fabric row is a real header child so it cannot cover Your chats */
header {
  overflow: visible !important;
  z-index: 30 !important;
  position: relative !important;
  align-items: start !important;
}
header .brand { overflow: hidden; }
header .fab-dl-bar {
  grid-area: fabs !important;
  display: flex !important;
  flex-wrap: wrap !important;
  gap: 0.4rem !important;
  padding: 0.15rem 0 0.35rem !important;
  margin: 0 !important;
  position: relative !important;
  z-index: 2 !important;
  width: 100% !important;
  max-width: 100% !important;
}
.body {
  position: relative !important;
  z-index: 1 !important;
}
.rail {
  padding-top: 0.35rem !important;
  z-index: 1 !important;
}
/* welcome duplicate fabric button */
.welcome-card a[href*="Fabric"],
.welcome-card a#btn-fabric-win,
#messages a[href*="Fabric-Client-Windows"] {
  display: none !important;
}


/* staff-desk unstack 2026-08-25e — last word */
html body .app {
  display: flex !important;
  flex-direction: column !important;
  max-width: none !important;
  height: 100% !important;
  width: 100% !important;
}
html body .app header {
  display: flex !important;
  flex-wrap: wrap !important;
  flex: 0 0 auto !important;
}
html body .app .soul-bar { flex: 0 0 auto !important; }
html body .app .body {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: wrap !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
  grid-template-columns: none !important;
  grid-template-rows: none !important;
}
html body .app .intranet-strip {
  flex: 0 0 100% !important;
  width: 100% !important;
  max-width: 100% !important;
  order: 0 !important;
  grid-column: 1 / -1 !important;
  position: relative !important;
  z-index: 4 !important;
  display: flex !important;
}
html body .app .rail,
html body .app .rail.open,
html body .app .rail:not(.open) {
  flex: 0 0 220px !important;
  width: 220px !important;
  order: 1 !important;
  position: relative !important;
  transform: none !important;
  top: auto !important; left: auto !important; bottom: auto !important;
  z-index: 1 !important;
}
html body .app .main {
  flex: 1 1 0 !important;
  order: 2 !important;
  min-width: 0 !important;
  min-height: 0 !important;
}
html body .app .side-stack {
  flex: 0 0 260px !important;
  order: 3 !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
}
html body .app .body > .presence-stage {
  flex: 0 0 240px !important;
  order: 3 !important;
  max-width: 240px !important;
  position: relative !important;
}
html body .app .body > .betty-dock {
  flex: 0 0 240px !important;
  order: 4 !important;
  max-width: 240px !important;
  position: relative !important;
  z-index: 2 !important;
  margin-top: 0 !important;
}
html body .app .welcome-card a[href*="Fabric"],
html body .app .welcome-card a[href*="fabric"] { display: none !important; }
html body .app .thomas-presence .frame {
  min-height: 160px !important;
  max-height: 220px !important;
  aspect-ratio: 3/4 !important;
}
html body .app .thomas-presence img.portrait {
  object-position: center 18% !important;
}
