/* Yumichan.ai — HD anime style, dynamic animations, touch, sounds */

:root {
  --bg-dark: #0d0d12;
  --bg-panel: #16161d;
  --bg-input: #1e1e26;
  --text: #e8e6e9;
  --text-muted: #888;
  --accent: #f472b6;
  --accent-dim: #c084a6;
  --glow: #f9a8d4;
  --cyan: #67e8f9;
  --font: 'Outfit', system-ui, sans-serif;
  --sakura: #ffb7c5;
  --blush-strong: rgba(249, 168, 212, 0.6);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg-dark);
  color: var(--text);
  overflow-x: hidden;
}

.bg {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse 120% 80% at 50% 0%, rgba(244, 114, 182, 0.12) 0%, transparent 50%),
              radial-gradient(ellipse 80% 60% at 80% 80%, rgba(255, 183, 197, 0.06) 0%, transparent 50%),
              var(--bg-dark);
  pointer-events: none;
  z-index: 0;
}

/* 3D background — full viewport, behind content */
.scene3d-background-wrap {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.scene3d-background-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
}

/* 3D character — inside character wrapper */
.scene3d-character-wrap {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  border-radius: 50%;
  overflow: hidden;
}
.scene3d-character-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  object-fit: contain;
}
/* When 3D is active, show 3D model and hide video/fallback */
body.use-3d .character-inner {
  min-height: 240px;
}

/* Sakura / petal layer */
.sakura-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}
.sakura-petal {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--sakura);
  border-radius: 50% 0 50% 50%;
  transform: rotate(0deg);
  opacity: 0.6;
  animation: sakura-fall linear forwards;
}
@keyframes sakura-fall {
  to {
    transform: translate(var(--sakura-x, 20px), 100vh) rotate(720deg);
    opacity: 0.2;
  }
}

/* Header */
.header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: rgba(13, 13, 18, 0.85);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.logo {
  font-weight: 700;
  font-size: 1.25rem;
}

.logo .dot {
  color: var(--accent);
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #86efac;
}
.live-badge::before {
  content: '●';
  color: #86efac;
  animation: live-pulse 1.5s ease-in-out infinite;
}
@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.user-badge {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.btn-ghost {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.9rem;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
}

.btn-ghost:hover {
  background: rgba(244, 114, 182, 0.15);
}

/* Main layout — single column by default (talk first); two columns when chat open */
.main {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
  min-height: calc(100vh - 56px);
}
.main.chat-visible {
  grid-template-columns: 1fr 1fr;
}
.main.chat-visible .character-section {
  max-width: 360px;
}

@media (max-width: 768px) {
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .main.chat-visible {
    grid-template-columns: 1fr;
  }
}

/* Character section — warming + shaking animation */
.character-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.character-wrapper {
  position: relative;
  width: 280px;
  height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Warm glow layers */
.glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(50px);
  opacity: 0.5;
  animation: glow-pulse 3s ease-in-out infinite;
}

.glow-1 {
  width: 220px;
  height: 220px;
  background: var(--glow);
  animation-delay: 0s;
}

.glow-2 {
  width: 160px;
  height: 160px;
  background: var(--accent);
  opacity: 0.4;
  animation-delay: 0.5s;
}

@keyframes glow-pulse {
  0%, 100% { transform: scale(1); opacity: 0.5; }
  50% { transform: scale(1.15); opacity: 0.7; }
}

/* Character container — subtle shake + idle breath */
.character {
  position: relative;
  z-index: 2;
  animation: character-shake 4s ease-in-out infinite;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.character-inner {
  position: relative;
  animation: idle-breathe 3.5s ease-in-out infinite;
}

.character-model-wrap {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  display: none;
  border-radius: 50%;
  overflow: hidden;
}
.character-model-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  object-fit: contain;
}
body.character-glb-loaded .character-model-wrap {
  display: block;
}
body.character-glb-loaded .character-img {
  display: none !important;
}

.character-inner::after {
  content: '';
  position: absolute;
  inset: -15%;
  background: linear-gradient(105deg, transparent 35%, rgba(255,255,255,0.12) 50%, transparent 65%);
  opacity: 0;
  animation: sparkle 6s ease-in-out infinite;
  pointer-events: none;
}

@keyframes sparkle {
  0%, 85%, 100% { opacity: 0; transform: translateX(-30%); }
  10% { opacity: 0; transform: translateX(-30%); }
  15% { opacity: 1; transform: translateX(30%); }
  20% { opacity: 0; transform: translateX(30%); }
}

@keyframes idle-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

.character.touched .character-inner {
  animation: touch-bounce 0.5s ease-out;
}

@keyframes touch-bounce {
  0% { transform: scale(1); }
  30% { transform: scale(1.08); }
  60% { transform: scale(0.98); }
  100% { transform: scale(1); }
}

@keyframes character-shake {
  0%, 90%, 100% { transform: translate(0, 0) rotate(0deg); }
  92% { transform: translate(-2px, 1px) rotate(-0.5deg); }
  94% { transform: translate(2px, -1px) rotate(0.5deg); }
  96% { transform: translate(-1px, 2px) rotate(-0.3deg); }
  98% { transform: translate(1px, -2px) rotate(0.3deg); }
}

.character-img {
  width: 240px;
  height: auto;
  display: block;
  filter: drop-shadow(0 0 20px rgba(249, 168, 212, 0.35)) drop-shadow(0 2px 8px rgba(0,0,0,0.2));
  transition: filter 0.3s;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

.character.touched .character-img {
  filter: drop-shadow(0 0 28px rgba(249, 168, 212, 0.5)) drop-shadow(0 2px 8px rgba(0,0,0,0.2));
}

.character.talking .character-inner {
  animation: talking-bob 0.5s ease-in-out infinite;
}

@keyframes talking-bob {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

/* Blink overlay (eyes closed) */
.character-overlays {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay-eyes-closed {
  position: absolute;
  width: 120px;
  height: 24px;
  top: 42%;
  left: 50%;
  margin-left: -60px;
  background: linear-gradient(180deg, #f5b8a8 0%, #e8a090 100%);
  border-radius: 50%;
  opacity: 0;
  transform: scaleY(0.3);
  transition: opacity 0.08s, transform 0.08s;
}

.character.blink .overlay-eyes-closed {
  opacity: 1;
  transform: scaleY(1);
}

/* Yawn: eyes closed + open mouth */
.character.yawn .overlay-eyes-closed {
  opacity: 1;
  transform: scaleY(1);
  height: 28px;
  top: 41%;
}

.overlay-yawn-mouth {
  position: absolute;
  width: 24px;
  height: 18px;
  top: 58%;
  left: 50%;
  margin-left: -12px;
  background: rgba(200, 132, 166, 0.9);
  border-radius: 0 0 50% 50%;
  opacity: 0;
  transform: scaleY(0);
  transition: opacity 0.2s, transform 0.2s;
}

.character.yawn .overlay-yawn-mouth {
  opacity: 1;
  transform: scaleY(1);
  animation: yawn-mouth 1.8s ease-in-out;
}

@keyframes yawn-mouth {
  0%, 100% { transform: scaleY(0.6); opacity: 0.8; }
  30% { transform: scaleY(1.2); opacity: 1; }
  70% { transform: scaleY(1.1); opacity: 1; }
}

/* Touch hearts */
.hearts-container {
  position: absolute;
  inset: -20px;
  pointer-events: none;
  z-index: 3;
}

.heart-particle {
  position: absolute;
  font-size: 22px;
  opacity: 0;
  animation: heart-float 1s ease-out forwards;
  pointer-events: none;
}

@keyframes heart-float {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(0.3);
  }
  20% {
    opacity: 1;
    transform: translate(var(--hx, 0), -10px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(var(--hx, 0), -80px) scale(0.8);
  }
}

.speech-bubble {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: var(--bg-panel);
  border: 1px solid rgba(244, 114, 182, 0.3);
  border-radius: 12px;
  padding: 8px 12px;
  max-width: 220px;
  font-size: 0.85rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.speech-bubble::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -6px;
  border: 6px solid transparent;
  border-top-color: var(--bg-panel);
}

.tagline {
  margin-top: 1rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Primary: Talk button (like Talking Tom) */
.talk-primary {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}
.btn-talk {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: 0 4px 24px rgba(244, 114, 182, 0.4);
  transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
}
.btn-talk:hover {
  background: var(--accent-dim);
  transform: scale(1.05);
  box-shadow: 0 6px 28px rgba(244, 114, 182, 0.5);
}
.btn-talk:active {
  transform: scale(0.98);
}
.btn-talk.listening {
  background: #67e8f9;
  color: var(--bg-dark);
  box-shadow: 0 0 0 4px rgba(103, 232, 249, 0.4);
  animation: pulse-mic 1s ease-in-out infinite;
}
@keyframes pulse-mic {
  0%, 100% { box-shadow: 0 0 0 4px rgba(103, 232, 249, 0.4); }
  50% { box-shadow: 0 0 0 12px rgba(103, 232, 249, 0.15); }
}
.btn-talk-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-talk-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.talk-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.btn-type-instead {
  margin-top: 1rem;
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.85rem;
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.btn-type-instead:hover {
  color: var(--text);
  border-color: var(--accent);
}
.btn-type-instead.hidden {
  display: none;
}

/* Chat section — secondary; expand when "Type instead" is used */
.chat-section {
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.06);
  overflow: hidden;
}
.chat-section.chat-secondary {
  max-height: 0;
  opacity: 0;
  margin: 0;
  padding: 0;
  border: none;
  overflow: hidden;
  transition: max-height 0.35s ease, opacity 0.25s ease, margin 0.25s ease;
}
.chat-section.chat-secondary.chat-open {
  max-height: 520px;
  opacity: 1;
  margin-top: 1rem;
  border: 1px solid rgba(255,255,255,0.06);
  padding: 0;
}
.chat-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-input);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.chat-section-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}
.btn-close-chat {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
.btn-close-chat:hover {
  color: var(--text);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  min-height: 200px;
  max-height: 420px;
}

.msg {
  margin-bottom: 1rem;
}

.msg-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.yumi-msg .msg-label { color: var(--accent); }
.user-msg .msg-label { color: var(--cyan); }

.msg-text {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-input-wrap {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: var(--bg-input);
  border-top: 1px solid rgba(255,255,255,0.06);
}

#chatInput {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 10px 14px;
  background: var(--bg-dark);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  resize: none;
}

#chatInput::placeholder {
  color: var(--text-muted);
}

#chatInput:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(244, 114, 182, 0.2);
}

.btn-send {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s ease, background 0.2s;
}

.btn-send:hover {
  background: var(--accent-dim);
  transform: scale(1.05);
}

.btn-send:active {
  transform: scale(0.96);
}

.btn-send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--bg-panel);
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.1);
  max-width: 400px;
  width: 100%;
  padding: 1.5rem;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-title {
  margin: 0 0 0.5rem;
  font-size: 1.35rem;
}

.modal-desc {
  margin: 0 0 1.25rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 1rem;
}

.auth-tab {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.9rem;
  cursor: pointer;
  border-radius: 8px;
}

.auth-tab:hover {
  color: var(--text);
}

.auth-tab.active {
  background: rgba(244, 114, 182, 0.2);
  color: var(--accent);
  border-color: var(--accent);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-form.hidden {
  display: none;
}

.auth-form input {
  padding: 10px 12px;
  background: var(--bg-dark);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.btn-primary {
  padding: 12px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-family: var(--font);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  margin-top: 4px;
}

.btn-primary:hover {
  background: var(--accent-dim);
}

.auth-divider {
  text-align: center;
  margin: 1rem 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.google-wrap {
  display: flex;
  justify-content: center;
  min-height: 44px;
}

.auth-hint {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: var(--accent);
  min-height: 1.2em;
}

.auth-hint.error {
  color: #f87171;
}
