"""Atmosphere — maps emotional tone to CSS classes for ambient background.""" from __future__ import annotations EMOTION_KEYWORDS: dict[str, list[str]] = { "anxious": [ "anxious", "worried", "nervous", "panic", "dread", "scared", "fear", "terrified", "overwhelmed", "racing", ], "sad": [ "sad", "depressed", "hopeless", "empty", "lonely", "grief", "loss", "crying", "worthless", "numb", ], "angry": [ "angry", "furious", "frustrated", "rage", "irritated", "resentful", "unfair", "hate", ], "calm": [ "calm", "peaceful", "relaxed", "okay", "better", "relieved", "content", "grateful", ], "breakthrough": [ "realize", "never thought of it", "that makes sense", "you're right", "actually", "huh", "wow", "i see", "that's true", ], } def detect_emotion(text: str) -> str: """Detect dominant emotional tone from conversation text. Returns CSS class name for the atmosphere gradient. """ text_lower = text.lower() scores: dict[str, int] = {} for emotion, keywords in EMOTION_KEYWORDS.items(): score = sum(1 for kw in keywords if kw in text_lower) if score > 0: scores[emotion] = score if not scores: return "atmosphere-neutral" dominant = max(scores, key=scores.get) return f"atmosphere-{dominant}"