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

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --success: #3fb950;
  --warning: #d29922;
  --danger: #f85149;
  --radius: 6px;
  --mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
  --ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  font-size: 14px;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── TOPBAR ── */
.topbar {
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  flex-shrink: 0;
}

.brand { font-weight: 700; font-size: 15px; color: var(--accent); white-space: nowrap; margin-right: 6px; }

.room-controls { display: flex; gap: 7px; align-items: center; flex: 1; }

.room-controls input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 9px;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--mono);
  outline: none;
  transition: border-color 0.15s;
}
.room-controls input:focus { border-color: var(--accent); }
#roomCode { width: 120px; text-transform: uppercase; letter-spacing: 2px; }
#roomPassword { width: 130px; }

.status { display: flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
.status-dot.online  { background: var(--success); }
.status-dot.syncing { background: var(--warning); animation: pulse 1s infinite; }
.status-dot.offline { background: var(--text-muted); }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }
@keyframes sweep { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* ── PANEL PROGRESS BAR ── */
.panel-progress {
  height: 2px;
  flex-shrink: 0;
  background: linear-gradient(90deg, transparent 0%, var(--accent) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: sweep 1.2s linear infinite;
}
.panel-progress.hidden { display: none; }

/* ── PANELS ── */
.panels {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 1px;
  background: var(--border);
  min-height: 0;
}

.panel { flex: 1; display: flex; flex-direction: column; background: var(--bg); overflow: hidden; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.panel-actions { display: flex; align-items: center; gap: 7px; }

.badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-family: var(--mono);
  white-space: nowrap;
}
.badge.detected { border-color: var(--accent); color: var(--accent); }
.badge.synced   { border-color: var(--success); color: var(--success); }

textarea {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: none;
  outline: none;
  resize: none;
  padding: 12px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.65;
  tab-size: 2;
  width: 100%;
}
textarea::placeholder { color: var(--text-muted); opacity: 0.5; }
#outputCode { color: #adbac7; }

.panel-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.hint {
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.7;
  white-space: nowrap;
}

.spacer { flex: 1; }

/* ── PANEL FOOTER (connection controls) ── */
.panel-footer {
  border-top: 1px solid var(--border);
  border-bottom: none;
}

.panel-toolbar input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 9px;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--mono);
  outline: none;
  transition: border-color 0.15s;
}
.panel-toolbar input:focus { border-color: var(--accent); }
#roomCode { width: 110px; text-transform: uppercase; letter-spacing: 2px; }
#roomPassword { width: 168px; }

/* ── AI PANEL ── */
.ai-panel {
  background: var(--surface);
  border-top: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.ai-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.ai-body { display: flex; gap: 10px; padding: 10px 14px; align-items: stretch; }

#aiCustomPrompt {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-family: var(--ui);
  font-size: 13px;
  resize: none;
  height: 60px;
  max-height: 80px;
}
#aiCustomPrompt:focus { border-color: var(--accent); outline: none; }

.ai-actions { display: flex; flex-direction: column; gap: 5px; justify-content: center; }

/* ── BUTTONS ── */
button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 11px;
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  font-family: var(--ui);
  transition: background 0.12s, border-color 0.12s;
}
button:hover { background: var(--border); }
button:disabled { opacity: 0.55; cursor: not-allowed; pointer-events: none; }
button:active { opacity: 0.8; }

button.primary { background: var(--accent); border-color: var(--accent); color: #0d1117; font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }

button.success { background: var(--success); border-color: var(--success); color: #0d1117; font-weight: 600; }

button.toggle { color: var(--text-muted); border-color: var(--border); }
button.toggle.active { color: var(--accent); border-color: var(--accent); background: rgba(88,166,255,.08); }

.toolbar-sep { width: 1px; height: 18px; background: var(--border); flex-shrink: 0; margin: 0 2px; }

button.ai-btn { font-size: 12px; padding: 6px 12px; }
button.claude { background: #cc785c18; border-color: #cc785c80; color: #cc785c; }
button.claude:hover { background: #cc785c30; }
button.gpt   { background: #74aa9c18; border-color: #74aa9c80; color: #74aa9c; }
button.gpt:hover { background: #74aa9c30; }

select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 7px;
  border-radius: var(--radius);
  font-size: 12px;
  font-family: var(--ui);
  cursor: pointer;
  outline: none;
}
select:focus { border-color: var(--accent); }

/* ── MODAL (encrypted output) ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  width: 600px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-title { font-weight: 700; font-size: 14px; }
.modal-desc  { font-size: 12px; color: var(--text-muted); }
.modal-code  { font-family: var(--mono); font-size: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; word-break: break-all; max-height: 200px; overflow-y: auto; user-select: all; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; }

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
  z-index: 300;
  transition: opacity 0.25s;
  pointer-events: none;
}
.toast.hidden  { opacity: 0; }
.toast.success { border-color: var(--success); color: var(--success); }
.toast.error   { border-color: var(--danger);  color: var(--danger);  }
.toast.warning { border-color: var(--warning); color: var(--warning); }

/* ── ANON REPORT ── */
.anon-report {
  position: fixed;
  top: 60px; right: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 12px;
  max-width: 280px;
  z-index: 150;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
  transition: opacity 0.3s;
}
.anon-report.hidden { opacity: 0; pointer-events: none; }
.anon-report h4 { font-size: 11px; font-weight: 700; letter-spacing: 0.8px; color: var(--text-muted); margin-bottom: 8px; }
.anon-item { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border-bottom: 1px solid var(--border); }
.anon-item:last-child { border-bottom: none; }
.anon-type  { color: var(--warning); font-family: var(--mono); font-size: 11px; }
.anon-orig  { color: var(--text-muted); font-family: var(--mono); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }

/* ── MOBILE ── */
@media (max-width: 768px) {
  body { height: auto; min-height: 100vh; overflow-y: auto; }

  .panels {
    flex-direction: column;
    overflow: visible;
    background: none;
    gap: 0;
  }

  .panel { overflow: visible; }

  textarea {
    height: 220px;
    flex: none;
  }

  .panel-toolbar {
    flex-wrap: wrap;
    gap: 5px;
  }

  .panel-toolbar input { flex: 1; min-width: 80px; }
  #roomCode    { width: auto; min-width: 90px; }
  #roomPassword { width: auto; flex: 1; }

  .toolbar-sep { display: none; }

  .ai-body { flex-direction: column; }
}
