/* =========================================================
   StarkLabs JARVIS Web UI — FULL app.css (drop-in)
   Glass + Orbs + Chat Animations + FIXED Thinking Bubble
   (No :has(), shimmer behind content, no clipping)
   ========================================================= */

:root{
  --bg: #0a0f1f;
  --text: #ebf0ff;
  --muted: #9aa9c9;

  --accent: #35d0ff;
  --accent2: #7df6c7;
  --accentSoft: rgba(53,208,255,.20);
  --danger: #ff7a92;
  --dangerSoft: rgba(255,122,146,.16);

  --glassBorder: rgba(102,139,255,.20);
  --innerBorder: rgba(255,255,255,.05);

  --shadow: 0 20px 45px rgba(0,0,0,.35);
  --shadowSoft: 0 12px 28px rgba(0,0,0,.24);

  /* Orb parallax vars (set by JS; harmless if JS isn't running) */
  --px: 0px;
  --py: 0px;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }

body{
  margin:0;
  font-family: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
  background:
    radial-gradient(circle, rgba(53,208,255,.06) 1px, transparent 1px),
    radial-gradient(circle at 80% -10%, rgba(64, 123, 255, 0.34), transparent 42%),
    radial-gradient(circle at 10% -20%, rgba(50, 225, 178, 0.18), transparent 40%),
    var(--bg);
  background-size: 28px 28px, 100% 100%, 100% 100%, 100% 100%;
  color: var(--text);
  overflow-x:hidden;
  position:relative;
}

/* =========================================================
   Animated Orb Background (CSS-only + parallax via vars)
   ========================================================= */

body::before,
body::after{
  content:"";
  position:fixed;
  inset:-20vh -20vw;
  pointer-events:none;
  background-repeat:no-repeat;
  transform: translate3d(0,0,0);
  will-change: transform, filter;
}

body::before{
  z-index:-2;
  opacity:.92;
  filter: blur(34px) saturate(155%);
  background-image:
    radial-gradient(520px 380px at 16% 18%, rgba(74,163,255,.30), transparent 62%),
    radial-gradient(560px 420px at 82% 14%, rgba(255,74,106,.20), transparent 64%),
    radial-gradient(620px 520px at 76% 86%, rgba(140,120,255,.18), transparent 62%),
    radial-gradient(620px 520px at 14% 84%, rgba(53,208,255,.14), transparent 60%);
  animation: orbDriftA 18s ease-in-out infinite alternate;
  transform: translate3d(calc(var(--px) * .35), calc(var(--py) * .35), 0);
}

body::after{
  z-index:-3;
  opacity:.80;
  filter: blur(56px) saturate(175%);
  background-image:
    radial-gradient(820px 620px at 42% 38%, rgba(53,208,255,.10), transparent 70%),
    radial-gradient(820px 620px at 54% 78%, rgba(255,74,106,.08), transparent 72%),
    radial-gradient(980px 700px at 92% 52%, rgba(255,255,255,.06), transparent 74%);
  animation: orbDriftB 26s ease-in-out infinite alternate;
  transform: translate3d(calc(var(--px) * -.20), calc(var(--py) * -.20), 0);
}

/* Scanline overlay */
.wrap::after{
  content:"";
  position:fixed;
  inset:0;
  pointer-events:none;
  z-index:9999;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,.03) 2px,
    rgba(0,0,0,.03) 4px
  );
}

/* Vignette + sheen */
.wrap::before{
  content:"";
  position:fixed;
  inset:0;
  z-index:-1;
  pointer-events:none;
  background:
    radial-gradient(1200px 700px at 50% -10%, rgba(255,255,255,.06), transparent 55%),
    radial-gradient(1200px 700px at 50% 110%, rgba(0,0,0,.60), transparent 55%),
    radial-gradient(900px 700px at 0% 50%, rgba(0,0,0,.40), transparent 55%),
    radial-gradient(900px 700px at 100% 50%, rgba(0,0,0,.40), transparent 55%);
}

@keyframes orbDriftA{
  0%   { filter: blur(34px) saturate(150%); }
  100% { filter: blur(38px) saturate(185%); }
}
@keyframes orbDriftB{
  0%   { filter: blur(56px) saturate(170%); }
  100% { filter: blur(62px) saturate(205%); }
}

@media (prefers-reduced-motion: reduce){
  body::before, body::after{ animation:none !important; }
}

/* =========================================================
   Base Layout
   ========================================================= */

.wrap{
  min-height:100vh;
  display:grid;
  place-items:center;
  padding:24px;
  position:relative;
}

/* =========================================================
   Glass Card
   ========================================================= */

.card{
  width:min(920px, 100%);
  border-radius:22px;
  border:1px solid var(--glassBorder);
  background: linear-gradient(180deg, rgba(12,17,34,.90), rgba(12,17,34,.78));
  box-shadow: var(--shadow), 0 0 0 1px var(--innerBorder) inset;
  overflow:hidden;

  backdrop-filter: blur(18px) saturate(155%);
  -webkit-backdrop-filter: blur(18px) saturate(155%);
  position:relative;
}

/* interior HUD glow */
.card::after{
  content:"";
  position:absolute;
  inset:0;
  pointer-events:none;
  border-radius:22px;
  box-shadow: inset 0 0 0 1px rgba(53,208,255,.08), inset 0 0 60px rgba(53,208,255,.04);
  z-index:0;
}

/* top gloss */
.card::before{
  content:"";
  position:absolute;
  inset:0;
  pointer-events:none;
  background:
    radial-gradient(920px 160px at 30% 0%, rgba(255,255,255,.10), transparent 62%),
    radial-gradient(920px 160px at 70% 0%, rgba(53,208,255,.10), transparent 66%);
  opacity:.55;
}

/* =========================================================
   Header
   ========================================================= */

.header{
  padding:18px 22px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;

  border-bottom:1px solid var(--glassBorder);
  background: rgba(0,0,0,.12);
  box-shadow: 0 1px 0 0 rgba(53,208,255,.25);

  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
}

/* Status dot */
.status-dot{
  width:8px;
  height:8px;
  border-radius:50%;
  background:#00ff88;
  box-shadow: 0 0 8px #00ff88, 0 0 16px rgba(0,255,136,.4);
  animation: statusPulse 2s ease-in-out infinite;
  flex-shrink:0;
}

@keyframes statusPulse{
  0%,100%{ opacity:1; }
  50%    { opacity:.5; }
}

.brand{ display:flex; flex-direction:column; gap:2px; }
.brand .title{
  font-weight:900;
  font-size:22px;
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing:.8px;
  color: var(--accent);
  text-shadow: 0 0 20px rgba(53,208,255,.6), 0 0 40px rgba(53,208,255,.3), 0 12px 34px rgba(0,0,0,.45);
}
.brand .subtitle{
  color: var(--muted);
  font-size:13px;
}

.small{ color: var(--muted); font-size:12px; }

/* =========================================================
   Buttons
   ========================================================= */

.btn{
  border:1px solid var(--glassBorder);
  background: rgba(255,255,255,.05);
  color: var(--text);
  padding:10px 12px;
  border-radius:14px;
  cursor:pointer;

  backdrop-filter: blur(10px) saturate(150%);
  -webkit-backdrop-filter: blur(10px) saturate(150%);

  box-shadow: var(--shadowSoft), 0 0 0 1px rgba(255,255,255,.04) inset;
  transition: transform .12s ease, background .12s ease, border-color .12s ease, box-shadow .12s ease;
}

.btn:hover{
  transform: translateY(-1px);
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.18);
  box-shadow: 0 18px 48px rgba(0,0,0,.30), 0 0 0 1px rgba(255,255,255,.05) inset;
}
.btn:active{ transform: translateY(0) scale(.99); }

.btn.primary{
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  border-color: transparent;
  color: #03101d;
  box-shadow: 0 18px 50px rgba(53,208,255,.15), 0 0 0 1px rgba(53,208,255,.08) inset;
}

.composer .btn.primary{
  padding: 10px 20px;
  font-weight: 600;
  letter-spacing: .5px;
}
.btn.primary:hover{ filter: brightness(1.04); }

.btn.danger{
  background: var(--dangerSoft);
  border-color: rgba(255,74,106,.42);
}

/* =========================================================
   Content / Forms
   ========================================================= */

.content{ padding:18px 22px; }

.grid{
  display:grid;
  grid-template-columns:1fr;
  gap:12px;
}
@media (min-width:820px){
  .grid{ grid-template-columns:1fr 1fr; }
}

.field label{
  display:block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size:13px;
}

.field input{
  width:100%;
  padding:12px 12px;
  border-radius:14px;
  border:1px solid var(--glassBorder);
  background: rgba(0,0,0,.20);
  color: var(--text);
  outline:none;

  backdrop-filter: blur(10px) saturate(150%);
  -webkit-backdrop-filter: blur(10px) saturate(150%);

  box-shadow: 0 12px 28px rgba(0,0,0,.20), 0 0 0 1px rgba(255,255,255,.03) inset;
  transition: border-color .12s ease, box-shadow .12s ease, background .12s ease;
}

.field input:focus{
  border-color: rgba(53,208,255,.55);
  background: rgba(0,0,0,.24);
  box-shadow:
    0 0 0 3px rgba(53,208,255,.14),
    0 18px 54px rgba(53,208,255,.10);
}

.note{
  color: var(--muted);
  font-size:13px;
  line-height:1.35;
}

.err{
  display:none;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid rgba(255,74,106,.45);
  background: rgba(255,74,106,.14);
  color: rgba(255,220,228,.98);

  backdrop-filter: blur(10px) saturate(150%);
  -webkit-backdrop-filter: blur(10px) saturate(150%);
}

/* =========================================================
   Chat Layout
   ========================================================= */

.chat{
  height: 72vh;
  min-height: 420px;
  display:grid;
  grid-template-rows: auto 1fr auto;
}

.messages{
  padding:18px 22px;
  overflow:auto;
  display:flex;
  flex-direction:column;
  gap:12px;

  scrollbar-width:thin;
  scrollbar-color: rgba(53,208,255,.20) rgba(0,0,0,.10);
}

.messages::-webkit-scrollbar{ width:6px; }
.messages::-webkit-scrollbar-thumb{
  background: rgba(53,208,255,.18);
  border-radius: 6px;
}
.messages::-webkit-scrollbar-track{ background: rgba(0,0,0,.08); }

/* bubbles */
.bubble{
  padding: 12px 14px;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(0,0,0,.18);
  line-height: 1.35;
  white-space: pre-wrap;

  backdrop-filter: blur(10px) saturate(150%);
  -webkit-backdrop-filter: blur(10px) saturate(150%);

  box-shadow: 0 12px 30px rgba(0,0,0,.18), 0 0 0 1px rgba(255,255,255,.02) inset;
}

/* entrance animation */
.bubble.in{ animation: bubbleIn .18s ease-out both; }
@keyframes bubbleIn{
  from{ opacity:0; transform: translateY(6px) scale(.985); }
  to  { opacity:1; transform: translateY(0) scale(1); }
}

.bubble.user{
  border-color: rgba(53,208,255,.55);
  border-right: 2px solid rgba(53,208,255,.5);
  background: rgba(53,208,255,.12);
  box-shadow:
    0 18px 44px rgba(53,208,255,.10),
    0 0 0 1px rgba(53,208,255,.06) inset;
}

.bubble.jarvis{
  border-left: 2px solid rgba(53,208,255,.35);
  padding-left: 16px;
}

/* Timestamp */
.bubble-time{
  font-size:10px;
  color: rgba(155,170,210,.5);
  display:block;
  margin-top:4px;
  font-family: "IBM Plex Mono", monospace;
}

/* =========================================================
   THINKING BUBBLE — FIXED (NO TEXT CLIPPING)
   - inline-flex + align-items center prevents baseline clipping
   - shimmer behind content
   - dots stable in Firefox/Chromium
   ========================================================= */

.bubble.jarvis.thinking{
  position:relative;
  overflow:hidden;

  /* IMPORTANT: prevents the "Thinking" text getting clipped */
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;

  /* Safety net: tiny minimum height so fonts never clip */
  min-height: 40px;

  border-color: rgba(53,208,255,.48);

  background:
    linear-gradient(90deg,
      rgba(53,208,255,.12),
      rgba(255,255,255,.06),
      rgba(53,208,255,.12)
    ),
    rgba(0,0,0,.18);
  background-size: 220% 100%;
  background-position: 0% 0%;

  /* Slightly tighter line-height helps some fonts on Linux/Firefox */
  line-height: 1.1;

  animation:
    thinkPulse 1.10s ease-in-out infinite,
    thinkSheen 2.30s linear infinite,
    thinkBreathe 1.60s ease-in-out infinite;
}

/* shimmer overlay BEHIND content */
.bubble.jarvis.thinking::after{
  content:"";
  position:absolute;
  inset:-40% -40%;
  z-index: 1;
  background: linear-gradient(
    120deg,
    transparent 40%,
    rgba(53,208,255,.14) 50%,
    transparent 60%
  );
  transform: translateX(-55%) translateY(12%) rotate(8deg);
  animation: jarvisScan 1.25s ease-in-out infinite;
  pointer-events:none;
  mix-blend-mode: screen;
  opacity: .85;
}

/* content above shimmer */
.bubble.jarvis.thinking > *{
  position:relative;
  z-index: 2;
}

/* label */
.bubble .thinkingLabel{
  color: rgba(234,242,255,.92);
  font-size: 14px;
  line-height: 1.1;
  white-space: nowrap;
}

/* dots */
.bubble .dots{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:6px;
  line-height: 1;
  vertical-align: middle;
}

.bubble .dots span{
  display:inline-block;
  width:7px;
  height:7px;
  border-radius:999px;
  background: rgba(231,238,252,.80);
  box-shadow: 0 0 12px rgba(53,208,255,.14);
  animation: dotBounce 1.0s ease-in-out infinite;
  transform: translateZ(0);
}
.bubble .dots span:nth-child(2){ animation-delay:.12s; opacity:.85; }
.bubble .dots span:nth-child(3){ animation-delay:.24s; opacity:.70; }

@keyframes dotBounce{
  0%,100%{ transform: translateY(0); opacity:.65; }
  50%    { transform: translateY(-5px); opacity:1; }
}

@keyframes jarvisScan{
  0%   { transform: translateX(-55%) translateY(12%) rotate(8deg); opacity:.55; }
  50%  { opacity:.95; }
  100% { transform: translateX(55%) translateY(-12%) rotate(8deg); opacity:.55; }
}

@keyframes thinkSheen{
  0%   { background-position: 0% 0%; }
  100% { background-position: 200% 0%; }
}

@keyframes thinkBreathe{
  0%,100%{ transform: translateY(0); }
  50%    { transform: translateY(-1px); }
}

@keyframes thinkPulse{
  0%,100%{
    box-shadow:
      0 0 0 1px rgba(53,208,255,.10) inset,
      0 12px 30px rgba(0,0,0,.18),
      0 0 18px rgba(53,208,255,.10);
  }
  50%{
    box-shadow:
      0 0 0 1px rgba(53,208,255,.14) inset,
      0 12px 30px rgba(0,0,0,.18),
      0 0 34px rgba(53,208,255,.22);
  }
}

/* =========================================================
   Composer
   ========================================================= */

.composer{
  border-top: 1px solid var(--glassBorder);
  padding: 14px 16px;
  display:grid;
  grid-template-columns: 1fr auto auto;
  gap:10px;

  background: rgba(0,0,0,.12);
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
}

.composer textarea{
  width:100%;
  resize:none;
  padding:12px 12px 24px;
  border-radius:14px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.18);
  color: var(--text);
  outline:none;
  min-height:44px;
  max-height:160px;

  backdrop-filter: blur(10px) saturate(150%);
  -webkit-backdrop-filter: blur(10px) saturate(150%);

  box-shadow: 0 12px 28px rgba(0,0,0,.18), 0 0 0 1px rgba(255,255,255,.03) inset;
  transition: border-color .12s ease, box-shadow .12s ease, background .12s ease;
}

.composer textarea:focus{
  border-color: rgba(53,208,255,.55);
  background: rgba(0,0,0,.22);
  box-shadow:
    0 0 0 3px rgba(53,208,255,.14),
    0 18px 54px rgba(53,208,255,.10);
}

/* =========================================================
   Bubble Wrap (copy button host)
   ========================================================= */

.bubble-wrap {
  position: relative;
  align-self: flex-start;
  max-width: 78%;
}
.bubble-wrap.user {
  align-self: flex-end;
}
.bubble-wrap .copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.35);
  color: rgba(200,220,255,.6);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .15s ease, color .15s ease;
  backdrop-filter: blur(8px);
}
.bubble-wrap:hover .copy-btn {
  opacity: 1;
}
.bubble-wrap .copy-btn:hover {
  color: rgba(53,208,255,1);
  border-color: rgba(53,208,255,.4);
}
.bubble-wrap .copy-btn.copied {
  color: #00ff88;
  border-color: rgba(0,255,136,.4);
}

/* =========================================================
   Character Counter
   ========================================================= */

.composer-input-wrap {
  position: relative;
  min-width: 0;
}
.composer-input-wrap textarea {
  width: 100%;
}
.char-count {
  position: absolute;
  bottom: 6px;
  right: 10px;
  font-size: 10px;
  color: rgba(155,170,210,.4);
  font-family: "IBM Plex Mono", monospace;
  pointer-events: none;
}
.char-count.warn {
  color: rgba(255,200,80,.7);
}
.char-count.limit {
  color: rgba(255,100,100,.8);
}

/* =========================================================
   Button Size Variants
   ========================================================= */

.btn.small {
  padding: 6px 10px;
  font-size: 13px;
  border-radius: 10px;
}

/* =========================================================
   Mic Button
   ========================================================= */

.mic-btn {
  padding: 10px 12px;
  font-size: 16px;
  transition: background .15s ease, box-shadow .15s ease;
}
.mic-btn.listening {
  background: rgba(255,80,80,.18);
  border-color: rgba(255,80,80,.5);
  box-shadow: 0 0 16px rgba(255,80,80,.25);
  animation: micPulse 1s ease-in-out infinite;
}
@keyframes micPulse {
  0%,100% { box-shadow: 0 0 8px rgba(255,80,80,.2); }
  50%      { box-shadow: 0 0 24px rgba(255,80,80,.5); }
}

/* =========================================================
   Markdown rendered content inside Jarvis bubbles
   ========================================================= */

.bubble.jarvis code {
  font-family: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: rgba(53,208,255,.10);
  border: 1px solid rgba(53,208,255,.18);
  border-radius: 5px;
  padding: 1px 5px;
}

.bubble.jarvis pre {
  margin: 8px 0 4px;
  border-radius: 10px;
  background: rgba(0,0,0,.38);
  border: 1px solid rgba(53,208,255,.16);
  padding: 10px 14px;
  overflow-x: auto;
  white-space: pre;
}

.bubble.jarvis pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.86em;
}
