:root{
  --bg0:#000;
  --bg1:#0b0f14;
  --ui: rgba(255,255,255,0.08);
  --ui2: rgba(255,255,255,0.12);
  --text: rgba(255,255,255,0.85);
  --muted: rgba(255,255,255,0.55);

  --headerH: 170px; /* JS updates this dynamically */
}

*{ box-sizing:border-box; }
html,body{ height:100%; margin:0; background:var(--bg0); color:var(--text); font-family:system-ui, -apple-system, Segoe UI, Roboto, Arial; overflow:hidden; }

body{
  background:
    radial-gradient(900px 700px at 50% 20%, rgba(255,255,255,0.07), transparent 60%),
    radial-gradient(900px 700px at 25% 80%, rgba(255,255,255,0.05), transparent 60%),
    linear-gradient(180deg, var(--bg1), var(--bg0));
}

#topbar{
  position:fixed;
  left:0; right:0; top:0;
  padding: 18px 18px 12px;
  z-index: 50;
  pointer-events:auto;
  background: linear-gradient(180deg, rgba(0,0,0,0.78), rgba(0,0,0,0.15), transparent);
  backdrop-filter: blur(6px);
}

.title{
  text-align:center;
  letter-spacing: 0.22em;
  font-weight: 800;
  font-size: clamp(54px, 7vw, 92px);
  opacity: 0.45;
  margin-bottom: 12px;
}

.controls{
  display:flex;
  gap:10px;
  align-items:center;
  justify-content:center;
  flex-wrap:wrap;
}

.pill{
  appearance:none;
  border:1px solid var(--ui2);
  background: rgba(0,0,0,0.35);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 999px;
  cursor:pointer;
  user-select:none;
  display:flex;
  align-items:center;
  gap:10px;
  transition: transform 140ms cubic-bezier(.2,.8,.2,1), box-shadow 140ms ease, border-color 140ms ease;
}
.pill:hover{ transform: translateY(-1px); box-shadow: 0 10px 26px rgba(0,0,0,0.35); }
.pill:active{ transform: translateY(0px) scale(0.99); }

.pill.isOn{
  border-color: rgba(255,255,255,0.25);
  box-shadow: 0 0 0 2px rgba(255,255,255,0.06), 0 12px 28px rgba(0,0,0,0.40);
}

.factions{
  display:flex;
  gap:10px;
  align-items:center;
  justify-content:center;
  flex-wrap:wrap;
}

.factionBtn{
  width: 78px;
  height: 46px;
  border-radius: 999px;
  border: 1px solid var(--ui2);
  background: rgba(0,0,0,0.35);
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  padding: 4px 10px;
  transition: transform 140ms cubic-bezier(.2,.8,.2,1), box-shadow 140ms ease, border-color 140ms ease;
  position:relative;
  overflow:hidden;
}
.factionBtn:hover{ transform: translateY(-1px); }
.factionBtn img{
  max-height: 30px;
  max-width: 100%;
  display:block;
  filter: saturate(1.05) contrast(1.05);
  opacity: 0.85;
}
.factionBtn .fallbackText{
  font-size: 11px;
  letter-spacing: 0.12em;
  opacity: 0.75;
  font-weight: 700;
}
.factionBtn.isActive{
  border-color: color-mix(in srgb, var(--ring) 70%, white 10%);
  box-shadow:
    0 0 0 2px color-mix(in srgb, var(--ring) 38%, transparent),
    0 0 18px color-mix(in srgb, var(--ring) 35%, transparent);
}
.factionBtn.isActive img{ opacity: 1; }

/* Stage */
#stage{
  position:absolute;
  left:0; right:0;
  top: var(--headerH);
  bottom:0;
  overflow:hidden;
}

/* Bubble */
.bubble{
  position:absolute;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  display:grid;
  place-items:center;
  cursor:pointer;
  user-select:none;

  /* Black interior to match GIF backgrounds */
  background: #000;

  border: 2px solid rgba(255,255,255,0.10);
  box-shadow:
    0 8px 22px rgba(0,0,0,0.55),
    inset 0 0 0 2px rgba(255,255,255,0.05);
  transition: transform 140ms cubic-bezier(.2,.8,.2,1), box-shadow 140ms ease, border-color 140ms ease;
  will-change: transform, left, top;

  overflow: hidden;
}

.bubble:hover{
  transform: translate(-50%, -50%) scale(1.09);
  box-shadow:
    0 10px 28px rgba(0,0,0,0.62),
    0 0 18px rgba(255,255,255,0.06),
    inset 0 0 0 2px rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.16);
}

.bubble img{
  width: 100%;
  height: 100%;
  object-fit: cover;
  display:block;
  pointer-events:none;
  filter: drop-shadow(0 10px 18px rgba(0,0,0,0.7));

  border-radius: 50%;

  transform: scale(0.9);
}

/* Faction rim glow on bubbles when active */
.bubble.factionGlow{
  border-color: color-mix(in srgb, var(--ring) 75%, rgba(255,255,255,0.15));
  box-shadow:
    0 10px 28px rgba(0,0,0,0.62),
    0 0 0 2px color-mix(in srgb, var(--ring) 40%, transparent),
    0 0 22px color-mix(in srgb, var(--ring) 35%, transparent),
    inset 0 0 0 2px rgba(255,255,255,0.05);
}

/* Selected bubble gets a subtle lift */
.bubble.isSelected{
  z-index: 20;
  transform: translate(-50%, -50%) scale(1.10);
  border-color: rgba(255,255,255,0.22);
}

/* Overlay modal */
.overlay{
  position:fixed;
  inset:0;
  background: rgba(0,0,0,0.62);
  display:grid;
  place-items:center;
  z-index: 100;
  backdrop-filter: blur(10px);
}

.card{
  width: min(760px, calc(100vw - 28px));
  border-radius: 22px;
  border: 1px solid rgba(255,255,255,0.12);
  background: linear-gradient(180deg, rgba(20,20,22,0.92), rgba(8,8,10,0.92));
  box-shadow: 0 28px 70px rgba(0,0,0,0.75);
  padding: 18px 18px 20px;
  position:relative;
}

.close{
  position:absolute;
  right: 14px;
  top: 12px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(0,0,0,0.35);
  color: rgba(255,255,255,0.8);
  font-size: 20px;
  line-height: 0;
  cursor:pointer;
}

.cardTop{
  display:grid;
  grid-template-columns: 170px 1fr;
  gap: 16px;
  align-items:center;
}

.cardBubble{
  width: 170px;
  height: 170px;
  border-radius: 50%;
  background: #000;
  border: 2px solid rgba(255,255,255,0.12);
  display:grid;
  place-items:center;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.05);
}
.cardBubble img{
  width: 80%;
  height: 80%;
  object-fit:contain;
}

.cardText h2{
  margin: 8px 0 6px;
  font-size: 28px;
  letter-spacing: 0.02em;
}
.cardText p{
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
  font-size: 15px;
}

.metaRow{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
}

.badge{
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(0,0,0,0.30);
  color: rgba(255,255,255,0.78);
}
.badge.subtle{
  opacity: 0.75;
}

@media (max-width: 640px){
  .cardTop{ grid-template-columns: 1fr; }
  .cardBubble{ margin: 0 auto; }
  .cardText{ text-align:center; }
  .metaRow{ justify-content:center; }
}


/* --- Faction bar: 11 buttons across the top --- */
.controls{
  flex-direction: column;
  gap: 12px;
}

.factions{
  flex-wrap: nowrap;
  overflow-x: auto;
  padding: 2px 6px 10px;
  scrollbar-width: thin;
}

.factions::-webkit-scrollbar{ height: 8px; }
.factions::-webkit-scrollbar-thumb{
  background: rgba(255,255,255,0.10);
  border-radius: 999px;
}

.factionBtn{
  width: 74px;
  height: 44px;
  padding: 6px 12px;
}

.factionBtn img{
  max-height: 28px;
}

@media (max-width: 720px){
  .factionBtn{ width: 68px; height: 42px; }
}

/* Faction badge logo in pop-out */
.badge.hasLogo{
  padding: 6px 10px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
}
.badge.hasLogo img{
  height: 18px;
  width: auto;
  display:block;
  filter: saturate(1.05) contrast(1.05);
}



/* -----------------------------
   Pop-out (card) layout upgrades
   ----------------------------- */
#cardFactionLogo{
  height: 44px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
}
.cardBody{
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 18px;
  padding: 18px;
}
@media (max-width: 840px){
  .cardBody{ grid-template-columns: 1fr; }
}
.cardMedia{
  width: 380px;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  background: #000;
  overflow: hidden;
  display:flex;
  align-items:center;
  justify-content:center;
}
@media (max-width: 840px){
  }
#cardImg{
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.cardText h2{
  font-size: 34px;
  line-height: 1.05;
  margin: 2px 0 8px;
}
.role{
  display:inline-block;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.85;
}
.cardText p{
  font-size: 14px;
  line-height: 1.45;
  margin-top: 10px;
  max-width: 52ch;
}

/* Ensure creature art is clipped cleanly inside bubbles */
.bubble{
  overflow: hidden;
  border-radius: 999px;
}
.bubble img{
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 999px;
}

/* Make title and buttons bigger (tweakable) */
.title{
  font-size: clamp(48px, 6vw, 86px);
}
.factionBtn{
  width: 74px;
  height: 74px;
}
.factionBtn img{
  width: 58px;
  height: 58px;
}


/* Pop-out: faction logo lives in the right column above the name (no white header) */
.factionLogoWrap{
  display:flex;
  align-items:flex-start;
  justify-content:flex-start;
  margin: 2px 0 10px;
}
.factionLogoWrap img{
  width: 150px;
  height: 54px;
  object-fit: contain;
  background: transparent;
  border: 0;
  filter: drop-shadow(0 6px 18px rgba(0,0,0,.55));
}

/* -----------------------------------------
   TUNING: Bigger faction logo in pop-out
   + Bigger faction buttons in rounded boxes
   ----------------------------------------- */

/* Pop-out faction logo: BIG banner */
.factionLogoWrap{
  width: 100%;
  margin: 0 0 18px 0;
}

#cardFactionLogo{
  width: clamp(420px, 38vw, 520px);
  height: auto;            /* key: don't force a small height */
  max-height: 160px;       /* cap so it never gets silly */
  object-fit: contain;
  display: block;
}

/* Top faction buttons: rounded-corner boxes with logos filling the space */
.factionBtn{
  width: clamp(110px, 10.5vw, 160px);
  height: 72px;
  border-radius: 18px;
  padding: 8px 12px;
}
.factionBtn img{
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: contain;
  opacity: 0.92;
}
.factionBtn .fallbackText{
  font-size: 12px;
}

/* -----------------------------------------
   FINAL TUNE: Much bigger pop-out faction logo
   (matches red box reference)
   ----------------------------------------- */

.factionLogoWrap{
  margin-bottom: 18px;
}

.factionLogoWrap img{
  width: clamp(420px, 38vw, 520px);
  height: auto;
  max-height: 140px;
}

/* Tighten spacing between faction logo and name in pop-out */
.factionLogoWrap{
  margin-bottom: -4px;   /* was larger */
}

#cardName{
  margin-top: 0;        /* kill default h2 top margin */
}


/* Faction accent line */
.factionAccent{
  height: 3px;
  width: 64px;
  border-radius: 999px;
  margin: 6px 0 10px;
  background: var(--ring, rgba(255,255,255,0.25));
  box-shadow: 0 0 12px color-mix(in srgb, var(--ring) 50%, transparent);
}


/* Pop-out animation (class-based so it animates reliably) */
.overlay{
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .22s ease;
}

.overlay.isOpen{
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.overlay .card{
  transform: scale(0.94) translateY(12px);
  opacity: 0;
  transition: transform .22s cubic-bezier(.2,.8,.2,1), opacity .18s ease;
}

.overlay.isOpen .card{
  transform: scale(1) translateY(0);
  opacity: 1;
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce){
  .overlay, .overlay .card{ transition: none !important; }
}


#cardVid{width:100%;height:100%;object-fit:contain;display:block;}

.cardMedia{ position: relative; }
.cardMedia video, .cardMedia img{ position:absolute; inset:0; }

/* === FIX: make the stage visible under the fixed header === */
#stage{
  position: absolute;
  left: 0;
  right: 0;
  top: var(--headerH);
  bottom: 0;
  overflow: hidden;
}


#cardVideo{
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 16px;
  display:block;
}


@keyframes popBubble{ 0%{ transform: translate(var(--x), var(--y)) scale(1); } 60%{ transform: translate(var(--x), var(--y)) scale(1.06); } 100%{ transform: translate(var(--x), var(--y)) scale(1); } }

@keyframes bubblePop{ 0%{ transform: translate(-50%, -50%) scale(1);} 60%{ transform: translate(-50%, -50%) scale(1.06);} 100%{ transform: translate(-50%, -50%) scale(1);} }

.bubble.pop{ animation: bubblePop 220ms ease-out; }

/* Modal polish */
.overlay{
  opacity: 0;
  transition: opacity 140ms ease;
}
.overlay.isOpen{
  opacity: 1;
}
.card{
  transform: translateY(10px) scale(0.985);
  opacity: 0;
  transition: transform 200ms ease, opacity 160ms ease;
}
.card.enter{
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* Stagger inside */
.card.enter .factionLogoWrap,
.card.enter .factionAccent,
.card.enter #cardName,
.card.enter #cardFaction,
.card.enter #cardDesc,
.card.enter #cardText,
.card.enter .cardMedia{
  animation: cardItemIn 280ms ease both;
}
.card.enter .cardMedia{ animation-delay: 40ms; }
.card.enter .factionLogoWrap{ animation-delay: 80ms; }
.card.enter .factionAccent{ animation-delay: 120ms; }
.card.enter #cardName{ animation-delay: 150ms; }
.card.enter #cardFaction{ animation-delay: 190ms; }
.card.enter #cardDesc{ animation-delay: 230ms; }
.card.enter #cardText{ animation-delay: 260ms; }

@keyframes cardItemIn{
  from{ opacity:0; transform: translateY(6px); filter: blur(2px); }
  to{ opacity:1; transform: translateY(0); filter: blur(0); }
}

/* Reduced motion button */
.motionToggle{
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 60;
  padding: 6px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  color: rgba(255,255,255,0.92);
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}
.motionToggle:hover{ background: rgba(255,255,255,0.12); }
.motionToggle[aria-pressed="true"]{ background: rgba(255,255,255,0.16); }


/* Respect system reduced motion */
@media (prefers-reduced-motion: reduce){
  .bubble, .card, .overlay{ transition: none !important; }
  .bubble.pop{ animation: none !important; }
  .card.enter .factionLogoWrap,
  .card.enter .factionAccent,
  .card.enter #cardName,
  .card.enter #cardFaction,
  .card.enter #cardText,
  .card.enter .cardMedia{ animation: none !important; }
}

@keyframes bubbleReturn{
  0%{ transform: translate(-50%, -50%) scale(1.12); }
  70%{ transform: translate(-50%, -50%) scale(0.98); }
  100%{ transform: translate(-50%, -50%) scale(1); }
}
.bubble.returning{
  animation: bubbleReturn 260ms cubic-bezier(.2,.8,.2,1);
}


/* Sound toggle (stacked under reduced motion) */
.soundToggle{
  position: fixed;
  top: 44px;
  right: 12px;
  z-index: 60;
  padding: 6px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  color: rgba(255,255,255,0.92);
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}
.soundToggle:hover{ background: rgba(255,255,255,0.12); }
.soundToggle[aria-pressed="true"]{ background: rgba(255,255,255,0.16); }
