:root {
  --bg: #FFFAF6;
  --panel: #FFFFFF;
  --border: #F0EAE2;
  --text: #1A1A1A;
  --muted: #999;
  --primary: #E8651A;
  --primary-light: #FFF0E6;
  --primary-dark: #C4520E;
  --danger: #ef4444;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}
.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.05);
}
.wl-content {
  padding: 24px;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.header-left {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.page-title {
  font-size: 24px;
  font-weight: 700;
}
.breadcrumb {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}
.breadcrumb a {
  color: var(--primary);
  text-decoration: none;
}
.breadcrumb a:hover {
  text-decoration: underline;
}
.breadcrumb-separator {
  margin: 0 6px;
  color: var(--border);
}
.header-actions {
  display: flex;
  gap: 8px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 14px rgba(232, 101, 26, 0.25);
}
.btn:hover {
  background: var(--primary-dark);
  box-shadow: 0 6px 18px rgba(232, 101, 26, 0.35);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-secondary {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}
.btn-secondary:hover {
  background: var(--bg);
  box-shadow: none;
}
.btn-danger {
  background: var(--danger);
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.25);
}
.btn-danger:hover {
  background: #dc2626;
}
.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
  border-radius: 6px;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}
.icon-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}
.icon-btn-danger:hover {
  background: #fef2f2;
  color: var(--danger);
  border-color: var(--danger);
}

/* Tabs */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}
.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: all 0.15s;
}
.tab-btn:hover {
  color: var(--text);
}
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab-count {
  font-size: 11px;
  font-weight: 700;
  background: var(--border);
  color: var(--muted);
  padding: 1px 7px;
  border-radius: 10px;
}
.tab-btn.active .tab-count {
  background: var(--primary-light);
  color: var(--primary);
}

/* Invitations section */
.invitations-section {
  background: #FFF7ED;
  border: 1px solid #FED7AA;
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 24px;
}
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: #9A3412;
}
.inv-count {
  font-size: 11px;
  font-weight: 700;
  background: #EA580C;
  color: #fff;
  padding: 1px 7px;
  border-radius: 10px;
}
.inv-empty {
  font-size: 13px;
  color: var(--muted);
  padding: 8px 0;
}
.inv-error {
  color: var(--danger);
}
.inv-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.inv-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border: 1px solid #FED7AA;
  border-radius: 8px;
  padding: 10px 14px;
  gap: 12px;
}
.inv-info {
  flex: 1;
  min-width: 0;
}
.inv-world-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.inv-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.inv-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* Role badges */
.role-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: capitalize;
}
.role-owner { background: #F3E8FF; color: #7C3AED; }
.role-viewer { background: #DBEAFE; color: #1D4ED8; }
.role-editor { background: #FEF3C7; color: #92400E; }
.role-creator { background: #D1FAE5; color: #065F46; }

/* World grid */
.world-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.world-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.world-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 16px rgba(232, 101, 26, 0.1);
  transform: translateY(-1px);
}
.world-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.world-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
}
.world-card-body {
  flex: 1;
}
.world-card-name {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.world-card-desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.world-card-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}
.world-card-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* Loading / Empty */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--muted);
}
.loading-spinner {
  width: 32px;
  height: 32px;
  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); } }
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 15px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal {
  background: var(--panel);
  border-radius: 14px;
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}
.modal-wide {
  max-width: 560px;
}
.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
}
.modal-subtitle {
  font-weight: 400;
  color: var(--muted);
  font-size: 14px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}
.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  padding: 9px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus {
  border-color: var(--primary);
}
.form-textarea {
  min-height: 80px;
  resize: vertical;
}

/* Collaborator modal styles */
.collab-invite-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
}
.collab-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.collab-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 8px;
}
.collab-email {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.collab-status {
  font-size: 11px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 3px;
}
.collab-status-pending { background: #FEF3C7; color: #92400E; }
.collab-status-accepted { background: #D1FAE5; color: #065F46; }
.collab-status-declined { background: #FEE2E2; color: #991B1B; }
.collab-role-select {
  width: auto;
  font-size: 12px;
  padding: 4px 8px;
}
.collab-empty {
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  background: #333;
  opacity: 0;
  transition: all 0.3s;
  z-index: 2000;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { background: #059669; }
.toast.error { background: var(--danger); }

/* Responsive */
@media (max-width: 640px) {
  .container { padding: 16px; }
  .header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .world-grid { grid-template-columns: 1fr; }
  .inv-card { flex-direction: column; align-items: flex-start; }
  .inv-actions { width: 100%; }
  .collab-invite-row { flex-wrap: wrap; }
  .collab-invite-row .form-input:first-child { min-width: 0; }
}
