:root {
  --bg: #ffffff;
  --bg-elevated: #f5f5f7;
  --bg-elevated-2: #ebebed;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --border: #d2d2d7;
  --accent: #0071e3;
  --accent-contrast: #ffffff;
  --danger: #ff3b30;
  --success: #2fa84f;
  --radius: 16px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;
}

[data-theme="dark"] {
  --bg: #000000;
  --bg-elevated: #1c1c1e;
  --bg-elevated-2: #2c2c2e;
  --text: #f5f5f7;
  --text-secondary: #98989d;
  --border: #38383a;
  --accent: #0a84ff;
  --accent-contrast: #ffffff;
  --danger: #ff453a;
  --success: #32d74b;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background .2s ease, color .2s ease;
}

button { font-family: inherit; }

.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  z-index: 50;
}
.theme-toggle:hover { background: var(--bg-elevated-2); }

/* ───────────────── landing ───────────────── */
.landing {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
}
.landing h1 {
  font-size: clamp(40px, 8vw, 72px);
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0 0 8px;
}
.landing .tagline {
  color: var(--text-secondary);
  font-size: 19px;
  margin: 0 0 8px;
  max-width: 480px;
}
.accent-dot { color: var(--accent); }

.bg-glow {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(600px circle at 18% 20%, rgba(0,113,227,0.09), transparent 60%),
    radial-gradient(520px circle at 85% 78%, rgba(0,113,227,0.07), transparent 55%);
  animation: glowShift 14s ease-in-out infinite alternate;
}
[data-theme="dark"] .bg-glow {
  background:
    radial-gradient(600px circle at 18% 20%, rgba(10,132,255,0.18), transparent 60%),
    radial-gradient(520px circle at 85% 78%, rgba(10,132,255,0.13), transparent 55%);
}
@keyframes glowShift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(-3%, 3%) scale(1.06); }
}

.demo-window {
  margin: 32px 0 40px;
  width: 100%;
  max-width: 560px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  text-align: left;
  box-shadow: 0 24px 60px -24px rgba(0,0,0,0.28);
}
[data-theme="dark"] .demo-window { box-shadow: 0 24px 60px -24px rgba(0,0,0,0.7); }
.demo-titlebar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated-2);
}
.demo-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--border); }
.demo-title {
  margin-left: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--mono);
}
.demo-code {
  margin: 0;
  padding: 20px 22px;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.7;
  min-height: 132px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}
.demo-code .tok-kw { color: var(--accent); font-weight: 600; }
.demo-code .tok-str { color: var(--text-secondary); }
.demo-code .tok-b { color: #ff9f0a; }
.demo-caret {
  display: inline-block;
  width: 2px;
  height: 15px;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: caretBlink 1s step-start infinite;
}
.demo-caret.demo-caret-b { background: #ff9f0a; }
@keyframes caretBlink { 50% { opacity: 0; } }
.demo-typists {
  display: flex;
  gap: 8px;
  padding: 0 22px 16px;
  min-height: 20px;
}
.demo-typist {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  animation: fadeIn .3s ease;
}
.demo-typist .dot { width: 7px; height: 7px; border-radius: 50%; }
.demo-typist .dot { animation: caretBlink 1.1s ease-in-out infinite; }

.actions {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}
.btn {
  appearance: none;
  border: none;
  border-radius: 980px;
  padding: 14px 28px;
  font-size: 17px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: transform .1s ease, opacity .15s ease, background .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { opacity: .88; }
.btn-secondary { background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-elevated-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }

.panel {
  margin-top: 28px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 420px;
  text-align: left;
  animation: fadeIn .18s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: translateY(0);} }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}
.field input, .field select {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
}
.field input.code-input {
  letter-spacing: .3em;
  font-family: var(--mono);
  text-align: center;
  font-size: 22px;
}

.hint { font-size: 13px; color: var(--text-secondary); margin-top: 10px; }
.error-text { color: var(--danger); font-size: 14px; margin-top: 10px; }

.status-box {
  margin-top: 28px;
  padding: 28px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  max-width: 420px;
}
.spinner {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────────────── room ───────────────── */
.room {
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.room-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}
.room-code {
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: .1em;
  font-size: 15px;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
}
.room-lang {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 6px 10px;
}
.participants {
  display: flex;
  gap: 6px;
  margin-left: auto;
  align-items: center;
}
.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  border: 2px solid var(--bg-elevated);
  margin-left: -8px;
  position: relative;
}
.avatar:first-child { margin-left: 0; }
.avatar[title]:hover::after {
  content: attr(title);
  position: absolute;
  top: 34px; left: 50%; transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  white-space: nowrap;
  z-index: 10;
}
.header-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg-elevated-2); }

.join-requests {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  display: flex;
  flex-direction: column-reverse;
  gap: 12px;
  pointer-events: none;
}
.join-card {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(245, 245, 247, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 12px 36px -12px rgba(0, 0, 0, 0.35);
  animation: cardIn .28s cubic-bezier(.2,.8,.2,1);
}
[data-theme="dark"] .join-card {
  background: rgba(28, 28, 30, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.join-card.leaving { animation: cardOut .18s ease forwards; }
@keyframes cardIn {
  from { opacity: 0; transform: translateY(16px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes cardOut {
  to { opacity: 0; transform: translateY(8px) scale(.96); }
}
.join-card-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
}
.join-card-text { flex: 1; min-width: 0; }
.join-card-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.join-card-sub { font-size: 12px; color: var(--text-secondary); margin-top: 1px; }
.join-card-actions { display: flex; gap: 8px; flex-shrink: 0; }
.join-card-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  transition: transform .1s ease, opacity .15s ease;
}
.join-card-btn:active { transform: scale(.9); }
.join-card-btn.accept { background: var(--success); color: #fff; }
.join-card-btn.decline { background: rgba(142,142,147,0.2); color: var(--text); }
[data-theme="dark"] .join-card-btn.decline { background: rgba(142,142,147,0.25); }

.editor-wrap { flex: 1; min-height: 0; }
.cm-editor { height: 100%; font-size: 14px; }
.cm-scroller { font-family: var(--mono) !important; }

.overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 20px;
  z-index: 100;
}
.overlay > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: fadeIn .25s ease;
}
.overlay h2 { font-size: 26px; margin: 0; letter-spacing: -0.01em; }
.overlay p { color: var(--text-secondary); margin: 0; max-width: 380px; line-height: 1.5; }
.hidden { display: none !important; }
