/* === RESET & BASE === */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --sphere-size: min(280px, 65vw);
    --color-primary: #e85d3a;
    --color-primary-light: #f07b5e;
    --color-primary-dark: #c44a2a;
    --color-bg-start: #1a0f0a;
    --color-bg-mid: #241210;
    --color-bg-end: #0d0806;
    --color-text: #f0d5cc;
    --color-text-secondary: #c4a89e;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --transition-smooth: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: var(--font-family);
    background: linear-gradient(160deg, var(--color-bg-start), var(--color-bg-mid) 40%, var(--color-bg-end));
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
    touch-action: manipulation;
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* === CONTAINER === */
.container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* === BACKGROUND GLOW === */
.background-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 350px;
    height: 350px;
    background: radial-gradient(circle, rgba(232, 93, 58, 0.12) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
    animation: glowPulse 4s ease-in-out infinite;
    z-index: 0;
}

@keyframes glowPulse {
    0%, 100% { opacity: 0.6; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
}

/* === SPHERE WRAPPER === */
.sphere-wrapper {
    position: absolute;
    top: 50%;
    left: 50%;
    width: var(--sphere-size);
    height: var(--sphere-size);
    flex-shrink: 0;
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
    
    /* Usamos márgenes negativos para centrar SIN usar transform */
    margin-left: calc(var(--sphere-size) / -2);
    margin-top: calc(var(--sphere-size) / -2);
}

/* === SPHERE === */
.sphere {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: radial-gradient(
        circle at 35% 35%,
        var(--color-primary-light),
        var(--color-primary) 40%,
        var(--color-primary-dark) 70%,
        #8b2a10 100%
    );
    box-shadow: 
        0 0 60px rgba(232, 93, 58, 0.25),
        0 0 120px rgba(232, 93, 58, 0.1),
        inset 0 -8px 20px rgba(0, 0, 0, 0.3),
        inset 0 8px 20px rgba(255, 255, 255, 0.08);
    animation: sphereRotate 25s linear infinite;
    cursor: pointer;
    transition: transform var(--transition-smooth), box-shadow var(--transition-smooth);
    transform-origin: center center;
}

.sphere:hover {
    transform: scale(1.03);
}

.sphere:active {
    transform: scale(0.97);
    transition: transform 0.15s ease;
}

@keyframes sphereRotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* === SPHERE LAYERS === */
.sphere-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    pointer-events: none;
}

.layer-1 {
    background: radial-gradient(ellipse at 30% 25%, rgba(255, 255, 255, 0.2) 0%, transparent 50%);
}

.layer-2 {
    background: radial-gradient(ellipse at 65% 60%, rgba(255, 200, 150, 0.12) 0%, transparent 40%);
}

.layer-3 {
    background: conic-gradient(from 0deg, transparent 0deg, rgba(255, 255, 255, 0.03) 60deg, transparent 120deg, rgba(0, 0, 0, 0.05) 200deg, transparent 280deg, rgba(255, 255, 255, 0.04) 340deg, transparent 360deg);
    animation: layerShift 15s linear infinite;
}

@keyframes layerShift {
    from { transform: rotate(0deg); }
    to { transform: rotate(-360deg); }
}

/* === VOICE RINGS === */
.voice-rings {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-smooth);
}

.voice-rings.active {
    opacity: 1;
}

.ring {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    border: 2px solid rgba(255, 200, 170, 0.5);
    animation: ringExpand 1.5s ease-out infinite;
}

.ring-1 { width: var(--sphere-size); height: var(--sphere-size); animation-delay: 0s; }
.ring-2 { width: var(--sphere-size); height: var(--sphere-size); animation-delay: 0.5s; }
.ring-3 { width: var(--sphere-size); height: var(--sphere-size); animation-delay: 1s; }

@keyframes ringExpand {
    0% { width: var(--sphere-size); height: var(--sphere-size); opacity: 1; border-width: 2px; }
    100% { width: calc(var(--sphere-size) * 1.8); height: calc(var(--sphere-size) * 1.8); opacity: 0; border-width: 0.5px; }
}

/* === LISTENING WAVES === */
.listening-waves {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-smooth);
}

.listening-waves.active { opacity: 1; }

.wave {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.4);
    animation: waveContract 1.2s ease-out infinite;
}

.wave-1 { animation-delay: 0s; }
.wave-2 { animation-delay: 0.4s; }
.wave-3 { animation-delay: 0.8s; }

@keyframes waveContract {
    0% { width: calc(var(--sphere-size) * 1.6); height: calc(var(--sphere-size) * 1.6); opacity: 1; }
    100% { width: var(--sphere-size); height: var(--sphere-size); opacity: 0; }
}

/* === RESPONSE AREA === */
.response-area {
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 85%;
    max-width: 450px;
    max-height: 55vh;
    overflow-y: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    text-align: left;
    z-index: 5;
    pointer-events: auto;
    padding: 10px 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.response-text {
    color: var(--color-text);
    font-size: clamp(15px, 4vw, 17px);
    font-weight: 300;
    line-height: 1.6;
    letter-spacing: 0.3px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 20px 24px;
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.response-text.visible {
    opacity: 1;
    transform: translateY(0);
}

/* === TEXT INPUT === */
.text-input-container {
    position: absolute;
    bottom: 160px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 400px;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 0.4s ease, opacity 0.3s ease;
    z-index: 20;
}

.text-input-container.open {
    max-height: 80px;
    opacity: 1;
}

.text-input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 25px;
    padding: 6px 8px 6px 20px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.text-input-wrapper:focus-within {
    border-color: var(--color-primary-light);
    background: rgba(255, 255, 255, 0.1);
}

.text-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--color-text);
    font-size: 16px;
    font-family: var(--font-family);
    font-weight: 300;
}

.text-input::placeholder {
    color: var(--color-text-secondary);
    opacity: 0.6;
}

.send-button {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--color-primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.send-button:active {
    transform: scale(0.93);
}

/* === ACTION BUTTONS === */
.action-buttons {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    align-items: center;
    z-index: 20;
}

.action-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.04);
    color: var(--color-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.action-btn:active {
    transform: scale(0.92);
}

.voice-btn {
    width: 64px;
    height: 64px;
    background: var(--color-primary);
    border: none;
    color: white;
    box-shadow: 0 4px 20px rgba(232, 93, 58, 0.35);
}

.voice-btn.listening {
    background: #ff4444;
    box-shadow: 0 0 30px rgba(255, 68, 68, 0.5);
    animation: listenPulse 1s ease-in-out infinite;
}

@keyframes listenPulse {
    0%, 100% { box-shadow: 0 0 20px rgba(255, 68, 68, 0.4); }
    50% { box-shadow: 0 0 40px rgba(255, 68, 68, 0.7); }
}

/* === STATUS INDICATOR === */
.status-indicator {
    position: absolute;
    bottom: 110px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
}

.status-text {
    color: var(--color-text-secondary);
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 1px;
    text-transform: uppercase;
    opacity: 0.6;
}

/* === SPHERE STATES === */

/* Minimizada arriba */
.sphere-wrapper.minimized {
    top: 12%;
    width: calc(var(--sphere-size) * 0.3);
    height: calc(var(--sphere-size) * 0.3);
    margin-left: calc(var(--sphere-size) * 0.3 / -2);
    margin-top: 0;
}

.sphere-wrapper.minimized .sphere {
    animation: sphereRotate 15s linear infinite;
    box-shadow: 0 0 30px rgba(232, 93, 58, 0.2), 0 0 60px rgba(232, 93, 58, 0.08), inset 0 -4px 10px rgba(0, 0, 0, 0.3), inset 0 4px 10px rgba(255, 255, 255, 0.06);
}

/* Pensando */
.sphere-wrapper.thinking .sphere {
    animation: sphereRotate 8s linear infinite, thinkPulse 0.6s ease-in-out infinite;
}

@keyframes thinkPulse {
    0%, 100% { box-shadow: 0 0 60px rgba(232, 93, 58, 0.25), 0 0 120px rgba(232, 93, 58, 0.1); }
    50% { box-shadow: 0 0 100px rgba(232, 93, 58, 0.5), 0 0 180px rgba(232, 93, 58, 0.25); }
}

/* Escuchando */
.sphere-wrapper.listening .sphere {
    animation: sphereRotate 20s linear infinite, listenGlow 1s ease-in-out infinite;
}

@keyframes listenGlow {
    0%, 100% { box-shadow: 0 0 60px rgba(232, 93, 58, 0.25), 0 0 120px rgba(232, 93, 58, 0.1); }
    50% { box-shadow: 0 0 90px rgba(255, 100, 60, 0.5), 0 0 160px rgba(255, 100, 60, 0.3); }
}

/* Hablando */
.sphere.speaking {
    animation: sphereRotate 25s linear infinite, sphereSpeak 0.3s ease-in-out infinite;
}

@keyframes sphereSpeak {
    0%, 100% { box-shadow: 0 0 60px rgba(232, 93, 58, 0.25), 0 0 120px rgba(232, 93, 58, 0.1), inset 0 -8px 20px rgba(0, 0, 0, 0.3), inset 0 8px 20px rgba(255, 255, 255, 0.08); }
    50% { box-shadow: 0 0 80px rgba(232, 93, 58, 0.4), 0 0 150px rgba(232, 93, 58, 0.2), inset 0 -8px 20px rgba(0, 0, 0, 0.3), inset 0 8px 20px rgba(255, 255, 255, 0.12); }
}

/* === RESPONSIVE === */

@media (max-width: 480px) {
    :root { --sphere-size: min(240px, 60vw); }
    .sphere-wrapper.minimized {
        top: 10%;
        width: calc(var(--sphere-size) * 0.25);
        height: calc(var(--sphere-size) * 0.25);
        margin-left: calc(var(--sphere-size) * 0.25 / -2);
    }
    .response-text { font-size: clamp(16px, 4.5vw, 18px); }
    .action-btn { width: 46px; height: 46px; }
    .voice-btn { width: 56px; height: 56px; }
}

@media (min-width: 768px) {
    :root { --sphere-size: 300px; }
    .sphere-wrapper.minimized {
        top: 8%;
        width: calc(var(--sphere-size) * 0.3);
        height: calc(var(--sphere-size) * 0.3);
        margin-left: calc(var(--sphere-size) * 0.3 / -2);
    }
}

/* === BURGER MENU === */
.menu-button {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.04);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    z-index: 30;
    transition: all 0.3s ease;
    padding: 0;
}

.menu-button span {
    display: block;
    width: 16px;
    height: 1.5px;
    background: var(--color-text-secondary);
    border-radius: 2px;
    transition: all 0.3s ease;
}

.menu-button:hover {
    background: rgba(255, 255, 255, 0.08);
}

.menu-button.active {
    background: rgba(255, 255, 255, 0.1);
}

.menu-button.active span:nth-child(1) {
    transform: translateY(5.5px) rotate(45deg);
}

.menu-button.active span:nth-child(2) {
    opacity: 0;
}

.menu-button.active span:nth-child(3) {
    transform: translateY(-5.5px) rotate(-45deg);
}

.menu-dropdown {
    position: absolute;
    top: 65px;
    right: 20px;
    background: rgba(30, 20, 15, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 6px;
    z-index: 29;
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
    transition: all 0.3s ease;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    min-width: 180px;
}

.menu-dropdown.open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.menu-item {
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--color-text);
    font-size: 14px;
    font-family: var(--font-family);
    font-weight: 300;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.2s ease;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

.logout-item:hover {
    background: rgba(255, 68, 68, 0.15);
    color: #ff6b6b;
}

/* Markdown formatting inside the assistant response text */
.response-text {
  word-break: break-word;
  line-height: 1.5;
}

.response-text p {
  margin: 0 0 8px 0;
}

.response-text p:last-child {
  margin-bottom: 0;
}

.response-text ul, 
.response-text ol {
  margin: 8px 0;
  padding-left: 1.25rem;
  text-align: left;
}

.response-text li {
  margin-bottom: 4px;
}

.response-text strong {
  font-weight: 600;
  color: inherit;
}

