/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', sans-serif;
}

html, body {
    height: 100%;
    width: 100%;
}

body {
    background-color: #000;
    color: #aaa;
    height: 100vh;
    width: 100vw;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow: hidden;
}

/* CHAT: antes del primer mensaje, centrado verticalmente */
#chat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100%;
    max-width: 900px;
    padding-top: 40px;
    overflow: hidden;
}

/* Mensajes */
#messages {
    flex: 1;
    width: 100%;
    overflow-y: auto;
    padding: 20px 0 20px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-behavior: smooth;
    overscroll-behavior-y: contain;
    min-height: 0;
}
#messages::-webkit-scrollbar { display: none; }

.mensaje {
    max-width: 80%;
    background: rgba(255,255,255,0.04);
    color: #ddd;
    padding: 10px 14px;
    border-radius: 12px;
    margin-bottom: 10px;
    word-break: break-word;
}
.mensaje.user { align-self: flex-end; background: rgba(0,120,255,0.12); }
.mensaje.ia { align-self: flex-start; background: rgba(255,255,255,0.03); color: #eee; }
.mensaje.ia-thinking { align-self: center; opacity: 0.7; font-style: italic; }
.mensaje.error { align-self: center; background: rgba(255,0,0,0.08); color: #f88; }

/* INPUT WRAPPER — mismo tamaño antes y después */
.input-wrapper {
    background-color: #111;
    border-radius: 40px;
    display: flex;
    align-items: center;
    padding: 10px 20px;

    /* mismo ancho responsivo en ambos estados */
    width: min(500px, 90vw);
    max-width: 100%;

    margin-bottom: 22px;
    transition: transform 0.45s cubic-bezier(.2,.9,.2,1);
    position: relative;
    z-index: 10;
    box-shadow: 0 6px 20px rgba(0,0,0,0.5);
}

.input-wrapper:focus-within {
    box-shadow: 0 0 8px 2px rgba(0,102,204,0.4);
}

.input-wrapper input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #ddd;
    font-size: 16px;
}

.input-wrapper button {
    background: none;
    border: none;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(255,255,255,0.04);
    box-shadow: inset 0 0 0 2px rgba(255,255,255,0.03);
    transition: filter 0.2s ease, transform 0.12s ease;
    background-image: url("data:image/svg+xml,%3Csvg fill='%23aaa' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M2 21l21-9L2 3v7l15 2-15 2z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 60%;
}

.input-wrapper button:hover {
    filter: brightness(1.25);
    transform: translateY(-1px);
}

/* Selector de idioma */
.language-toggle {
    width: min(500px, 90vw);
    max-width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    font-size: 14px;
    color: #a6a6a6;
    margin: 0;
    transform: translateY(-10px);
    pointer-events: auto;
    transition: opacity 0.3s ease;
}

.language-toggle input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.language-toggle label {
    cursor: pointer;
    color: #a6a6a6;
    transition: color 0.12s ease;
}

.language-toggle input:checked + label {
    color: #fff;
    font-weight: 700;
}

.language-toggle span {
    width: 1px;
    height: 14px;
    background-color: #444;
}

/* Estado final del input */
.input-wrapper.fixed {
    position: relative;
    left: auto;
    transform: auto;
    bottom: auto;
    margin: 0 auto 12px auto;
    width: min(500px, 90vw); /* mismo ancho que el estado normal */
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
    z-index: 999;
    transition: none;
    flex-shrink: 0;
}

/* --- Sigmaz badge --- */
.sigmaz-badge {
    position: fixed;
    bottom: 14px;
    right: 14px;
    background: rgba(255,255,255,0.05);
    color: #ccc;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
    z-index: 9999;
    backdrop-filter: blur(6px);
    box-shadow: 0 0 10px rgba(0,0,0,0.3);
}
.sigmaz-badge strong {
    color: #fff;
}
.sigmaz-badge:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
    transform: translateY(-2px);
}

/* --- Modal --- */
.sigmaz-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(4px);
}

.sigmaz-modal.active {
    display: flex;
}

.sigmaz-modal-content {
    background: #111;
    color: #ddd;
    padding: 22px 30px;
    border-radius: 20px;
    box-shadow: 0 0 25px rgba(0,0,0,0.6);
    width: min(90%, 380px);
    text-align: center;
    animation: fadeInScale 0.25s ease forwards;
}

.sigmaz-modal-content h2 {
    margin-bottom: 10px;
    color: #fff;
}

.sigmaz-modal-content button {
    margin-top: 16px;
    padding: 8px 16px;
    background: rgba(255,255,255,0.1);
    color: #fff;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.25s ease;
    font-weight: 500;
    letter-spacing: 0.3px;
}

.sigmaz-modal-content button:hover {
    background: rgba(255,255,255,0.2);
    transform: translateY(-2px);
    box-shadow: 0 0 10px rgba(255,255,255,0.25);
}

@keyframes fadeInScale {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

/* --- Enlaces dentro del modal --- */
.sigmaz-modal-content a {
    color: #ccc;
    text-decoration: none;
    font-weight: 500;
    margin: 0 8px;
    transition: color 0.2s ease, transform 0.2s ease;
    display: inline-block;
}

.sigmaz-modal-content a:hover {
    color: #fff;
    transform: translateY(-1px);
}

/* --- Íconos de redes dentro del modal --- */
.sigmaz-links {
    margin-top: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 18px;
}

.sigmaz-links a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255,255,255,0.08);
    transition: all 0.25s ease;
}

.sigmaz-links a:hover {
    background: rgba(255,255,255,0.18);
    transform: translateY(-2px) scale(1.05);
}

.sigmaz-links img {
    width: 40px;
    height: 40px;
    filter: invert(80%);
    transition: filter 0.25s ease;
}

.sigmaz-links a:hover img {
    filter: invert(100%);
}

/* ---------------- REEMPLAZAR BLOQUE DE ESTILO DE RESULTADO FINAL ---------------- */
/* overlay que cubre todo el viewport */
.result-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    background: linear-gradient(180deg, rgba(0,0,0,0.65), rgba(0,0,0,0.85));
    backdrop-filter: blur(6px);
    z-index: 10001;
    pointer-events: auto;
}

/* tarjeta centrada */
.result-screen {
    width: min(760px, 94%);
    max-width: 760px;
    background: linear-gradient(180deg, rgba(10,10,12,0.92), rgba(4,4,6,0.98));
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.7), inset 0 1px 0 rgba(255,255,255,0.02);
    padding: 28px;
    color: #e9eef8;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    transform: translateY(12px);
    opacity: 0;
    animation: resultFadeIn 420ms cubic-bezier(.2,.9,.2,1) forwards;
}

/* pequeña carta interna para contenido */
.result-card {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* encabezado */
.result-header {
    font-size: 20px;
    color: #bcd1ff;
    letter-spacing: 0.6px;
    margin-bottom: 4px;
}

/* contenedor del SVG / anillo */
.progress-wrap {
    width: 220px;
    height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* SVG ring styles */
/* Si no inyectas un <linearGradient id="grad1"> desde JS, usamos un color sólido aquí */
.progress-ring__bg {
    stroke: rgba(255,255,255,0.06);
}
.progress-ring__progress {
    stroke: #3ec0ff; /* color de acento */
    transition: stroke-dashoffset 120ms linear;
    filter: drop-shadow(0 6px 18px rgba(0,115,255,0.18));
}

/* contenido centrado dentro del círculo */
.center-content {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    width: 100%;
    height: 100%;
    text-align: center;
}

.percentage {
    font-size: 48px;
    font-weight: 700;
    color: #ffffff;
    line-height: 1;
}
.gosling {
    font-size: 14px;
    margin-top: 4px;
    color: rgba(220,230,255,0.9);
}

/* cita */
.quote {
    margin-top: 12px;
    font-style: italic;
    color: #cfd9ff;
    max-width: 84%;
    text-align: center;
    opacity: 0.95;
}

/* acciones/botones */
.result-actions {
    margin-top: 12px;
    display: flex;
    gap: 12px;
}

.retry-btn, .close-btn {
    padding: 10px 16px;
    border-radius: 14px;
    border: none;
    cursor: pointer;
    font-weight: 700;
    letter-spacing: 0.3px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.45);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.retry-btn {
    background: linear-gradient(180deg,#007bff,#0062d6);
    color: #fff;
}
.close-btn {
    background: rgba(255,255,255,0.06);
    color: #e6eefc;
}

/* hover */
.retry-btn:hover { transform: translateY(-3px); box-shadow: 0 12px 30px rgba(0,123,255,0.18); }
.close-btn:hover { transform: translateY(-3px); box-shadow: 0 12px 30px rgba(0,0,0,0.25); }

/* estado final para pulso / brillo cuando llega al 100% */
.result-screen.done .percentage {
    animation: popIn 420ms ease forwards;
}
.result-screen.done .progress-ring__progress {
    animation: ringGlow 900ms ease 120ms forwards;
}

/* animaciones */
@keyframes resultFadeIn {
    from { opacity: 0; transform: translateY(18px) scale(0.995); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes popIn {
    0% { transform: scale(0.96); opacity: 0.6; }
    60% { transform: scale(1.06); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}
@keyframes ringGlow {
    0% { filter: drop-shadow(0 4px 10px rgba(0,115,255,0.06)); }
    50% { filter: drop-shadow(0 16px 40px rgba(0,115,255,0.22)); transform: scale(1.02); }
    100% { filter: drop-shadow(0 10px 26px rgba(0,115,255,0.16)); transform: scale(1); }
}

/* Responsive */
@media (max-width: 520px) {
    #messages { padding: 16px 0 130px; }
    .input-wrapper, .language-toggle {
        border-radius: 30px;
        padding: 10px 16px;
    }

    .progress-wrap { width: 180px; height: 180px; }
    .percentage { font-size: 40px; }
    .result-screen { padding: 18px; border-radius: 16px; }
}
/* ---------- estilos para la pantalla final ---------- */
.result-overlay { position: fixed; inset: 0; display:flex; align-items:center; justify-content:center; background: rgba(0,0,0,0.6); z-index: 9999; }
.result-screen { max-width: 640px; width: 100%; padding: 20px; box-sizing: border-box; }

/* El contenedor relativo que contiene el SVG y el contenido centrado */
.progress-wrap {
  position: relative;      /* importante: para poder posicionar el contenido encima */
  width: 220px;
  height: 220px;
  margin: 0 auto;
  display: block;
}

/* Forzar SVG a ocupar todo el contenedor */
.progress-wrap svg { display: block; width: 100%; height: 100%; }

/* Contenido centrado sobre el SVG (posición absoluta dentro de progress-wrap) */
.progress-wrap .center-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%); /* centra perfecto en el medio del SVG */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none; /* para que clicks pasen al SVG si lo deseas */
}

/* estilo del porcentaje y label */
.progress-wrap .percentage {
  font-size: 2.6rem;
  font-weight: 700;
  color: #fff;
  line-height: 1;
}
.progress-wrap .gosling {
  font-size: 0.95rem;
  margin-top: 6px;
  color: #dfe6f0;
}
/* Fix para reCAPTCHA en modal: permite interacción con iframes y overlays de Google */
body.captcha-locked iframe[src*="recaptcha"],
body.captcha-locked .g-recaptcha iframe,
body.captcha-locked [role="presentation"] iframe,
body.captcha-locked .rc-anchor-iframe,
body.captcha-locked .rc-imageselect,
body.captcha-locked .rc-anchor,
body.captcha-locked .g-recaptcha * {
    pointer-events: auto !important;
    z-index: 10000 !important; /* Asegura que el overlay de imágenes quede por encima del backdrop */
}

/* Evita que el overflow hidden afecte al iframe */
body.captcha-locked .g-recaptcha {
    overflow: visible !important;
    position: relative;
}

/* Si el desafío abre un popup/overlay, fuerza visibilidad */
.rc-imageselect-viewport,
.rc-imageselect-tiles {
    pointer-events: auto !important;
    z-index: 10001 !important;
}
/* --- Mejor manejo de altura en móviles (evita solapamiento por teclado) --- */
/* usa unidades dinámicas (dvh) y safe-area para dispositivos modernos */
:root {
  --input-bottom-safe: env(safe-area-inset-bottom, 12px);
  --input-height: 64px; /* altura estimada del input wrapper en estado fijo */
}

/* Usar 100dvh evita que el teclado reduzca la altura visible en algunos navegadores */
html, body, #chat {
  height: 100dvh;
}

/* Mensajes: permitir que el área de mensajes tenga espacio adicional
   en la parte inferior igual a la altura del input + safe-area */
#messages {
  padding-bottom: calc(var(--input-height) + var(--input-bottom-safe) + 24px);
  transition: padding-bottom 180ms ease;
}

/* Cuando el input está fijo en el fondo */
.input-wrapper.fixed {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--input-bottom-safe));
  /* asegurar que la altura sea la esperada para calcular padding-bottom arriba */
  height: var(--input-height);
  display: flex;
  align-items: center;
  z-index: 999;
}

/* Badge (About the authors): no solapar el input en pantallas pequeñas */
.sigmaz-badge {
  /* en móviles, subirlo ligeramente si el input está fijo */
  margin-bottom: calc(var(--input-height) + var(--input-bottom-safe) + 8px);
  right: 14px;
  bottom: auto; /* permitimos usar margin-bottom en lugar de bottom fijo */
  position: fixed;
  transform: none;
}

/* Alternativa: en pantallas muy pequeñas, hacer el badge más compacto */
@media (max-width: 520px) {
  :root { --input-height: 56px; }
  .sigmaz-badge { padding: 6px 10px; font-size: 12px; border-radius: 16px; }
  .input-wrapper.fixed { width: min(92%, 500px); }
}

/* Si quieres un comportamiento extra cuando el teclado aparece (Android Chrome),
   reducimos el espacio superior del contenedor de mensajes ligeramente */
@media (pointer: coarse) and (max-width: 900px) {
  #messages { max-height: calc(100dvh - var(--input-height) - var(--input-bottom-safe) - 40px); overflow-y: auto; }
}
