/* Fixie: calm, high-contrast and large, for older adults.
   Lobby is light (easy to read), the call is dark (the camera is the star). */
:root {
  --teal-900: #0B3B3A;
  --teal-700: #0E7490;
  --teal-500: #14B8A6;
  --teal-50: #F3F8F7;
  --green: #15803D;        /* call button, white text 5:1 */
  --green-hi: #22C55E;     /* "listening" signal on dark */
  --amber: #F59E0B;        /* "thinking" signal + warnings */
  --red: #DC2626;          /* hang up, white text 4.8:1 */
  --ink: #102A2A;
  --ink-muted: #3F5554;
  --glass: rgba(12, 20, 22, .72);
  --glass-line: rgba(255, 255, 255, .14);
  --radius: 20px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--teal-50); color: var(--ink);
  font-family: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 18px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; flex: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid #67E8F9; outline-offset: 3px; border-radius: 12px; }

/* ---------- Lobby ---------- */
#lobby { min-height: 100%; display: grid; place-items: center;
  padding: calc(1.5rem + var(--safe-t)) 1.25rem calc(1.5rem + var(--safe-b));
  background:
    radial-gradient(60rem 30rem at 50% -10%, rgba(20, 184, 166, .18), transparent 70%),
    var(--teal-50); }
.lobby-card { width: min(30rem, 100%); display: flex; flex-direction: column; align-items: center;
  text-align: center; gap: .85rem; animation: rise .5s var(--ease) both; }
#lobby h1 { margin: 0; font-size: 2.3rem; line-height: 1.1; color: var(--teal-900); letter-spacing: -.01em; }
.lead { margin: 0; font-size: 1.15rem; line-height: 1.45; color: var(--ink-muted); max-width: 26rem; }
.how { margin: 1rem 0 0; font-size: .85rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--teal-700); }

.steps { list-style: none; margin: 0; padding: 0; width: 100%; display: grid; gap: .6rem; text-align: left; }
.steps li { display: flex; align-items: center; gap: .9rem; padding: .8rem 1rem; border-radius: 16px;
  background: #fff; border: 1px solid #DCEBE8; font-size: 1.1rem; }
.steps b { color: var(--teal-900); }
.step-ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: #E0F2EF; color: var(--teal-700); }

.lang { display: flex; align-items: center; gap: .75rem; font-size: 1.05rem; color: var(--ink-muted); }
.lang select { font: inherit; font-size: 1.1rem; color: var(--ink); min-height: 48px; padding: 0 2.5rem 0 1rem;
  border-radius: 12px; border: 1.5px solid #B9D3CF; background: #fff
  url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230E7490' stroke-width='2.5' stroke-linecap='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E")
  no-repeat right .8rem center / 18px; appearance: none; -webkit-appearance: none; cursor: pointer; }

.call-cta { width: 100%; min-height: 68px; margin-top: .25rem; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; gap: .75rem;
  background: var(--green); color: #fff; font-size: 1.4rem; font-weight: 700;
  box-shadow: 0 10px 24px -8px rgba(21, 128, 61, .6), inset 0 1px 0 rgba(255, 255, 255, .2);
  transition: transform .15s var(--ease), box-shadow .2s var(--ease), background .2s; }
.call-cta svg { width: 28px; height: 28px; }
.call-cta:hover { background: #166534; }
.call-cta:active { transform: scale(.98); box-shadow: 0 4px 12px -6px rgba(21, 128, 61, .6); }
.hint { margin: 0; font-size: 1rem; color: var(--ink-muted); }

.avatar { width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center;
  font-size: 2rem; font-weight: 700; color: #fff; position: relative;
  background: linear-gradient(135deg, #14B8A6, #0E7490 60%, #155E75);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .9), 0 8px 20px -6px rgba(14, 116, 144, .6); }
.avatar.big { width: 88px; height: 88px; font-size: 2.6rem; }
.avatar.speaking { animation: pulse 1.4s ease-out infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 3px rgba(255,255,255,.9), 0 0 0 3px rgba(20,184,166,.7); }
  100% { box-shadow: 0 0 0 3px rgba(255,255,255,.9), 0 0 0 18px rgba(20,184,166,0); }
}
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

/* ---------- Call ---------- */
#call { position: fixed; inset: 0; background: #000; color: #fff; overflow: hidden; }
#cam { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }

.topbar { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: center;
  padding: calc(.9rem + var(--safe-t)) 1rem 2.5rem;
  background: linear-gradient(rgba(0, 0, 0, .55), transparent); pointer-events: none; }
.live { display: inline-flex; align-items: center; gap: .5rem; padding: .35rem .9rem; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--glass-line); font-size: 1rem; font-variant-numeric: tabular-nums;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green-hi);
  box-shadow: 0 0 0 4px rgba(34, 197, 94, .25); }

#helperTile { position: absolute; top: calc(4rem + var(--safe-t)); right: .75rem; width: 116px; padding: .75rem .5rem .65rem;
  border-radius: var(--radius); background: var(--glass); border: 1px solid var(--glass-line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  display: flex; flex-direction: column; align-items: center; gap: .35rem;
  box-shadow: 0 12px 32px -10px rgba(0, 0, 0, .7); animation: rise .4s var(--ease) both; }
#helperTile .avatar { width: 56px; height: 56px; font-size: 1.6rem; box-shadow: 0 0 0 3px rgba(255, 255, 255, .9); }
#helperTile .name { font-weight: 700; font-size: 1.05rem; }
#helperTile .state { display: flex; align-items: center; gap: .4rem; padding: .2rem .6rem; border-radius: 999px;
  font-size: .9rem; color: #D6E4E2; background: rgba(255, 255, 255, .08); text-align: center;
  transition: background .25s, color .25s; }

/* Little sound bars: show what Fixie is doing at a glance */
.bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; }
.bars i { width: 3px; height: 4px; border-radius: 2px; background: currentColor; opacity: .7; }
[data-state="idle"] .bars { display: none; }
[data-state="listening"] #helperTile .state { background: rgba(34, 197, 94, .2); color: #BBF7D0; }
[data-state="listening"] .bars i { animation: bar .9s ease-in-out infinite; }
[data-state="listening"] .bars i:nth-child(2) { animation-delay: .15s; }
[data-state="listening"] .bars i:nth-child(3) { animation-delay: .3s; }
[data-state="thinking"] #helperTile .state { background: rgba(245, 158, 11, .22); color: #FDE68A; }
[data-state="thinking"] .bars i { height: 4px; animation: dotb 1s ease-in-out infinite; }
[data-state="thinking"] .bars i:nth-child(2) { animation-delay: .15s; }
[data-state="thinking"] .bars i:nth-child(3) { animation-delay: .3s; }
[data-state="speaking"] #helperTile .state { background: rgba(20, 184, 166, .25); color: #99F6E4; }
[data-state="speaking"] .bars i { animation: bar .6s ease-in-out infinite; }
[data-state="speaking"] .bars i:nth-child(2) { animation-delay: .1s; }
[data-state="speaking"] .bars i:nth-child(3) { animation-delay: .2s; }
@keyframes bar { 0%, 100% { height: 4px; } 50% { height: 12px; } }
@keyframes dotb { 0%, 100% { transform: translateY(0); opacity: .5; } 50% { transform: translateY(-5px); opacity: 1; } }

#camWarn { position: absolute; top: calc(4rem + var(--safe-t)); left: .75rem; right: calc(116px + 1.5rem);
  display: flex; gap: .6rem; align-items: flex-start; padding: .75rem .9rem; border-radius: 16px;
  background: #FEF3C7; color: #451A03; font-size: 1.05rem; line-height: 1.35;
  box-shadow: 0 10px 24px -10px rgba(0, 0, 0, .6); animation: rise .3s var(--ease) both; }
#camWarn svg { color: #B45309; margin-top: 1px; }

/* Bottom dock: captions + typing + buttons stacked, as small as possible so the camera stays visible */
.dock { position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; align-items: center;
  gap: .5rem; padding: 2rem .75rem 0; background: linear-gradient(transparent, rgba(0, 0, 0, .55) 35%, rgba(0, 0, 0, .8)); }

/* Captions: a short subtitle strip (Fixie also says everything out loud) */
#captions { width: min(36rem, 100%); display: flex; flex-direction: column; gap: .3rem; }
#captions div:empty { display: none; }
#youSaid, #fixieSaid { line-height: 1.35; text-shadow: 0 1px 3px rgba(0, 0, 0, .9); }
#youSaid { font-size: .95rem; font-style: italic; color: #CFE3E0; padding: 0 .25rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#youSaid::before { content: "You: "; font-style: normal; font-weight: 700; color: #9FB7B4; }
/* At most 3 lines; longer answers scroll inside the strip */
/* Bottom spacing is a transparent border, not padding, so scrolled text is cut exactly at a line */
#fixieSaid { font-size: 1.1rem; color: #fff; padding: .5rem .8rem 0; border-radius: 14px;
  background: rgba(8, 14, 16, .55); border-left: 3px solid var(--teal-500); border-bottom: .5rem solid transparent;
  max-height: calc(1.1rem * 1.35 * 3 + 1rem); overflow-y: auto; overscroll-behavior: contain;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: rise .25s var(--ease) both; }
#fixieSaid::before { content: "Fixie: "; font-weight: 700; color: #5EEAD4; }

#typeForm { width: min(30rem, 100%); margin: 0; display: flex; gap: .5rem; padding: .2rem .2rem .2rem .9rem;
  border-radius: 999px; background: var(--glass); border: 1px solid var(--glass-line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
#typeInput { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: #fff; font: inherit; font-size: 1.05rem; }
#typeInput::placeholder { color: #A9BDBA; }
#typeForm:focus-within { border-color: #67E8F9; }
.send { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--teal-700); color: #fff;
  transition: background .2s, transform .15s var(--ease); }
.send svg { width: 20px; height: 20px; }
.send:active { transform: scale(.94); }

.controls { display: flex; justify-content: center; gap: 1.75rem; padding: .15rem 0 calc(.75rem + var(--safe-b)); }
.ctl { display: flex; flex-direction: column; align-items: center; gap: .25rem; color: #fff; }
.ctl .ic { width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(255, 255, 255, .2); border: 1px solid rgba(255, 255, 255, .22);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: background .2s, color .2s, transform .15s var(--ease); }
.ctl .ic svg { width: 28px; height: 28px; }
.ctl .lbl { font-size: .95rem; font-weight: 700; text-shadow: 0 1px 2px rgba(0, 0, 0, .8); }
.ctl:hover .ic { background: rgba(255, 255, 255, .3); }
.ctl:active .ic { transform: scale(.92); }
.ctl.red .ic { background: var(--red); border-color: transparent; box-shadow: 0 8px 20px -6px rgba(220, 38, 38, .7); }
.ctl.red:hover .ic { background: #B91C1C; }
.hang { transform: rotate(135deg); }

/* Mute toggle: app.js adds .off to #micBtn when muted */
.ctl .when-off { display: none; }
.ctl.off .when-on { display: none; }
.ctl.off .when-off { display: block; }
.ctl.off .ic { background: #fff; color: #111; }

/* Pointer: a glowing ring on the spot Fixie is talking about (yellow + dark edge shows on any background) */
#pointer { position: absolute; width: 0; height: 0; pointer-events: none; z-index: 1; }
#pointer::before, #pointer::after { content: ""; position: absolute; left: 0; top: 0; border-radius: 50%; box-sizing: border-box; }
#pointer::before { width: 76px; height: 76px; margin: -38px 0 0 -38px; border: 4px solid #FDE047;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, .5), inset 0 0 0 3px rgba(0, 0, 0, .35), 0 0 28px 8px rgba(253, 224, 71, .55);
  animation: ring-in .5s var(--ease) both, ring-pulse 1.4s .5s ease-in-out infinite; }
#pointer::after { width: 14px; height: 14px; margin: -7px 0 0 -7px; background: #FDE047; box-shadow: 0 0 0 3px rgba(0, 0, 0, .55); }
@keyframes ring-in { from { transform: scale(2.2); opacity: 0; } }
@keyframes ring-pulse { 50% { transform: scale(1.18); } }

/* Celebration: star card pops in with a confetti burst */
#cheer { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 3; }
.cheer-card { display: flex; flex-direction: column; align-items: center; gap: .3rem; padding: 1rem 1.75rem;
  border-radius: 24px; background: rgba(255, 255, 255, .97); color: var(--teal-900); font-size: 1.7rem; font-weight: 700;
  box-shadow: 0 20px 50px -12px rgba(0, 0, 0, .6); }
.cheer-card svg { width: 56px; height: 56px; fill: #F59E0B; stroke: #B45309; stroke-width: 1; }
#cheer.go .cheer-card { animation: pop 2.6s var(--ease) both; }
@keyframes pop {
  0% { transform: scale(.5); opacity: 0; }
  14% { transform: scale(1.08); opacity: 1; }
  22% { transform: scale(1); }
  82% { transform: scale(1); opacity: 1; }
  100% { transform: scale(.95); opacity: 0; }
}
.confetti { position: absolute; left: 50%; top: 50%; }
.confetti i { position: absolute; width: 10px; height: 14px; border-radius: 2px; opacity: 0; }
#cheer.go .confetti i { animation: burst 1.6s cubic-bezier(.15, .7, .3, 1) both; }
@keyframes burst {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  45% { transform: translate(calc(var(--dx) * .8), var(--dy)) rotate(calc(var(--r) * .5)); opacity: 1; }
  100% { transform: translate(var(--dx), calc(var(--dy) + 280px)) rotate(var(--r)); opacity: 0; }
}

/* Small phones (e.g. Galaxy S22 is 360px wide) */
@media (max-width: 380px) {
  #camWarn { font-size: .98rem; }
  .controls { gap: 1.25rem; }
}
@media (max-height: 700px) {
  #lobby { padding-top: calc(1rem + var(--safe-t)); }
  .lobby-card { gap: .7rem; }
  .avatar.big { width: 72px; height: 72px; font-size: 2.2rem; }
  #lobby h1 { font-size: 2rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .confetti { display: none; }
}
