html, body {
  height: 100%;
  overflow: hidden; 
}
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial,
    sans-serif;
  background: #0f172a; 
  color: #e2e8f0; 
}


#bkg-gif {
  position: fixed;
  inset: 0; /* anchor to all edges */
  width: 100vw;
  height: 100vh;
  object-fit: cover; /* scale to cover viewport while preserving aspect */
  pointer-events: none;
  user-select: none;
  z-index: 0;
  opacity: 0.95;
}

:root {
  /* Expose safe area insets to JS via CSS variables */
  --safe-area-top: env(safe-area-inset-top);
  --safe-area-bottom: env(safe-area-inset-bottom);
  /* Keyboard height offset, driven by JS via VisualViewport */
  --keyboard-offset: 0px;
  /* Prompt height for stacking vn-box above it */
  --prompt-height: 0px;
}

/* Prevent unintended iOS text zoom on focus */
html { -webkit-text-size-adjust: 100%; }


.live2d-widget-container, .live2d-widget {
  z-index: 10 !important;
}

#live2d-widget-container {
  position: fixed;
  inset: 0; 
  width: 100vw;
  /* Lock to large viewport so keyboard won't shrink canvas */
  height: 100vh;                 /* fallback */
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden; 
  z-index: 2147483647;
}

/* Prefer new large viewport unit when supported (prevents keyboard shrink) */
@supports (height: 100lvh) {
  #live2d-widget-container { height: 100lvh; }
}

#live2d-widget-container canvas {
  display: block; 
  max-width: 100vw;
  max-height: 100%;
}

#live2d-controls {
  position: fixed; /* anchor to visual viewport */
  /* Keep controls above iOS home bar / browser UI */
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  align-items: center;
  background: rgba(2, 6, 23, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 14px;
  padding: 10px 12px;
  backdrop-filter: blur(6px);
  z-index: 2147483647; /* ensure above canvas */
}

#live2d-controls.locked {
  opacity: 0.55;
  filter: grayscale(20%);
  pointer-events: none; /* fully non-interactive while showing vn-box */
}

#live2d-controls input {
  /* Use flex so the input naturally shrinks on small screens */
  flex: 1 1 auto;
  min-width: 0; /* allow the input to be narrower than its content box when needed */
  background: rgba(30, 41, 59, 0.7);
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 10px;
  padding: 10px 12px;
  /* Avoid iOS Safari auto-zoom on focus */
  font-size: 16px;
  outline: none;
}

#live2d-controls input:disabled {
  background: rgba(30, 41, 59, 0.45);
  color: #94a3b8;
}

#live2d-controls button {
  background: linear-gradient(135deg, #7c3aed, #3b82f6);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
}

#live2d-controls button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#live2d-controls button.loading {
  position: relative;
  background: linear-gradient(135deg, #8b5cf6, #60a5fa);
}

#live2d-controls button.loading::before,
#live2d-controls button.loading::after { content: none; display: none; }

#live2d-controls button .dots {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 1em;
}

#live2d-controls button .dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.92);
  opacity: 0.45;
  transform: translateY(0);
  animation: dotBounce 1s infinite ease-in-out;
}

#live2d-controls button .dots i:nth-child(2) { animation-delay: .15s; }
#live2d-controls button .dots i:nth-child(3) { animation-delay: .30s; }

@keyframes dotBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .45; }
  40% { transform: translateY(-4px); opacity: 1; }
}

#speech-bubble {
  position: absolute;
  max-width: min(62ch, 48vw);
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  color: #0f172a;
  border: 2px solid #0b1220;
  border-radius: 18px;
  padding: 14px 16px;
  font-size: 16px;
  line-height: 1.45;
  box-shadow: 0 14px 36px rgba(0,0,0,0.38);
  transform: translate(-10%, -100%) scale(0.98);
  opacity: 0;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 2147483647;
}

#speech-bubble.show {
  opacity: 1;
  transform: translate(-10%, -100%) scale(1);
}

#speech-bubble::before,
#speech-bubble::after {
  content: "";
  position: absolute;
  bottom: -14px;
  left: 26px;
  width: 0;
  height: 0;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
}

#speech-bubble::before {
  border-top: 14px solid #0b1220;
  filter: blur(0.2px);
}

#speech-bubble::after {
  bottom: -12px;
  left: 26px;
  border-top: 14px solid #ffffff;
}

#vn-box {
  position: absolute;
  left: 50%;
  max-width: min(70vw, 820px);
  /* Allow VN to shrink on small viewports */
  min-width: 0;
  background: linear-gradient(180deg, rgba(2,6,23,0.88), rgba(15,23,42,0.9));
  color: #e5e7eb;
  border: 1px solid rgba(148,163,184,0.4);
  border-radius: 18px;
  padding: 14px 18px;
  font-size: 16.5px;
  line-height: 1.5;
  box-shadow: 0 18px 38px rgba(0,0,0,0.5);
  backdrop-filter: blur(6px);
  transform: translate(-50%, 6px) scale(0.98);
  opacity: 0;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 2147483647;
}

#vn-box.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

#vn-text { white-space: pre-wrap; }

/* Mobile adjustments: smaller text, tighter padding, full-width controls */
@media (max-width: 720px), (max-device-width: 720px) {
  #live2d-controls {
    left: 8px;
    right: 8px;
    transform: none;
    bottom: calc(10px + env(safe-area-inset-bottom));
    padding: 8px 10px;
    gap: 8px;
    border-radius: 12px;
    width: auto;
    justify-content: space-between;
  }

  #live2d-controls input {
    font-size: 14px;
    padding: 8px 10px;
    border-radius: 10px;
  }

  #live2d-controls button {
    padding: 8px 10px;
    font-size: 14px;
      #vn-box {
        /* Center VN box and allow JS to set width to match prompt */
        left: 50%;
        right: auto;
        max-width: calc(100% - 16px); /* prevent overflow */
        min-width: 0;
        padding: 10px 12px;
        font-size: 14px;
        border-radius: 12px;
        /* retain base transform from desktop CSS */
      }

      #vn-box.show {
        /* Centered show transform */
        transform: translate(-50%, 0) scale(1);
      }
    min-width: 0;
    padding: 10px 12px;
    font-size: 14px;
    border-radius: 12px;
  }
    #vn-box.show { transform: translate(-50%, 0) scale(1); }
}
