:root{
  --bg: #05070b;
  --panel: rgba(12, 16, 24, 0.82);
  --panel2: rgba(10, 12, 18, 0.72);
  --border: rgba(140, 160, 210, 0.12);
  --border2: rgba(140, 160, 210, 0.18);
  --text: #e9eef5;
  --muted: rgba(233, 238, 245, 0.62);
  --muted2: rgba(233, 238, 245, 0.45);

  --accent: #a81dff;        /* eerie purple */
  --accent2: #00d5ff;       /* cold cyan (tiny hints) */
  --danger: #ff2a6d;

  --shadow: 0 18px 60px rgba(0,0,0,0.75);
  --shadow2: 0 0 0 1px rgba(168,29,255,0.10), 0 18px 60px rgba(0,0,0,0.75);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 600px at 20% 10%, rgba(168,29,255,0.10), transparent 60%),
    radial-gradient(900px 500px at 80% 30%, rgba(0,213,255,0.08), transparent 60%),
    radial-gradient(900px 700px at 50% 100%, rgba(255,42,109,0.06), transparent 60%),
    linear-gradient(180deg, #020308, #05070b 35%, #020308);
  overflow-x: hidden;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  /* use dynamic viewport height fix */
  height: 100vh;
  height: calc(var(--vh, 1vh) * 100);
  overflow: hidden; /* IMPORTANT: prevent page from extending */
}

/* Make wrap take the full screen height */
.wrap {
  min-height: 100vh;
  min-height: calc(var(--vh, 1vh) * 100);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 18px;
}
.wrap {
  height: 100vh;
  height: calc(var(--vh, 1vh) * 100);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center; /* centers when short */
  padding: 28px 18px;
  gap: 16px;
  overflow: hidden;
}

/* subtle animated noise */
body::before{
  content:"";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.18'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
  opacity: .22;
  animation: grain 9s steps(10) infinite;
}
@keyframes grain {
  0% { transform: translate(0,0); }
  10% { transform: translate(-2%, -1%); }
  20% { transform: translate(-4%, 2%); }
  30% { transform: translate(2%, -4%); }
  40% { transform: translate(-1%, 3%); }
  50% { transform: translate(-3%, -2%); }
  60% { transform: translate(3%, 1%); }
  70% { transform: translate(0%, 4%); }
  80% { transform: translate(-4%, 0%); }
  90% { transform: translate(2%, 2%); }
  100% { transform: translate(0,0); }
}

/* CENTER the first card on open */
.wrap{
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;   /* vertical center */
  justify-content: center; /* horizontal center */
  padding: 28px 18px;
}

/* LOGO AREA */
/* Logo shouldn't force overflow */
.logo-area {
  flex: 0 0 auto;
}
.logo-area{
  width: 100%;
  text-align: center;
  margin-bottom: 26px;
  user-select: none;
}

.logo-area img{
  max-width: 250px;
  height: auto;
  filter:
    drop-shadow(0 0 20px rgba(168,29,255,0.45))
    drop-shadow(0 0 40px rgba(0,213,255,0.15));
}

/* Logo default (landing / scanning) */
.logo-area img {
  width: 140px;          /* or whatever you currently use */
  transition: width 0.25s ease, opacity 0.25s ease;
}

/* When chat is active */
body.in-chat .logo-area img {
  width: 50px;           /* 👈 requested size */
  opacity: 0.85;
}

/* Optional: tighten spacing in chat mode */
body.in-chat .logo-area {
  margin-bottom: 6px;
}

.logo-text{
  font-size: clamp(42px, 6vw, 64px);
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #e9eef5;
  text-shadow:
    0 0 18px rgba(168,29,255,0.45),
    0 0 38px rgba(168,29,255,0.25),
    0 0 70px rgba(0,213,255,0.12);
}

.logo-sub{
  margin-top: 6px;
  font-size: 13px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: rgba(233,238,245,0.55);
}


/* panel/card */

.card {
  border-radius: var(--radius);
  padding: 20px 20px 18px;
  background: linear-gradient(180deg, rgba(14,18,28,0.88), rgba(8,10,16,0.78));
  border: 1px solid var(--border);
  box-shadow: var(--shadow2);
  backdrop-filter: blur(10px);

  width: min(920px, 100%);
  max-height: 100%;        /* never exceed viewport */
  display: flex;
  flex-direction: column;  /* so chatbox can flex */
  overflow: hidden;        /* IMPORTANT */
}

/* Card grows to fill available height ONLY in chat mode */
body.in-chat .card {
  flex: 1 1 auto;
}

/* glowing edge */
.card::after{
  content:"";
  position:absolute;
  inset:-2px;
  border-radius: calc(var(--radius) + 2px);
  padding: 2px;
  background: linear-gradient(135deg,
    rgba(168,29,255,0.35),
    rgba(0,213,255,0.10),
    rgba(255,42,109,0.10),
    rgba(168,29,255,0.20)
  );
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  opacity: .55;
}

.topbar{
  display:flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-bottom: 10px;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(140,160,210,0.10);
}

.muted { color: var(--muted); }

.status{
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(233,238,245,0.55);
  padding: 8px 10px;
  border: 1px solid rgba(140,160,210,0.12);
  border-radius: 999px;
  background: rgba(0,0,0,0.18);
}

.row{
  display:flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

input, textarea{
  flex: 1;
  min-width: 240px;
  background: linear-gradient(180deg, rgba(9,12,18,0.95), rgba(6,8,12,0.92));
  color: var(--text);
  border: 1px solid rgba(140,160,210,0.16);
  border-radius: 14px;
  padding: 12px 13px;
  font-size: 15px;
  outline: none;
  box-shadow: 0 0 0 0 rgba(168,29,255,0);
  transition: border-color .15s ease, box-shadow .15s ease, transform .05s ease;
}

input:focus, textarea:focus{
  border-color: rgba(168,29,255,0.40);
  box-shadow: 0 0 0 4px rgba(168,29,255,0.12);
}

button{
  background:
    radial-gradient(90% 140% at 10% 10%, rgba(168,29,255,0.35), transparent 50%),
    linear-gradient(180deg, rgba(20,26,40,0.92), rgba(10,12,18,0.92));
  color: var(--text);
  border: 1px solid rgba(168,29,255,0.22);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .02em;
  cursor: pointer;
  transition: transform .08s ease, border-color .15s ease, filter .15s ease, box-shadow .15s ease;
  box-shadow: 0 10px 28px rgba(0,0,0,0.45);
}

button:hover{
  border-color: rgba(168,29,255,0.45);
  filter: brightness(1.06);
}
button:active{ transform: translateY(1px); }
button:disabled{
  opacity: .6;
  cursor:not-allowed;
  filter: saturate(.7);
}

/* Scan + Chat areas spacing */
#joinArea, #scanArea, #chatArea {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;           /* IMPORTANT for flex scroll */
}
#chatArea {
  min-height: 0;
}

/* chat box */
#chatBox{
  height: 440px;
  overflow:auto;
  margin-top: 12px;
  border-radius: 16px;
  border: 1px solid rgba(140,160,210,0.14);
  background:
    radial-gradient(700px 280px at 20% 0%, rgba(168,29,255,0.10), transparent 65%),
    radial-gradient(520px 260px at 80% 0%, rgba(0,213,255,0.08), transparent 60%),
    linear-gradient(180deg, rgba(7,9,14,0.78), rgba(5,6,10,0.82));
  padding: 14px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.30);
}
#chatBox {
  flex: 1 1 auto;
  min-height: 0;           /* MOST IMPORTANT LINE */
  overflow: auto;
  height: auto;            /* remove fixed height */
}

/* scrollbar */
#chatBox::-webkit-scrollbar { width: 10px; }
#chatBox::-webkit-scrollbar-thumb {
  background: rgba(168,29,255,0.20);
  border-radius: 999px;
  border: 2px solid rgba(0,0,0,0.25);
}
#chatBox::-webkit-scrollbar-track { background: rgba(0,0,0,0.20); }
#chatArea .row:last-of-type {
  flex: 0 0 auto;
}
.msg{
  margin: 10px 0;
  display:flex;
  gap: 10px;
}
.msg.mine{ justify-content:flex-end; }

.bubble{
  max-width: 76%;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid rgba(140,160,210,0.16);
  background: rgba(10, 12, 18, 0.68);
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 10px 20px rgba(0,0,0,0.35);
  position: relative;
}

/* eerie bubble glow */
.bubble::after{
  content:"";
  position:absolute;
  inset:-1px;
  border-radius: 16px;
  pointer-events:none;
  opacity: .35;
  background: radial-gradient(120px 60px at 20% 10%, rgba(0,213,255,0.10), transparent 60%),
              radial-gradient(160px 70px at 80% 10%, rgba(168,29,255,0.16), transparent 65%);
}

.mine .bubble{
  background: rgba(17, 10, 22, 0.74);
  border-color: rgba(168,29,255,0.26);
}

/* header text */
.card .topbar > div:first-child > div:first-child{
  font-size: 20px;
  font-weight: 800;
  letter-spacing: .02em;
}

/* subtle “danger” hints for Next button */
#nextBtn{
  border-color: rgba(255,42,109,0.22);
  background:
    radial-gradient(90% 140% at 10% 10%, rgba(255,42,109,0.24), transparent 55%),
    linear-gradient(180deg, rgba(20,26,40,0.92), rgba(10,12,18,0.92));
}
#nextBtn:hover{ border-color: rgba(255,42,109,0.42); }

/* small text */
#scanText, #chatHint { color: var(--muted2); }

/* mobile tweaks */
@media (max-width: 520px){
  #chatBox{ height: 54vh; }
  .bubble{ max-width: 86%; }
  input{ min-width: 0; }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce){
  body::before{ animation: none; }
  *{ transition: none !important; }
}