@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg: #0b1121; --panel: rgba(30, 41, 59, 0.7); 
  --fg: #e2e8f0; --muted: #94a3b8;
  --border: rgba(148, 163, 184, 0.15); 
  --mood: #60a5fa; 
  --shadow: 0 20px 40px -10px rgba(0,0,0,0.6);
  --input-bg: rgba(15, 23, 42, 0.6); 
  --chip-bg: rgba(255, 255, 255, 0.05);
  
  --msg-me-bg: #3b82f6; --msg-me-fg: #ffffff;
  --msg-ai-bg: rgba(51, 65, 85, 0.6); --msg-ai-fg: #e2e8f0;
  
  --glass-blur: blur(20px);
}

:root.light {
  --bg: #f0f4f8; --panel: rgba(255, 255, 255, 0.75); 
  --fg: #334155; --muted: #64748b;
  --border: rgba(203, 213, 225, 0.6); 
  --mood: #3b82f6; 
  --shadow: 0 20px 40px -10px rgba(0,0,0,0.1);
  --input-bg: rgba(241, 245, 249, 0.8); 
  --chip-bg: rgba(0, 0, 0, 0.03);
  
  --msg-me-bg: #3b82f6; --msg-me-fg: #ffffff;
  --msg-ai-bg: rgba(255, 255, 255, 0.8); --msg-ai-fg: #334155;
}

body.mood-sadness { --mood: #94a3b8; --msg-me-bg: #64748b; }
:root.light body.mood-sadness { --mood: #64748b; }
body.mood-joy { --mood: #22c55e; --msg-me-bg: #16a34a; }
:root.light body.mood-joy { --mood: #16a34a; }
body.mood-anger { --mood: #ef4444; --msg-me-bg: #dc2626; }
:root.light body.mood-anger { --mood: #dc2626; }
body.mood-fear { --mood: #14b8a6; --msg-me-bg: #0d9488; }
:root.light body.mood-fear { --mood: #0d9488; }
body.mood-surprise { --mood: #a855f7; --msg-me-bg: #9333ea; }
:root.light body.mood-surprise { --mood: #9333ea; }
body.mood-disgust { --mood: #84cc16; --msg-me-bg: #65a30d; }
:root.light body.mood-disgust { --mood: #65a30d; }

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin:0; color:var(--fg); background: var(--bg); 
  font-family: 'Inter', sans-serif;
  font-size: 15px; line-height: 1.6; 
  display: flex; flex-direction: column; height: 100vh;
  transition: background-color 1s cubic-bezier(0.2, 0.8, 0.2, 1), color 1s ease;
  background-image: radial-gradient(circle at 50% 0%, rgba(var(--mood), 0.15), transparent 70%);
}

.appbar {
  flex-shrink: 0; display:flex; justify-content:space-between; align-items:center;
  padding: 16px 32px; 
  border-bottom: 1px solid var(--border);
  background: rgba(var(--bg), 0.01); 
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  position: relative; z-index: 10;
}
.brand { display:flex; align-items:center; gap:14px; }
.logo { 
  font-size: 1.8rem; 
  filter: drop-shadow(0 0 15px rgba(34, 197, 94, 0.4)); 
}
.brand-title { font-weight: 700; font-size: 1.3rem; letter-spacing: -0.5px; }
.brand-tagline { font-size: 0.85rem; color: var(--muted); font-weight: 500; opacity: 0.8; }

.mobile-menu-btn { display: none; }

.controls { display:flex; gap:12px; align-items:center; }
.chip {
  border:1px solid var(--border); padding: 8px 18px; border-radius: 99px; 
  color:var(--muted); background:var(--chip-bg); cursor: pointer; 
  transition: all .3s cubic-bezier(0.34, 1.56, 0.64, 1); 
  font-size: 0.85rem; font-weight: 600; white-space: nowrap;
  backdrop-filter: blur(5px);
}
.chip:hover { 
  color: var(--fg); background: rgba(255,255,255,0.1); 
  transform: translateY(-2px) scale(1.05); 
  border-color: var(--mood);
}

.user-menu { position: relative; display: inline-block; }
.dropdown-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 14px);
  background-color: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; min-width: 180px; box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  z-index: 20; padding: 6px; 
  animation: fadeIn 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.dropdown-menu.show { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }
.dropdown-menu a { color: var(--fg); padding: 10px 16px; text-decoration: none; display: block; border-radius: 10px; font-size: 0.9rem; transition: background 0.2s; }
.dropdown-menu a:hover { background-color: var(--chip-bg); }

.chat-container { flex-grow: 1; width: 100%; max-width: 1000px; margin: 0 auto; display: flex; flex-direction: column; overflow: hidden; position: relative; }
.chat-area { flex-grow: 1; overflow-y: auto; padding: 40px; scroll-behavior: smooth; }

.group { display:flex; gap:18px; margin: 32px 0; max-width: 85%; }
.group.user { align-self: flex-end; flex-direction: row-reverse; }

.group .ai-avatar { 
  font-size: 1.6rem; flex-shrink: 0; width: 44px; height: 44px; 
  display: grid; place-items: center; 
  background: var(--chip-bg); border: 1px solid var(--border);
  border-radius: 50%; 
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.message-content { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.group.user .message-content { align-items: flex-end; }

.msg { 
  padding: 14px 22px; border-radius: 22px; line-height: 1.65; 
  position: relative; 
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.msg.me { 
  background: linear-gradient(135deg, var(--msg-me-bg), color-mix(in srgb, var(--msg-me-bg), #000 10%)); 
  color: var(--msg-me-fg); 
  border-bottom-right-radius: 4px; 
}
.msg.ai { 
  background: var(--msg-ai-bg); 
  color: var(--msg-ai-fg); 
  border-bottom-left-radius: 4px;
  backdrop-filter: blur(10px); 
  border: 1px solid var(--border);
}

.emotion-tag {
  font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  padding: 4px 12px; border-radius: 99px;
  background: rgba(var(--mood), 0.1); 
  border: 1px solid rgba(var(--mood), 0.2);
  color: var(--muted);
}

.composer-area { 
  flex-shrink: 0; padding: 20px 32px 40px 32px; 
  background: linear-gradient(to top, var(--bg) 20%, transparent); 
  width: 100%; max-width: 1000px; margin: 0 auto; pointer-events: none; 
}
.composer { 
  pointer-events: auto; 
  position: relative; width: 100%; 
  background: var(--panel); 
  backdrop-filter: blur(25px); -webkit-backdrop-filter: blur(25px);
  border-radius: 28px; 
  border: 1px solid rgba(255,255,255,0.08); 
  box-shadow: 0 15px 40px -10px rgba(0,0,0,0.3); 
  display: flex; align-items: flex-end; overflow: hidden; 
  transition: all .3s cubic-bezier(0.2, 0.8, 0.2, 1); 
}
.composer:focus-within { 
  border-color: var(--mood); 
  box-shadow: 0 20px 50px -10px rgba(var(--mood), 0.15); 
  transform: translateY(-2px);
}
.composer textarea { 
  width: 100%; min-height:60px; max-height:250px; resize:vertical; 
  padding: 18px 120px 18px 24px; 
  border: none; background: transparent; color:var(--fg); 
  font-size:1.05rem; outline: none; display: block; 
  font-family: inherit;
}
.composer-actions { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 8px; }
.action-btn { 
  width: 42px; height: 42px; border-radius: 50%; 
  border: none; cursor: pointer; display: grid; place-items: center; 
  font-size: 18px; transition: all .3s cubic-bezier(0.34, 1.56, 0.64, 1); 
}
.action-btn.send { background: var(--mood); color: #fff; box-shadow: 0 4px 15px rgba(var(--mood), 0.4); }
.action-btn.send:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(var(--mood), 0.6); }
.action-btn.send.stop { background: var(--muted); animation: pulseRed 2s infinite; }
.action-btn.mic { background: transparent; color: var(--muted); }
.action-btn.mic:hover { background: var(--chip-bg); color: var(--fg); transform: scale(1.1); }
.action-btn.mic.listening { color: #ef4444; background: rgba(239, 68, 68, 0.1); transform: scale(1.1); }

@keyframes pulseRed { 0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); } 70% { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0); } 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); } }

.modal { display: none; position: fixed; inset: 0; z-index: 1000; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(8px); padding: 20px; transition: opacity 0.3s; }
.modal.show { display: flex; animation: fadeInModal 0.3s ease-out; }
@keyframes fadeInModal { from { opacity: 0; } to { opacity: 1; } }

.panel { 
  background: var(--panel); 
  border: 1px solid var(--border); border-radius: 32px; 
  padding: 40px; 
  box-shadow: 0 30px 60px -15px rgba(0,0,0,0.5); 
  width: min(550px, 90vw); max-height: 85vh; overflow-y: auto; 
  backdrop-filter: blur(30px);
}
.panel.center { text-align:center; }
.panel h1 { margin:12px 0; font-size: 2.5rem; letter-spacing: -1.5px; background: linear-gradient(to right, var(--fg), var(--muted)); -webkit-background-clip: text; -webkit-text-fill-color: transparent;}
.actions { display:flex; gap:16px; justify-content:center; margin-top:32px; }

.btn { padding:14px 32px; border-radius:18px; border:1px solid var(--border); background:var(--chip-bg); color:var(--fg); cursor:pointer; font-weight: 600; font-size: 1rem; transition: all .3s cubic-bezier(0.34, 1.56, 0.64, 1); text-decoration: none; display: inline-block; }
.btn.primary { background:var(--mood); color:#fff; border-color: var(--mood); box-shadow: 0 8px 25px -5px rgba(var(--mood), 0.5); }
.btn:hover { transform: translateY(-3px) scale(1.02); }

.histbar { display:flex; justify-content:space-between; align-items: center; gap:12px; margin-bottom:24px; }
.histbar input { flex:1; padding:14px; border-radius:14px; border:2px solid var(--border); background:var(--input-bg); color:var(--fg); font-size: 1rem; transition: border 0.3s; }
.histbar input:focus { border-color: var(--mood); outline: none; }
.histlist { display:grid; gap:10px; max-height:60vh; overflow:auto; padding-right: 8px;}
.histitem {
  display: flex; justify-content: space-between; align-items: center;
  cursor:pointer; padding: 18px; border-radius:18px; border:1px solid transparent;
  background: rgba(255,255,255,0.03);
  transition: all .2s;
}
.histitem:hover { background: var(--chip-bg); border-color: var(--border); transform: translateX(4px); }
.histitem .title { font-weight: 600; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-right: 16px; }
.histitem .meta { color:var(--muted); font-size:0.85rem; flex-shrink: 0; }

.watermark { text-align: center; font-size: 0.8rem; opacity:.5; color:var(--muted); margin-bottom: 16px; letter-spacing: 0.5px; }

@media (max-width: 768px) {
  body { font-size: 14px; }
  .appbar { padding: 12px 20px; }
  .mobile-menu-btn { display: block; position: absolute; top: 16px; right: 20px; background: none; border: none; font-size: 1.5rem; color: var(--fg); }
  .controls-container { display: none; width: 100%; order: 3; margin-top: 16px; background: var(--panel); border-radius: 20px; padding: 16px; border: 1px solid var(--border); animation: fadeIn 0.2s; }
  .controls-container.menu-open { display: block; }
  .controls { flex-direction: column; align-items: stretch; gap: 10px; }
  .chat-area { padding: 20px 16px; }
  .composer-area { padding: 10px; background: var(--panel); border-top: 1px solid var(--border); }
  .composer { border-radius: 24px; backdrop-filter: none; }
  .watermark { display: none; }
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--muted); }