/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:      #000000;
  --bg2:     #0c0c0e;
  --card:    rgba(28,28,30,0.92);
  --card2:   rgba(44,44,46,0.8);
  --border:  rgba(255,255,255,0.08);
  --t1:      #ffffff;
  --t2:      rgba(255,255,255,0.55);
  --t3:      rgba(255,255,255,0.25);
  --green:   #30d158;
  --red:     #ff453a;
  --blue:    #0a84ff;
  --font:    -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', sans-serif;
  --ease:    cubic-bezier(.25,.46,.45,.94);
}
body.light {
  --bg:      #f2f2f7;
  --bg2:     #ffffff;
  --card:    rgba(255,255,255,0.85);
  --card2:   rgba(242,242,247,0.9);
  --border:  rgba(0,0,0,0.07);
  --t1:      #000000;
  --t2:      rgba(0,0,0,0.5);
  --t3:      rgba(0,0,0,0.22);
}

html, body {
  height: 100%; width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--t1);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ── Screens ── */
.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center;
  padding: max(env(safe-area-inset-top), 54px) 0 max(env(safe-area-inset-bottom), 32px);
  opacity: 0; pointer-events: none;
  transform: translateY(10px) scale(.985);
  transition: opacity .3s var(--ease), transform .3s var(--ease);
  z-index: 10;
  background: var(--bg);
}
.screen.active {
  opacity: 1; pointer-events: all;
  transform: none;
}

/* ── Top bar (home) ── */
.top-bar {
  width: 100%; max-width: 420px;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 24px 0;
}
.wordmark {
  font-size: 12px; font-weight: 700;
  letter-spacing: 4px; color: var(--t3);
}
.ghost-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 13px; font-weight: 500;
  color: var(--t2); cursor: pointer;
  font-family: var(--font);
  transition: opacity .15s;
}
.ghost-btn:active { opacity: .6; }

/* ── Avatar stage ── */
.avatar-stage {
  position: relative;
  width: var(--sz); height: var(--sz);
  display: flex; align-items: center; justify-content: center;
}
.avatar-stage canvas {
  position: absolute; inset: 0;
  width: 100% !important; height: 100% !important;
}
.avatar-core {
  position: relative; z-index: 2;
  width: 88px; height: 88px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 38px;
  background: var(--card2);
  box-shadow: 0 0 0 1.5px var(--border), 0 16px 40px rgba(0,0,0,.5);
  transition: transform .3s var(--ease);
}
.avatar-core.large { width: 100px; height: 100px; font-size: 44px; }
.avatar-core.small { width: 60px;  height: 60px;  font-size: 26px; }
body.light .avatar-core { box-shadow: 0 0 0 1.5px var(--border), 0 8px 24px rgba(0,0,0,.08); }

/* ── Stage wrapper ── */
.stage-center {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 6px;
}
.av-name {
  font-size: 28px; font-weight: 700;
  letter-spacing: -.5px;
  color: var(--t1);
  margin-top: 8px;
}
.av-sub {
  font-size: 14px; color: var(--t2);
  font-weight: 400;
}

/* ── Home footer ── */
.home-foot {
  display: flex; flex-direction: column;
  align-items: center; gap: 12px;
}
.fab-hint {
  font-size: 13px; color: var(--t2);
  font-weight: 500; letter-spacing: .2px;
}

/* ── Big FAB ── */
.big-fab {
  width: 72px; height: 72px; border-radius: 50%;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s var(--ease), opacity .15s;
  box-shadow: 0 0 0 0 transparent;
}
.big-fab:active { transform: scale(.91); opacity: .85; }
.big-fab.green {
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(48,209,88,.35), 0 4px 20px rgba(48,209,88,.3);
  animation: pulse 2.8s ease-in-out infinite;
}
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(48,209,88,.35), 0 4px 20px rgba(48,209,88,.3); }
  50%      { box-shadow: 0 0 0 14px rgba(48,209,88,.0), 0 4px 20px rgba(48,209,88,.3); }
}

/* ── Incoming ── */
.incoming-label {
  font-size: 14px; font-weight: 600;
  color: var(--t2); letter-spacing: .3px;
  padding-top: 8px;
}
.incoming-stage { margin-top: -12px; }
.answer-row {
  display: flex; justify-content: space-evenly; align-items: flex-start;
  width: 100%; max-width: 280px;
  padding-bottom: 8px;
}
.answer-col {
  display: flex; flex-direction: column;
  align-items: center; gap: 10px;
}
.round-btn {
  width: 72px; height: 72px; border-radius: 50%;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s, opacity .15s;
}
.round-btn:active { transform: scale(.88); opacity: .8; }
.round-btn.green { background: var(--green); box-shadow: 0 4px 18px rgba(48,209,88,.35); }
.round-btn.red   { background: var(--red);   box-shadow: 0 4px 18px rgba(255,69,58,.3); }
.btn-label {
  font-size: 13px; color: var(--t2);
  font-weight: 500;
}

/* ── In-Call ── */
.call-topbar {
  width: 100%; max-width: 420px;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 24px;
}
.status-pill {
  display: flex; align-items: center; gap: 7px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--t3);
  transition: background .3s, box-shadow .3s;
  flex-shrink: 0;
}
.dot.active   { background: var(--green); box-shadow: 0 0 0 3px rgba(48,209,88,.2); }
.dot.thinking { background: var(--blue);  box-shadow: 0 0 0 3px rgba(10,132,255,.2); animation: blink .9s ease-in-out infinite; }
.dot.speaking { background: var(--green); box-shadow: 0 0 0 3px rgba(48,209,88,.25); animation: blink .5s ease-in-out infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }
.status-txt {
  font-size: 12px; font-weight: 600;
  color: var(--t2); letter-spacing: .3px;
  min-width: 76px;
}
.timer {
  font-size: 15px; font-weight: 500;
  color: var(--t2); font-variant-numeric: tabular-nums;
  letter-spacing: .5px;
}

.call-avatar-wrap {
  display: flex; flex-direction: column;
  align-items: center; gap: 2px;
  padding-top: 8px;
}
.call-name { font-size: 22px; font-weight: 700; }

/* ── Chat feed ── */
.chat-feed {
  flex: 1; width: 100%; max-width: 400px;
  overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px 20px 4px;
  scrollbar-width: none;
  mask-image: linear-gradient(to bottom, transparent, black 20%);
  -webkit-mask-image: linear-gradient(to bottom, transparent, black 20%);
}
.chat-feed::-webkit-scrollbar { display: none; }

.bubble {
  max-width: 76%; padding: 9px 14px;
  border-radius: 18px; font-size: 14px;
  line-height: 1.4; font-weight: 400;
  animation: pop .18s var(--ease) both;
  word-break: break-word;
}
@keyframes pop {
  from { opacity:0; transform: scale(.88) translateY(6px); }
  to   { opacity:1; transform: none; }
}
.bubble.user {
  align-self: flex-end;
  background: var(--blue);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.bubble.ai {
  align-self: flex-start;
  background: var(--card);
  color: var(--t1);
  border-bottom-left-radius: 5px;
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

/* ── Controls bar ── */
.controls-bar {
  width: calc(100% - 48px); max-width: 380px;
  background: var(--card);
  backdrop-filter: blur(32px) saturate(1.8);
  -webkit-backdrop-filter: blur(32px) saturate(1.8);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 14px 20px;
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 4px;
}
.ctrl {
  display: flex; flex-direction: column;
  align-items: center; gap: 5px;
  background: none; border: none;
  color: var(--t1); cursor: pointer;
  font-family: var(--font);
  padding: 8px 16px;
  border-radius: 16px;
  transition: background .15s, opacity .15s;
}
.ctrl:active { background: var(--card2); opacity: .7; }
.ctrl.active .ctrl-icon { background: rgba(255,255,255,.18); }
.ctrl-icon {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--card2);
  display: flex; align-items: center; justify-content: center;
  color: var(--t1); border: 1px solid var(--border);
  transition: background .2s;
}
.ctrl-lbl {
  font-size: 11px; font-weight: 500;
  color: var(--t2); letter-spacing: .2px;
}
.end-btn .ctrl-icon.end-icon {
  background: var(--red);
  border-color: transparent;
  width: 52px; height: 52px;
  box-shadow: 0 4px 16px rgba(255,69,58,.4);
}
.end-btn .ctrl-lbl.end-lbl { color: var(--red); font-weight: 600; }

/* ── Post-call ── */
.postcall-wrap {
  flex: 1; width: 100%;
  display: flex; flex-direction: column;
  align-items: center;
  padding: 0 24px;
}
.postcall-dur {
  font-size: 14px; color: var(--t2);
  margin-top: 4px; font-weight: 400;
}
.postcall-log {
  width: 100%; max-width: 380px;
  max-height: 260px;
  overflow-y: auto;
  margin-top: 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 10px;
  scrollbar-width: none;
}
.postcall-log:empty { display: none; }
.postcall-log::-webkit-scrollbar { display: none; }
.log-entry {
  font-size: 13px; line-height: 1.5;
  color: var(--t2);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.log-entry:last-child { border-bottom: none; padding-bottom: 0; }
.log-entry strong { color: var(--t1); font-weight: 600; }

/* ── Login sheet ── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex; align-items: flex-end;
  z-index: 100;
  animation: fade-in .2s ease;
}
.modal.hidden { display: none; }
@keyframes fade-in { from { opacity:0; } to { opacity:1; } }

.sheet {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  padding: 12px 24px calc(max(env(safe-area-inset-bottom), 20px) + 20px);
  display: flex; flex-direction: column; gap: 14px;
  animation: slide-up .28s var(--ease);
}
@keyframes slide-up { from { transform: translateY(100%); } to { transform: none; } }
.sheet-handle {
  width: 36px; height: 4px;
  background: var(--card2);
  border-radius: 2px;
  margin: 0 auto 6px;
}
.sheet-title {
  font-size: 20px; font-weight: 700;
  text-align: center; color: var(--t1);
}
.field-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
}
.field-row input {
  flex: 1; background: none; border: none; outline: none;
  font-size: 16px; color: var(--t1); font-family: var(--font);
}
.field-row input::placeholder { color: var(--t3); }
.primary-btn {
  background: var(--blue);
  border: none; border-radius: 14px;
  padding: 16px; font-size: 16px; font-weight: 600;
  color: #fff; cursor: pointer; font-family: var(--font);
  box-shadow: 0 4px 18px rgba(10,132,255,.35);
  transition: opacity .15s, transform .15s;
}
.primary-btn:active { opacity: .8; transform: scale(.98); }
.err { font-size: 13px; color: var(--red); text-align: center; }
.err.hidden { display: none; }
