:root {
  --bg: #0f0f0f;
  --bg-card: #1a1a1a;
  --bg-elevated: #242424;
  --bg-input: #1e1e1e;
  --text: #e8e8e8;
  --text-muted: #888;
  --text-dim: #555;
  --primary: #6c5ce7;
  --primary-hover: #7c6ef7;
  --primary-glow: rgba(108, 92, 231, 0.3);
  --secondary: #2d2d2d;
  --secondary-hover: #3a3a3a;
  --danger: #e74c3c;
  --success: #2ecc71;
  --border: #2a2a2a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

[data-theme="light"] {
  --bg: #f5f5f7;
  --bg-card: #fff;
  --bg-elevated: #fff;
  --bg-input: #f0f0f2;
  --text: #1a1a1a;
  --text-muted: #777;
  --text-dim: #aaa;
  --primary: #6c5ce7;
  --primary-hover: #5a4bd6;
  --primary-glow: rgba(108, 92, 231, 0.15);
  --secondary: #e8e8ea;
  --secondary-hover: #ddd;
  --border: #e0e0e0;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 600px;
  margin: 0 auto;
  padding: 0 16px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon { font-size: 24px; }

.logo h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.icon-btn:hover { color: var(--text); background: var(--bg-elevated); }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  transition: background 0.3s;
}

.status-dot.connected { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-dot.connecting { background: #f39c12; animation: pulse 1.5s infinite; }
.status-dot.disconnected { background: var(--text-dim); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Views */
.view { display: none; flex: 1; padding: 24px 0; }
.view.active { display: flex; flex-direction: column; }

/* Hero */
.hero { text-align: center; padding: 40px 0 32px; }

.tagline {
  font-size: 18px;
  color: var(--text-muted);
  font-weight: 400;
}

/* Cards */
.action-cards {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  color: var(--text);
}

.card:hover { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary-glow); }
.card:active { transform: scale(0.98); }

.card-icon { font-size: 36px; }
.card-title { font-size: 18px; font-weight: 600; }
.card-desc { font-size: 13px; color: var(--text-muted); line-height: 1.4; }

/* Room Info */
.room-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px 0;
}

.room-label { color: var(--text-muted); font-size: 14px; }

.room-code {
  font-family: var(--mono);
  font-size: 48px;
  font-weight: 700;
  letter-spacing: 8px;
  color: var(--primary);
  user-select: all;
  text-align: center;
}

.qr-container {
  background: #fff;
  padding: 16px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-container canvas { display: block; }

.room-url {
  font-size: 12px;
  color: var(--text-dim);
  word-break: break-all;
  text-align: center;
}

/* Waiting */
.waiting-animation {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 40px 0;
  color: var(--text-muted);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Join Form */
.join-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 40px 0;
}

.join-label { color: var(--text-muted); font-size: 16px; }

.code-input-group { position: relative; }

.code-input {
  font-family: var(--mono);
  font-size: 40px;
  font-weight: 700;
  letter-spacing: 10px;
  text-align: center;
  width: 280px;
  padding: 16px;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.code-input:focus { border-color: var(--primary); }
.code-input::placeholder { color: var(--text-dim); letter-spacing: 14px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
  color: var(--text);
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.97); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary { background: var(--secondary); }
.btn-secondary:hover:not(:disabled) { background: var(--secondary-hover); }

.btn-ghost { background: none; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }

.btn-small { padding: 8px 14px; font-size: 13px; }

.error-text { color: var(--danger); font-size: 13px; text-align: center; }

/* Connected View */
.connected-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 16px;
}

.connected-header h2 { font-size: 16px; font-weight: 600; color: var(--text-muted); }

/* Snap Area */
.snap-area { margin-bottom: 20px; }

.snap-input-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.snap-input {
  width: 100%;
  padding: 16px;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  outline: none;
  min-height: 100px;
}

.snap-input::placeholder { color: var(--text-dim); }

.snap-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}

.char-count { font-size: 12px; color: var(--text-dim); }

.btn-snap {
  padding: 10px 24px;
  font-size: 16px;
}

.snap-icon { font-size: 18px; }

/* Paste Area */
.paste-area {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.paste-display {
  min-height: 80px;
  max-height: 300px;
  overflow-y: auto;
  padding: 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.5;
}

.paste-display.has-text { color: var(--text); }
.paste-placeholder { color: var(--text-dim); font-style: italic; }

.paste-area .btn { width: 100%; }

/* History */
.history-section { margin-top: auto; padding-top: 16px; }

.history-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  border-top: 1px solid var(--border);
}

.history-toggle:hover { color: var(--text); }

.history-chevron {
  transition: transform 0.2s;
  font-size: 12px;
}

.history-chevron.open { transform: rotate(180deg); }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 24px;
}

.history-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

.history-item:hover { border-color: var(--primary); }

.history-item-text {
  flex: 1;
  font-size: 13px;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.history-item-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.history-item-dir {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.history-item-time {
  font-size: 11px;
  color: var(--text-dim);
}

.history-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 16px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--success);
  color: #fff;
  padding: 10px 24px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  transition: all 0.3s;
  z-index: 1000;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.hidden { display: none !important; }

/* Mobile Optimizations */
@media (max-width: 480px) {
  .room-code { font-size: 36px; letter-spacing: 6px; }
  .code-input { font-size: 32px; width: 240px; letter-spacing: 8px; }
  .hero { padding: 24px 0 20px; }
  .tagline { font-size: 16px; }
  .card { padding: 20px; }
}

/* Desktop Wide */
@media (min-width: 768px) {
  #app { max-width: 640px; padding: 0 24px; }
  .room-code { font-size: 56px; }
}
