:root {
  --bg-base: #0b0f17;
  --bg-surface: #121826;
  --bg-elevated: #1a2233;
  --bg-hover: #232d42;
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text-primary: #e6edf7;
  --text-secondary: #9aa5b9;
  --text-muted: #6b7489;
  --accent-teal: #4ec9b0;
  --accent-blue: #3b82f6;
  --accent-blue-hover: #2563eb;
  --accent-danger: #ef4444;
  --brand-gradient: linear-gradient(135deg, #3b82f6 0%, #4ec9b0 100%);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  height: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: radial-gradient(1200px 600px at 0% -10%, rgba(59, 130, 246, 0.08), transparent 60%),
              radial-gradient(900px 500px at 100% 110%, rgba(78, 201, 176, 0.06), transparent 60%),
              var(--bg-base);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---------- Header ---------- */
.header {
  background: rgba(18, 24, 38, 0.75);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  gap: 16px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.brand-logo {
  height: 30px;
  width: auto;
  max-width: 120px;
  display: block;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
}

.room-id {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 6px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

#roomName {
  color: var(--accent-teal);
  font-weight: 600;
  margin-left: 4px;
}

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

.user-count {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.user-count #userCount {
  color: var(--text-primary);
  font-weight: 600;
}

.user-icon {
  font-size: 15px;
}

/* ---------- Form controls ---------- */
.language-select {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  padding: 8px 30px 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa5b9' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color var(--transition), background-color var(--transition);
}

.language-select:hover,
.language-select:focus {
  background-color: var(--bg-hover);
  border-color: var(--border-strong);
}

.language-select option {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* ---------- Buttons ---------- */
.btn {
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color var(--transition), border-color var(--transition), transform var(--transition);
  line-height: 1;
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent-blue);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--accent-blue-hover);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn-share {
  background: var(--brand-gradient);
  color: #0b0f17;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.btn-share:hover {
  filter: brightness(1.08);
}

.share-icon,
.upload-icon {
  font-size: 15px;
  line-height: 1;
}

/* ---------- Main layout ---------- */
.main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.editor-container {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: var(--bg-base);
}

#editor {
  width: 100%;
  height: 100%;
}

.CodeMirror {
  height: 100% !important;
  font-size: 15px;
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', 'Monaco', monospace;
  line-height: 1.65;
  background: transparent !important;
}

.CodeMirror-gutters {
  background: transparent !important;
  border-right: 1px solid var(--border-subtle) !important;
}

/* ---------- Footer ---------- */
.footer {
  background: rgba(18, 24, 38, 0.75);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  padding: 10px 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  color: var(--text-secondary);
  font-weight: 500;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-teal);
}

.status-indicator.connected {
  background: var(--accent-teal);
  box-shadow: 0 0 0 3px rgba(78, 201, 176, 0.18);
  animation: pulse 2s ease-in-out infinite;
}

.status-indicator.disconnected {
  background: var(--accent-danger);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
  animation: none;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(78, 201, 176, 0.18); }
  50% { box-shadow: 0 0 0 5px rgba(78, 201, 176, 0.08); }
}

.info {
  color: var(--text-muted);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 72px;
  right: 20px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 240ms ease, transform 240ms ease;
  z-index: 1000;
  will-change: opacity, transform;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 320px;
  background: rgba(18, 24, 38, 0.6);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.sidebar-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px 8px;
  font-size: 14px;
  border-radius: var(--radius-sm);
  transition: background-color var(--transition), color var(--transition);
  line-height: 1;
}

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

.file-upload-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.btn-upload {
  width: 100%;
  padding: 10px 16px;
  background: var(--brand-gradient);
  color: #0b0f17;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: filter var(--transition), transform var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--shadow-sm);
}

.btn-upload:hover {
  filter: brightness(1.08);
}

.btn-upload:active {
  transform: translateY(1px);
}

.upload-progress {
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 12px;
  color: var(--accent-teal);
  font-weight: 500;
}

.files-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  contain: layout style;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 20px;
  font-size: 13px;
}

.file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  margin-bottom: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  transition: background-color var(--transition), border-color var(--transition), transform var(--transition);
}

.file-item:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.file-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.file-icon {
  font-size: 22px;
  flex-shrink: 0;
}

.file-details {
  flex: 1;
  min-width: 0;
}

.file-name {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.file-size {
  font-size: 11px;
  color: var(--text-muted);
}

.file-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.file-actions .btn-icon {
  padding: 6px 7px;
  font-size: 14px;
}

.download-btn:hover {
  background: rgba(59, 130, 246, 0.16) !important;
  color: var(--accent-blue) !important;
}

.delete-btn:hover {
  background: rgba(239, 68, 68, 0.14) !important;
  color: var(--accent-danger) !important;
}

/* ---------- Scrollbars ---------- */
.files-list::-webkit-scrollbar,
.CodeMirror-vscrollbar::-webkit-scrollbar {
  width: 8px;
}

.files-list::-webkit-scrollbar-track,
.CodeMirror-vscrollbar::-webkit-scrollbar-track {
  background: transparent;
}

.files-list::-webkit-scrollbar-thumb,
.CodeMirror-vscrollbar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
}

.files-list::-webkit-scrollbar-thumb:hover,
.CodeMirror-vscrollbar::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.16);
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
  }

  .header-left,
  .header-right {
    width: 100%;
    justify-content: space-between;
  }

  .header-right {
    flex-wrap: wrap;
    gap: 8px;
  }

  .brand-name {
    font-size: 15px;
  }

  .brand-logo {
    height: 26px;
  }

  .room-id {
    font-size: 12px;
  }

  .CodeMirror {
    font-size: 13.5px;
  }

  .footer {
    flex-direction: column;
    gap: 6px;
    text-align: center;
  }

  .sidebar {
    width: 100%;
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    transform: translateX(100%);
    transition: transform 0.3s;
  }

  .sidebar.collapsed {
    transform: translateX(0);
  }

  .main-content {
    flex-direction: column;
  }
}
