/* Turbo Chat. Apple-style tokens, plain CSS, no build step.
   Theme: follows the system; [data-theme] on <html> forces light or dark. Every color is light-dark(). */

:root {
  color-scheme: light dark;

  --bg: light-dark(#f5f5f7, #000);
  --ink: light-dark(#1d1d1f, #f5f5f7);
  --muted: light-dark(#6e6e73, #98989d);
  --line: light-dark(rgba(0, 0, 0, 0.08), rgba(255, 255, 255, 0.1));
  --glass: light-dark(rgba(255, 255, 255, 0.62), rgba(28, 28, 30, 0.62));
  --glass-2: light-dark(rgba(255, 255, 255, 0.86), rgba(44, 44, 46, 0.86));
  --stroke: light-dark(rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.08));
  --field: light-dark(rgba(118, 118, 128, 0.12), rgba(118, 118, 128, 0.24));
  --thumb: light-dark(#fff, #636366);
  --shade: light-dark(rgba(20, 16, 40, 0.07), rgba(0, 0, 0, 0.45));
  --blue: light-dark(#007aff, #0a84ff);
  --green: light-dark(#34c759, #30d158);
  --red: light-dark(#ff3b30, #ff453a);

  /* Bubbles: Messages gray for others, blue for mine. */
  --in: light-dark(#e9e9eb, #262629);
  --out: light-dark(#0a7aff, #0a84ff);

  --blob-1: light-dark(#ffc9a0, #4a2410);
  --blob-2: light-dark(#d9d2ff, #1f1a52);
  --blob-3: light-dark(#ffd0e6, #43122b);

  --shadow-1: 0 1px 2px var(--shade), 0 10px 30px var(--shade);
  --shadow-2: 0 2px 8px var(--shade), 0 40px 90px -20px var(--shade);
  --dusk: linear-gradient(100deg, #ff9f5a 0%, #ff5f9e 50%, #8c7cff 100%);
  --sun: linear-gradient(135deg, #ffb86b 0%, #ff7a59 48%, #ff5fa2 100%);
  --sky: linear-gradient(135deg, #5ac8fa 0%, #7c8cff 55%, #b48cff 100%);
  --mint: linear-gradient(135deg, #30d158 0%, #2fc6a2 50%, #5ac8fa 100%);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --max: 1180px;
  --gutter: max(16px, env(safe-area-inset-left), env(safe-area-inset-right));
  --column: min(var(--max), 100% - 2 * var(--gutter));
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* Soft color fields. Static gradients, no blur filter: cheap to paint on phones. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(45vmax 45vmax at 0% 0%, var(--blob-1), transparent 70%),
    radial-gradient(45vmax 45vmax at 100% 30%, var(--blob-2), transparent 70%),
    radial-gradient(50vmax 50vmax at 40% 110%, var(--blob-3), transparent 70%);
  opacity: 0.6;
}

h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button, input { font: inherit; color: inherit; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 3px solid #7c8cff; outline-offset: 3px; border-radius: 12px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.muted { color: var(--muted); }

/* ---------- Glass ---------- */

.nav, .card, .join, .composer, .sheet, .pill, .toast, .segmented {
  background: var(--glass);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow-1);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
}

/* ---------- Buttons & fields ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 54px;
  padding: 0 26px;
  border: 0;
  border-radius: 999px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.35s var(--ease), box-shadow 0.35s var(--ease), background 0.35s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(0.98); }

.btn-dark { background: var(--ink); color: var(--bg); box-shadow: 0 10px 28px var(--shade); }
.btn-glass { background: var(--glass-2); border: 1px solid var(--line); }
.btn-sm { height: 40px; padding: 0 16px; font-size: 15px; }

.icon-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--blue);
  cursor: pointer;
  transition: background 0.25s;
}
.icon-btn:hover { background: var(--field); }

.field, .join input, .link-row input {
  width: 100%;
  min-width: 0;
  height: 54px;
  padding: 0 20px;
  border: 0;
  border-radius: 16px;
  background: var(--field);
  outline-offset: 0;
}
input::placeholder { color: var(--muted); }

/* ---------- Screen: home & name pages fit the viewport, no scroll ---------- */

.screen {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) var(--gutter) max(16px, env(safe-area-inset-bottom));
}

.hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: min(760px, 100%);
  margin: 0 auto;
  text-align: center;
}

.app-icon {
  display: grid;
  place-items: center;
  width: clamp(52px, 8dvh, 68px);
  aspect-ratio: 1;
  margin-bottom: clamp(12px, 2.5dvh, 22px);
  border-radius: 24%;
  background: var(--sky);
  box-shadow: 0 10px 30px rgba(90, 120, 255, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.app-icon svg { width: 56%; height: 56%; fill: #fff; stroke: none; }

.eyebrow {
  margin-bottom: clamp(8px, 1.6dvh, 16px);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.hero h1 {
  font-size: clamp(36px, min(10vw, 10.5dvh), 96px);
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: -0.045em;
}

.grad {
  background: var(--dusk);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.lead {
  max-width: 540px;
  margin-top: clamp(14px, 2.6dvh, 24px);
  color: var(--muted);
  font-size: clamp(17px, 2.2vw, 20px);
  line-height: 1.45;
}

.actions { margin-top: clamp(20px, 4dvh, 36px); }

.join {
  display: flex;
  gap: 8px;
  width: min(440px, 100%);
  margin-top: 16px;
  padding: 6px;
  border-radius: 999px;
}
.join input { height: 40px; padding: 0 14px; background: transparent; border-radius: 999px; }

.foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: var(--column);
  margin: 0 auto;
  padding-top: 16px;
}

.note {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}
.note svg { width: 16px; height: 16px; }

/* ---------- Segmented control (theme) ---------- */

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--field);
  box-shadow: none;
}
.segmented label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.3s var(--ease), color 0.3s, box-shadow 0.3s;
}
.segmented svg { width: 15px; height: 15px; }
.segmented label:has(:checked) { background: var(--thumb); color: var(--ink); box-shadow: 0 1px 3px var(--shade), 0 3px 8px var(--shade); }
.segmented label:has(:focus-visible) { outline: 3px solid #7c8cff; outline-offset: 1px; }

/* ---------- Name card ---------- */

.card {
  display: grid;
  justify-items: center;
  width: min(440px, 100%);
  padding: 32px 28px 28px;
  border-radius: 28px;
  box-shadow: var(--shadow-2);
}
.card h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.03em; }
.card .muted { margin-top: 6px; }
.stack { display: grid; gap: 12px; width: 100%; margin-top: 24px; }

/* ---------- Room ---------- */

.room {
  display: flex;
  flex-direction: column;
  width: var(--column);
  height: 100dvh;
  margin: 0 auto;
}

.nav {
  position: relative;
  z-index: 10;
  display: flex;
  flex: none;
  align-items: center;
  gap: 12px;
  height: 60px;
  margin-top: max(12px, env(safe-area-inset-top));
  padding: 0 10px 0 8px;
  border-radius: 999px;
}

.room-title { display: grid; line-height: 1.2; }
.room-title strong { font-size: 16px; }
.room-title span { color: var(--muted); font-size: 12px; font-family: ui-monospace, "SF Mono", Menlo, monospace; }

.pill {
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--glass-2);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.dot { width: 8px; height: 8px; margin-right: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 25%, transparent); }

.thread {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 8px 12px;
  scrollbar-width: thin;
}

.empty {
  display: grid;
  justify-items: center;
  gap: 12px;
  max-width: 320px;
  margin: 12vh auto 0;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
}
.empty svg { width: 32px; height: 32px; }
.empty strong { color: var(--ink); }
.thread:has(.msg) .empty { display: none; }

/* ---------- Bubbles (Messages style) ---------- */

.msg {
  display: grid;
  justify-items: start;
  margin-top: 10px;
}
.msg.cont { margin-top: 2px; }
.msg.mine { justify-items: end; }

/* Centered timestamp, only after a pause. */
.msg time { display: none; }
.msg.stamp time {
  display: block;
  justify-self: center;
  margin: 14px 0 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.who { margin: 0 0 2px 14px; color: var(--muted); font-size: 11.5px; }
.msg.cont .who, .msg.mine .who { display: none; }

.bubble {
  position: relative;
  max-width: min(72%, 620px);
  padding: 7px 13px 8px;
  border-radius: 19px;
  background: var(--in);
  font-size: 16px;
  line-height: 1.35;
  letter-spacing: -0.005em;
  overflow-wrap: anywhere;
  animation: pop 0.45s var(--ease);
  transform-origin: bottom left;
}
.msg.mine .bubble {
  background: var(--out);
  color: #fff;
  transform-origin: bottom right;
}

/* The tail: only on the last bubble of a group. Drawn with clip-path, so it works over any background. */
.msg.tail .bubble::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: -6px;
  width: 20px;
  height: 20px;
  z-index: -1; /* under the text */
  background: var(--in);
  clip-path: path("M20 0H6C6 9 4.6 15.4 0 20C5 20 9 19 12.2 17.3C14.3 19 16.8 20 20 20Z");
}
.msg.mine.tail .bubble::after { left: auto; right: -6px; background: var(--out); transform: scaleX(-1); }

/* Emoji-only messages: big, no bubble. */
.msg.jumbo .bubble { padding: 0 2px; background: none; font-size: 44px; line-height: 1.15; }
.msg.jumbo .bubble::after { display: none; }

@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(0.92); }
}

/* ---------- Composer ---------- */

.composer {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: max(12px, env(safe-area-inset-bottom));
  padding: 6px 6px 6px 18px;
  border-radius: 999px;
}
.composer input { flex: 1; min-width: 0; height: 40px; border: 0; background: transparent; outline: none; }
.composer:focus-within { box-shadow: var(--shadow-1), 0 0 0 3px color-mix(in srgb, var(--blue) 35%, transparent); }

.send {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  transition: transform 0.3s var(--ease), opacity 0.2s;
}
.send svg { width: 20px; height: 20px; stroke-width: 2.5; }
.send:active { transform: scale(0.92); }
.composer:has(input:placeholder-shown) .send { opacity: 0.4; }

.composer-error {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 18px;
  color: var(--red);
  font-size: 13px;
  font-weight: 500;
}

/* ---------- Info sheet ---------- */

.sheet {
  width: min(440px, 100% - 2 * var(--gutter));
  max-height: min(680px, 88dvh);
  padding: 28px 24px 24px;
  border-radius: 28px;
  background: var(--glass-2);
  box-shadow: var(--shadow-2);
  color: var(--ink);
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.25); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.sheet[open] { animation: rise 0.45s var(--ease); }
.sheet h2 { font-size: 22px; letter-spacing: -0.02em; }
.sheet .muted { margin-top: 4px; font-size: 15px; }
.sheet h3 { margin: 24px 0 8px; color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.close { position: absolute; top: 14px; right: 14px; color: var(--muted); }

@keyframes rise {
  from { opacity: 0; transform: translateY(24px) scale(0.98); }
}

.link-row { display: flex; gap: 8px; margin-top: 18px; }
.copy { min-width: 116px; } /* same width for "Copiar link" and "Copiado" */
.link-row input { height: 40px; padding: 0 14px; border-radius: 12px; color: var(--muted); font-size: 14px; text-overflow: ellipsis; }

.people { margin: 0; padding: 0; list-style: none; }
.person { display: flex; align-items: center; gap: 12px; padding: 8px 0; font-weight: 500; }
.person + .person { border-top: 1px solid var(--line); }

.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: #fff;
  font-size: 15px;
  font-weight: 650;
}
.g0 { background: var(--sky); }
.g1 { background: var(--sun); }
.g2 { background: var(--mint); }
.g3 { background: var(--dusk); }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  z-index: 20;
  max-width: calc(100% - 2 * var(--gutter));
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--glass-2);
  font-size: 15px;
  font-weight: 500;
  transform: translateX(-50%);
  animation: toast 4.5s var(--ease) forwards;
  pointer-events: none;
}
.toast-alert { color: var(--red); }

@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, -12px); }
  8%, 85% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -12px); visibility: hidden; }
}

/* ---------- Small screens ---------- */

@media (max-width: 600px) {
  .foot { justify-content: center; }
  .segmented span { display: none; }
  .segmented label { padding: 0 14px; }
  .sheet .segmented span { display: inline; }
  .bubble { max-width: 80%; }
  .card { padding: 28px 20px 20px; }
}

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