:root {
  --bg: #050505;
  --bg-2: #0c0c0c;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.22);
  --text: #f5f5f5;
  --muted: rgba(255, 255, 255, 0.52);
  --faint: rgba(255, 255, 255, 0.28);
  --white: #ffffff;
  --green: #22c55e;
  --green-hover: #4ade80;
  --sans: "Space Grotesk", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --pixel: "Tiny5", var(--mono);
  --pad: clamp(16px, 3vw, 40px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--mono); }

#flow {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 40%, transparent 0%, rgba(0, 0, 0, 0.55) 75%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 3px);
}

.app {
  position: relative;
  z-index: 2;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 0 var(--pad);
}

/* ---------- Top bar ---------- */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
}

.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.logo {
  font-family: var(--pixel);
  font-size: 30px;
  line-height: 1;
  color: var(--white);
  letter-spacing: 0.02em;
}
.brand-name { font-size: 14px; font-weight: 300; letter-spacing: 0.02em; color: var(--muted); }
.brand-name b { font-weight: 600; }

.trail {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
  font-size: 11px;
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  mask-image: linear-gradient(90deg, transparent, #000 15%, #000 85%, transparent);
}
.trail span::before { content: "/ "; opacity: 0.5; }
.trail span:last-child { color: var(--muted); }

.status {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--muted);
  flex-shrink: 0;
}
.dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--white);
  box-shadow: 0 0 10px var(--white);
  animation: blink 2s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: 0.25; } }

.reset {
  margin-left: 6px;
  background: none;
  border: 1px solid var(--line-strong);
  color: var(--text);
  width: 26px; height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.2s, color 0.2s;
}
.reset:hover { background: var(--white); color: var(--bg); }

/* ---------- Stage ---------- */
.stage {
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 2.6vh, 28px);
  text-align: center;
  overflow: hidden;
}

.agent { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.orb {
  width: clamp(44px, 7vh, 64px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  display: flex; align-items: center; justify-content: center; gap: 4px;
  position: relative;
}
.orb::before {
  content: "";
  position: absolute; inset: -8px;
  border-radius: 50%;
  border: 1px solid var(--line);
  animation: pulse 3s ease-out infinite;
}
@keyframes pulse {
  0% { transform: scale(0.9); opacity: 1; }
  100% { transform: scale(1.5); opacity: 0; }
}
.orb span {
  width: 3px; height: 8px;
  background: var(--white);
  border-radius: 2px;
  transition: height 0.2s;
}
.orb.talking span { animation: wave 0.6s ease-in-out infinite; }
.orb.talking span:nth-child(2) { animation-delay: 0.15s; }
.orb.talking span:nth-child(3) { animation-delay: 0.3s; }
@keyframes wave { 50% { height: 22px; } }


.speech {
  max-width: 880px;
  font-size: clamp(22px, 3.6vh, 40px);
  font-weight: 300;
  line-height: 1.22;
  letter-spacing: -0.015em;
  min-height: 1.3em;
}
.speech p + p { margin-top: 0.45em; }
.speech p.small { font-size: 0.55em; color: var(--muted); line-height: 1.5; letter-spacing: 0; }
.speech strong { font-weight: 600; color: var(--white); }
.speech .cursor {
  display: inline-block;
  width: 0.5em; height: 1em;
  margin-left: 2px;
  vertical-align: -0.12em;
  background: var(--white);
  animation: blink 0.9s steps(1) infinite;
}

/* ---------- Cards ---------- */
.card-slot {
  width: 100%;
  max-width: 980px;
  display: flex;
  justify-content: center;
}
.reveal { animation: rise 0.5s cubic-bezier(.2,.8,.2,1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); filter: blur(4px); } }

.grid {
  display: grid;
  gap: 1px;
  width: 100%;
  background: var(--line);
  border: 1px solid var(--line);
}
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-5 { grid-template-columns: repeat(5, 1fr); }

.cell {
  background: rgba(8, 8, 8, 0.85);
  backdrop-filter: blur(6px);
  padding: clamp(12px, 2vh, 20px);
  text-align: left;
  display: flex; flex-direction: column; gap: 6px;
}
.cell .k { font-family: var(--mono); font-size: 10px; letter-spacing: 0.18em; color: var(--faint); }
.cell .t { font-size: clamp(14px, 2vh, 17px); font-weight: 500; }
.cell .d { font-size: clamp(12px, 1.6vh, 13px); color: var(--muted); line-height: 1.45; }
.cell .big { font-size: clamp(22px, 3.4vh, 32px); font-weight: 300; letter-spacing: -0.02em; }
.cell.hl { background: var(--white); color: var(--bg); }
.cell.hl .k, .cell.hl .d { color: rgba(0, 0, 0, 0.55); }
.cell.clickable { cursor: pointer; transition: background 0.2s; }
.cell.clickable:hover { background: rgba(28, 28, 28, 0.95); }
.cell.hl.clickable:hover { background: #e6e6e6; }

/* Calculator */
.calc { width: 100%; max-width: 760px; }
.calc .cell { gap: 10px; }
.calc label { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.calc label output { color: var(--white); }
.calc input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 1px; background: var(--line-strong); outline: none;
}
.calc input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%; background: var(--white); cursor: pointer;
  box-shadow: 0 0 0 4px rgba(255,255,255,0.12);
}
.calc input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--white); cursor: pointer;
}
.calc .note { font-family: var(--mono); font-size: 10px; color: var(--faint); text-align: left; padding: 8px 0 0; }

/* Lead form */
.lead { width: 100%; max-width: 620px; }
.lead .row { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); }
.lead input, .lead select {
  width: 100%;
  background: rgba(8, 8, 8, 0.9);
  border: 0;
  color: var(--text);
  font: 14px var(--sans);
  padding: 14px 16px;
  outline: none;
}
.lead select { appearance: none; color: var(--muted); }
.lead input:focus, .lead select:focus { background: rgba(24, 24, 24, 0.95); }
.lead input::placeholder { color: var(--faint); }
.lead button {
  width: 100%;
  background: var(--white); color: var(--bg);
  border: 0; padding: 14px;
  font: 500 12px var(--mono); letter-spacing: 0.15em;
  cursor: pointer;
}
.lead button:hover { background: #e6e6e6; }
.lead .wrap { border: 1px solid var(--line); display: grid; gap: 1px; background: var(--line); }

/* ---------- Dock ---------- */
.dock {
  padding: 14px 0 max(18px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}

.chips {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  min-height: 36px;
  max-width: 980px;
}
.chip {
  font: 13px var(--sans);
  color: var(--text);
  background: rgba(10, 10, 10, 0.7);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  animation: rise 0.4s cubic-bezier(.2,.8,.2,1) both;
}
.chip:hover, .chip:focus-visible { background: var(--white); color: var(--bg); border-color: var(--white); outline: none; }
.chip.primary { background: var(--white); color: var(--bg); border-color: var(--white); }
.chip.primary:hover { background: #e6e6e6; }

.prompt {
  width: 100%; max-width: 680px;
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line-strong);
  background: rgba(8, 8, 8, 0.8);
  padding: 4px 6px 4px 16px;
}
.prompt:focus-within { border-color: var(--white); }
.caret { color: var(--white); font-size: 14px; }
.prompt input {
  flex: 1; min-width: 0;
  background: none; border: 0; outline: none;
  color: var(--text);
  font: 15px var(--sans);
  padding: 10px 0;
}
.prompt input::placeholder { color: var(--faint); }
.send {
  background: none; border: 0; color: var(--muted);
  font-size: 11px; letter-spacing: 0.1em; padding: 8px 10px; cursor: pointer;
}
.send:hover { color: var(--white); }

/* ---------- Voz ---------- */
.mic {
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: none;
  color: var(--text);
  display: grid; place-items: center;
  cursor: pointer;
  position: relative;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.mic:hover { border-color: var(--white); }
.mic.on { background: var(--white); color: var(--bg); border-color: var(--white); }
.mic.on::after {
  content: "";
  position: absolute; inset: -5px;
  border-radius: 50%;
  border: 1px solid var(--white);
  animation: pulse 1.4s ease-out infinite;
}
.mic.paused { background: rgba(255, 255, 255, 0.18); color: var(--white); }

.sound { display: grid; place-items: center; }
.sound .mute { display: none; }
.sound[aria-pressed="false"] .wave { display: none; }
.sound[aria-pressed="false"] .mute { display: inline; }
.sound[aria-pressed="true"] { background: var(--white); color: var(--bg); }

.voice-note { font-size: 10px; color: var(--faint); text-align: center; margin-top: -4px; }

/* La IA escucha: el círculo se llena y respira */
.orb.listening { border-color: var(--white); }
.orb.listening::before { border-color: var(--white); animation-duration: 1.4s; }
.orb.listening span { animation: listen 1.2s ease-in-out infinite; height: 4px; }
.orb.listening span:nth-child(2) { animation-delay: 0.2s; }
.orb.listening span:nth-child(3) { animation-delay: 0.4s; }
@keyframes listen { 50% { height: 12px; opacity: 0.5; } }

.dot.listening { animation-duration: 0.6s; }

/* ---------- Llamada ---------- */
.call {
  width: min(420px, 100%);
  display: flex; align-items: center; gap: 14px;
  padding: 12px 12px 12px 14px;
  background: rgba(14, 14, 14, 0.92);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  animation: rise 0.5s cubic-bezier(.2,.8,.2,1) both;
}
.call[hidden] { display: none; }

/* Sonando: toda la tarjeta vibra (5 s, controlado desde app.js) */
.call.ringing { animation: rise 0.5s cubic-bezier(.2,.8,.2,1) both, buzz 1.2s ease-in-out 0.5s infinite; }
@keyframes buzz {
  0%, 45%, 100% { transform: translateX(0); }
  5%, 15%, 25%, 35% { transform: translateX(-3px); }
  10%, 20%, 30%, 40% { transform: translateX(3px); }
}

/* En espera: quieta, con el punto parpadeando */
.call.waiting .call-k::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px; margin-right: 6px;
  border-radius: 50%;
  background: var(--white);
  vertical-align: 1px;
  animation: blink 1.6s ease-in-out infinite;
}

.call-avatar {
  flex-shrink: 0;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--white);
  color: var(--bg);
  display: grid; place-items: center;
  position: relative;
}
.call.ringing .call-avatar { animation: ring 1.6s ease-in-out infinite; }
.call.ringing .call-avatar::before,
.call.ringing .call-avatar::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 1px solid var(--white);
  animation: pulse 1.6s ease-out infinite;
}
.call.ringing .call-avatar::after { animation-delay: 0.5s; }
@keyframes ring {
  0%, 50%, 100% { transform: rotate(0); }
  5%, 15%, 25% { transform: rotate(-9deg); }
  10%, 20%, 30% { transform: rotate(9deg); }
}

.call-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; text-align: left; }
.call-k { font-size: 10px; letter-spacing: 0.18em; color: var(--muted); }
.call-t { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.call-actions { display: flex; gap: 8px; flex-shrink: 0; }
.call-btn {
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: none;
  color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer;
  font: 500 13px var(--sans);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.call-btn.decline { width: 44px; }
.call-btn.decline:hover { background: rgba(255, 255, 255, 0.12); border-color: var(--white); }
.call-btn.accept { padding: 0 18px; background: var(--green); color: var(--bg); border-color: var(--green); font-weight: 600; }
.call-btn.accept:hover { background: var(--green-hover); border-color: var(--green-hover); }

/* En llamada: solo queda colgar */
.call.active .accept { display: none; }
.call.active .call-k { color: var(--white); }
.call.active .call-k::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px; margin-right: 6px;
  border-radius: 50%;
  background: var(--white);
  vertical-align: 1px;
  animation: blink 1.2s ease-in-out infinite;
}

@media (max-width: 560px) {
  .call { gap: 10px; }
  .call-avatar { width: 38px; height: 38px; }
  .call-btn { height: 38px; }
  .call-btn.decline { width: 38px; }
  .call-btn.accept { padding: 0 14px; }
}

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .grid.cols-4, .grid.cols-5 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-5 .cell:last-child { grid-column: span 2; }
  .trail { display: none; }
}
@media (max-width: 560px) {
  .grid.cols-3 { grid-template-columns: 1fr; }
  .grid .cell .d { display: none; }
  .lead .row { grid-template-columns: 1fr; }
  .calc .grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
  .calc .grid .cell:nth-child(-n+3) { grid-column: span 3; padding: 10px 14px; }
  .calc .grid .cell:nth-child(n+4) { padding: 10px; }
  .calc .cell .k { font-size: 8px; letter-spacing: 0.08em; }
  .calc .cell .big { font-size: 18px; }
  .calc .note { display: none; }
  .chip { padding: 8px 12px; font-size: 12px; }
}
@media (max-height: 720px) {
  .bar { height: 52px; }
  .cell .d { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
