/* =========================================================
   Luna · Guardiana de Moonwater
   Paleta: noche profunda, agua turquesa y luz de luna.
   ========================================================= */

:root {
  color-scheme: dark;

  --night-950: #040e1c;
  --night-900: #071426;
  --night-800: #0a1931;
  --night-700: #102846;
  --teal: #4fd1c5;
  --teal-bright: #82e8dc;
  --cream: #f6e8c1;
  --cream-bright: #fff9e8;
  --text: #eaf3ee;
  --muted: #9fb9b7;
  --line: rgba(79, 209, 197, 0.18);
  --line-warm: rgba(246, 232, 193, 0.16);

  --font-display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --font-body: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;

  --radius-card: 30px;
  --shadow-card: 0 32px 90px -34px rgba(0, 0, 0, 0.9), 0 0 0 1px rgba(246, 232, 193, 0.045);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  padding: 12px;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background:
    radial-gradient(ellipse 70% 55% at 16% 4%, rgba(79, 209, 197, 0.12), transparent 58%),
    radial-gradient(ellipse 55% 48% at 92% 94%, rgba(246, 232, 193, 0.075), transparent 62%),
    linear-gradient(145deg, #071628 0%, #08172b 46%, #040e1c 100%);
}

/* Cielo estrellado, sin imágenes externas. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.58;
  background-image:
    radial-gradient(circle at 16% 18%, rgba(246, 232, 193, 0.85) 0 1px, transparent 1.8px),
    radial-gradient(circle at 72% 12%, rgba(255, 255, 255, 0.65) 0 1px, transparent 1.6px),
    radial-gradient(circle at 88% 58%, rgba(79, 209, 197, 0.55) 0 1px, transparent 1.8px),
    radial-gradient(circle at 34% 82%, rgba(246, 232, 193, 0.45) 0 1px, transparent 1.6px),
    radial-gradient(circle at 58% 39%, rgba(255, 255, 255, 0.38) 0 1px, transparent 1.5px);
  background-size: 310px 310px, 270px 270px, 360px 360px, 420px 420px, 240px 240px;
  background-position: 0 0, 80px 45px, 120px 10px, 35px 160px, 170px 90px;
}

/* Halo de agua bajo la tarjeta. */
body::after {
  content: "";
  position: fixed;
  left: 8%;
  right: 8%;
  bottom: -26%;
  height: 48%;
  pointer-events: none;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(79, 209, 197, 0.15), transparent 68%);
  filter: blur(42px);
}

::selection {
  background: rgba(79, 209, 197, 0.34);
  color: var(--cream-bright);
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:not(:disabled) {
  cursor: pointer;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ===== Estructura principal ===== */

.page {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 560px;
  height: calc(100vh - 24px);
  height: calc(100svh - 24px);
  max-height: 820px;
  min-width: 0;
  min-height: 0;
}

.card {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(79, 209, 197, 0.23);
  border-radius: var(--radius-card);
  background:
    radial-gradient(circle at 13% -6%, rgba(79, 209, 197, 0.17), transparent 35%),
    radial-gradient(circle at 92% 3%, rgba(246, 232, 193, 0.1), transparent 27%),
    linear-gradient(165deg, rgba(15, 39, 68, 0.98) 0%, rgba(10, 25, 49, 0.99) 52%, rgba(6, 20, 38, 1) 100%);
  box-shadow: var(--shadow-card);
}

/* Polvo de estrellas dentro del refugio. */
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.34;
  background-image:
    radial-gradient(circle at 22% 18%, rgba(246, 232, 193, 0.8) 0 1px, transparent 1.6px),
    radial-gradient(circle at 74% 9%, rgba(255, 255, 255, 0.55) 0 1px, transparent 1.4px),
    radial-gradient(circle at 90% 36%, rgba(79, 209, 197, 0.5) 0 1px, transparent 1.8px),
    radial-gradient(circle at 38% 55%, rgba(246, 232, 193, 0.3) 0 1px, transparent 1.5px);
  background-size: 210px 210px, 260px 260px, 290px 290px, 330px 330px;
  animation: starlight 11s ease-in-out infinite alternate;
}

/* Resplandor de marea en la base. */
.card::after {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: -82px;
  z-index: 0;
  height: 160px;
  pointer-events: none;
  border-radius: 50%;
  background: rgba(79, 209, 197, 0.2);
  filter: blur(58px);
}

.header,
.chat,
.controls {
  position: relative;
  z-index: 1;
}

/* ===== Cabecera ===== */

.header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 15px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(17, 45, 74, 0.48), rgba(10, 25, 49, 0));
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar {
  position: relative;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.45), transparent 22%),
    radial-gradient(circle at 65% 72%, rgba(79, 209, 197, 0.65), transparent 46%),
    linear-gradient(145deg, #173e56 0%, #0c2a44 55%, #07182b 100%);
  border: 1px solid rgba(246, 232, 193, 0.3);
  box-shadow:
    0 0 0 4px rgba(79, 209, 197, 0.055),
    0 8px 24px -8px rgba(0, 0, 0, 0.8),
    0 0 26px rgba(79, 209, 197, 0.15);
}

.avatar::after {
  content: "";
  position: absolute;
  top: 22%;
  right: 16%;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  box-shadow:
    -5px 8px 0 rgba(255, 255, 255, 0.52),
    -3px 20px 0 rgba(246, 232, 193, 0.46);
}

.avatar--header {
  width: 54px;
  height: 54px;
}

.avatar .moon {
  position: absolute;
  top: 14%;
  left: 17%;
  width: 70%;
  height: 70%;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fffdf0 0%, #f6e8c1 47%, #d6c48d 100%);
  box-shadow:
    inset -9px -4px 0 2px rgba(11, 38, 59, 0.9),
    0 0 20px rgba(246, 232, 193, 0.42);
  transform: rotate(-15deg);
}

.identity {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 3px;
  overflow: hidden;
  color: var(--teal);
  font-size: 0.6rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.16em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

h1 {
  margin: 0;
  color: var(--cream-bright);
  font-family: var(--font-display);
  font-size: 1.74rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.02em;
  text-shadow: 0 2px 24px rgba(246, 232, 193, 0.14);
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 5px 0 0;
  color: #b8d1cb;
  font-size: 0.71rem;
  line-height: 1.2;
}

.status-dot {
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 3px rgba(79, 209, 197, 0.12), 0 0 10px rgba(79, 209, 197, 0.75);
  animation: statusGlow 3.2s ease-in-out infinite;
}

.site-link {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 33px;
  padding: 0 10px;
  border: 1px solid var(--line-warm);
  border-radius: 999px;
  color: var(--cream);
  font-size: 0.66rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.01em;
  text-decoration: none;
  background: rgba(246, 232, 193, 0.045);
  transition: border-color 180ms ease, background-color 180ms ease, transform 180ms ease;
}

.site-link svg {
  width: 13px;
  height: 13px;
  flex: 0 0 auto;
}

.site-link:hover {
  border-color: rgba(246, 232, 193, 0.38);
  background: rgba(246, 232, 193, 0.1);
  transform: translateY(-1px);
}

.site-link:active {
  transform: translateY(0);
}

/* ===== Conversación ===== */

.chat {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 16px 10px;
  scrollbar-color: rgba(79, 209, 197, 0.34) transparent;
  scrollbar-width: thin;
  scroll-behavior: smooth;
}

.chat::-webkit-scrollbar {
  width: 6px;
}

.chat::-webkit-scrollbar-track {
  background: transparent;
}

.chat::-webkit-scrollbar-thumb {
  border-radius: 99px;
  background: rgba(79, 209, 197, 0.3);
}

#chat:focus-visible {
  outline: 1px solid rgba(79, 209, 197, 0.5);
  outline-offset: -3px;
}

.msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  animation: messageIn 360ms cubic-bezier(0.2, 0.8, 0.25, 1) both;
}

.msg.bot {
  justify-content: flex-start;
}

.msg.user {
  justify-content: flex-end;
}

.msg-avatar {
  position: relative;
  align-self: flex-start;
  flex: 0 0 auto;
  width: 27px;
  height: 27px;
  margin-top: 2px;
  overflow: hidden;
  border: 1px solid rgba(246, 232, 193, 0.27);
  border-radius: 50%;
  background: linear-gradient(145deg, #173e56 0%, #0a223a 100%);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
}

.msg-avatar .moon {
  position: absolute;
  top: 14%;
  left: 17%;
  width: 70%;
  height: 70%;
  border-radius: 50%;
  background: var(--cream);
  box-shadow: inset -5px -2px 0 1px rgba(11, 38, 59, 0.9);
  transform: rotate(-15deg);
}

.msg-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: min(87%, 445px);
  min-width: 0;
}

.msg.user .msg-body {
  align-items: flex-end;
  max-width: min(82%, 420px);
}

.bubble {
  max-width: 100%;
  padding: 11px 14px;
  border: 1px solid rgba(79, 209, 197, 0.16);
  border-radius: 18px 18px 18px 6px;
  color: var(--text);
  background: linear-gradient(145deg, rgba(21, 53, 79, 0.92), rgba(12, 34, 58, 0.94));
  box-shadow: 0 10px 28px -20px rgba(0, 0, 0, 0.85);
}

.msg.user .bubble {
  border-color: rgba(255, 255, 255, 0.18);
  border-radius: 18px 18px 6px 18px;
  color: #06242a;
  background: linear-gradient(135deg, #85ebe0 0%, #4fd1c5 100%);
  box-shadow: 0 10px 26px -16px rgba(79, 209, 197, 0.38);
}

.bubble-text {
  margin: 0;
  font-size: 0.91rem;
  line-height: 1.56;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.msg.user .bubble-text {
  font-weight: 500;
}

.cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 8px 11px;
  border: 1px solid rgba(246, 232, 193, 0.28);
  border-radius: 10px;
  color: var(--cream-bright);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  background: rgba(246, 232, 193, 0.075);
  transition: border-color 180ms ease, background-color 180ms ease;
}

.cta:hover {
  border-color: rgba(246, 232, 193, 0.54);
  background: rgba(246, 232, 193, 0.14);
}

.cta:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.cta span {
  font-size: 0.92em;
}

.meta {
  margin: 5px 5px 0;
  color: rgba(199, 221, 214, 0.44);
  font-size: 0.59rem;
  line-height: 1.3;
  letter-spacing: 0.02em;
}

.msg.user .meta {
  text-align: right;
}

/* Indicador de escritura */
.typing-bubble {
  display: flex;
  align-items: center;
  min-width: 54px;
  min-height: 37px;
}

.dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 10px;
}

.dots i {
  display: block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--teal);
  animation: typingDot 1.2s ease-in-out infinite;
}

.dots i:nth-child(2) {
  animation-delay: 140ms;
}

.dots i:nth-child(3) {
  animation-delay: 280ms;
}

/* ===== Controles ===== */

.controls {
  flex: 0 0 auto;
  min-width: 0;
  padding: 9px 14px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(8, 23, 42, 0.84), rgba(5, 16, 31, 0.97));
  box-shadow: 0 -18px 35px -30px rgba(0, 0, 0, 0.9);
}

.chips {
  display: flex;
  gap: 7px;
  min-width: 0;
  padding: 2px 1px 9px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  padding: 6px 10px;
  border: 1px solid rgba(79, 209, 197, 0.24);
  border-radius: 999px;
  color: #cbe8e2;
  font-size: 0.69rem;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  background: rgba(79, 209, 197, 0.06);
  transition: color 180ms ease, border-color 180ms ease, background-color 180ms ease, transform 180ms ease;
}

.chip:hover {
  border-color: rgba(79, 209, 197, 0.55);
  color: var(--cream-bright);
  background: rgba(79, 209, 197, 0.13);
}

.chip:active {
  transform: scale(0.97);
}

.chip:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.composer {
  display: flex;
  align-items: center;
  gap: 7px;
}

#input {
  flex: 1 1 auto;
  min-width: 0;
  height: 46px;
  padding: 0 16px;
  border: 1px solid rgba(79, 209, 197, 0.23);
  border-radius: 999px;
  outline: none;
  color: var(--cream-bright);
  font-size: 1rem;
  line-height: 1.2;
  background: rgba(4, 16, 30, 0.78);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035);
  transition: border-color 180ms ease, box-shadow 180ms ease, background-color 180ms ease;
}

#input::placeholder {
  color: #89a5a3;
  opacity: 1;
}

#input:focus {
  border-color: rgba(79, 209, 197, 0.72);
  background: rgba(4, 16, 30, 0.93);
  box-shadow: 0 0 0 3px rgba(79, 209, 197, 0.11), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

#input.shake {
  animation: shake 320ms ease;
}

.btn {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid rgba(79, 209, 197, 0.23);
  border-radius: 50%;
  color: #d9eae5;
  background: rgba(79, 209, 197, 0.055);
  transition: color 180ms ease, border-color 180ms ease, background-color 180ms ease, transform 160ms ease, box-shadow 180ms ease;
}

.btn svg {
  display: block;
  width: 19px;
  height: 19px;
}

.btn:hover {
  border-color: rgba(79, 209, 197, 0.52);
  color: var(--cream-bright);
  background: rgba(79, 209, 197, 0.12);
}

.btn:active {
  transform: scale(0.94);
}

.btn:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.btn-send {
  width: 46px;
  height: 46px;
  border-color: rgba(255, 255, 255, 0.2);
  color: #04242b;
  background: linear-gradient(135deg, #86ece1 0%, #4fd1c5 100%);
  box-shadow: 0 5px 20px -7px rgba(79, 209, 197, 0.6);
}

.btn-send svg {
  width: 20px;
  height: 20px;
}

.btn-send:hover {
  border-color: rgba(255, 255, 255, 0.34);
  color: #032027;
  background: linear-gradient(135deg, #a0f3e9 0%, #5edbd0 100%);
  box-shadow: 0 7px 24px -7px rgba(79, 209, 197, 0.72);
}

.btn-mic {
  color: var(--cream);
}

#mic.listening {
  border-color: rgba(246, 232, 193, 0.65);
  color: #05222b;
  background: var(--cream);
  animation: micPulse 1.35s ease-out infinite;
}

#mic.listening:hover {
  color: #05222b;
  background: var(--cream-bright);
}

#voiceToggle .icon-off {
  display: none;
}

#voiceToggle.is-muted {
  color: #819b9a;
  border-color: rgba(159, 185, 183, 0.18);
  background: rgba(159, 185, 183, 0.035);
  opacity: 0.72;
}

#voiceToggle.is-muted .icon-on {
  display: none;
}

#voiceToggle.is-muted .icon-off {
  display: block;
}

#voiceToggle.is-speaking {
  color: var(--teal-bright);
  border-color: rgba(79, 209, 197, 0.55);
  box-shadow: 0 0 0 3px rgba(79, 209, 197, 0.08);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin: 8px 0 0;
  color: rgba(184, 207, 201, 0.6);
  font-size: 0.68rem;
  line-height: 1.35;
  text-align: center;
}

.hint-dot {
  width: 4px;
  height: 4px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--teal);
  opacity: 0.7;
}

/* ===== Animaciones ===== */

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes typingDot {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@keyframes micPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(246, 232, 193, 0.4);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(246, 232, 193, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(246, 232, 193, 0);
  }
}

@keyframes statusGlow {
  0%,
  100% {
    box-shadow: 0 0 0 3px rgba(79, 209, 197, 0.1), 0 0 8px rgba(79, 209, 197, 0.55);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(79, 209, 197, 0.15), 0 0 13px rgba(79, 209, 197, 0.9);
  }
}

@keyframes starlight {
  from {
    opacity: 0.26;
  }
  to {
    opacity: 0.42;
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  55% {
    transform: translateX(4px);
  }
  80% {
    transform: translateX(-2px);
  }
}

/* ===== Adaptación a móvil y a iframes pequeños ===== */

@media (max-width: 460px) {
  body {
    padding: 0;
    background: #071426;
  }

  body::after {
    bottom: -18%;
  }

  .page {
    width: 100%;
    max-width: none;
    height: 100vh;
    height: 100svh;
    max-height: none;
  }

  .card {
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .header {
    padding: max(14px, env(safe-area-inset-top)) 14px 12px;
  }

  .avatar--header {
    width: 49px;
    height: 49px;
  }

  h1 {
    font-size: 1.58rem;
  }

  .site-link {
    width: 34px;
    height: 34px;
    padding: 0;
  }

  .site-link__text {
    display: none;
  }

  .chat {
    gap: 12px;
    padding: 14px 13px 7px;
  }

  .controls {
    padding: 8px 12px max(10px, env(safe-area-inset-bottom));
  }

  .chips {
    flex-wrap: wrap;
    overflow-x: visible;
  }

  .msg-body {
    max-width: 88%;
  }

  .msg.user .msg-body {
    max-width: 84%;
  }

  .bubble-text {
    font-size: 0.89rem;
  }

  .composer {
    gap: 6px;
  }

  .btn {
    width: 40px;
    height: 40px;
  }

  .btn-send {
    width: 44px;
    height: 44px;
  }

  .hint {
    font-size: 0.64rem;
  }
}

@media (max-width: 350px) {
  .eyebrow {
    display: none;
  }

  .status {
    font-size: 0.67rem;
  }

  .btn {
    width: 38px;
    height: 38px;
  }

  .btn-send {
    width: 42px;
    height: 42px;
  }

  .btn svg {
    width: 18px;
    height: 18px;
  }

  #input {
    padding: 0 12px;
  }

  .chip {
    font-size: 0.66rem;
  }
}

@media (max-height: 610px) {
  .header {
    padding-top: 11px;
    padding-bottom: 10px;
  }

  .avatar--header {
    width: 44px;
    height: 44px;
  }

  h1 {
    font-size: 1.42rem;
  }

  .chat {
    padding-top: 12px;
    gap: 11px;
  }

  .chips {
    padding-bottom: 7px;
  }

  .hint {
    display: none;
  }
}

@media (max-height: 500px) {
  .eyebrow {
    display: none;
  }

  .chips {
    display: none;
  }

  .bubble-text {
    font-size: 0.86rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
