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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3349;
  --accent: #6c63ff;
  --accent-hover: #8078ff;
  --danger: #e05252;
  --success: #4caf7d;
  --warning: #e0a952;
  --text: #e8e9f0;
  --text-muted: #7a7f9a;
  --radius: 10px;
  --font: 'Inter', system-ui, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Layout ── */
.app { width: 100%; max-width: 760px; padding: 24px 16px; }

.screen { display: none; flex-direction: column; gap: 24px; }
.screen.active { display: flex; }

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.card h2 { font-size: 1.1rem; margin-bottom: 16px; color: var(--text); }

/* ── Header ── */
header {
  width: 100%;
  max-width: 760px;
  padding: 20px 16px 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.5px; }
.logo span { color: var(--accent); }
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ── Forms ── */
label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
input[type=text] {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  padding: 10px 14px;
  outline: none;
  transition: border-color .15s;
}
input[type=text]:focus { border-color: var(--accent); }

textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
  font-family: monospace;
  padding: 10px 12px;
  resize: vertical;
  outline: none;
  min-height: 90px;
  transition: border-color .15s;
}
textarea:focus { border-color: var(--accent); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #e86868; }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
.btn-success { background: var(--success); color: #fff; }
.btn-full { width: 100%; justify-content: center; }

/* ── Role selector ── */
.role-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.role-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  text-align: center;
}
.role-card:hover { border-color: var(--accent); background: var(--surface2); }
.role-card.selected { border-color: var(--accent); background: var(--surface2); }
.role-card .icon { font-size: 2rem; margin-bottom: 8px; }
.role-card .title { font-weight: 600; font-size: 15px; }
.role-card .desc { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── Participants ── */
.participants { display: flex; flex-direction: column; gap: 8px; }
.participant {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface2);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.participant .avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.participant .name { font-weight: 500; flex: 1; }
.participant .status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
}
.status-connected { background: rgba(76,175,125,.15); color: var(--success); }
.status-waiting   { background: rgba(224,169,82,.15); color: var(--warning); }
.status-recording { background: rgba(224,82,82,.15); color: var(--danger); }

/* ── Recording controls ── */
.rec-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.rec-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.rec-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
}
.rec-dot.active {
  background: var(--danger);
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}
#rec-timer { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ── Chat ── */
.chat-box {
  display: flex;
  flex-direction: column;
  height: 240px;
}
#chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.chat-msg { font-size: 13px; line-height: 1.4; }
.chat-msg .from { font-weight: 600; color: var(--accent); margin-right: 6px; }
.chat-msg.system { color: var(--text-muted); font-style: italic; }
.chat-input-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.chat-input-row input { flex: 1; }
.chat-input-row .btn { flex-shrink: 0; padding: 10px 14px; }

/* ── SDP manual ── */
.sdp-steps { display: flex; flex-direction: column; gap: 16px; }
.sdp-step { display: flex; flex-direction: column; gap: 6px; }
.sdp-step-label {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.step-num {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}
.copy-row { display: flex; gap: 8px; }
.copy-row textarea { flex: 1; }

/* ── Connection code ── */
.room-code {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 6px;
  text-align: center;
  padding: 20px;
  background: var(--surface2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color .15s;
}
.room-code:hover { border-color: var(--accent); }
.room-code-hint { font-size: 12px; color: var(--text-muted); text-align: center; }

/* ── Progress bar ── */
.progress-wrap { display: flex; flex-direction: column; gap: 6px; }
.progress-label { font-size: 12px; color: var(--text-muted); display: flex; justify-content: space-between; }
.progress-bar-bg {
  background: var(--surface2);
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width .2s;
}

/* ── Download list ── */
.track-list { display: flex; flex-direction: column; gap: 8px; }
.track-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface2);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.track-item .track-name { flex: 1; font-weight: 500; font-size: 14px; }
.track-item .track-size { font-size: 12px; color: var(--text-muted); }

/* ── Alerts ── */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert-info    { background: rgba(108,99,255,.1); border: 1px solid rgba(108,99,255,.3); }
.alert-warning { background: rgba(224,169,82,.1); border: 1px solid rgba(224,169,82,.3); color: var(--warning); }
.alert-success { background: rgba(76,175,125,.1); border: 1px solid rgba(76,175,125,.3); color: var(--success); }

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

/* ── Share link ── */
.share-link-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.share-link-row input {
  flex: 1;
  font-family: monospace;
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Studio track rows ── */
.studio-track {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface2);
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
}
.studio-track:last-child { margin-bottom: 0; }
.studio-track-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.studio-track-name {
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.studio-track-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.track-size-label { font-size: 12px; color: var(--text-muted); }

.track-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
}
.track-badge-received  { background: rgba(76,175,125,.15); color: var(--success); }
.track-badge-receiving { background: rgba(224,169,82,.15);  color: var(--warning); }
.track-badge-pending   { background: rgba(122,127,154,.12); color: var(--text-muted); }

/* ── Recordings library ── */
.recordings-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.recordings-header h2 { margin-bottom: 0; }
.recordings-count {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.recordings-empty { font-size: 13px; color: var(--text-muted); }

.rec-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.rec-table thead th {
  text-align: left;
  padding: 8px 12px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
}
.rec-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.rec-table tbody tr:last-child { border-bottom: none; }
.rec-table tbody tr:hover { background: var(--surface2); }
.rec-table td { padding: 10px 12px; vertical-align: middle; }
.rec-col-name { font-weight: 500; word-break: break-all; }
.rec-col-date { color: var(--text-muted); white-space: nowrap; }
.rec-col-size { color: var(--text-muted); white-space: nowrap; }
.rec-col-actions { text-align: right; white-space: nowrap; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-delete:hover { border-color: var(--danger); color: var(--danger); }
.delete-confirm {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--danger);
  white-space: nowrap;
}

/* ── Footer ── */
footer {
  width: 100%;
  text-align: center;
  padding: 24px 16px;
  font-size: 11px;
  color: var(--text-muted);
  opacity: .5;
}

/* ── Misc ── */
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.flex-1 { flex: 1; }
small { font-size: 12px; color: var(--text-muted); }
.hidden { display: none !important; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
