html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #f4f5f4;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: #18181b;
  -webkit-font-smoothing: antialiased;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

#status {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font: 500 14px/1.4 inherit;
  color: #6b716e;
  pointer-events: none;
  z-index: 10;
}

#status:empty {
  display: none;
}

/* Auth Gate */
#auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(244, 245, 244, 0.94);
  backdrop-filter: blur(8px);
}

#auth-overlay.visible {
  display: flex;
}

#auth-overlay.reauth {
  background: rgba(24, 24, 27, 0.36);
}

.auth-card {
  width: 360px;
  max-width: calc(100vw - 32px);
  background: #ffffff;
  border-radius: 12px;
  padding: 28px 26px 24px;
  box-shadow: 0 0 0 0.5px rgba(24, 24, 27, 0.12), 0 12px 36px rgba(0, 0, 0, 0.08);
}

.auth-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.auth-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.auth-subtitle {
  font-size: 13px;
  color: #71717a;
  margin: 0 0 20px;
  line-height: 1.5;
}

.auth-field {
  margin-bottom: 14px;
}

.auth-field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: #52525b;
  margin-bottom: 6px;
}

.auth-field input {
  width: 100%;
  box-sizing: border-box;
  height: 36px;
  padding: 0 11px;
  border-radius: 8px;
  border: 1px solid #e4e4e7;
  background: #ffffff;
  font-size: 14px;
  color: #18181b;
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.auth-field input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.auth-error {
  min-height: 18px;
  font-size: 12px;
  color: #dc2626;
  margin: 2px 0 12px;
  line-height: 1.4;
}

.auth-submit {
  width: 100%;
  height: 38px;
  border: none;
  border-radius: 8px;
  background: #18181b;
  color: #ffffff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.auth-submit:hover {
  background: #27272a;
}

.auth-submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.auth-footer {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: #71717a;
}

.mode-switch {
  display: inline-flex;
  background: #f4f4f5;
  border-radius: 7px;
  padding: 2px;
  gap: 2px;
}

.mode-switch button {
  border: none;
  background: transparent;
  padding: 3px 8px;
  border-radius: 5px;
  font-size: 11px;
  color: #71717a;
  cursor: pointer;
}

.mode-switch button.active {
  background: #ffffff;
  color: #18181b;
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* Floating Cloud Status HUD (bottom-right, clear of top bar, search box and sidebar) */
#cloud-hud {
  position: fixed;
  bottom: 14px;
  right: 16px;
  z-index: 30;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  box-shadow: 0 0 0 0.5px rgba(24, 24, 27, 0.12), 0 4px 16px rgba(0, 0, 0, 0.08);
  font-size: 12px;
  color: #3f3f46;
  user-select: none;
  max-width: calc(100vw - 32px);
}

#cloud-hud.visible {
  display: inline-flex;
}

.sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
  background: #a1a1aa;
}

.sync-dot.saved { background: #16a34a; }
.sync-dot.saving { background: #2563eb; animation: pulse 1.1s ease-in-out infinite; }
.sync-dot.unsynced { background: #d97706; }
.sync-dot.conflict { background: #dc2626; }

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

.hud-text {
  font-weight: 500;
  white-space: nowrap;
}

.hud-sep {
  width: 1px;
  height: 12px;
  background: #e4e4e7;
}

.hud-user {
  color: #71717a;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-btn {
  border: none;
  background: transparent;
  color: #52525b;
  font-size: 12px;
  padding: 2px 7px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}

.hud-btn:hover {
  background: #f4f4f5;
  color: #18181b;
}

.hud-btn.primary {
  background: #18181b;
  color: #ffffff;
}

.hud-btn.primary:hover {
  background: #27272a;
}

.hud-btn.warn {
  background: #fef3c7;
  color: #92400e;
}

.hud-btn.danger {
  background: #fee2e2;
  color: #991b1b;
}

/* Conflict / Recovery Banner */
#cloud-banner {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 32;
  display: none;
  flex-direction: column;
  gap: 8px;
  width: min(560px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 0 0 0.5px rgba(220, 38, 38, 0.25), 0 12px 32px rgba(0, 0, 0, 0.1);
  font-size: 13px;
}

#cloud-banner.visible {
  display: flex;
}

.banner-title {
  font-weight: 600;
  color: #991b1b;
}

.banner-desc {
  color: #52525b;
  line-height: 1.5;
}

.banner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Recovery Snapshots Drawer */
#recovery-modal {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(24, 24, 27, 0.35);
}

#recovery-modal.visible {
  display: flex;
}

.recovery-card {
  width: min(520px, calc(100vw - 32px));
  max-height: 75vh;
  overflow: auto;
  background: #ffffff;
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: 0 0 0 0.5px rgba(24, 24, 27, 0.12), 0 16px 40px rgba(0, 0, 0, 0.14);
}

.recovery-item {
  border: 1px solid #e4e4e7;
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 10px;
  font-size: 12px;
}

.recovery-item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

/* Mock-only floating debug toolbar (hidden in real backend mode) */
#mock-bar {
  position: fixed;
  bottom: 52px;
  right: 16px;
  z-index: 35;
  display: none;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 9px;
  background: rgba(24, 24, 27, 0.9);
  color: #f4f4f5;
  font-size: 11px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}

#mock-bar.visible {
  display: inline-flex;
}

#mock-bar button {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #f4f4f5;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 5px;
  cursor: pointer;
}

#mock-bar button.active {
  background: #f59e0b;
  color: #18181b;
  border-color: #f59e0b;
  font-weight: 600;
}
