/* Minimal dark-mode voice+text chat with a modern, animated, React-app feel.
   Dependency-free: all motion is CSS + a little JS for ripples/toasts.
   Design language from the TFNCA client (near-black #0f0f0f, glassy panels,
   Zoom-style mic button). */

:root {
  --bg: #0f0f0f;
  --panel-a: rgba(24, 24, 24, 0.94);
  --panel-b: rgba(10, 10, 10, 0.96);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f5f5f5;
  --muted: #b6b6b6;
  --accent: #4a95ff;
  --accent-soft: rgba(74, 149, 255, 0.18);
  --good: #43c463;
  --warn: #e0b34a;
  --hot: #ff5b5b;
  --amber: #e0873a;
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* Ambient gradient wash so the near-black isn't flat. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(60% 50% at 50% -10%, rgba(74, 149, 255, 0.12), transparent 70%),
    radial-gradient(50% 40% at 100% 100%, rgba(224, 135, 58, 0.08), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  height: 100%;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 14px max(20px, env(safe-area-inset-bottom));
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────────────── */

.header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(180deg, var(--panel-a), var(--panel-b));
  backdrop-filter: blur(12px);
  flex-shrink: 0;
  animation: drop-in 0.5s var(--spring) both;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 20px;
  transition: transform 0.6s var(--spring), color 0.3s var(--ease);
}
.brand-mark.spin { transform: rotate(360deg); color: var(--accent); }

.brand-copy h1 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -0.02em; }

.status-line {
  margin: 3px 0 0;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  text-transform: capitalize;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #666;
  transition: background 0.3s var(--ease), box-shadow 0.3s var(--ease);
}
.state-active .status-dot,
.state-listening_to_ai .status-dot { background: var(--good); box-shadow: 0 0 0 4px rgba(67,196,99,0.16); animation: breathe 2.4s var(--ease) infinite; }
.state-recording .status-dot { background: var(--hot); box-shadow: 0 0 0 4px rgba(255,91,91,0.2); animation: breathe 1s var(--ease) infinite; }
.state-connecting .status-dot,
.state-configuring .status-dot,
.state-reconnecting .status-dot { background: var(--warn); box-shadow: 0 0 0 4px rgba(224,179,74,0.16); animation: breathe 1.4s var(--ease) infinite; }
.state-degraded .status-dot { background: var(--amber); box-shadow: 0 0 0 4px rgba(224,135,58,0.16); }
.state-failed .status-dot, .state-disconnected .status-dot { background: #666; }

/* Animated hamburger -> X */
.hamburger { position: relative; }
.hamburger span {
  position: absolute; left: 11px; width: 18px; height: 2px; border-radius: 2px;
  background: currentColor; transition: transform 0.35s var(--spring), opacity 0.2s var(--ease);
}
.hamburger span:nth-child(1) { top: 15px; }
.hamburger span:nth-child(2) { top: 21px; }
.hamburger span:nth-child(3) { top: 27px; }
.hamburger.open span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ── Feed ───────────────────────────────────────────────────────── */

.feed-panel {
  flex: 1 1 auto;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(180deg, var(--panel-a), var(--panel-b));
  backdrop-filter: blur(12px);
  overflow: hidden;
  animation: drop-in 0.5s var(--spring) 0.05s both;
}

.feed {
  height: 100%;
  overflow-y: auto;
  padding: 16px 10px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}
.feed::-webkit-scrollbar { width: 10px; }
.feed::-webkit-scrollbar-thumb {
  background: var(--line-strong); border-radius: 999px; border: 2px solid var(--panel-b);
}

.feed-hint {
  margin: auto;
  text-align: center;
  color: #6f6f6f;
  animation: fade-in 0.6s var(--ease) 0.2s both;
}
.feed-hint-mark { font-size: 42px; opacity: 0.5; margin-bottom: 10px; animation: float 4s ease-in-out infinite; }
.feed-hint p { margin: 0; line-height: 1.6; font-size: 14px; }

.row { display: flex; animation: bubble-in 0.4s var(--spring) both; }
.row.user { justify-content: flex-end; }
.row.assistant { justify-content: flex-start; }

.bubble {
  max-width: min(74%, 360px);
  padding: 10px 12px;
  border-radius: 16px;
  line-height: 1.48;
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble.assistant { background: rgba(255,255,255,0.05); border-top-left-radius: 8px; }
.bubble.user {
  background: linear-gradient(180deg, #f7f7f7, #d7d7d7);
  color: #101010; border-top-right-radius: 8px;
  box-shadow: 0 6px 18px rgba(255,255,255,0.05);
}
.bubble.interim { opacity: 0.6; }
.bubble.interim::after {
  content: "";
  display: inline-block; width: 6px; height: 14px; margin-left: 3px;
  border-radius: 999px; background: currentColor; vertical-align: -2px;
  animation: blink 1s steps(1) infinite;
}

.bubble-image {
  margin-top: 8px; width: 180px; max-width: 100%;
  border-radius: 12px; display: block; cursor: zoom-in;
  transition: transform 0.25s var(--spring), box-shadow 0.25s var(--ease);
}
.bubble-image:hover { transform: scale(1.03); box-shadow: 0 12px 30px rgba(0,0,0,0.4); }
.bubble.user .bubble-image { margin-left: auto; }

/* ── Composer ───────────────────────────────────────────────────── */

.composer {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(180deg, var(--panel-a), var(--panel-b));
  backdrop-filter: blur(12px);
  animation: drop-in 0.5s var(--spring) 0.1s both;
}

.composer-attachment {
  display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
  padding: 8px 10px; border-radius: 14px; background: rgba(255,255,255,0.06);
  font-size: 13px; animation: bubble-in 0.3s var(--spring) both;
}
.composer-attachment img { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; }
.composer-attachment span { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-attachment button {
  width: 24px; height: 24px; border: none; border-radius: 999px;
  background: rgba(255,255,255,0.14); color: var(--text); cursor: pointer;
}

.composer-bar {
  display: flex; align-items: flex-end; gap: 8px;
  border: 1px solid var(--line); border-radius: 24px;
  background: rgba(255,255,255,0.04); padding: 5px 5px 5px 16px;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.composer-bar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.composer-input {
  flex: 1 1 auto; min-width: 0; resize: none; border: none; background: transparent;
  color: #fafafa; padding: 9px 0; outline: none; font: inherit; font-size: 16px;
  line-height: 1.5; max-height: 120px;
}
.composer-input::placeholder { color: #868686; }

.composer-buttons {
  margin-top: 14px; display: flex; align-items: center; justify-content: center; gap: 22px;
}

/* ── Buttons: ripple + spring press ─────────────────────────────── */

.icon-button, .send-button, .mic-button, .menu-button, .chip {
  font: inherit; border: none; border-radius: 999px; cursor: pointer; color: var(--text);
  position: relative; overflow: hidden;
  transition: transform 0.2s var(--spring), background 0.2s var(--ease),
              color 0.2s var(--ease), box-shadow 0.2s var(--ease), border-color 0.2s var(--ease);
}
.icon-button:active, .send-button:active, .menu-button:active, .chip:active { transform: scale(0.92); }

.icon-button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; background: rgba(255,255,255,0.07); border: 1px solid var(--line);
}
.icon-button svg { width: 20px; height: 20px; }
.icon-button.ghost { width: 40px; height: 40px; background: transparent; }
.icon-button:hover { transform: translateY(-2px); background: rgba(255,255,255,0.12); }
.icon-button.like-active { color: var(--hot); animation: pop 0.4s var(--spring); }
.icon-button.like-active svg path { fill: currentColor; }

.send-button {
  width: 40px; height: 40px; flex-shrink: 0; background: #f2f2f2; color: #0d0d0d;
  display: inline-flex; align-items: center; justify-content: center;
}
.send-button svg { width: 18px; height: 18px; transition: transform 0.2s var(--spring); }
.send-button:not(:disabled):hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(255,255,255,0.12); }
.send-button:not(:disabled):hover svg { transform: translateX(2px) rotate(-8deg); }
.send-button:disabled { background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.46); cursor: not-allowed; }

/* Zoom-style mic: muted by default, open + pulsing rings while capturing */
.mic-button {
  width: 72px; height: 72px;
  border: 2px solid var(--line-strong);
  background: linear-gradient(145deg, rgba(36,36,36,0.92), rgba(14,14,14,0.96));
  box-shadow: 0 12px 36px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.72);
  display: inline-flex; align-items: center; justify-content: center;
  touch-action: none; user-select: none;
}
.mic-button svg { width: 28px; height: 28px; position: relative; z-index: 2; }
.mic-button:hover { border-color: rgba(255,255,255,0.3); color: #fff; transform: translateY(-2px); }
.mic-button:disabled { opacity: 0.4; cursor: not-allowed; }
.mic-ring {
  position: absolute; inset: -2px; border-radius: 999px; border: 2px solid var(--good);
  opacity: 0; pointer-events: none;
}
.mic-button.mic-on {
  background: #f5f5f5; border-color: #f5f5f5; color: #111;
}
.mic-button.mic-on .mic-ring { animation: ring 1.8s var(--ease) infinite; }
.mic-button.mic-on .mic-ring-2 { animation-delay: 0.9s; }

/* JS-driven ripple */
.ripple-dot {
  position: absolute; border-radius: 50%; transform: scale(0);
  background: rgba(255,255,255,0.35); pointer-events: none;
  animation: ripple 0.6s var(--ease);
}

/* ── Drawer (settings menu) ─────────────────────────────────────── */

.scrim {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(3px);
  animation: fade-in 0.25s var(--ease) both;
}
.scrim.closing { animation: fade-out 0.25s var(--ease) both; }

.drawer {
  position: fixed; top: 0; right: 0; z-index: 160;
  width: min(360px, 88vw); height: 100%;
  background: linear-gradient(180deg, rgba(22,22,22,0.98), rgba(9,9,9,0.99));
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 60px rgba(0,0,0,0.5);
  transform: translateX(100%);
  transition: transform 0.42s var(--spring);
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 18px 12px; flex-shrink: 0;
}
.drawer-head h2 { margin: 0; font-size: 18px; font-weight: 600; }

.drawer-body {
  flex: 1 1 auto; overflow-y: auto; padding: 0 18px 24px;
  display: flex; flex-direction: column; gap: 18px;
}

.drawer-section {
  border: 1px solid var(--line); border-radius: 18px; padding: 14px;
  background: rgba(255,255,255,0.02);
  animation: bubble-in 0.4s var(--spring) both;
}
.drawer.open .drawer-section:nth-child(1) { animation-delay: 0.08s; }
.drawer.open .drawer-section:nth-child(2) { animation-delay: 0.14s; }
.drawer.open .drawer-section:nth-child(3) { animation-delay: 0.20s; }
.drawer.open .drawer-section:nth-child(4) { animation-delay: 0.26s; }

.drawer-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.14em;
  color: #7a7a7a; margin-bottom: 10px;
}
.drawer-note { margin: -4px 0 10px; font-size: 12px; color: #8a8a8a; line-height: 1.4; }
.drawer-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 0; font-size: 14px; color: #ddd;
}
.pill {
  padding: 3px 10px; border-radius: 999px; background: rgba(255,255,255,0.08);
  font-size: 12px; color: #cfcfcf; font-variant-numeric: tabular-nums;
}
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11px; color: #9a9a9a; }

.menu-button {
  width: 100%; margin-top: 10px; padding: 11px; border-radius: 14px;
  background: rgba(255,255,255,0.07); border: 1px solid var(--line); color: var(--text);
  font-size: 14px; font-weight: 500;
}
.menu-button:hover { background: rgba(255,255,255,0.12); transform: translateY(-1px); }
.menu-button.primary { background: var(--accent); border-color: transparent; color: #06183a; font-weight: 600; }
.menu-button.primary:hover { background: #5aa0ff; box-shadow: 0 10px 24px var(--accent-soft); }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 500;
  background: rgba(255,255,255,0.06); border: 1px solid var(--line); color: #e6e6e6;
}
.chip:hover { background: var(--accent-soft); border-color: var(--accent); transform: translateY(-2px); }

.switch {
  width: 46px; height: 27px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: rgba(255,255,255,0.08); position: relative; cursor: pointer; padding: 0; flex-shrink: 0;
  transition: background 0.25s var(--ease), border-color 0.25s var(--ease);
}
.switch span {
  position: absolute; top: 2px; left: 2px; width: 21px; height: 21px; border-radius: 50%;
  background: #c8c8c8; transition: transform 0.3s var(--spring), background 0.25s var(--ease);
}
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"] span { transform: translateX(19px); background: #fff; }

/* ── TV mode ────────────────────────────────────────────────────── */

.tv {
  position: fixed; inset: 0; z-index: 100; background: #000;
  display: flex; align-items: center; justify-content: center;
  animation: fade-in 0.4s var(--ease) both;
}
.tv-frame { width: 100%; height: 100%; object-fit: contain; }
.tv-badge {
  position: fixed; top: 18px; left: 18px; padding: 6px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.12em;
  background: rgba(67,196,99,0.9); color: #05210f;
  animation: bubble-in 0.4s var(--spring) both;
}
.tv-badge.degraded { background: rgba(224,135,58,0.92); color: #241102; }
.tv-exit {
  position: fixed; top: 16px; right: 16px; width: 40px; height: 40px; border: none;
  border-radius: 999px; background: rgba(20,20,20,0.7); color: #f5f5f5; font-size: 18px;
  cursor: pointer; backdrop-filter: blur(8px);
}
.tv-exit:hover { background: rgba(40,40,40,0.8); transform: rotate(90deg); }

/* ── Full-size image overlay ────────────────────────────────────── */

.overlay {
  position: fixed; inset: 0; z-index: 120; background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center; cursor: zoom-out; padding: 24px;
  animation: fade-in 0.25s var(--ease) both;
}
.overlay-img {
  max-width: 100%; max-height: 100%; border-radius: 12px;
  animation: zoom-in 0.35s var(--spring) both;
}

/* ── Toasts ─────────────────────────────────────────────────────── */

.toast-stack {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 200;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
}
.toast {
  padding: 11px 18px; border-radius: 999px; font-size: 14px;
  background: rgba(28,28,28,0.96); color: #f2f2f2; border: 1px solid var(--line-strong);
  box-shadow: 0 12px 30px rgba(0,0,0,0.4); backdrop-filter: blur(10px);
  animation: toast-in 0.4s var(--spring) both;
  max-width: 90vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toast.error { background: rgba(78,26,26,0.96); border-color: rgba(255,120,120,0.3); color: #ffe7e7; }
.toast.leaving { animation: toast-out 0.3s var(--ease) both; }

/* ── Keyframes ──────────────────────────────────────────────────── */

@keyframes drop-in { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }
@keyframes bubble-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes zoom-in { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px) scale(0.95); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px) scale(0.96); } }
@keyframes ripple { to { transform: scale(2.6); opacity: 0; } }
@keyframes ring { 0% { opacity: 0.7; transform: scale(1); } 100% { opacity: 0; transform: scale(1.5); } }
@keyframes breathe { 0%,100% { box-shadow: 0 0 0 0 rgba(255,255,255,0.14); } 50% { box-shadow: 0 0 0 6px rgba(255,255,255,0.03); } }
@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.3); } 100% { transform: scale(1); } }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes blink { 50% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

@media (max-width: 540px) {
  .composer-buttons { gap: 16px; }
  .bubble-image { width: 150px; }
}
