:root {
  --bg: #0f1419;
  --panel: #1a212b;
  --panel-2: #222c38;
  --border: #2d3845;
  --text: #e6edf3;
  --muted: #8b97a5;
  --accent: #4f9cf9;
  --accent-deep: #2f6fd0;
  --me: #2f6fd0;
  --them: #222c38;
  --error: #f0883e;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* ---------- Cards / forms (join + settings) ---------- */

#join-screen {
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card h1,
.card h2 {
  margin: 0;
  font-size: 1.6rem;
}

.subtitle {
  margin: -0.5rem 0 0.5rem;
  color: var(--muted);
}

.card label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.hint {
  font-size: 0.72rem;
  color: var(--muted);
  opacity: 0.85;
  line-height: 1.3;
}

.join-error {
  margin: 0;
  color: var(--error);
  font-size: 0.85rem;
}

.notify-group {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0.85rem;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.notify-group legend {
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0 0.4rem;
}

input[type="text"],
input[type="password"],
textarea,
select {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  outline: none;
}

select {
  cursor: pointer;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 2px),
    calc(100% - 13px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2rem;
}

input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
}

.checkbox {
  flex-direction: row !important;
  align-items: center;
  gap: 0.55rem !important;
  color: var(--text) !important;
  font-size: 0.95rem !important;
  cursor: pointer;
}

.checkbox input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
}

button {
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent-deep);
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  cursor: pointer;
}

button:hover {
  background: var(--accent);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 0.35rem 0.55rem;
  font-size: 1rem;
  line-height: 1;
}

.icon-btn:hover {
  background: var(--panel-2);
}

/* ---------- Settings modal ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 50;
}

.settings-card {
  max-height: 90vh;
  overflow-y: auto;
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ---------- Chat screen ---------- */

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.room-info {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.status {
  font-size: 0.8rem;
  color: var(--muted);
}

.status.connected {
  color: #56d364;
}

.status.disconnected {
  color: var(--error);
}

.members {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
}

.member-chip {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  color: var(--muted);
}

.member-chip .tag {
  color: var(--accent);
  font-weight: 600;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.msg {
  max-width: min(680px, 80%);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.msg.me {
  align-self: flex-end;
  align-items: flex-end;
}

.msg .meta {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0 0.3rem;
}

.bubble {
  background: var(--them);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
}

.msg.me .bubble {
  background: var(--me);
  border-color: var(--accent-deep);
}

.bubble .original {
  font-size: 1rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble .translated {
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px dashed rgba(255, 255, 255, 0.18);
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.me .bubble .translated {
  color: rgba(255, 255, 255, 0.82);
}

.lang-tag {
  font-size: 0.7rem;
  font-weight: 700;
  opacity: 0.7;
  margin-right: 0.35rem;
}

/* Optimistic "sending…" placeholder */
.msg.pending .bubble {
  opacity: 0.7;
}

.pending-dots {
  display: flex;
  gap: 4px;
  margin-top: 0.45rem;
}

.pending-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  animation: pending-blink 1.2s infinite ease-in-out;
}

.pending-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.pending-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes pending-blink {
  0%,
  70%,
  100% {
    opacity: 0.25;
  }
  35% {
    opacity: 0.95;
  }
}

.translated.error {
  color: var(--error);
  font-style: italic;
  border-top-color: rgba(240, 136, 62, 0.4);
}

.system {
  align-self: center;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--panel);
  border-radius: 999px;
  padding: 0.2rem 0.8rem;
}

.typing-row {
  min-height: 1.2rem;
  padding: 0 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem 1rem;
  background: var(--panel);
  border-top: 1px solid var(--border);
}

.chat-form textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
}

.chat-form button {
  align-self: flex-end;
}
