/* LFM3 Voice Chat — interface inspired by the LiquidAI LFM3-Omni WebGPU demo,
   without the animated orb. Light "paper" theme + dark mode. */

:root {
  --bg: #f6f4ef;
  --bg-accent: #efece4;
  --surface: #ffffff;
  --ink: #1c222b;
  --ink-soft: #5b6472;
  --ink-faint: #8d95a3;
  --line: #e2ded4;
  --accent: #0f7f95;
  --accent-ink: #0b5e6e;
  --talk: #0ea5b7;
  --think: #7c8698;
  --speak: #d24b73;
  --ready: #3aa76d;
  --danger: #c2453d;
  --chip: #eceae2;
  --shadow: 0 1px 2px rgba(28, 34, 43, 0.06), 0 8px 28px rgba(28, 34, 43, 0.08);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --dark: 0;
}

html[data-theme='dark'] {
  --bg: #12151b;
  --bg-accent: #171b23;
  --surface: #1c212b;
  --ink: #e8ebf2;
  --ink-soft: #9aa4b5;
  --ink-faint: #677182;
  --line: #262d3a;
  --accent: #4cc3d9;
  --accent-ink: #8fe0ef;
  --chip: #232a36;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
  --dark: 1;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    --bg: #12151b;
    --bg-accent: #171b23;
    --surface: #1c212b;
    --ink: #e8ebf2;
    --ink-soft: #9aa4b5;
    --ink-faint: #677182;
    --line: #262d3a;
    --accent: #4cc3d9;
    --accent-ink: #8fe0ef;
    --chip: #232a36;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
    --dark: 1;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(120% 90% at 50% -20%, var(--bg-accent), transparent 60%),
    var(--bg);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

select, input, textarea { font: inherit; color: inherit; }

kbd {
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0 5px;
  font-size: 0.8em;
  background: var(--surface);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  clip-path: inset(50%); overflow: hidden;
}

.icon { width: 22px; height: 22px; display: block; }

/* ---------- top bar ---------- */

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  letter-spacing: 0.2px;
}

#status-dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--think);
  transition: background 0.35s;
}

body[data-state='idle'] #status-dot { background: var(--ready); }
body[data-state='booting'] #status-dot,
body[data-state='connecting'] #status-dot { background: var(--think); animation: pulse 1.4s infinite; }
body[data-state='loading-model'] #status-dot { background: var(--think); animation: pulse 1s infinite; }
body[data-state='listening'] #status-dot { background: var(--talk); animation: pulse 1.2s infinite; }
body[data-state='thinking'] #status-dot { background: var(--think); animation: pulse 0.7s infinite; }
body[data-state='speaking'] #status-dot { background: var(--speak); animation: pulse 0.9s infinite; }
body[data-state='error'] #status-dot { background: var(--danger); }

@keyframes pulse { 50% { opacity: 0.35; } }

.top-controls { display: inline-flex; align-items: center; gap: 6px; }

#model-select {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 8px;
  color: var(--ink-soft);
  max-width: 170px;
}

.top-controls button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px;
  border-radius: 10px;
  border: 1px solid transparent;
  color: var(--ink-soft);
  transition: background 0.2s, color 0.2s;
}

.top-controls button:hover { background: var(--chip); color: var(--ink); }
.top-controls button[aria-pressed='true'] { color: var(--accent); }

#voice-toggle .voice-off { display: none; }
#voice-toggle[aria-pressed='false'] .voice-on { display: none; }
#voice-toggle[aria-pressed='false'] .voice-off { display: block; }

#turn-count { font-size: 13px; min-width: 12px; }

/* ---------- main stage ---------- */

#stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 20px;
}

#intro {
  text-align: center;
  max-width: 560px;
  transition: opacity 0.4s;
}

body:not([data-empty]) #intro { display: none; }

#intro h1 { font-size: clamp(26px, 4.5vw, 38px); margin: 0 0 10px; letter-spacing: -0.5px; }
#intro p { color: var(--ink-soft); margin: 0 0 18px; }

#suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

#suggestions button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  color: var(--ink-soft);
  box-shadow: var(--shadow);
  transition: transform 0.2s var(--ease), color 0.2s;
}

#suggestions button:hover { color: var(--ink); transform: translateY(-1px); }

#exchange {
  width: min(660px, 100%);
  max-height: 100%;
  display: none;
  flex-direction: column;
  gap: 18px;
  padding: 10px 0;
}

body:not([data-empty]) #exchange { display: flex; }

#you { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: flex-end; }
#you .you-text { color: var(--ink-soft); }

#reply-wrap {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
  --hidden-top: 0px;
  --hidden-bottom: 0px;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 var(--hidden-top), #000 calc(100% - var(--hidden-bottom)), transparent);
}

body[data-state='thinking'] #reply:empty::after { content: '…'; color: var(--ink-faint); }

#reply { font-size: clamp(19px, 2.9vw, 25px); line-height: 1.55; letter-spacing: -0.1px; overflow-wrap: break-word; }

#reply.error { color: var(--danger); font-size: 16px; }
#reply.ghost .word { opacity: 0.32; }
#reply.ghost .word.spoken { opacity: 1; }
#reply.interrupted::after { content: ' —'; color: var(--ink-faint); }

.word { display: inline-block; }

@media (prefers-reduced-motion: no-preference) {
  .word { animation: word-in 0.5s var(--ease) both; transition: opacity 0.45s ease; }
  @keyframes word-in {
    from { opacity: 0; transform: translateY(6px); filter: blur(3px); }
  }
}

#meta { color: var(--ink-faint); font-size: 13px; min-height: 18px; }

/* voice chip (user recordings and assistant replies) */

.voice-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 13px;
  color: var(--ink-soft);
  font-size: 14px;
}

button.voice-chip:hover { color: var(--ink); }
button.voice-chip.playing { border-color: var(--accent); color: var(--accent); }
.voice-chip svg rect { fill: currentColor; }

/* ---------- dock ---------- */

#dock {
  padding: 10px 16px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.dock-row {
  width: min(660px, 100%);
  display: flex;
  align-items: center;
  gap: 10px;
}

#inputbox {
  flex: 1;
  min-width: 0;
  display: flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 8px 16px;
  box-shadow: var(--shadow);
}

#inputbox textarea {
  flex: 1;
  width: 100%;
  border: 0;
  outline: 0;
  background: none;
  resize: none;
  max-height: 168px;
  line-height: 1.45;
  padding: 6px 0;
}

#inputbox textarea::placeholder { color: var(--ink-faint); }

#primary {
  width: 56px; height: 56px;
  flex: none;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  display: grid;
  place-items: center;
  transition: transform 0.2s var(--ease), background 0.3s, box-shadow 0.3s;
}

#primary:active { transform: scale(0.94); }
#primary .icon { width: 24px; height: 24px; }
#primary .send, #primary .stop { display: none; }
#primary[data-action='send'] .mic { display: none; }
#primary[data-action='send'] .send { display: block; }
#primary[data-action='stop'] .mic { display: none; }
#primary[data-action='stop'] .stop { display: block; }
#primary[data-action='stop'] { background: var(--speak); color: #fff; }

body[data-state='listening'] #primary { background: var(--talk); color: #fff; box-shadow: 0 0 0 8px color-mix(in srgb, var(--talk) 18%, transparent); }

#hint { font-size: 13px; color: var(--ink-faint); margin: 0; text-align: center; min-height: 18px; }
#hint kbd { vertical-align: 1px; }

/* recording bar */

#recbar {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

#recbar[hidden] { display: none; }
body[data-recording] #inputbox { display: none; }

#record-time { width: 40px; }

#wave { flex: 1; min-width: 0; height: 34px; }

#recbar button { padding: 6px; border-radius: 50%; color: var(--ink-soft); }
#recbar button:hover { background: var(--chip); color: var(--ink); }

/* ---------- transcript drawer ---------- */

#drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(380px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(102%);
  transition: transform 0.35s var(--ease);
  display: flex;
  flex-direction: column;
  z-index: 30;
}

body[data-transcript-open] #drawer { transform: none; }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.drawer-head h2 { font-size: 16px; margin: 0; }
.drawer-head button { padding: 6px; border-radius: 8px; color: var(--ink-soft); }

#log {
  list-style: none;
  margin: 0;
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.log-empty { color: var(--ink-faint); font-size: 14px; }

.turn { display: flex; flex-direction: column; gap: 6px; }
.turn-head { display: flex; gap: 8px; align-items: baseline; font-size: 12px; color: var(--ink-faint); }
.turn-head b { color: var(--ink-soft); font-weight: 650; }
.turn-body { display: flex; flex-direction: column; gap: 8px; font-size: 14.5px; }
.turn-user .turn-body { align-items: flex-end; }
.turn p { margin: 0; }
.turn time { font-size: 12px; color: var(--ink-faint); }

.pill-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12.5px;
  color: var(--ink-soft);
  display: inline-flex;
  gap: 5px;
  align-items: center;
  width: max-content;
}
.pill-button:hover { color: var(--ink); }

@media (prefers-reduced-motion: no-preference) {
  .turn-new .turn-body { animation: turn-in 0.5s var(--ease) both; }
  @keyframes turn-in { from { opacity: 0; transform: translateY(8px); } }
}

#scrim {
  position: fixed; inset: 0;
  background: rgba(10, 12, 16, 0.35);
  z-index: 25;
  opacity: 0;
  transition: opacity 0.3s;
}
body[data-transcript-open] #scrim { opacity: 1; }
#scrim[hidden] { display: none; }

/* ---------- settings ---------- */

#settings {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  padding: 22px;
  width: min(420px, 92vw);
  box-shadow: var(--shadow);
}

#settings::backdrop { background: rgba(10, 12, 16, 0.4); }
#settings h2 { margin: 0 0 14px; font-size: 17px; }

#settings label { display: block; font-size: 13.5px; color: var(--ink-soft); margin-bottom: 12px; }

#settings input, #settings textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  outline: none;
}

#settings input:focus, #settings textarea:focus { border-color: var(--accent); }

.fine { font-size: 12px; color: var(--ink-faint); margin: 4px 0 14px; }

.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.dialog-actions button { border-radius: 10px; padding: 8px 16px; font-size: 14px; }
.dialog-actions .ghost { color: var(--ink-soft); }
.dialog-actions .primary { background: var(--accent); color: #fff; }

/* ---------- toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(110px + env(safe-area-inset-bottom));
  transform: translate(-50%, 16px);
  background: var(--ink);
  color: var(--bg);
  border-radius: 12px;
  padding: 9px 15px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s var(--ease);
  z-index: 50;
  max-width: 88vw;
}

#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 640px) {
  #model-select { max-width: 120px; }
  #hint { display: none; }
}
