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

:root {
  --bg: #f8f8f6;
  --surface: #ffffff;
  --border: #e4e4e1;
  --text: #111111;
  --muted: #888884;
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'SF Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;

  --s0-color: #4f46e5; --s0-bg: rgba(79,70,229,0.07);  --s0-line: rgba(79,70,229,0.38);
  --s1-color: #0891b2; --s1-bg: rgba(8,145,178,0.07);  --s1-line: rgba(8,145,178,0.38);
  --s2-color: #c2410c; --s2-bg: rgba(194,65,12,0.07);  --s2-line: rgba(194,65,12,0.38);
}

html, body { height: 100%; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; }

body { display: flex; flex-direction: column; height: 100dvh; }

/* ── Header ─────────────────────────────── */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 56px; border-bottom: 1px solid var(--border);
  background: var(--surface); flex-shrink: 0; gap: 16px;
}

.logo {
  font-size: 15px; font-weight: 600; letter-spacing: -0.01em;
  color: var(--text); display: flex; align-items: center; gap: 7px;
  text-decoration: none; flex-shrink: 0;
}
.logo-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text); }

.conn-area { display: flex; align-items: center; overflow: hidden; }
.state-panel { align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-family: var(--font);
  font-size: 13px; font-weight: 500; cursor: pointer; transition: background 0.1s;
  white-space: nowrap; user-select: none; flex-shrink: 0;
}
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--text); color: #fff; border-color: var(--text); }
.btn-primary:hover { opacity: 0.82; background: var(--text); }

.join-group { display: flex; align-items: center; gap: 6px; }

.code-input {
  width: 96px; padding: 6px 10px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface);
  font-family: var(--mono); font-size: 14px; letter-spacing: 0.12em;
  color: var(--text); outline: none; text-align: center;
}
.code-input:focus { border-color: var(--text); }
.code-input::placeholder { color: var(--muted); letter-spacing: 0; font-family: var(--font); }

.session-info { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.muted { color: var(--muted); }
.session-code {
  font-family: var(--mono); font-size: 15px; font-weight: 600;
  letter-spacing: 0.15em; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 10px;
}
.session-code.small { font-size: 13px; letter-spacing: 0.1em; padding: 3px 8px; }

.copy-btn { font-size: 12px; padding: 4px 10px; color: var(--muted); }
.copy-btn:hover { color: var(--text); }
.end-btn { color: var(--muted); }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border); flex-shrink: 0; }
.status.waiting .status-dot  { background: #f59e0b; }
.status.connected .status-dot { background: #16a34a; }

/* ── Legend ─────────────────────────────── */
.legend { display: flex; align-items: center; gap: 6px; }

.legend-chip {
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; padding: 3px 9px; border-radius: 4px;
  border: 1px solid transparent; display: flex; align-items: center; gap: 5px;
}
.legend-chip::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; flex-shrink: 0;
}

.legend-chip.slot-0 { color: var(--s0-color); background: var(--s0-bg); border-color: var(--s0-line); }
.legend-chip.slot-1 { color: var(--s1-color); background: var(--s1-bg); border-color: var(--s1-line); }
.legend-chip.slot-2 { color: var(--s2-color); background: var(--s2-bg); border-color: var(--s2-line); }
.legend-chip.is-you { font-style: italic; }

/* ── Main ───────────────────────────────── */
main { flex: 1; display: flex; overflow: hidden; position: relative; background: var(--surface); }

.idle-overlay {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; background: var(--surface); z-index: 1; pointer-events: none;
}
.idle-label { font-size: 13px; color: var(--muted); text-align: center; line-height: 1.8; }

/* ── Editor ─────────────────────────────── */
.editor {
  flex: 1; padding: 32px 48px;
  font-family: var(--mono); font-size: 14px; line-height: 1.85;
  color: var(--text); outline: none; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word;
  caret-color: var(--text); cursor: text;
}
.editor[contenteditable="false"] { cursor: default; }
.editor:empty::before {
  content: attr(data-placeholder); color: var(--muted);
  font-family: var(--font); pointer-events: none;
}

/* Per-slot segment highlights */
.seg-0 { background: var(--s0-bg); border-bottom: 1.5px solid var(--s0-line); border-radius: 1px; }
.seg-1 { background: var(--s1-bg); border-bottom: 1.5px solid var(--s1-line); border-radius: 1px; }
.seg-2 { background: var(--s2-bg); border-bottom: 1.5px solid var(--s2-line); border-radius: 1px; }

/* ── Footer ─────────────────────────────── */
footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 36px; border-top: 1px solid var(--border);
  background: var(--surface); flex-shrink: 0;
}
.footer-left, .footer-right { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 12px; }

/* ── Floating typing bubbles ────────────── */
.typing-bubbles {
  position: absolute;
  bottom: 20px;
  left: 28px;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
  z-index: 10;
}

.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 7px 14px 7px 10px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(0,0,0,0.07);
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.05);
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  opacity: 0;
  transform: translateY(8px) scale(0.96);
  transition: opacity 0.22s ease, transform 0.22s ease;
  will-change: opacity, transform;
}

.typing-bubble.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.typing-bubble .bubble-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.typing-bubble .bubble-label {
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.01em;
}

/* Bouncing dots */
.typing-bubble .dots {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-left: 2px;
}

.typing-bubble .dots span {
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  animation: dotBounce 1.1s ease-in-out infinite;
}

.typing-bubble .dots span:nth-child(2) { animation-delay: 0.18s; }
.typing-bubble .dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes dotBounce {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.35; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

/* Slot colors for bubble dot + dots */
.typing-bubble.slot-0 .bubble-dot,
.typing-bubble.slot-0 .dots span { background: var(--s0-color); }

.typing-bubble.slot-1 .bubble-dot,
.typing-bubble.slot-1 .dots span { background: var(--s1-color); }

.typing-bubble.slot-2 .bubble-dot,
.typing-bubble.slot-2 .dots span { background: var(--s2-color); }

.btn-ghost {
  background: none; border: none; cursor: pointer;
  font-family: var(--font); font-size: 12px; color: var(--muted);
  padding: 0; transition: color 0.1s;
}
.btn-ghost:hover { color: var(--text); }

/* ── Toast ──────────────────────────────── */
.toast-wrap {
  position: fixed; bottom: 52px; left: 50%; transform: translateX(-50%);
  z-index: 100; pointer-events: none;
}
.toast {
  background: var(--text); color: #fff; font-size: 13px;
  padding: 8px 16px; border-radius: var(--radius);
  opacity: 0; transform: translateY(6px);
  transition: opacity 0.18s, transform 0.18s; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ── Responsive ─────────────────────────── */
@media (max-width: 640px) {
  header { padding: 0 14px; flex-wrap: wrap; height: auto; padding-top: 10px; padding-bottom: 10px; }
  .editor { padding: 20px 18px; font-size: 16px; } /* 16px prevents iOS auto-zoom on focus */
  footer { padding: 0 14px; flex-wrap: wrap; height: auto; min-height: 36px; gap: 4px; }
  .footer-brand { display: none; }
}
