:root {
  color-scheme: dark;
  font-family: Inter, ui-rounded, -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, sans-serif;
  font-synthesis: none;
  --ink: #f5f7fb;
  --muted: #9aa3b5;
  --surface: #151923;
  --surface-high: #202633;
  --line: rgba(255, 255, 255, 0.09);
  --accent: #54d7ff;
  --incoming: #242a36;
  --outgoing: #075f7d;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 10%, rgba(40, 111, 142, 0.22), transparent 34rem),
    radial-gradient(circle at 85% 90%, rgba(68, 45, 116, 0.2), transparent 32rem),
    #0d1016;
}

button, textarea, input { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.center-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.brand-mark {
  width: 4.4rem;
  height: 4.4rem;
  display: grid;
  place-items: center;
  border-radius: 1.45rem;
  color: #06141b;
  background: linear-gradient(145deg, #b6f1ff, #45c8f4 58%, #1986b4);
  box-shadow: 0 1rem 3rem rgba(30, 177, 224, 0.22);
  font-size: 1.28rem;
  font-weight: 850;
  letter-spacing: -0.06em;
}

#loading-screen .brand-mark { animation: breathe 1.8s ease-in-out infinite; }
.loading-pulse { display: none; }
@keyframes breathe { 50% { transform: scale(1.06); filter: brightness(1.12); } }

.auth-card {
  width: min(100%, 31rem);
  padding: clamp(1.8rem, 5vw, 3rem);
  border: 1px solid var(--line);
  border-radius: 2rem;
  background: rgba(21, 25, 35, 0.86);
  box-shadow: 0 2rem 7rem rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(24px);
}

.auth-card .brand-mark { margin-bottom: 2.4rem; }
.eyebrow { margin: 0 0 0.55rem; color: var(--accent); font-size: 0.75rem; font-weight: 750; letter-spacing: 0.14em; text-transform: uppercase; }
.auth-card h1 { margin: 0; font-size: clamp(2rem, 7vw, 3.15rem); line-height: 0.98; letter-spacing: -0.055em; }
.auth-copy { margin: 1.35rem 0 2rem; color: var(--muted); line-height: 1.55; }

.google-button {
  width: 100%;
  min-height: 3.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  border: 0;
  border-radius: 0.9rem;
  color: #151515;
  background: #fff;
  font-weight: 700;
  cursor: pointer;
}
.google-button:hover { background: #eef7fb; }
.google-button:disabled { opacity: 0.58; cursor: wait; }
.google-button svg { width: 1.35rem; height: 1.35rem; }
.auth-error { margin: 1rem 0 0; color: #ff9f9f; font-size: 0.9rem; }
a { color: var(--muted); text-underline-offset: 0.2em; }
a:hover { color: var(--ink); }

.chat-shell {
  width: min(100%, 62rem);
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  overflow: hidden;
  border-inline: 1px solid var(--line);
  background: rgba(13, 16, 22, 0.76);
  box-shadow: 0 0 6rem rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(22px);
}

.chat-header {
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 4.8rem;
  padding: max(0.7rem, env(safe-area-inset-top)) 1.15rem 0.7rem;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 19, 26, 0.9);
}
.contact { display: flex; align-items: center; gap: 0.8rem; }
.avatar { width: 2.8rem; height: 2.8rem; display: grid; place-items: center; border-radius: 1rem; color: #07202b; background: linear-gradient(145deg, #a9edff, #42c6f1); font-size: 0.82rem; font-weight: 850; }
.contact h1 { margin: 0; font-size: 1.02rem; letter-spacing: -0.02em; }
.contact p { margin: 0.12rem 0 0; color: var(--muted); font-size: 0.72rem; }
.status-dot { display: inline-block; width: 0.46rem; height: 0.46rem; margin-right: 0.38rem; border-radius: 50%; background: #8991a1; }
.status-dot.online { background: #66dea0; box-shadow: 0 0 0.55rem #66dea077; }
.status-dot.retrying { background: #ffc45a; }
.account-menu { display: flex; align-items: center; gap: 0.8rem; }
.account-menu span { max-width: 16rem; overflow: hidden; color: var(--muted); font-size: 0.73rem; text-overflow: ellipsis; }
.quiet-button { padding: 0.48rem 0.72rem; border: 1px solid var(--line); border-radius: 0.65rem; background: transparent; cursor: pointer; }
.quiet-button:hover { background: var(--surface-high); }

.timeline {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 1.5rem clamp(0.8rem, 3vw, 2rem) 1.2rem;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.empty-state { max-width: 23rem; margin: max(4rem, 16vh) auto 0; color: var(--muted); text-align: center; }
.empty-state h2 { margin: 1.4rem 0 0.5rem; color: var(--ink); font-size: 1.15rem; }
.empty-state p { margin: 0; font-size: 0.86rem; line-height: 1.55; }
.empty-orbit { width: 4rem; height: 4rem; margin: auto; border: 1px solid rgba(84, 215, 255, 0.3); border-radius: 50%; animation: rotate 5s linear infinite; }
.empty-orbit span { display: block; width: 0.7rem; height: 0.7rem; margin: -0.35rem auto 0; border-radius: 50%; background: var(--accent); box-shadow: 0 0 1rem var(--accent); }
@keyframes rotate { to { transform: rotate(360deg); } }
.day-label { margin: 1.3rem 0; color: #7f899b; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em; text-align: center; text-transform: uppercase; }

.message-row { display: flex; margin: 0.28rem 0; }
.message-row.outgoing { justify-content: flex-end; }
.message-stack { max-width: min(77%, 35rem); }
.message-bubble { position: relative; padding: 0.68rem 0.86rem 0.5rem; border-radius: 1.14rem 1.14rem 1.14rem 0.35rem; background: var(--incoming); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.035); overflow-wrap: anywhere; }
.outgoing .message-bubble { border-radius: 1.14rem 1.14rem 0.35rem 1.14rem; background: linear-gradient(145deg, #096d8f, var(--outgoing)); }
.message-bubble p { margin: 0; white-space: pre-wrap; }
.message-bubble a { color: #c8f3ff; }
.message-media { display: grid; gap: 0.35rem; margin: -0.25rem -0.43rem 0.55rem; }
.message-media img, .message-media video { width: 100%; max-height: 28rem; display: block; border-radius: 0.82rem; background: #090b10; object-fit: contain; }
.message-meta { min-height: 1rem; display: flex; align-items: center; justify-content: flex-end; gap: 0.34rem; margin-top: 0.3rem; color: rgba(255, 255, 255, 0.65); font-size: 0.61rem; }

.delivery-checks { display: inline-flex; align-items: center; }
.delivery-checks svg { width: 0.9rem; height: 0.9rem; overflow: visible; }
.delivery-checks svg + svg { margin-left: -0.26rem; }
.delivery-checks .ring { fill: none; stroke: currentColor; stroke-width: 1.55; }
.delivery-checks .tick { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.65; }
.delivery-checks.read svg { color: #5ce0ff; }
.delivery-checks.read .ring { fill: currentColor; }
.delivery-checks.read .tick { stroke: #073542; }
.delivery-failure { color: #ffd0d0; font-weight: 800; }

.reaction-bar { display: flex; flex-wrap: wrap; gap: 0.25rem; margin: 0.22rem 0 0 0.35rem; }
.outgoing .reaction-bar { justify-content: flex-end; margin-right: 0.35rem; }
.reaction-chip { padding: 0.12rem 0.38rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-high); font-size: 0.76rem; }
.reaction-picker { position: relative; margin-top: 0.12rem; }
.reaction-picker summary { width: 1.65rem; height: 1.4rem; display: grid; place-items: center; margin-inline: 0.28rem auto; border-radius: 0.6rem; color: #7f899b; cursor: pointer; list-style: none; }
.outgoing .reaction-picker summary { margin-inline: auto 0.28rem; }
.reaction-picker summary::-webkit-details-marker { display: none; }
.reaction-picker summary:hover { color: var(--ink); background: var(--surface-high); }
.reaction-options { position: absolute; z-index: 5; bottom: 1.7rem; display: flex; gap: 0.1rem; padding: 0.28rem; border: 1px solid var(--line); border-radius: 999px; background: #202633; box-shadow: 0 0.8rem 2rem rgba(0, 0, 0, 0.35); }
.outgoing .reaction-options { right: 0; }
.reaction-options button { width: 2rem; height: 2rem; border: 0; border-radius: 50%; background: transparent; cursor: pointer; }
.reaction-options button:hover, .reaction-options button.active { background: #3b4557; }

.attachment-tray { display: flex; gap: 0.55rem; overflow-x: auto; padding: 0.65rem 1rem; border-top: 1px solid var(--line); background: rgba(19, 23, 31, 0.94); }
.attachment-preview { position: relative; flex: 0 0 5rem; height: 4.3rem; display: grid; place-items: center; padding: 0.35rem; border-radius: 0.72rem; background: var(--surface-high); color: var(--muted); font-size: 0.62rem; overflow: hidden; text-align: center; }
.attachment-preview button { position: absolute; top: 0.15rem; right: 0.15rem; width: 1.25rem; height: 1.25rem; border: 0; border-radius: 50%; background: rgba(0, 0, 0, 0.68); cursor: pointer; }

.composer { display: grid; grid-template-columns: auto 1fr auto; align-items: end; gap: 0.55rem; padding: 0.72rem max(0.85rem, env(safe-area-inset-right)) max(0.72rem, env(safe-area-inset-bottom)) max(0.85rem, env(safe-area-inset-left)); border-top: 1px solid var(--line); background: rgba(16, 19, 26, 0.94); }
.attach-button, .send-button { width: 2.7rem; height: 2.7rem; display: grid; place-items: center; border: 0; border-radius: 50%; cursor: pointer; }
.attach-button { color: var(--accent); background: var(--surface-high); }
.attach-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.attach-button svg, .send-button svg { width: 1.3rem; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.send-button { color: #06202b; background: var(--accent); }
.send-button:disabled { opacity: 0.3; cursor: default; }
.composer textarea { width: 100%; max-height: 8.5rem; resize: none; padding: 0.64rem 0.85rem; border: 1px solid var(--line); border-radius: 1.15rem; outline: 0; color: var(--ink); background: var(--surface-high); line-height: 1.35; }
.composer textarea:focus { border-color: rgba(84, 215, 255, 0.55); }

.toast { position: fixed; z-index: 20; left: 50%; bottom: max(5.8rem, calc(env(safe-area-inset-bottom) + 5.8rem)); max-width: min(90vw, 30rem); transform: translateX(-50%); padding: 0.7rem 0.95rem; border: 1px solid var(--line); border-radius: 0.75rem; background: #2b3240; box-shadow: 0 0.8rem 2rem rgba(0, 0, 0, 0.4); font-size: 0.8rem; text-align: center; }

@media (max-width: 38rem) {
  .chat-shell { border: 0; }
  .account-menu span { display: none; }
  .message-stack { max-width: 86%; }
  .quiet-button { font-size: 0.72rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; }
}
