:root {
  --bg-0: #1e1e1e;
  --bg-1: #252526;
  --bg-2: #2d2d30;
  --bg-3: #333336;
  --border: #3c3c3c;
  --text-0: #d4d4d4;
  --text-1: #a0a0a0;
  --text-muted: #6b6b6b;
  --accent: #007acc;
  --accent-hover: #1590dd;
  --success: #4caf50;
  --danger: #e5534b;
  --radius: 8px;
  --sidebar-w: 280px;
  --chat-w: 300px;
}

:root[data-theme="light"] {
  --bg-0: #ffffff;
  --bg-1: #f5f5f6;
  --bg-2: #ececee;
  --bg-3: #e2e2e5;
  --border: #d8d8dc;
  --text-0: #1e1e1e;
  --text-1: #4a4a4f;
  --text-muted: #767680;
  --accent: #007acc;
  --accent-hover: #0064a8;
  --success: #2e7d32;
  --danger: #c62828;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-0);
  color: var(--text-0);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: inherit; }

button, input, select {
  font-family: inherit;
  font-size: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius);
  padding: 10px 18px;
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-3); color: var(--text-0); border: 1px solid var(--border); }
.btn-secondary:hover { background: #3f3f42; }
.btn-lg { padding: 14px 30px; font-size: 17px; }
.btn-block { width: 100%; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-1);
  font-size: 16px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
}
.icon-btn:hover { background: var(--bg-3); color: var(--text-0); }

.badge {
  background: var(--bg-3);
  color: var(--text-1);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 12px;
  font-weight: 600;
}

/* ============================= LANDING ============================= */

#landing { max-width: 1100px; margin: 0 auto; padding: 0 24px 60px; }

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 0;
}
.nav-brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.logo-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); display: inline-block; }
.nav-actions { display: flex; align-items: center; gap: 10px; }
.theme-toggle { font-size: 18px; border: 1px solid var(--border); }

.hero { text-align: center; padding: 70px 0 40px; }
.hero h1 { font-size: 46px; line-height: 1.15; margin: 0 0 18px; }
.hero .accent { color: var(--accent); }
.subhead { font-size: 18px; color: var(--text-1); max-width: 640px; margin: 0 auto 32px; }
.hero-note { color: var(--text-muted); font-size: 13px; margin-top: 14px; }

.hero-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}
.join-room-form { display: flex; gap: 8px; }
.join-room-form input {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-0);
  padding: 0 14px;
  font-size: 15px;
  width: 160px;
}

.features {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin: 50px 0;
}
.feature-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 18px;
}
.feature-icon { font-size: 26px; margin-bottom: 10px; }
.feature-card h3 { margin: 0 0 8px; font-size: 16px; }
.feature-card p { margin: 0; color: var(--text-1); font-size: 13.5px; line-height: 1.5; }

.how-it-works { text-align: center; margin: 60px 0; }
.how-it-works h2 { font-size: 26px; margin-bottom: 30px; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.step-num {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px;
}
.step h4 { margin: 0 0 6px; }
.step p { color: var(--text-1); font-size: 13.5px; margin: 0; }

.ad-slot {
  background: var(--bg-1);
  border: 1px dashed var(--border);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  border-radius: 6px;
}
.ad-slot-landing { height: 90px; margin: 40px 0; }
.ad-slot-bottom { height: 50px; flex: 1; min-width: 0; }

.site-footer {
  display: flex; justify-content: space-between; align-items: center;
  border-top: 1px solid var(--border);
  padding-top: 20px; margin-top: 30px;
  color: var(--text-muted); font-size: 13px;
}
.site-footer a { text-decoration: none; color: var(--text-1); }
.footer-links { display: flex; gap: 18px; }
.footer-links a:hover { color: var(--text-0); }

/* ============================= POLICY PAGES ============================= */

.policy-page { max-width: 760px; margin: 0 auto; padding: 0 24px 60px; }
.policy-content h1 { font-size: 32px; margin-bottom: 4px; }
.policy-updated { color: var(--text-muted); font-size: 13px; margin-top: 0; margin-bottom: 32px; }
.policy-content h2 { font-size: 19px; margin: 32px 0 10px; }
.policy-content p { color: var(--text-1); line-height: 1.65; margin: 0 0 14px; }
.policy-content ul { color: var(--text-1); line-height: 1.65; padding-left: 20px; margin: 0 0 14px; }
.policy-content li { margin-bottom: 8px; }
.policy-content a { color: var(--accent); }
.policy-content code { background: var(--bg-1); border-radius: 4px; padding: 1px 6px; font-size: 13px; }
.policy-back { margin-top: 40px; }

/* ============================= COOKIE CONSENT ============================= */

.cookie-consent {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-1);
  border-top: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
  z-index: 90;
  box-shadow: 0 -4px 14px rgba(0,0,0,0.3);
}
.cookie-consent p { margin: 0; color: var(--text-1); font-size: 13.5px; max-width: 620px; }
.cookie-consent a { color: var(--accent); }

/* =============================== ROOM =============================== */

#room[hidden] { display: none; }
#room { height: 100%; display: flex; flex-direction: column; }

.room-shell {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sidebar-section h4 {
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.room-id-block { border-bottom: 1px solid var(--border); padding-bottom: 16px; }
.room-id-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.room-id-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; }
#room-id-text { background: var(--bg-3); padding: 2px 8px; border-radius: 4px; font-size: 12px; }
.expiry-row { margin-top: 10px; font-size: 12.5px; color: var(--text-1); }
.expiry-row strong { color: var(--text-0); }

.roster-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.roster-item { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

.dropzone {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 10px;
  text-align: center;
  margin-bottom: 10px;
}
.dropzone.drag-over { border-color: var(--accent); background: rgba(0,122,204,0.08); }
.dropzone-hint { font-size: 11px; color: var(--text-muted); margin-top: 6px; }

.file-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.file-item {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 8px;
  font-size: 12.5px;
}
.file-icon { flex-shrink: 0; }
.file-info { flex: 1; min-width: 0; }
.file-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.file-size { color: var(--text-muted); font-size: 11px; }
.file-actions { display: flex; gap: 2px; flex-shrink: 0; }
.file-actions .icon-btn { font-size: 13px; padding: 4px 6px; }

.editor-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-0);
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
}
.toolbar-spacer { flex: 1; }

.editor-host { flex: 1; min-height: 0; overflow: hidden; }
.editor-host .cm-editor { height: 100%; background: var(--bg-0); color: var(--text-0); }
.editor-host .cm-scroller { overflow: auto; }
.editor-host .cm-gutters { background: var(--bg-0); color: var(--text-muted); border-right: 1px solid var(--border); }
.editor-host .cm-activeLine { background: var(--bg-1); }
.editor-host .cm-activeLineGutter { background: var(--bg-1); }

.chat-pane {
  width: var(--chat-w);
  flex-shrink: 0;
  background: var(--bg-1);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.chat-pane.collapsed { display: none; }
.chat-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chat-messages { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { font-size: 13px; line-height: 1.4; }
.chat-msg .who { font-weight: 700; margin-right: 6px; }
.chat-msg .ts { color: var(--text-muted); font-size: 10.5px; margin-left: 6px; }
.chat-msg .body { color: var(--text-0); word-break: break-word; }
.chat-form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--border); }
.chat-form input {
  flex: 1;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-0);
  padding: 8px 10px;
}

.bottom-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-1);
  flex-shrink: 0;
}
.status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-1); white-space: nowrap; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); display: inline-block; }
.conn-dot.connected { background: var(--success); }
.sep { color: var(--text-muted); }

/* Overlays / modals */
.overlay[hidden] {
  display: none;
}
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.overlay-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  max-width: 420px;
  width: 90%;
  text-align: center;
}
.overlay-card h2 { margin-top: 0; }
#name-input {
  width: 100%;
  padding: 10px 12px;
  margin: 16px 0;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-0);
  text-align: center;
}

.modal-card { max-width: 900px; width: 92%; text-align: left; display: flex; flex-direction: column; max-height: 86vh; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-body { flex: 1; overflow: auto; min-height: 200px; }
.modal-footer { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-top: 14px; }
.modal-status { color: var(--text-muted); font-size: 12px; margin-right: auto; }

.modal-body .cm-editor { height: 50vh; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-0); color: var(--text-0); }
.modal-body .cm-gutters { background: var(--bg-0); color: var(--text-muted); border-right: 1px solid var(--border); }

/* Editable table grid for CSV / XLSX */
.grid-toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.grid-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 6px; max-height: 55vh; }
table.grid-table { border-collapse: collapse; width: 100%; }
table.grid-table td, table.grid-table th {
  border: 1px solid var(--border);
  padding: 0;
}
table.grid-table th {
  background: var(--bg-2);
  color: var(--text-muted);
  font-size: 11px;
  padding: 4px 6px;
}
table.grid-table td input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-0);
  padding: 6px 8px;
  font-size: 13px;
}
table.grid-table td input:focus { background: rgba(0,122,204,0.12); outline: none; }
.row-del-btn { cursor: pointer; color: var(--text-muted); }
.row-del-btn:hover { color: var(--danger); }

.toast {
  position: fixed;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-0);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 100;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}

.mobile-only { display: none; }

/* Yjs remote cursor styling (y-codemirror.next default classes) */
.cm-ySelectionInfo { font-size: 11px !important; padding: 2px 5px !important; border-radius: 4px !important; }

/* =============================== RESPONSIVE =============================== */

@media (max-width: 900px) {
  .features { grid-template-columns: repeat(2, 1fr); }
  .steps { grid-template-columns: 1fr; }
  .hero h1 { font-size: 32px; }

  .mobile-only { display: inline-flex; }

  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 4px 0 16px rgba(0,0,0,0.4);
  }
  .sidebar.open { transform: translateX(0); }

  .chat-pane {
    position: fixed;
    top: 0; bottom: 0; right: 0;
    z-index: 40;
    width: 85vw;
    max-width: 340px;
    transform: translateX(100%);
    transition: transform 0.2s ease;
    box-shadow: -4px 0 16px rgba(0,0,0,0.4);
  }
  .chat-pane.open { transform: translateX(0); }

  .ad-slot-bottom { display: none; }
}

@media (max-width: 560px) {
  .hero h1 { font-size: 28px; }
  .subhead { font-size: 15px; }
  .features { grid-template-columns: 1fr; }
}
