:root {
  --bg: #070b10;
  --bg-elev: #101820;
  --line: rgba(212, 160, 23, 0.28);
  --gold: #d4a017;
  --cyan: #4fd2ff;
  --text: #e8eef4;
  --muted: #8b9aab;
  --user: #18222d;
  --jarvis: #0d151c;
  --danger: #ff6b6b;
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: radial-gradient(1200px 600px at 80% -10%, rgba(79, 210, 255, 0.08), transparent 50%),
    radial-gradient(900px 500px at 0% 100%, rgba(212, 160, 23, 0.07), transparent 45%),
    var(--bg);
  color: var(--text);
  font-family: Heebo, "Segoe UI", Tahoma, sans-serif;
}

body {
  min-height: 100dvh;
}

.hidden,
[hidden] {
  display: none !important;
}

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  grid-template-columns: minmax(0, 1fr); /* בלי זה עמודה אחת רחבה דוחפת את כל הדף מחוץ למסך בטלפון */
  max-width: 720px;
  margin: 0 auto;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 16px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 11, 16, 0.88);
  backdrop-filter: blur(12px);
}

.identity {
  display: flex;
  gap: 12px;
  align-items: center;
}

.identity h1,
.gate h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.status {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.orb {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #fff 0 8%, var(--cyan) 18%, #0a3a4a 62%, #070b10 100%);
  box-shadow: 0 0 0 2px rgba(212, 160, 23, 0.55), 0 0 24px rgba(79, 210, 255, 0.35);
  animation: pulse 3.2s ease-in-out infinite;
}

.orb.small {
  width: 38px;
  height: 38px;
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 2px rgba(212, 160, 23, 0.55), 0 0 18px rgba(79, 210, 255, 0.28);
  }
  50% {
    box-shadow: 0 0 0 3px rgba(212, 160, 23, 0.8), 0 0 28px rgba(79, 210, 255, 0.55);
  }
}

button,
textarea,
input {
  font-family: inherit;
}

.ghost {
  background: transparent;
  color: var(--gold);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}

.thread {
  overflow-y: auto;
  padding: 20px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.welcome {
  margin: auto;
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px 12px;
}

.welcome .orb {
  width: 72px;
  height: 72px;
}

.msg {
  max-width: min(88%, 520px);
  padding: 12px 14px;
  border-radius: var(--radius);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user {
  align-self: start;
  background: var(--user);
  border: 1px solid rgba(212, 160, 23, 0.18);
}

.msg.jarvis {
  align-self: end;
  background: var(--jarvis);
  border: 1px solid rgba(79, 210, 255, 0.22);
}

.msg.system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(7, 11, 16, 0.95);
}

.compose-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.composer textarea {
  flex: 1;
  resize: none;
  min-height: 46px;
  max-height: 140px;
  overflow-y: auto;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  outline: none;
}

.composer #send,
.mic-btn {
  flex: 0 0 auto;
  min-height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 14px;
  font-weight: 700;
  cursor: pointer;
}

.composer #send {
  background: var(--gold);
  color: #1a1404;
}

.mic-btn.on {
  background: #14313a;
  color: var(--cyan);
  box-shadow: 0 0 0 1px rgba(79, 210, 255, 0.35);
}

.mic-btn.off {
  background: var(--bg-elev);
  color: var(--muted);
  box-shadow: 0 0 0 1px var(--line);
}

.listen-hint {
  margin: 0;
  text-align: center;
  color: var(--cyan);
  font-size: 0.95rem;
  font-weight: 600;
  min-height: 1.3em;
}

.listen-hint.live {
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(79, 210, 255, 0.45);
}

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

.gate {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: grid;
  place-items: center;
  z-index: 20;
}

.gate.hidden {
  display: none !important;
}

.gate-card {
  width: min(360px, 92vw);
  text-align: center;
  padding: 32px 22px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--bg-elev);
}

.gate-card p {
  color: var(--muted);
}

.gate-card form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.gate-card input,
.gate-card button {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.gate-card input {
  background: #0a1016;
  color: var(--text);
  text-align: center;
  letter-spacing: 0.3em;
}

.gate-card button {
  background: var(--cyan);
  color: #041016;
  font-weight: 700;
  cursor: pointer;
  border: 0;
}

.error {
  color: var(--danger);
}

.memory {
  position: absolute;
  top: calc(72px + var(--safe-top));
  left: 12px;
  right: 12px;
  z-index: 15;
  padding: 14px 16px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #121a22;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
}

.memory-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.memory h2 {
  margin: 0;
  font-size: 1rem;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
}

.memory ul {
  margin: 0;
  padding: 0 18px 8px 0;
}

.memory li {
  margin: 6px 0;
}

.typing::after {
  content: "▍";
  animation: blink 1s step-end infinite;
  color: var(--cyan);
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.top-actions {
  display: flex;
  gap: 8px;
}

.badge {
  display: inline-block;
  min-width: 1.4em;
  padding: 0 6px;
  margin-inline-start: 4px;
  border-radius: 999px;
  background: var(--gold);
  color: #041016;
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
}

.changes {
  max-height: calc(100dvh - 140px);
  overflow-y: auto;
}

.proposal {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 10px 0;
  background: var(--bg-elev);
}

.proposal-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.proposal-reason {
  margin: 6px 0;
}

.proposal-file {
  direction: ltr;
  text-align: left;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.8rem;
  color: var(--cyan);
}

.proposal-warn {
  margin: 6px 0;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(255, 107, 107, 0.12);
  color: var(--danger);
  font-size: 0.85rem;
}

.proposal pre {
  direction: ltr;
  text-align: left;
  max-height: 320px;
  overflow: auto;
  margin: 6px 0 0;
  padding: 8px;
  border-radius: 8px;
  background: var(--bg);
  font-size: 0.75rem;
  line-height: 1.4;
  white-space: pre;
}

.proposal pre .add {
  color: #7ee787;
}

.proposal pre .del {
  color: var(--danger);
}

.proposal-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.proposal-actions .ok {
  background: var(--gold);
  color: #041016;
  border: 0;
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 700;
  cursor: pointer;
}

.proposal-msg {
  font-size: 0.85rem;
  color: var(--muted);
}

/* --- הפנים של ג'ארביס --- */
.avatar-stage {
  display: flex;
  justify-content: center;
  padding: 10px 0 4px;
  border-bottom: 1px solid var(--line);
}

.avatar {
  width: 168px;
  height: 184px;
  overflow: visible;
  filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.45));
}

.av-halo {
  fill: none;
  stroke: var(--cyan);
  stroke-width: 2;
  opacity: 0.12;
  transition: opacity 0.4s ease, stroke 0.4s ease;
}

.avatar-stage[data-state="listening"] .av-halo {
  opacity: 0.55;
  animation: halo 1.8s ease-in-out infinite;
}

.avatar-stage[data-state="speaking"] .av-halo {
  stroke: var(--gold);
  opacity: 0.45;
}

.av-think {
  fill: var(--cyan);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.avatar-stage[data-state="thinking"] .av-think {
  opacity: 0.75;
  animation: think 1.2s ease-in-out infinite;
}

@keyframes halo {
  50% {
    opacity: 0.2;
  }
}

@keyframes think {
  50% {
    opacity: 0.3;
  }
}

@media (max-height: 700px), (max-width: 480px) {
  .avatar {
    width: 112px;
    height: 124px;
  }
}

.welcome .orb {
  display: none;
}

/* --- פנים אנושיות חיות (Simli) --- */
.real-face {
  display: none;
}

.avatar-stage[data-real="1"] .avatar {
  display: none;
}

.avatar-stage[data-real="1"] .real-face {
  display: block;
  position: relative;
}

.real-face video {
  display: block;
  width: 220px;
  height: 220px;
  object-fit: cover;
  border-radius: 50%;
  background: #0d151c;
  box-shadow: 0 0 0 2px rgba(79, 210, 255, 0.15), 0 10px 28px rgba(0, 0, 0, 0.5);
  transition: box-shadow 0.4s ease;
}

.avatar-stage[data-state="listening"] .real-face video {
  box-shadow: 0 0 0 3px rgba(79, 210, 255, 0.6), 0 0 26px rgba(79, 210, 255, 0.35);
}

.avatar-stage[data-state="speaking"] .real-face video {
  box-shadow: 0 0 0 3px rgba(212, 160, 23, 0.55), 0 10px 28px rgba(0, 0, 0, 0.5);
}

.avatar-stage[data-state="thinking"] .real-face::after {
  content: "…";
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--cyan);
  font-size: 1.6rem;
  animation: think 1.2s ease-in-out infinite;
}

@media (max-height: 700px), (max-width: 480px) {
  .real-face video {
    width: 150px;
    height: 150px;
  }
}

/* קולות — זיהוי דובר */
.speaker-tag {
  display: inline-block;
  margin-inline-end: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(212, 160, 23, 0.18);
  color: #d4a017;
  font-size: 0.78em;
  vertical-align: middle;
}
.voices .voice-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}
.voices .enroll {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.voices .enroll input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
  color: inherit;
  font: inherit;
}
.voices .enroll-text {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(212, 160, 23, 0.1);
  line-height: 1.7;
  font-size: 1.05em;
}
button.small {
  padding: 2px 10px;
  font-size: 0.85em;
}
.voices .enroll button {
  padding: 8px 14px;
  border-radius: 10px;
  border: 0;
  background: #d4a017;
  color: #0d151c;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.voices .enroll button:disabled {
  opacity: 0.5;
  cursor: default;
}

/* מצלמה — זיהוי פנים */
.cam-preview {
  position: fixed;
  inset-inline-start: 12px;
  bottom: 96px;
  width: 132px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(212, 160, 23, 0.4);
  background: #0d151c;
  z-index: 30;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}
.cam-preview[hidden] {
  display: none;
}
.cam-preview video {
  display: block;
  width: 100%;
  transform: scaleX(-1);
}
.cam-label {
  display: block;
  padding: 3px 6px;
  font-size: 0.78em;
  text-align: center;
  color: #d4a017;
}
#cam-btn.on {
  border-color: #d4a017;
  color: #d4a017;
}
.voices .sub-head {
  margin: 18px 0 4px;
  font-size: 1em;
}

#enroll-text.kid { white-space: pre-line; font-size: 1.05rem; line-height: 1.6; }

/* --- שיחת וידאו עם הילדים --- */
.call-bar { display: none; }
body.kid-call .app { grid-template-rows: 1fr auto auto; max-width: none; }
body.kid-call .composer { grid-row: 3; border-top: 0; background: transparent; }
body.kid-call .topbar { display: none; }
body.kid-call .avatar-stage {
  grid-row: 1;
  position: relative;
  margin: calc(10px + var(--safe-top)) 10px 0;
  border: 0;
  border-radius: 26px;
  overflow: hidden;
  align-items: flex-end;
  padding: 0;
  min-height: 0;
  background:
    radial-gradient(60% 45% at 50% 38%, rgba(255, 255, 255, 0.55), transparent 70%),
    radial-gradient(circle at 15% 20%, #fff7 2px, transparent 3px) 0 0 / 70px 70px,
    linear-gradient(180deg, #bfe6ff 0%, #d9f0ff 55%, #ffe3c2 56%, #ffd3a8 100%);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
}
body.kid-call .avatar-stage .avatar {
  height: 100%;
  width: auto;
  max-width: 100%;
  align-self: flex-end;
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.25));
}
body.kid-call .av-halo, body.kid-call .av-think { display: none; }
body.kid-call .call-bar {
  display: flex;
  position: fixed;
  top: calc(20px + var(--safe-top));
  inset-inline: 22px;
  align-items: center;
  gap: 10px;
  z-index: 40;
  color: #fff;
  font-weight: 600;
  font-size: 1.15rem;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}
.call-live { width: 12px; height: 12px; border-radius: 50%; background: #3ddc84; box-shadow: 0 0 0 4px rgba(61, 220, 132, 0.3); animation: halo 1.6s ease-in-out infinite; }
.call-time { font-weight: 400; opacity: 0.85; font-size: 0.95rem; }
.call-end {
  margin-inline-start: auto;
  pointer-events: auto;
  background: rgba(0, 0, 0, 0.35);
  border: 0;
  border-radius: 999px;
  width: 44px;
  height: 44px;
  font-size: 1.3rem;
  cursor: pointer;
}
/* רק הכתובית האחרונה, קטנה, בתחתית (בשביל ההורים / יונתן שקורא קצת) */
body.kid-call .thread {
  grid-row: 2;
  max-height: 22vh;
  padding: 8px 14px;
}
body.kid-call .thread .msg:not(:last-child), body.kid-call .welcome { display: none; }
body.kid-call .thread .msg { margin-inline: auto; align-self: center; text-align: center; font-size: 1.05rem; }
body.kid-call .composer textarea, body.kid-call .composer #send { display: none; }
body.kid-call .compose-row { justify-content: center; }
body.kid-call .mic-btn { min-width: 160px; min-height: 56px; font-size: 1.1rem; border-radius: 999px; }
/* «אני» בפינה — כמו בשיחת וידאו */
body.kid-call .cam-preview {
  top: calc(74px + var(--safe-top));
  bottom: auto;
  inset-inline-start: auto;
  inset-inline-end: 22px;
  width: min(30vw, 170px);
  border-radius: 18px;
  border: 3px solid #fff;
}
body.kid-call .cam-label { display: none; }

/* פנים אמיתיות (Simli) בשיחת וידאו — ממלאות את כל החלון */
body.kid-call .avatar-stage[data-real="1"] .real-face { position: absolute; inset: 0; }
body.kid-call .real-face video { width: 100%; height: 100%; border-radius: 0; object-fit: cover; box-shadow: none; }

/* דמויות תלת-ממד (TalkingHead) */
.avatar3d { display: none; }
.avatar-stage[data-three="1"] .avatar3d { display: block; width: 220px; height: 240px; }
.avatar-stage[data-three="1"] svg.avatar, .avatar-stage[data-three="1"] .real-face { display: none !important; }
body.kid-call .avatar-stage[data-three="1"] .avatar3d { position: absolute; inset: 0; width: 100%; height: 100%; }

/* שיחה חיה — וידאו של הדמות מהשרת (Simli דרך Pipecat) */
.live-face { display: none; }
.avatar-stage[data-live="1"] .live-face { display: block; }
.avatar-stage[data-live="1"] svg.avatar, .avatar-stage[data-live="1"] .real-face, .avatar-stage[data-live="1"] .avatar3d { display: none !important; }
.live-face video { display: block; width: 220px; height: 220px; object-fit: cover; border-radius: 50%; background: #0d151c; }
body.kid-call .avatar-stage[data-live="1"] .live-face { position: absolute; inset: 0; }
body.kid-call .live-face video { width: 100%; height: 100%; border-radius: 0; }
#live-btn.on { border-color: #3ddc84; color: #3ddc84; }

/* תהליך החשיבה — מה ג'ארביס עושה בפועל, מעל התשובה */
.steps {
  align-self: end;
  max-width: min(88%, 520px);
  margin-bottom: -4px;
  padding: 6px 12px;
  border-inline-start: 2px solid rgba(79, 210, 255, 0.35);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}
.steps summary {
  cursor: pointer;
  list-style: none;
  color: var(--cyan);
  opacity: 0.8;
  user-select: none;
}
.steps summary::-webkit-details-marker { display: none; }
.steps summary::before { content: "◂ "; }
.steps[open] summary::before { content: "▾ "; }
.steps ol { margin: 4px 0 0; padding: 0; list-style: none; }
.steps li { padding: 1px 0; word-break: break-word; }
.steps li.sub { padding-inline-start: 14px; opacity: 0.85; }
.steps li.bad { color: var(--danger); }

/* 📎 צירוף קבצים */
.attach-btn {
  flex: 0 0 auto;
  min-height: 46px;
  min-width: 46px;
  padding: 0 10px;
  border: 0;
  border-radius: 14px;
  background: var(--bg-elev);
  box-shadow: 0 0 0 1px var(--line);
  font-size: 1.2rem;
  cursor: pointer;
}
.attach-btn:disabled { opacity: 0.5; cursor: wait; }
.attach-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 6px; }
.attach-chips[hidden] { display: none; }
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 4px 6px 4px 10px;
  border-radius: 999px;
  background: #14313a;
  color: var(--cyan);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attach-chip button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0 4px;
}
.attach-tag { margin-top: 6px; font-size: 0.8rem; color: var(--muted); }
body.kid-call .attach-btn { display: none; }

/* טלפון: הכפתורים למעלה גוללים לצדדים במקום לדחוף את כל הדף מחוץ למסך */
@media (max-width: 560px) {
  .topbar { min-width: 0; gap: 8px; }
  .top-actions {
    min-width: 0;
    flex: 1 1 auto;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .top-actions::-webkit-scrollbar { display: none; }
  .top-actions .ghost { flex: 0 0 auto; white-space: nowrap; }
  .identity { flex: 0 0 auto; }
}

/* 🎙️ הקלטת פגישה */
.rec-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  padding-top: calc(8px + var(--safe-top)) !important;
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 16px;
  background: rgba(40, 12, 14, 0.94);
  border-bottom: 1px solid rgba(255, 107, 107, 0.5);
  color: var(--text);
  font-size: 0.9rem;
}
.rec-bar[hidden] { display: none; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: rec-pulse 1.2s infinite; }
@keyframes rec-pulse { 50% { opacity: 0.3; } }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 700; }
.rec-note { color: var(--muted); font-size: 0.8rem; flex: 1 1 auto; }
.rec-stop { border: 0; border-radius: 12px; padding: 8px 14px; background: var(--danger); color: #fff; font-weight: 700; cursor: pointer; }
.rec-cancel { padding: 6px 10px; }
body.recording #rec-btn { color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }
