/* Lingua — "Cálido nocturno". Tokens y reglas: ver DESIGN.md. */

:root {
  --bg: #131118;
  --surface: #1A171F;
  --surface-2: #221E28;
  --border: #2E2935;
  --border-strong: #423B4A;

  --text: #F2EFEA;
  --text-dim: #A79FB0;
  --text-faint: #6E6678;

  --accent: #E07A5F;
  --accent-hover: #EA8D74;
  --accent-deep: #B85C44;
  --on-accent: #1C120E;

  --bubble-self: #E07A5F;
  --bubble-other: #211F2B;
  --bubble-other-accent: #8B84D7;

  --ok: #5DBB7C;
  --warn: #D9A13B;
  --danger: #E5484D;

  --font-ui: 'Instrument Sans', system-ui, sans-serif;
  --font-brand: 'Fraunces', Georgia, serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --r-ctrl: 10px;
  --r-card: 14px;
  --ease: cubic-bezier(0.25, 0.9, 0.3, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 300px;
}

.icon { display: inline-flex; width: 18px; height: 18px; flex: none; }
.icon--sm { width: 15px; height: 15px; }
.icon svg { width: 100%; height: 100%; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ===== Headers ===== */

.header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex: none;
}

.header--lobby { justify-content: center; background: transparent; border-bottom-color: transparent; }

.brand {
  font-family: var(--font-brand);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.01em;
  color: var(--text-dim);
}

.header-spacer { flex: 1; }

.code-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-ctrl);
  color: var(--text);
  transition: border-color 160ms var(--ease), background 160ms var(--ease);
}
.code-chip:hover { border-color: var(--accent-deep); background: #262130; }
.code-chip .icon { color: var(--text-faint); }

.code-text {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.12em;
}

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

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: background 200ms var(--ease);
}
.status-dot[data-status="connected"] { background: var(--ok); }
.status-dot[data-status="connecting"],
.status-dot[data-status="reconnecting"] { background: var(--warn); }
.status-dot[data-status="offline"] { background: var(--text-faint); }

.status-label { font-size: 11px; color: var(--text-faint); }
@media (max-width: 359px) { .visually-hidden-narrow { display: none; } }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 32px;
  height: 32px;
  padding: 0 6px;
  border-radius: var(--r-ctrl);
  color: var(--text-dim);
  transition: background 160ms var(--ease), color 160ms var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn--danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.icon-btn--ghost { min-width: 26px; height: 26px; }
.icon-btn.is-copied { color: var(--ok); }
.icon-btn.is-speaking { color: var(--accent); }
.icon-btn.is-speaking .icon { animation: speaking-pulse 1s ease-in-out infinite; }
@keyframes speaking-pulse { 50% { opacity: 0.45; } }
.icon-btn:disabled { opacity: 0.4; cursor: default; }
.icon-btn:disabled:hover { background: none; color: var(--text-dim); }

.count-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0 6px;
  border-radius: 999px;
  line-height: 18px;
}

.conn-banner {
  flex: none;
  text-align: center;
  font-size: 12px;
  padding: 5px 10px;
  color: #2A2007;
  background: var(--warn);
  animation: banner-in 220ms var(--ease);
}

/* ===== Views ===== */

.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ===== Lobby ===== */

.view--lobby {
  padding: 8px 22px 26px;
  overflow-y: auto;
  gap: 20px;
}

.lobby-hero { text-align: center; padding: 26px 0 2px; }

.lobby-title {
  font-family: var(--font-brand);
  font-weight: 600;
  font-size: 44px;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.lobby-tagline {
  margin-top: 8px;
  color: var(--text-dim);
  font-size: 14px;
}

.lobby-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 340px;
  margin: 0 auto;
}

.field { display: flex; flex-direction: column; gap: 6px; }

.field label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
}

input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-ctrl);
  padding: 9px 12px;
  width: 100%;
  transition: border-color 160ms var(--ease);
}
input:not([type="checkbox"]):not([type="radio"]):focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }

/* Chrome paints autofilled fields (password ones especially) with its own
   light background, which breaks the dark theme. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--surface-2) inset;
  caret-color: var(--text);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23A79FB0' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 34px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  border-radius: var(--r-ctrl);
  font-weight: 600;
  font-size: 14px;
  transition: background 160ms var(--ease), transform 120ms var(--ease);
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: default; }

.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn--secondary {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
}
.btn--secondary:hover:not(:disabled) { border-color: var(--accent-deep); }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-faint);
  font-size: 12px;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.join-row { display: flex; gap: 8px; }
.join-row .btn { flex: none; }

.code-input {
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-align: center;
}

.advanced { margin-top: 2px; }
.advanced summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-faint);
  user-select: none;
}
.advanced summary:hover { color: var(--text-dim); }
.advanced-body { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.advanced .field { margin-top: 0; }
.advanced input { font-family: var(--font-mono); font-size: 12px; letter-spacing: 0; }

.server-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}
.server-status .status-dot { flex: none; }

#server-fields { display: flex; flex-direction: column; gap: 10px; }

.server-actions { display: flex; align-items: center; gap: 12px; }

.btn--sm { padding: 7px 14px; font-size: 13px; }

.link-btn {
  align-self: flex-start;
  font-size: 12px;
  color: var(--accent);
  padding: 2px 0;
  border-bottom: 1px solid transparent;
}
.link-btn:hover { border-bottom-color: currentColor; }

/* ===== Banners ===== */

.banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--r-card);
  border: 1px solid;
  max-width: 340px;
  margin: 0 auto;
  width: 100%;
}
.banner--warn {
  background: color-mix(in srgb, var(--warn) 9%, var(--surface));
  border-color: color-mix(in srgb, var(--warn) 40%, var(--border));
  color: var(--text);
}
.banner--warn .icon { color: var(--warn); }
.banner-title { font-weight: 600; font-size: 13px; }
.banner-body { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.banner--slim { border-radius: 0; max-width: none; border-left: none; border-right: none; border-top: none; padding: 8px 14px; }

/* ===== Room: participants ===== */

.participants-panel {
  flex: none;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  max-height: 240px;
  overflow-y: auto;
  animation: banner-in 180ms var(--ease);
}

/* Your own language lives here, above the list of who reads what: the panel is
   where you find out you joined in the wrong one. */
.participants-lang {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.participants-list { list-style: none; padding: 6px 8px; }

.participant {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: var(--r-ctrl);
}
.participant:hover { background: var(--surface-2); }

.participant-avatar {
  width: 26px; height: 26px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
}

.participant-name { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.participant-you { color: var(--accent); font-weight: 600; font-size: 12px; }
.participant-lang { font-size: 12px; color: var(--bubble-other-accent); }

/* ===== Room: messages ===== */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.empty-state {
  margin: auto;
  text-align: center;
  max-width: 260px;
  padding: 20px 0;
}
.empty-title {
  font-family: var(--font-brand);
  font-weight: 500;
  font-size: 20px;
  color: var(--text-dim);
}
.empty-body { margin-top: 8px; font-size: 13px; color: var(--text-faint); }

.msg { display: flex; flex-direction: column; max-width: 86%; animation: msg-in 220ms var(--ease); }
.msg--self { align-self: flex-end; align-items: flex-end; }
.msg--other { align-self: flex-start; align-items: flex-start; }
.msg--followup { margin-top: -4px; }

.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 4px 3px;
}
.msg-name { font-size: 12px; font-weight: 600; color: var(--bubble-other-accent); }
.msg-lang { font-size: 11px; color: var(--text-faint); }

.bubble {
  border-radius: var(--r-card);
  padding: 9px 12px 7px;
  min-width: 90px;
}
.bubble--self {
  background: var(--bubble-self);
  color: var(--on-accent);
  border-bottom-right-radius: 4px;
}
.bubble--other {
  background: var(--bubble-other);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.bubble-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble-text.is-translating { color: var(--text-faint); font-style: italic; }
.bubble--self .bubble-text.is-translating { color: color-mix(in srgb, var(--on-accent) 60%, transparent); }

.bubble-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.msg-time { font-size: 10px; opacity: 0.6; }
.bubble--other .msg-time { color: var(--text-faint); opacity: 1; }

.msg-actions { display: inline-flex; gap: 2px; margin-left: auto; }
.bubble--other .icon-btn--ghost { color: var(--text-faint); }
.bubble--other .icon-btn--ghost:hover { color: var(--text); background: var(--surface-2); }

.bubble-toggle {
  font-size: 11px;
  color: var(--bubble-other-accent);
  padding: 1px 4px;
  border-radius: 6px;
}
.bubble-toggle:hover { background: var(--surface-2); }
/* Dim the original only when there IS a translation to go back to. Keyed on
   data-translated, not on data-showing alone: own messages and same-language
   ones are also "original", and dimming them put --text-dim on the accent
   background at 1.16:1 contrast — unreadable. */
.bubble[data-translated][data-showing="original"] .bubble-text { color: var(--text-dim); }

.bubble-badge {
  display: inline-block;
  margin-top: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--warn);
}

.msg-system {
  align-self: center;
  font-size: 12px;
  color: var(--text-faint);
  padding: 2px 10px;
  animation: msg-in 220ms var(--ease);
}

.new-msgs {
  position: absolute;
  bottom: 130px;
  right: 16px;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-weight: 700;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.4);
  z-index: 5;
}
.new-msgs:hover { border-color: var(--accent); }

.view--room { position: relative; }

/* ===== Download strip ===== */

.download-strip {
  flex: none;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Lobby twin: it sits inside the scrolling column instead of being pinned above
   the composer, so it reads as a card rather than a bottom bar. */
#lobby-download-strip {
  width: 100%;
  max-width: 340px;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: var(--r-card);
}

.dl-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}
.dl-row .icon { color: var(--accent); }
.dl-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-pct { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); }
.dl-bar {
  grid-column: 1 / -1;
  height: 3px;
  border-radius: 2px;
  background: var(--surface-2);
  overflow: hidden;
}
.dl-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 300ms var(--ease);
}

.dl-gesture {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--accent);
  padding: 7px 10px;
  border: 1px dashed var(--accent-deep);
  border-radius: var(--r-ctrl);
  text-align: left;
}
.dl-gesture:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }

/* ===== Composer ===== */

.composer {
  flex: none;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.previews { display: flex; flex-direction: column; gap: 6px; }
.previews:empty { display: none; }

.preview-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent-deep);
  border-radius: var(--r-ctrl);
  padding: 7px 10px;
  animation: msg-in 200ms var(--ease);
}
.preview-card.is-error { border-left-color: var(--warn); }

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.preview-lang {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
}
.preview-card.is-error .preview-lang { color: var(--warn); }
.preview-actions { display: inline-flex; gap: 2px; }
.preview-actions .icon-btn { min-width: 24px; height: 24px; color: var(--text-faint); }
.preview-actions .icon-btn:hover { color: var(--text); }

.preview-text {
  margin-top: 3px;
  font-size: 13px;
  color: var(--text);
  transition: opacity 150ms var(--ease);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.preview-card.is-stale .preview-text { opacity: 0.45; }

.composer-row { display: flex; gap: 8px; align-items: flex-end; }

#composer-input {
  resize: none;
  max-height: 120px;
  line-height: 1.45;
  overflow-y: auto;
  scrollbar-width: thin;
}

.send-btn {
  flex: none;
  width: 38px; height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-ctrl);
  background: var(--accent);
  color: var(--on-accent);
  transition: background 160ms var(--ease), transform 120ms var(--ease);
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.94); }
.send-btn .icon { width: 17px; height: 17px; }

/* ===== Toasts ===== */

.toasts {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 50;
  pointer-events: none;
  width: max-content;
  max-width: 90vw;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.45);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 200ms var(--ease), transform 200ms var(--ease);
}
.toast--in { opacity: 1; transform: translateY(0); }
.toast--ok { border-color: color-mix(in srgb, var(--ok) 50%, var(--border-strong)); }
.toast--warn { border-color: color-mix(in srgb, var(--warn) 55%, var(--border-strong)); }
.toast--danger { border-color: color-mix(in srgb, var(--danger) 55%, var(--border-strong)); }

/* ===== Scrollbars ===== */

.messages, .participants-panel, .view--lobby {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

/* ===== Animations ===== */

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes banner-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .messages { scroll-behavior: auto; }
}
